Интеграционные тесты с Arquillian WELD-001408: неудовлетворенные зависимости для типа XXXX с квалификаторами @Default - PullRequest
0 голосов
/ 14 марта 2019

Я создаю свой первый тест EJB с Arquillian, и я сталкиваюсь с чем-то, что кажется очень распространенным, принимая во внимание количество постов с такой же проблемой. Но, попробовав все предложения, я не смог найти решение. Я бегу по дикой бабочке14.

Мой тестовый класс

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.spec.WebArchive;
import org.junit.*;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.inject.*;

@RunWith(Arquillian.class)
public class LicenseManagerTest {

@Deployment
public static WebArchive createDeployment() {
    WebArchive war = ShrinkWrap.create(WebArchive.class)
                    .addClasses(LicenseManager.class)
                    .addPackages(true, "package1", "package2");
    return war;
    }

@Inject
private LicenseManager licenseManager;

@Test
public void getAboutTest() {
    Assert.assertNotNull(licenseManager.getAbout().getText());
    }
}

EJB Manager

import javax.ejb.Remote;

@Remote
public interface LicenseManager {

AboutDTO getAbout();

}

Бобовый класс

@Stateless(name = "LicenseManagerEJB3")
@Remote(LicenseManager.class)
public class LicenseManagerBean implements LicenseManager{

@Override
public AboutDTO getAbout(){
    *My code goes here*
}

}

Arquillian.xml

<?xml version="1.0"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://jboss.org/schema/arquillian"
        xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<defaultProtocol type="Servlet 3.0"/>
<container qualifier="widlfly-managed" default="true">
    <configuration>
        <property name="jbossHome">target/wildFly-14.0.1.Final</property>
        <!--<property name="managementAddress">127.0.0.1</property>-->
        <!-- Port offset allows running the tests while a WildFly server is already running -->
        <property name="javaVmArguments">-Djboss.socket.binding.port-offset=10000 -Xms512m -Xmx1024m -XX:MaxPermSize=512m --add-modules java.se</property>
        <property name="managementPort">19990</property>
        <property name="username">admin</property>
        <property name="password">admin</property>
    </configuration>
</container>

POM файл

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>artifactName</artifactId>
<parent>
    <groupId>package1</groupId>
    <artifactId>artifactName</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../name1/pom.xml</relativePath>
</parent>
<properties>
    <version.arquillian>1.4.1.Final</version.arquillian>
    <version.wildfly>14.0.1.Final</version.wildfly>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>false</addClasspath>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
    <!-- Project dependencies -->
    <dependency>
        <groupId>org.jboss.arquillian</groupId>
        <artifactId>arquillian-bom</artifactId>
        <version>${version.arquillian}</version>
        <scope>test</scope>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <version>${version.arquillian}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.core</groupId>
        <artifactId>arquillian-core-api</artifactId>
        <version>${version.arquillian}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.protocol</groupId>
        <artifactId>arquillian-protocol-servlet</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-arquillian-container-managed</artifactId>
        <version>8.2.1.Final</version>
        <exclusions>
            <exclusion>
                <groupId>sun.jdk</groupId>
                <artifactId>jconsole</artifactId>
            </exclusion>
        </exclusions>
        <scope>test</scope>
    </dependency>
</dependencies>

<profiles>
    <profile>
        <id>wildFlyManaged</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <testResources>
                <testResource>
                    <directory>src/test/resources</directory>
                </testResource>
            </testResources>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>unpack</id>
                            <phase>process-test-classes</phase>
                            <goals>
                                <goal>unpack</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>org.wildfly</groupId>
                                        <artifactId>wildfly-dist</artifactId>
                                        <version>${version.wildfly}</version>
                                        <type>zip</type>
                                        <overWrite>false</overWrite>
                                        <outputDirectory>target</outputDirectory>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Во время тестовой конфигурации несколько EJB, которые имеют смешанные зависимости с моей, запускаются без проблем, но LicenseManagerEJB3 нет, и когда тестовый код выполняется, я получаю следующую ошибку:

Причина: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001408: неудовлетворенные зависимости для типа LicenseManager с квалификаторами @Default в точке внедрения [BackedAnnotatedField] @Inject private package1.LicenseManagerTest.licenseManager в package1.LicenseManagerTest.licenseManager (LicenseManagerTest.java:0) по адресу org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget (InjectionTargetFactoryImpl.java:83). по адресу org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget (InjectionTargetFactoryImpl.java:70). по адресу org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.BeanManagerImpl.createInjectionTarget (BeanManagerImpl.java:1025) по адресу org.jboss.weld.core@3.0.5.Final//org.jboss.weld.util.ForwardingBeanManager.createInjectionTarget (ForwardingBeanManager.java:204). при развертывании.0d8da7a8-dc23-4657-ac07-40964685a2c1.war // org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectNonContextualInstance (CDIInjectionEnricher.java:143) при развертывании.0d8da7a8-dc23-4657-ac07-40964685a2c1.war // org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass (CDIInjectionEnricher.java:125) ... еще 142 Вызвано: org.jboss.weld.exceptions.DeploymentException: WELD-001408: неудовлетворенные зависимости для типа LicenseManager с квалификаторами @Default в точке внедрения [BackedAnnotatedField] @Inject private package1.LicenseManagerTest.licenseManager в package1.LicenseManagerTest.licenseManager (LicenseManagerTest.java:0) по адресу org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems (Validator.java:378). по адресу org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bootstrap.Validator.validateInjectionPoint (Validator.java:290). по адресу org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bootstrap.Validator.validateProducer (Validator.java:425). по адресу org.jboss.weld.core@3.0.5.Final//org.jboss.weld.injection.producer.InjectionTargetService.validateProducer (InjectionTargetService.java:36). в org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.InjectionTargetFactoryImpl.validate (InjectionTargetFactoryImpl.java:153) по адресу org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget (InjectionTargetFactoryImpl.java:81). ... еще 147

Вы знаете, что я делаю не так? Спасибо

1 Ответ

0 голосов
/ 30 марта 2019

Я думаю, что вам не хватает beans.xml в Deployment, поэтому CDI не находит никаких bean-компонентов в архиве, потому что CDI не включен для архива.

Попытайтесь добавить beans.xml вваше развертывание через

archive.addAsRessource("META-INF/beans.xml);
...