vendredi 19 juin 2015

Arquillian tool implementation for EJB unit testing

A very good morning

I am working on unit test implementation for EJB module. I am using EJB3, JBOSS 7 , JEE 7 and JTA. I am using arquillian for EJB unit test.

I am facing some issues while configuring arquillian for EJB unit test. Here is my unit test code

    @RunWith(Arquillian.class)
public class TestCountryInfoControl {

    private static final Logger LOGGER = Logger.getLogger(TestCountryInfoControl.class.getName());

    @Deployment
    public static JavaArchive createDeployment() {
        return ShrinkWrap.create(JavaArchive.class, "test.war")
                .addClasses(CountryInfoControl.class, AddressParameterControl.class, AvStatusCodeControl.class)
                .addAsManifestResource("META-INF/persistence.xml", "persistence.xml")
                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    }
    @EJB
    private CountryInfoControl countryInfoControl;

   @Test
    public void callServiceToAddNewUserToDB() {
        String countryCode = "USA";
       System.out.println(countryCode);
    }
}

This is my POM.xml configuration

<!-- JSR-303 (Bean Validation) Implementation -->
        <!-- Provides portable constraints such as @Email -->
        <!-- Hibernate Validator is shipped in JBoss AS 7 -->
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.arquillian.protocol</groupId>
            <artifactId>arquillian-protocol-servlet</artifactId>
            <scope>test</scope>
        </dependency>

    <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

    <profile>
            <!-- An optional Arquillian testing profile that executes tests
               in your JBoss AS instance -->
            <!-- This profile will start a new JBoss AS instance, and execute
               the test, shutting it down when done -->
            <!-- Run with: mvn clean test -Parq-jbossas-managed -->
            <id>arq-jbossas-managed</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.as</groupId>
                    <artifactId>jboss-as-arquillian-container-managed</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>

        <profile>
            <!-- An optional Arquillian testing profile that executes tests
               in a remote JBoss AS instance -->
            <!-- Run with: mvn clean test -Parq-jbossas-remote -->
            <id>arq-jbossas-remote</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.as</groupId>
                    <artifactId>jboss-as-arquillian-container-remote</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>

And this is code in arqullian.xml

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://ift.tt/Rj5rcy"
   xmlns:xsi="http://ift.tt/ra1lAU"
   xsi:schemaLocation="http://ift.tt/Rj5rcy
        http://ift.tt/U5TLp1">

   <!-- Uncomment to have test archives exported to the file system for inspection -->
<!--    <engine>  -->
<!--       <property name="deploymentExportPath">target/</property>  -->
<!--    </engine> -->

   <!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature -->
   <defaultProtocol type="Servlet 3.0" />

   <!-- Example configuration for a remote JBoss AS 7 instance -->
   <container qualifier="jboss" default="true">
      <!-- If you want to use the JBOSS_HOME environment variable, just delete the jbossHome property -->
      <!--<configuration>-->
         <!--<property name="jbossHome">/path/to/jboss/as</property>-->
      <!--</configuration>-->
   </container>

</arquillian>

I am getting following exception when I am executing test case.

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 147.567 sec <<< FAILURE!
callServiceToAddNewUserToDB(com.pb.gpp.addressverification.ejb.controller.TestCountryInfoControl)  Time elapsed: 182 sec  <<< ERROR!
java.lang.ClassNotFoundException: com.pb.gpp.addressverification.ejb.controller.TestCountryInfoControl from [Module "deployment.test.war:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134)
    at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:158)
    at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126)
    at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926)
    at java.lang.Thread.run(Thread.java:745)


Results :

Tests in error: 
  callServiceToAddNewUserToDB(com.pb.gpp.addressverification.ejb.controller.TestCountryInfoControl): com.pb.gpp.addressverification.ejb.controller.TestCountryInfoControl from [Module "deployment.test.war:main" from Service Module Loader]

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:30.619s
[INFO] Finished at: Fri Jun 19 16:18:18 IST 2015
[INFO] Final Memory: 24M/445M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.3:test (default-cli) on project gpp-addressverification-ejb: There are test failures.
[ERROR] 
[ERROR] Please refer to D:\Dev\Project\GCS\Code\gpp-working-copy-production-zazzle\gpp-addressverification\gpp-addressverification-ejb\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
Disconnected from the target VM, address: '127.0.0.1:55875', transport: 'socket'
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://ift.tt/1aCDfYM

I don't know how to fix this issue. I have no idea about it. I really appreciate your help. Thanks, Awadhendra

Aucun commentaire:

Enregistrer un commentaire