13

I want to have different container configurations in my arquillian.xml and select them in my test. But I am unable to load any container but the default one.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://jboss.org/schema/arquillian"
    xsi:schemaLocation="http://jboss.org/schema/arquillian http://www.jboss.org/schema/arquillian/arquillian_1_0.xsd">

    <container qualifier="weld" default="false">
    </container>
</arquillian>

Test case:

@Deployment(name="depl1")
@TargetsContainer("weld")
public static JavaArchive createTestArchive() throws UnsupportedEncodingException {
    return ShrinkWrap
            .create(JavaArchive.class, "test.jar")
            .addClasses(SomeOtherCdiService.class)
            .addAsManifestResource(new ByteArrayAsset(beansXmlContent.getBytes("utf-8")), ArchivePaths.create("beans.xml"));
}

@Test
@OperateOnDeployment("depl1")
public void shouldBeAbleToInjectInject() {
    assertNotNull(someOtherCdiService);
}

But the tests does not start because Arquilian does not find the container

org.jboss.arquillian.container.test.impl.client.deployment.ValidationException: DeploymentScenario contains targets not matching any defined Container in the registry. weld. Possible causes are: No Deployable Container found on Classpath or your have defined a @org.jboss.arquillian.container.test.api.Deployment with a @org.jboss.arquillian.container.test.api.TargetsContainer value that does not match any found/configured Containers (see arquillian.xml container@qualifier)

I have had a look into the source and found that Aquilian in only finding the _DEFAULT_ Container.

The tests work, when I remove @TargetsContainer("weld") from the deployer method. So I think the general test is ok.

The tests also work if I modify the container configuration to default="true" (<container qualifier="weld" default="ture">) then the tests work, so I think the configuration file is loaded.

Does anybody has an Idea what is going wrong?


Details

Complete Stacktrace:

org.jboss.arquillian.container.test.impl.client.deployment.ValidationException:
DeploymentScenario contains targets not matching any defined Container in the registry. weld.
Possible causes are: No Deployable Container found on Classpath or your have defined a
@org.jboss.arquillian.container.test.api.Deployment with a
@org.jboss.arquillian.container.test.api.TargetsContainer value that does not match any found/configured Containers
(see arquillian.xml container@qualifier) 
at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.validate(DeploymentGenerator.java:102)
at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:80)
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:179)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:311)
at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:196)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:144)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

POM.XML Dependencies

    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.0-SP4</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>jsr250-api</artifactId>
        <scope>provided</scope>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <scope>provided</scope>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.0.0.GA</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-api</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
    </dependency>


    <!-- ejb -->

    <dependency>
        <groupId>javax.ejb</groupId>
        <artifactId>ejb-api</artifactId>
        <version>3.0</version>
        <scope>provided</scope>
    </dependency>



    <!-- Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>${hamcrest.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <version>${hamcrest.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <version>1.0.0.CR6</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-weld-se-embedded-1.1</artifactId>
        <version>1.0.0.CR3</version>
        <!-- works with arquillian core 1.0.0.CR6 -->
        <scope>test</scope>
    </dependency>

    <!-- do not use org.jboss.weld.se:weld-se because is contains the CODE
        of slf4j in an not compatible version so we need the parts of weld-se seperate:
        weld-se-core, weld-core, org.javassist, slf4j-jdk14 https://issues.jboss.org/browse/WELD-903 -->

    <dependency>
        <groupId>org.jboss.weld.se</groupId>
        <artifactId>weld-se-core</artifactId>
        <version>1.1.5.Final</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.weld</groupId>
        <artifactId>weld-core</artifactId>
        <version>1.1.5.Final</version>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-api</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.14.0-GA</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.6.1</version>
        <scope>test</scope>
    </dependency>
Ralph
  • 118,862
  • 56
  • 287
  • 383
  • Are you looking to run multiple containers at once? If so, this page from the manual says multiple `container` elements should be placed in a `group`: https://docs.jboss.org/author/display/ARQ/Multiple+Containers – oksayt Mar 19 '12 at 10:20
  • @oksayt No, I do not want to run them at once, I will have two kind of tests, one that requires weld-se and a second kind that requires a complete Glassfish container. -- I know I could use Glassfish for the weld tests to, but this will be much to slow. – Ralph Mar 19 '12 at 11:24

2 Answers2

7

If you set the arquillian.launch system property from maven via a surefire config to the container you want to launch that will work. You can see what we've done in Solder at https://github.com/seam/solder/blob/develop/testsuite/pom.xml

LightGuard
  • 5,298
  • 19
  • 19
  • This answer doesnt help me so much, but I do not want to lapse the bounty. – Ralph Mar 26 '12 at 17:56
  • Yes (you can see parts of the pom in the question). But this is not the point. I need to run some tests with one container and some tests with an other one. So Maven profiles does not work, because they are fixed for all tests. – Ralph Mar 27 '12 at 07:31
  • I think I understand better now. You want to have a few containers and run some tests against one and some against another in the same run, but not specify which container in the deployment annotation. – LightGuard Mar 27 '12 at 16:46
  • I do not understand "but not specify which container in the deployment annotation." -- but I think you now know want I want: In the end I want to select the container for the tests with some annotation at the test method (@OperateOnDeployment) – Ralph Mar 27 '12 at 17:06
  • But anyway, the problem is that this does not work even with a single (not) default configuration. – Ralph Mar 27 '12 at 17:07
  • Ah. You can specify which container the deployment should run on, and then you can specify on the test which deployment to use. I'd have to double check on the annotation names though. – LightGuard Mar 28 '12 at 16:30
  • You can do it with a combination of OperateOnDeployment and and TargetContainer. You may not need OperateOnDeployment, but you never know. https://github.com/arquillian/arquillian-core/tree/master/container/test-api/src/main/java/org/jboss/arquillian/container/test/api – LightGuard Apr 10 '12 at 05:23
  • Have a look at the code in the question, this is what I tryed. I am not able to select an other container than the default one. As soon as I set `default="false"` in the xml, the tests does throw the exception. – Ralph Apr 10 '12 at 06:24
5

You see your requested solution here: https://docs.jboss.org/author/display/ARQ/Container+config+runtime+selection Link your maven profile with the arquillian-launch property to select the container from arquillian.xml

Jens Kreidler
  • 364
  • 1
  • 4
  • 10