0
votes

I'm creating my first EJB test with Arquillian and I'm facing something that seems very common taking in mind the number of posts with the same problem. But after trying all suggestions I've been unable to find a solution.

I'm running it over a wildfly14.

My test class:

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();

}

BEAN class:

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

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

During the test configuration, several EJB's that have mixed dependencies with mine, are started without problem, but LicenseManagerEJB3 is not, and when the test code is executed I get the following error:

Caused by: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001408: Unsatisfied dependencies for type LicenseManager with qualifiers @Default at injection point [BackedAnnotatedField] @Inject private package1.LicenseManagerTest.licenseManager at package1.LicenseManagerTest.licenseManager(LicenseManagerTest.java:0) at [email protected]//org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:83) at [email protected]//org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:70) at [email protected]//org.jboss.weld.manager.BeanManagerImpl.createInjectionTarget(BeanManagerImpl.java:1025) at [email protected]//org.jboss.weld.util.ForwardingBeanManager.createInjectionTarget(ForwardingBeanManager.java:204) at deployment.0d8da7a8-dc23-4657-ac07-40964685a2c1.war//org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectNonContextualInstance(CDIInjectionEnricher.java:143) at deployment.0d8da7a8-dc23-4657-ac07-40964685a2c1.war//org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:125) ... 142 more Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type LicenseManager with qualifiers @Default at injection point [BackedAnnotatedField] @Inject private package1.LicenseManagerTest.licenseManager at package1.LicenseManagerTest.licenseManager(LicenseManagerTest.java:0) at [email protected]//org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:378) at [email protected]//org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290) at [email protected]//org.jboss.weld.bootstrap.Validator.validateProducer(Validator.java:425) at [email protected]//org.jboss.weld.injection.producer.InjectionTargetService.validateProducer(InjectionTargetService.java:36) at [email protected]//org.jboss.weld.manager.InjectionTargetFactoryImpl.validate(InjectionTargetFactoryImpl.java:153) at [email protected]//org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:81) ... 147 more

Do you know what am I doing wrong? Thanks

1

1 Answers

0
votes

I think you are missing the beans.xml in the Deployment, therefore CDI does not find any beans in the archive, because CDI is not enabled for the archive.

Try to add the beans.xml into your deployment via:

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