Hooks not running in Cucumber 4 - java

#Before and #After methods of hooks are not running while running the Runner class.
I am using the dependencies:
cucumber-java 4.3.0
cucumber-jvm 4.3.0
All steps in stepdef file are running fine except hooks. Is it some issue with latest cucumber version?
public class Hooks {
#Before
public void beforeHooks() {
System.out.println("Run Before Scenario");
}
#After
public void afterHooks() {
System.out.println("Run After Scenario");
}

First Make sure you are using cucumber.api.java.Before (interface) rather than org.junit.Before as Cucumber will not process JUnit annotations.
#Before - import cucumber.api.java.Before;
#After - import cucumber.api.java.After;
Hope we are on the same page here and let's move further without making any delay.
Second lets understand in case your STEPS IMPLEMENTATION METHODS and HOOK CLASS is in the same package then we do not need to specify path of Hooks class additionally in the glue option of runner. In my case, i do have both in same package so we need to set only one package.
But if they are in the different packages then please include the package of the Hooks class in the glue option of the runner file.
Cucumber Runner :
package com.jacksparrow.automation.suite.runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features = "classpath:features/functional/",
glue = {"com.jacksparrow.automation.steps_definitions.functional" },
plugin = { "pretty","json:target/cucumber-json/cucumber.json",
"junit:target/cucumber-reports/Cucumber.xml", "html:target/cucumber-reports"},
tags = { "#BAMS_Submitted_State_Guest_User" },
strict = false,
dryRun = false,
monochrome = true)
public class RunCukeTest {
}
Key Point: We shall not mix direct & transitive dependencies specially their versions! Doing so can cause unpredictable outcome. You can add below set of cucumber minimal dependencies.
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>

Related

class junit.framework.TestSuite cannot be cast to class org.junit.jupiter.api.Test

