Arquillian- Test class not found as the war is undeployed

635 Views Asked by At

I'm trying to run my unit testing with Arquillian. I configured it with Maven having both Wildfly managed and remote servers. After running the test the server starts and deploys my war. Immediately after deploying it undeploys and removes the war resluting in ClassNotFound exception, I'm providing below the stacktrace:

19:46:23,101 INFO  [org.jboss.as.repository] (management-handler-thread - 3) JBAS014900: Content added at location /home/remotedev/QSDev2/app-qs/target/wildfly-8.2.1.Final/standalone/data/content/29/401e4f9cd9cff55c2a0cd817a4163817b4d7c4/content 19:46:23,172 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "testwar.war" (runtime-name: "testwar.war") 19:46:25,769 WARN  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016012: Deployment deployment "testwar.war" contains CDI annotations but no bean archive was found (no beans.xml or class with bean defining annotations). 19:46:26,590 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017534: Registered web context: /testwar 19:46:26,736 INFO  [org.jboss.as.server] (management-handler-thread - 3) JBAS018559: Deployed "testwar.war" (runtime-name : "testwar.war") 2021-03-23 19:46:28 DEBUG nio:429 - Started channel thread 'Remoting "endpoint" I/O-1', selector sun.nio.ch.EPollSelectorImpl@381d206c 2021-03-23 19:46:28 DEBUG VersionedConectionFactory:173 - Available version (Versions  0x00 0x01) 2021-03-23 19:46:28 DEBUG VersionedConectionFactory:179 - Calling a stable server 2021-03-23 19:46:28 DEBUG VersionedConectionFactory:131 - Selecting version 0x00 to receive full version list. 2021-03-23 19:46:28 DEBUG VersionedConectionFactory:173 - Available version (Versions  0x01 0x02) 2021-03-23 19:46:28 DEBUG VersionedConectionFactory:179 - Calling a stable server 2021-03-23 19:46:28 DEBUG VersionedConectionFactory:194 - Server version 2.0.0.Final 19:46:29,576 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017535: Unregistered web context: /testwar 19:46:29,678 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-1) HV000001: Hibernate Validator 5.1.3.Final 19:46:30,504 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment testwar.war (runtime-name: testwar.war) in 945ms 19:46:30,543 INFO  [org.jboss.as.repository] (management-handler-thread - 3) JBAS014901: Content removed from location /home/remotedev/QSDev2/app-qs/target/wildfly-8.2.1.Final/standalone/data/content/29/401e4f9cd9cff55c2a0cd817a4163817b4d7c4/content 19:46:30,551 INFO  [org.jboss.as.server] (management-handler-thread - 3) JBAS018558: Undeployed "testwar.war" (runtime-name: "testwar.war") Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 24.115 sec <<< FAILURE! testSaveLeaveRequest(com.maestro.application.authentication.util.PasswordStrengthTest)  Time elapsed: 0.343 sec  <<< ERROR! java.lang.ClassNotFoundException: com.maestro.application.authentication.util.PasswordStrengthTest from [Module "deployment.testwar.war:main" from Service Module Loader]

