4

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?

EngJon
  • 987
  • 8
  • 20
  • You seemed to misunderstand the maven life cycle. If you call maven via `mvn clean verify package install` than several things are running double or triple. What you simple need is: `mvn clean install` or `mvn clean verify`..Recommend to read https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html – khmarbaise May 01 '16 at 11:35
  • @khmarbaise thanks for your suggestion. I can clearly say that I am not an expert with maven. I formerly used your mentioned run configs and they worked, but my question was not aiming for the working builds. The `test` build is producing the above mentioned error and is leaving me clueless... – EngJon May 01 '16 at 17:52
  • Maybe your IContractService cannot be loaded because of missing dependencies. You may want to check in your log under the category org.jboss.weld.Bootstrap at level INFO to make sure all your beans definition are correctly registered. – Franck May 02 '16 at 13:28
  • maybe I'm looking in the wrong place, but my server startup log without test as well as with tests don't give me any org.jboss.weld.Bootstrap infos. What dependencies could those missing ones be? – EngJon May 02 '16 at 15:47
  • It seems like the ProjectStages are troublesome. The integration test environment seems to set the project stage to one of the excluded phases (in the ContractMockService). So, if I delete the Exclude-section, the test passes. Anyone here with a detailed insight on that?+ – EngJon May 03 '16 at 09:54
  • You can figure out the current project stage in looking at your log file (org.apache.deltaspike.core.util.ProjectStageProducer). By default, the project stage is Development so your test should work. However, there must be a variable that is set [somewhere (system,environment,files)](https://deltaspike.apache.org/documentation/configuration.html#ProvidingconfigurationusingConfigSources) that overrides this. – Franck May 03 '16 at 12:46

2 Answers2

0

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

Tim
  • 3,910
  • 8
  • 45
  • 80
  • 1
    That did the trick! I included the exclude for my producer as well, that solved other problems, too. – EngJon May 10 '16 at 04:41
  • As I don't want my bounty to expire, this answer seems suitable, although it could have more details on why this exclude didn't work, but hey, it worked ;) – EngJon May 10 '16 at 04:47
0

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.

EngJon
  • 987
  • 8
  • 20