I am new to JAVA and Junit and trying to do something simple. I have the test passed but I see in the terminal initailizationError side this error "class junit.framework.TestSuite cannot be cast to class org.junit.jupiter.api.Test" This is the version of my Junit dependencies.
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
This is the test that I am trying to run
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
#Test
public void firstTest() {
Assertions.assertEquals(2, 2);
}
/**
* Create the test case
*
* #param testName name of the test case
*/
/**
* #return the suite of tests being tested
*/
public static Test suite()
{
return (Test) new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
I could not understand the error as it is my first time useing it
I think the simplest fix is for you to delete your suite method. You don't need it, and your tests will run quite happily without it. Once you are a bit more confident and familiar with Java and JUnit, then maybe suites will help you organise and group tests, but you can certainly start without them.
The way you are attempting to create a test suite seems to follow the approach of JUnit 3, but you are using JUnit 5. JUnit changed a lot from JUnit 3 and JUnit 4, and also from JUnit 4 to JUnit 5, so it's not surprising that something from JUnit 3 doesn't work with JUnit 5.
I hadn't seen this way of writing test suites before, but I did find that this page talks about JUnit 5 and then presents examples using JUnit 3. To be quite frank I found the content of that page to be of poor quality and cannot recommend it. If you are using that page to learn about JUnit then I would advise you to look elsewhere.
the issue comes from these lines :
public static Test suite()
{
return (Test) new TestSuite( AppTest.class );
}
you are trying to cast 2 different Classes :
class junit.framework.TestSuite
to
class org.junit.jupiter.api.Test
which are 2 different classes , you can simply remove this function and the error will be fixed.
or if you want to have a TestSuite to bundle a few unit test cases and run them together,it can be in a separate class.
like what described in this article
hope this helps !!!

How to initialize environment variable in a Spring-Java integration test using Cucumber?

I added the following environment variable to my project's properties file (src/test/resources/application.properties):
#variables
limit=5
And I want to develop an integration test but it always goes wrong because the value of my limit variable is 0 instead of 5 (which was the value I set in properties). I tried using #SpringBootTest and #TestPropertySource but I was unsuccessful, the variable remains as zero:
#RunWith(Cucumber.class)
#SpringBootTest(properties = {"limit=5"})
#CucumberOptions(features = { "classpath:project/feature/list" }, plugin = {"pretty" }, monochrome = true)
public class RunCucumberTestIT {
}
#RunWith(Cucumber.class)
#TestPropertySource(properties = {"limit=5"})
#CucumberOptions(features = { "classpath:project/feature/list" }, plugin = {"pretty" }, monochrome = true)
public class RunCucumberTestIT {
}
You are trying to make Cucumber aware of your Spring application context configuration by annotating the JUnit runner class. However Cucumber integrates with multiple testing frameworks and has it's own CLI. As a result annotating the JUnit runner class will not always work (e.g. when the CLI).
So to do this you can annotate a configuration class on your glue path with #CucumberContextConfiguration and with #SpringBootTest.
With the latest version of Cucumber (v6.9.0) this should work:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
package com.example.app;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(features = { "classpath:project/feature/list" }, plugin = {"pretty" }, monochrome = true)
public class RunCucumberTestIT {
}
package com.example.app;
import org.springframework.boot.test.context.SpringBootTest;
import io.cucumber.spring.CucumberContextConfiguration;
#CucumberContextConfiguration
#SpringBootTest(properties = {"limit=5"})
public class CucumberSpringConfiguration {
}
Note: the package of the configuration class should be on the glue path. When not defined it defaults to the package of the runner class.
Thanks for everyone who tried to help. I will share how I managed to solve it, I didn't actually need to use #TestPropertySource or #SpringBootTest, I just changed the way my variable was declared within the service that my integrated test calls.
Before:
#Value("${limit}")
private static int dateFilterLimit;
After:
#Value("${limit:5}")
private int dateFilterLimit;
Thus, if the test fails to see what is declared in the properties, the value 5 is set within the variable. For the rest of the code, the variable in properties remains:
#variables
limit=5
And the configuration class looks like this:
#RunWith(Cucumber.class)
#CucumberOptions(features = { "classpath:project/feature/list" }, plugin = {"pretty" }, monochrome = true)
public class RunCucumberTestIT {
}

JUnit change class or method behaviour in integration tests

I have a java application (no Spring inside) that I want to test with an integration test.
My main use case is the main function that with a specified input do some things on the database and send some request to two different services, one SOAP and one REST.
Now I have a working JUnit configuration (splitted in unit and integration tests) + io.fabric8:docker-maven-plugin that use a docker image for the database during integration tests.
What I'm trying to do is to add a mock for these 2 services, in particular, the method that is used to call directly the external service.
The big problem is that I have this structure:
class A{
Result mainFunction(Request r){
....
B b = new B(params);
b.logEvent(someParameters)
....
}
}
class B{
int logEvent(Object someParameters){
....
NotifierHandler nh = new NotifierHandler(param1);
nh.sendNotification(json);
....
}
}
where I have:
class NotifierHandler{
String sendNotification(Json j){
...
[call to REST service with some parameters]
...
...
[call to SOAP service with some parameters]
...
}
}
What I need: call A.mainFunction(r) having, in the test environment, replaced the NotifierHandler with a FakeNotifierHandler and/or change the behaviour of the method sendNotification().
Actual problems: Using Mockito and PowerMock now I have the problem that I'm not able to change globally and directly the class NotifierHandler with FakeNotifierHandler. The same trying to changing the behaviour of the method.
In particular, what I need is to create a
class FakeNotifierHandler{
String sendNotification(Json j){
...
[save on an HashMap what I should send to the REST service]
...
...
[save on another HashMap what I should send to the SOAP service]
...
}
}
Reading all example that I tryed I saw only simple examples that change the return value of a method and not the behaviour of one method of one class used by another and another that I'm using as the start point of the integration test.
NOTE: probably there is a fast way to do this but I'm very new on this type of tests (Mockito, PowerMock,...) and I have found no example for this particular strange case.
EDIT: not similar to How to mock constructor with PowerMockito because I need to change the behaviour of the method, not only the return value.
Thanks a lot in advance
I found a solution that works very well and it is very simple!
The solution is PowerMock (https://github.com/powermock/powermock) and in particular replace the creation of an instance of a class with another: https://github.com/powermock/powermock/wiki/mockito#how-to-mock-construction-of-new-objects
There is only one problem in my project and it is JUnit 5. PowerMock support JUnit 4 and for this reason, only for some tests of the solution are using it.
In order to do this there is the needed to replace
import org.junit.jupiter.api.Test;
with
import org.junit.Test;
In order to use teh "whenNew()" methods I had extented the class that in tests must be replaced and I have overwritten only methods that are necessary for the integration test.
The big benefit of this solution is that my code is untouched and I can use this approach also on old code without the risk of introducing regressions during the refactor of the code.
Regarding the code of a integration test, here an example:
import org.junit.jupiter.api.DisplayName;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PowerMockIgnore({"javax.crypto.*" }) // https://github.com/powermock/powermock/issues/294
#PrepareForTest(LegacyCoreNetworkClassPlg.class) // it is the class that contains the "new SOAPCallHelper(..)" code that I want to intercept and replace with a stub
public class ITestExample extends InitTestSuite {
#Test
#DisplayName("Test the update of a document status")
public void iTestStubLegacyNetworkCall() throws Exception {
// I'm using JUnit 4
// I need to call #BeforeAll defined in InitTestSuite.init();
// that works only with JUnit 5
init();
LOG.debug("IN stubbing...");
SOAPCallHelperStub stub = new SOAPCallHelperStub("empty");
PowerMockito.whenNew(SOAPCallHelper.class).withAnyArguments().thenReturn(stub);
LOG.debug("OUT stubbing!!!");
LOG.debug("IN iTestStubLegacyNetworkCall");
...
// Here I can create any instance of every class, but when an instance of
// LegacyCoreNetworkClassPlg.class is created directly or indirectly, PowerMock
// is checking it and when LegacyCoreNetworkClassPlg.class will create a new
// instance of SOAPCallHelper it will change it with the
// SOAPCallHelperStub instance.
...
LOG.debug("OUT iTestStubLegacyNetworkCall");
}
}
Here the configuration of the pom.xml
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.jupiter.version>5.5.2</junit.jupiter.version>
<junit.vintage.version>5.5.2</junit.vintage.version>
<junit.platform.version>1.3.2</junit.platform.version>
<junit.platform.engine.version>1.5.2</junit.platform.engine.version>
<powermock.version>2.0.2</powermock.version>
<!-- FOR TEST -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Only required to run tests in an IDE that bundles an older version -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<!-- Only required to run tests in an IDE that bundles an older version -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- Only required to run tests in an IDE that bundles an older version -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>${junit.platform.engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
I think the main headache in your case is that you have tightly coupled dependencies between class A, B and NotifierHandler. I would start with:
class A {
private B b;
public A(B b) {
this.b = b;
}
Result mainFunction(Request r){
....
b.logEvent(someParameters)
....
}
}
class B {
private NotifierHandler nh;
public B(NotifierHandler nh) {
this.nh = nh;
}
int logEvent(Object someParameters){
....
nh.sendNotification(json);
....
}
}
Make NotifierHanlder an interface:
interface NotifierHandler {
String sendNotification(String json);
}
and make two implementations: one for a real use case, and one fake that you can stub whatever you want:
class FakeNotifierHandler implements NotifierHandler {
#Override
public String sendNotification(String json) {
// whatever is needed for you
}
}
Inject FakeNotifierHandler in your test.
I hope this helps you.

Cucumber on IntelliJ: getting errors as soon as I set up new project

I've been stuck for hours and I'm a bit confused, as I've tried to follow quite a few tutorials to set up Cucumber (Java version) + Selenium using IntelliJ as an IDE but I always end up getting errors from the very beginning, so I'm guessing there either is something the tutorials don't mention or some misconfiguration on my IDE.
This is something of what I've tried:
First, created a Maven project in IntelliJ IDEA and added dependencies for cucumber, junit and selenium to my pom.xml:
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
Then I created some structure for my project:
a folder named "resources" within src/test.
a folder named "features" within src/test/resources.
a package named "step_definitions" within src/test/java.
a file called MyTest.feature in the src/test/resources/features folder
In my MyTest.feature I added a simple test like this:
Feature: Check addition in Google calculator
Scenario: Addition
Given I open google
When I enter "2+2" in search textbox
Then I should get the result as "4"
Then from my feature file I auto-generated step definitions by using the IDE functionality (alt+enter > create step definitions), and I got a new file: MyStepDefs.java which I placed in src/test/java/step_definitions (leaving it in just src/test/java makes no difference), with the following contents:
package step_definitions;
import cucumber.api.PendingException;
public class MyStepdefs {
public MyStepdefs() {
Given("^I open google$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});}
}
The thing is, this is already showing errors. The "Given" keyword is not recognized: Cannot resolve method 'Given(java.lang.String)'
And on "new PendingException()" I get: Incompatible types. Required: java.lang.Throwable. Found: cucumber.api.PendingException
This sounds fishy, as it's auto-generated code so I assume it should be error-free (but it's not).
So I tried replacing this auto-generated code with something I got from this tutorial but then I get a "not applicable to method" error on #Before, #After, #Given, #When, #Then keywords.
package step_definitions;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class googleCalcStepDefinition {
protected WebDriver driver;
#Before
public void setup() {
driver = new FirefoxDriver();
}
#Given("^I open google$")
public void I_open_google() {
//Set implicit wait of 10 seconds and launch google
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://www.google.co.in");
}
#When("^I enter \"([^\"]*)\" in search textbox$")
public void I_enter_in_search_textbox(String additionTerms) {
//Write term in google textbox
WebElement googleTextBox = driver.findElement(By.id("gbqfq"));
googleTextBox.sendKeys(additionTerms);
//Click on searchButton
WebElement searchButton = driver.findElement(By.id("gbqfb"));
searchButton.click();
}
#Then("^I should get result as \"([^\"]*)\"$")
public void I_should_get_correct_result(String expectedResult) {
//Get result from calculator
WebElement calculatorTextBox = driver.findElement(By.id("cwos"));
String result = calculatorTextBox.getText();
//Verify that result of 2+2 is 4
Assert.assertEquals(result, expectedResult);
driver.close();
}
#After
public void closeBrowser() {
driver.quit();
}
}
What am I missing? Is there any way I can set up a fresh new project that uses Cucumber (Java) + Selenium on the IntelliJ IDE? Or is it just not possible at all?
Thanks!
Apparently, the Java JDK 9 that I had recently downloaded was the culprit. I went back to square 1 and started the project with JDK 8 and everything works as expected now.

Failed to process business interfaces for EJB class

While starting maven with test parameters, I get the above mentioned exception. While creating the integration test deployment, I get the following:
org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0466: Failed to process business interfaces for EJB class class ..contract.ContractMockService
The concerning class looks like this:
package ..integration.bestand.contract;
import java.time.LocalDate;
import java.util.ArrayList;
import javax.ejb.Local;
import javax.ejb.Stateless;
import org.apache.deltaspike.core.api.exclude.Exclude;
import org.apache.deltaspike.core.api.projectstage.ProjectStage;
...
#Exclude(ifProjectStage = {
ProjectStage.Production.class,
ProjectStage.Staging.class,
..Integration.class,
..Qs.class,
..PatchQs.class
})
#Stateless
#Local(IContractIntService.class)
public class ContractMockService implements IContractIntService {
...
return ContractBuilder.build();
}
}
The interface IContractIntService looks like:
package ..integration.bestand.contract;
import javax.ejb.Local;
...
#Local
public interface IContractIntService {
public enum State {
SUCCESS,
UNKNOWN_ERROR,
NOT_FOUND;
// TODO: Stati für Fehler hier definieren
}
//Interface comment
Result<State, ContractDTO> retrieveContract(String contractIdentifier);
}
Note: The interface is in another project which is included via maven.
The Test looks like this:
package ..api.contractregistration.service;
import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.logging.Logger;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestWatcher;
import org.junit.runner.RunWith;
import ..core.test.IntegrationTest;
#RunWith(Arquillian.class)
#Category(IntegrationTest.class)
public class ContractRegistrationIntegrationTest {
protected final Logger log = Logger.getLogger(ContractRegistrationIntegrationTest.class.getCanonicalName());
#Rule
public TestWatcher watcher = new TestWatcher() {
#Override
protected void starting(org.junit.runner.Description description) {
log.info(String.format("---> Starting test: %s", description));
}
#Override
protected void failed(Throwable e, org.junit.runner.Description description) {
log.info(String.format("<--- Test failed: %s", description));
}
#Override
protected void succeeded(org.junit.runner.Description description) {
log.info(String.format("<--- Test succeeded: %s", description));
}
};
#Deployment
public static WebArchive createDeployment() {
WebArchive result = ShrinkWrap.create(WebArchive.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml")
.addPackages(true, "..ejb.portal")
.addPackages(true, "..core")
.deletePackages(true, "..core.config.deltaspike")
.addPackages(true, "..integration")
.addPackages(true, "..api")
.addPackages(true, "org.apache.deltaspike.core")
.addPackages(true, "..ejb.util");
System.out.println("########## TEST DEPLOYMENT########" + result.toString(true));
return result;
}
#Test
public void test() {
String tempPw = "bla"; // result.getDto();
assertThat(tempPw, any(String.class));
}
}
The remarkable thing about this test is, that I'm not even using anything of the MockService inside a test.
The maven configuration looks like this:
Goals: clean test -Parq-wildfly-managed
JRE VM Arguments: -Djboss.home="myLocalWildflyDirectory"
JAVA_HOME is set to jdk8.
Last thing is my pom, specifically the part of the container "arq-wildfly-managed":
...
<profile>
<!-- An optional Arquillian testing profile that executes tests in your WildFly instance, e.g. for build server -->
<!-- This profile will start a new WildFly instance, and execute the test, shutting it down when done -->
<!-- Run with: mvn clean test -Parq-wildfly-managed -->
<id>arq-wildfly-managed</id>
<dependencies>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ivi.torino</groupId>
<artifactId>torino-integration-bestand-mock-ejb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ivi.torino</groupId>
<artifactId>torino-integration-docservice-mock-ejb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ivi.torino</groupId>
<artifactId>torino-integration-bestand-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
...
A normal maven build with clean verify package install (just no test included) builds successfully.
Note: For this post, I renamed the packages to exclude company specializations.
Similar errors suggest correcting the ShrinkWrap deployment, but I included virtually every package there is and even tried to explicitly include the interface-class. But still, the same error remains.
What could cause this?
Try this in the Test (ShrinkWrap):
.addAsResource(new StringAsset("org.apache.deltaspike.ProjectStage=IntegrationTest"), "META-INF/apache-deltaspike.properties")
And change your Exclude to this:
#Exclude(exceptIfProjectStage = ProjectStage.IntegrationTest.class)
If you need to exclude additional Stages, add them to this very exclude statement
A bit late, but a better solution to the problem was the following:
Inside the ShrinkWrap deployment, a use of the shrinkwrap maven resolver is needed. So, instead of
.addPackages(true, "org.apache.deltaspike.core")
inside the creation of result, use the maven resolver. Should look something like this:
ShrinkWrap
.create(WebArchive.class, "test.war")
.addAsLibraries(
resolver.artifact("org.apache.deltaspike.core")
.resolveAsFiles());
The artifact is the maven artifactId. this will return another .war. multiple .wars (created from the resolver or the way you see in the original question) can be merged. This merged .war then has to be returned from the deployment method.
Reason behind this:
External includes (in this case deltaspike) are missing resources once you import them via ShrinkWrap.create.*.addAsPackages.., so this should only be used for internal project packages. To use the maven resolver, you can include the following in the .pom-file:
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<scope>test</scope>
</dependency>
credits to dzone.com for the maven resolver code snippets. I'm currently working on another project, so I can't show the original code, but it was very similar to this.
Maybe this solution will help someone in the future.

Categories