I can't figure out why it's undeploying the war after deploying. Could anyone help me figure out the problem? (Posted at Arquillian forum, no reply yet http://discuss.arquillian.org/t/test-class-not-found-as-the-war-is-undeployed/656). Thanks

--Rashed

Latest update- 04-07-2021

Now getting following exception, CNFE is gone:

Caused by: java.lang.Exception: { "JBAS014671: Failed services" => {"jboss.deployment.unit."test.war".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit."test.war".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "test.war" Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011047: Component class com.maestro.ejb.dao.EntityManagerProvider for component LeaveRequestLocalHome has errors: JBAS011440: Can't find a persistence unit named optimalOneDefaultPersistenceUnit in deployment "test.war""}, "JBAS014771: Services with missing/unavailable dependencies" => ["jboss.deployment.unit."test.war".weld.weldClassIntrospector is missing [jboss.deployment.unit."test.war".beanmanager]"] }

The test code looks like below:

    @RunWith(Arquillian.class)
    public class PasswordStrengthTest { 
    @Deployment
    public static JavaArchive createDeployment() {
        return ShrinkWrap
                .create(JavaArchive.class)
                .addClasses(LeaveRequestLocal.class,
                        LeaveRequestLocalHome.class, LeaveRequestInfo.class,
                        LeaveRequestManagerBean.class,
                        LeaveRequestController.class, LeaveRequestBean.class,
                        EntityManagerProvider.class, JpaEntity.class,
                        MaestroEntityBean.class, MaestroValueObject.class,
                        JpaDaoBean.class, GenericDao.class,
                        SearchManagerException.class, MaestroException.class,
                        NoSuchLeaveRequestException.class,
                        MaestroExceptionDetails.class,
                        MaestroRuntimeException.class, TableParameters.class,
                        SearchParameters.class, PagedList.class)                        
                .addAsManifestResource("META-INF/persistence.xml")
                .addAsResource(EmptyAsset.INSTANCE, "beans.xml");   

    }

    @Inject
    private LeaveRequestManagerBean leaveRequestManagerBean;

    @Inject
    private LeaveRequestLocalHome leaveRequestLocalHome;

    @Inject
    private LeaveRequestController leaveRequestController;

    @Test   
    public void testSaveLeaveRequest() throws Exception {       
        String name = "abc";
        String requestDetails = "req1";
        leaveRequestManagerBean = (LeaveRequestManagerBean) EJBUtil
                .getLocalEJBManager("LeaveRequestManager");
        LeaveRequestInfo leaveReuestInfo = leaveRequestManagerBean.add();

        leaveReuestInfo.setName(name);
        leaveReuestInfo.setRequestDetails(requestDetails);      

        leaveRequestManagerBean.update(leaveReuestInfo);        
        
    }   
  }

And the POM looks like below:

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

    <groupId>com.quickschools</groupId>
    <artifactId>app-qs</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>app-qs</name>
    <url>http://maven.apache.org</url>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.org.jboss.arquillian>1.1.5.Final</version.org.jboss.arquillian>
        <version.org.wildfly>8.2.1.Final</version.org.wildfly>
        <version.junit>4.11</version.junit>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemProperties>
                        <property>
                            <name>java.util.logging.config.file</name>
                            <value>log4j.properties</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencyManagement>
        <dependencies>

            <!-- Arquillian BOM (Bill Of Materials). -->
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>1.1.5.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>

            <!-- JUnit regression testing framework. -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <profiles>

        <!-- Arquillian WildFly managed profile -->
        <profile>
            <id>arq-wildfly-managed</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.wildfly</groupId>
                    <artifactId>wildfly-arquillian-container-managed</artifactId>
                    <version>${version.org.wildfly}</version>
                    <scope>test</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>sun.jdk</groupId>
                            <artifactId>jconsole</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
            <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.org.wildfly}</version>
                                            <type>zip</type>
                                            <overWrite>false</overWrite>
                                            <outputDirectory>${project.build.directory}</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Arquillian WildFly remote profile -->
        <profile>
            <id>arq-widlfly-remote</id>
            <!-- <activation> <activeByDefault>true</activeByDefault> </activation> -->
            <dependencies>
                <dependency>
                    <groupId>org.wildfly</groupId>
                    <artifactId>wildfly-arquillian-container-remote</artifactId>
                    <version>${version.org.wildfly}</version>
                    <scope>test</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>sun.jdk</groupId>
                            <artifactId>jconsole</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
        </profile>

    </profiles>



    <dependencies>

        <dependency>
            <groupId>com.quickschools</groupId>
            <artifactId>sms-core</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>/home/remotedev/mnt/sms2/build/ear/01sms.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.quickschools</groupId>
            <artifactId>gengo</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>/home/remotedev/ProgramFiles/wildfly-12.0.0.Final/modules/com/quickschools/libs/main/gengo.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <!-- for arqillian -->
        <dependency>
            <groupId>javax.ejb</groupId>
            <artifactId>ejb-api</artifactId>
            <version>3.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.ejb</groupId>
            <artifactId>javax.ejb-api</artifactId>
            <version>3.2</version>
        </dependency>
        
        <dependency> <!-- for arqillian -->
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <version>1.1.5.Final</version>
            <!-- <version>1.6.0.Final</version> -->
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.protocol</groupId>
            <artifactId>arquillian-protocol-servlet</artifactId>
            <version>1.1.5.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>1.3.0.Final</version>
            <scope>provided</scope>
        </dependency>



        

        

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>3.0.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.6.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.6.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.8</version>
        </dependency>
        
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
            <scope>runtime</scope>
        </dependency>   
    </dependencies>

</project>

Thanks

Update 09-04-2021 Changed accordingly, now the delpoyment code looks like below:

 return ShrinkWrap
                .create(JavaArchive.class)
                .addClasses(LeaveRequestLocal.class,
                        LeaveRequestLocalHome.class, LeaveRequestInfo.class,
                        LeaveRequestManagerBean.class,
                        LeaveRequestController.class, LeaveRequestBean.class,
                        EntityManagerProvider.class, JpaEntity.class,
                        MaestroEntityBean.class, MaestroValueObject.class,
                        JpaDaoBean.class, GenericDao.class,
                        SearchManagerException.class, MaestroException.class,
                        NoSuchLeaveRequestException.class,
                        MaestroExceptionDetails.class,
                        MaestroRuntimeException.class, TableParameters.class,
                        SearchParameters.class, PagedList.class)
                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
                .addAsManifestResource("persistence.xml");

After deleting META-INF from persistence.xml path, it can't find it now, showing exception as follows:

Caused by: java.lang.IllegalArgumentException: persistence.xml doesn't exist or can't be accessed at org.jboss.shrinkwrap.impl.base.Validate.notNull(Validate.java:43) at org.jboss.shrinkwrap.impl.base.container.ContainerBase.fileFromResource(ContainerBase.java:1966) at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsManifestResource(ContainerBase.java:683)

I tried with keeping beans.xml and presistence.xml at both /resources/META-INF and /test/resources/META-INF, which path is correct? Thanks

0

There are 0 best solutions below