0 Replies Latest reply on Dec 11, 2017 8:09 AM by chaoran xiang

    entitymanager get null when configure arquillian with wildfly

    chaoran xiang Newbie

      Hi, I am new to the arquillian, and got a problem above.

      here is my pom.xml:

       

      <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>me.langker</groupId>
        <artifactId>LendingPlat</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
      
        <name>LendingPlat</name>
        <url>http://maven.apache.org</url>
      
        <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
        <build>
          <plugins>
            <plugin>
              <artifactId>maven-ejb-plugin</artifactId>
              <version>2.3</version>
              <configuration>
                <ejbVersion>3.1</ejbVersion>
              </configuration>
            </plugin>
            <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.0</version>
              <configuration>
                <source>1.8</source>
                <target>1.8</target>
              </configuration>
            </plugin>
            <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
          </plugin>
          <plugin>       
                      <artifactId>maven-war-plugin</artifactId>
                      <configuration>
                          <webXml>WebContent\WEB-INF\web.xml</webXml>
                          <source>1.7</source>
                   <target>1.7</target>
                      </configuration>
                  </plugin>
          </plugins>
        </build>
        <profiles>
        <profile>
        <id>WILDFLY_REMOTE_8.X</id>
        <dependencies>
        <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-arquillian-container-remote</artifactId>
        <version>8.2.1.Final</version>
        </dependency>
        </dependencies>
        </profile>
        </profiles>
        <dependencies>
          <!-- the test -->
          <!-- Make Arquillian work with JUnit -->
      <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>
       
      <!-- For managing and wrapping of maven dependencies used by the application under test -->
      <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
        <scope>test</scope>
      </dependency>
       
      <dependency>
        <groupId>org.jboss.arquillian.extension</groupId>
        <artifactId>arquillian-persistence-dbunit</artifactId>
        <version>1.0.0.Alpha7</version>
        <scope>test</scope>
      </dependency>
      <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <version>1.7.5</version>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-log4j12</artifactId>
             <version>1.7.5</version>
         </dependency>
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-core</artifactId>
            <version>2.3.5.Final</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.container</groupId>
            <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
            <version>1.0.0.CR9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
          <!-- end  -->
        <dependency>
          <groupId>javax.persistence</groupId>
          <artifactId>persistence-api</artifactId>
          <version>1.0.2</version>
        </dependency>
        <dependency>  
        <groupId>org.glassfish</groupId>   
        <artifactId>javax.faces</artifactId>   
        <version>2.1.10</version>   
        </dependency>
        <dependency>
          <groupId>javax.ejb</groupId>
          <artifactId>ejb-api</artifactId>
          <version>3.0</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>javax.inject</groupId>
          <artifactId>javax.inject</artifactId>
          <version>1</version>
        </dependency>  
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>3.0.1</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>6.1</version>
        </dependency>
        </dependencies>
         <dependencyManagement>  
              <dependencies>  
                  <dependency>
                    <groupId>org.jboss.arquillian</groupId>
                    <artifactId>arquillian-bom</artifactId>
                    <version>1.1.11.Final</version>
                    <scope>import</scope>
                    <type>pom</type>
              </dependency>
              </dependencies>  
          </dependencyManagement>
      </project>
      

       

      here is the  arquillian.xml(also I am not sure if this file has been read, because when I changed the value ,nothing new happen):

       

      <arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="
              http://jboss.org/schema/arquillian
              http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
      
          <!-- Sets the protocol which is how Arquillian talks and executes the tests inside the container -->
          <defaultProtocol type="Servlet 3.0" />
      
          <!-- Configuration to be used when the WidlFly remote profile is active -->
          <container qualifier="WILDFLY_REMOTE_8.X" default="true">
              <configuration>
                  <property name="managementAddress">127.0.0.1</property>
                  <property name="managementPort">9990</property>
                  <property name="username">langker</property>
                  <property name="password">abcd12345</property>
              </configuration>
          </container>
      
          <!-- Configuration to be used when the WildFly managed profile is active -->
          <container qualifier="widlfly-managed">
              <configuration>
                  <property name="jbossHome">/Users/langker/code/wildfly-11.0.0.Final</property>
              </configuration>
          </container>
      
      </arquillian>
      
      
      
      
      
      

       

      My test code is like this:

      package me.langker.LendingPlat.test;
      
      
      import org.jboss.arquillian.container.test.api.Deployment;
      import org.jboss.arquillian.junit.Arquillian;
      import org.jboss.shrinkwrap.api.Archive;
      import org.jboss.shrinkwrap.api.ArchivePaths;
      import org.jboss.shrinkwrap.api.ShrinkWrap;
      import org.jboss.shrinkwrap.api.asset.EmptyAsset;
      import org.jboss.shrinkwrap.api.spec.WebArchive;
      import org.junit.Assert;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      import me.langker.LendingPlat.Controller.UserController;
      
      @RunWith(Arquillian.class)
      public class MainTest {
      
      // Logger log = Logger.getLogger(MainTest.class);
      
        @Deployment
        public static Archive<?> createDeployment() {
        WebArchive archive = ShrinkWrap.create(WebArchive.class, "TestLendingPlat.war")
              .addPackages(true, "me.langker.LendingPlat.Controller")
              .addPackages(true, "me.langker.LendingPlat.Dao")
              .addPackages(true, "me.langker.LendingPlat.Entity")
              .addPackages(true, "me.langker.LendingPlat.Util")
              .addPackages(true, "me.langker.LendingPlat.Viewer")
              .addAsResource("META-INF/persistence.xml")
              .addAsResource("META-INF/arquillian.xml")
              .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
      
      // archive.as(ZipExporter.class).exportTo(
      //     new File("target/TestLendingPlat.war"), true);
      //
      return archive;
      //   return ShrinkWrap.create(WebArchive.class)
      //       .addPackage("me.langker.LendingPlat.Controller")
      //       .addAsResource("META-INF/persistence.xml");
        }
        @Test
        public void getAllTrickers() throws Exception
        {
           Assert.assertTrue(true);
        }
      }
      
      
      
      
      

       

       

      package me.langker.LendingPlat.test;
      
      
      import javax.inject.Inject;
      import org.jboss.arquillian.junit.Arquillian;
      import org.junit.Assert;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      
      
      import me.langker.LendingPlat.Controller.UserController;
      import me.langker.LendingPlat.Entity.User;
      
      
      @RunWith(Arquillian.class)
      public class UserTest extends MainTest {
      
      @Inject UserController uc;
      
      @Test
      public void testName() {
      User u = uc.reg("langke@123.com", "qwe", "qwe", "xiang", "666");
      Assert.assertEquals(null,u);
      }
      }
      
      
      
      
      
      
      
      
      
      
      

      the error happened when uc.reg called, the trace like this:

      java.lang.NullPointerException
      at me.langker.LendingPlat.Dao.UserDao.findByEmail(UserDao.java:26)
      at me.langker.LendingPlat.Controller.UserController.reg(UserController.java:36)
      at me.langker.LendingPlat.test.UserTest.testName(UserTest.java:19)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.jboss.arquillian.junit.Arquillian$8$1.invoke(Arquillian.java:374)
      at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      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:145)
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)
      at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
      at org.jboss.arquillian.container.test.impl.client.protocol.local.LocalContainerMethodExecutor.invoke(LocalContainerMethodExecutor.java:50)
      at org.jboss.arquillian.container.test.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:109)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      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:145)
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)
      at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
      at org.jboss.arquillian.container.test.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:57)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      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.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)
      at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createTestContext(ContainerEventController.java:129)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
      at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:130)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
      at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
      at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)
      at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:136)
      at org.jboss.arquillian.junit.Arquillian$8.evaluate(Arquillian.java:367)
      at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:245)
      at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:426)
      at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54)
      at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:259)
      at org.jboss.arquillian.junit.Arquillian$7$1.invoke(Arquillian.java:319)
      at org.jboss.arquillian.container.test.impl.execution.ClientBeforeAfterLifecycleEventExecuter.execute(ClientBeforeAfterLifecycleEventExecuter.java:99)
      at org.jboss.arquillian.container.test.impl.execution.ClientBeforeAfterLifecycleEventExecuter.on(ClientBeforeAfterLifecycleEventExecuter.java:72)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      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.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)
      at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createBeforeContext(ContainerEventController.java:124)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
      at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:130)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
      at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
      at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)
      at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.fireCustomLifecycle(EventTestRunnerAdaptor.java:159)
      at org.jboss.arquillian.junit.Arquillian$7.evaluate(Arquillian.java:312)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:204)
      at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:426)
      at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54)
      at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:218)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
      
      
      

       

      I think the reason is that the Arquillian has not connect to the wildfly right, so the entitymanager get null, but I don't know how to fix it.

       

      Also this is the github of this project:

      GitHub - langker/LendingPlat: the project for 2017/2018 SE in UNIPV

      the test code is here:

      https://github.com/langker/LendingPlat/blob/master/src/test/java/me/langker/LendingPlat/test/UserTest.java

       

      thank you all in advance.