Как выбрать контейнер по определителю из arquillian.xml? - PullRequest
10 голосов
/ 16 марта 2012

Я хочу иметь разные конфигурации контейнеров в моем arquillian.xml и выбрать их в моем тесте. Но я не могу загрузить ни один контейнер, кроме контейнера по умолчанию.

<?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>

Контрольный пример:

@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);
}

Но тесты не запускаются, потому что Arquilian не находит контейнер

org.jboss.arquillian.container.test.impl.client.deployment.ValidationException: DeploymentScenario содержит цели, не соответствующие ни одному из определенных контейнеров в реестре. сварной шов. Возможные причины: нет развертываемого контейнера найден на Classpath или вы определили @ org.jboss.arquillian.container.test.api.Deployment с @ org.jboss.arquillian.container.test.api.TargetsContainer значение, которое не соответствует ни одному найденному / настроенному контейнеру (см. arquillian.xml контейнер @ классификатор)

Я посмотрел на источник и обнаружил, что Аквилиан нашел только контейнер _DEFAULT_.

Тесты работают, когда я удаляю @TargetsContainer("weld") из метода развертывания. Так что я думаю, что общий тест в порядке.

Тесты также работают, если я изменяю конфигурацию контейнера на default="true" (<container qualifier="weld" default="ture">), тогда тесты работают, поэтому я думаю, что файл конфигурации загружен.

У кого-нибудь есть идея, что идет не так?


Подробнее

Полная трассировка стека:

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

    <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>

Ответы [ 2 ]

7 голосов
/ 20 марта 2012

Если вы установили системное свойство arquillian.launch из maven через конфигурацию surefire для контейнера, который вы хотите запустить, он будет работать. Вы можете увидеть, что мы сделали в Solder на https://github.com/seam/solder/blob/develop/testsuite/pom.xml

4 голосов
/ 19 июня 2013

Здесь вы видите требуемое решение: https://docs.jboss.org/author/display/ARQ/Container+config+runtime+selection Свяжите свой профиль maven со свойством arquillian-launch, чтобы выбрать контейнер из arquillian.xml

...