2016-04-14 17 views
0

Ich schreibe Wildfly Java EE App, aber ich habe Probleme mit Bean-Injektion in Testfällen. Es funktioniert nicht in eigenständigen Tests und auch in ShrinkWrap.Arquillian Bean und dao @Injection nicht funktionieren

Einfacher Test, aber beide injizierten Objekte sind null. Ich habe versucht, Injektion von org.jboss.arquillian.core.api.annotation.Inject Paket aber den gleichen Effekt.

Können Sie mir helfen? Ich habe keine Ahnung, was ich damit machen soll.

src/test/resources/arquillian.xml

<?xml version="1.0" encoding="UTF-8"?> 
<arquillian xmlns="http://www.jboss.org/arquillian-1.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
     http://www.jboss.org/arquillian-1.0 
     http://www.jboss.org/schema/arquillian/arquillian-1.0.xsd"> 

    <defaultProtocol type="Servlet 3.0" /> 

    <extension qualifier="webdriver"> 
     <property name="browser">chrome</property> 
    </extension> 

    <container qualifier="widlfly-remote" default="true"> 
     <configuration> 
      <property name="managementAddress">host</property> 
      <property name="managementPort">9990</property> 
      <property name="username">user</property> 
      <property name="password">password</property> 
     </configuration> 
    </container> 
</arquillian> 

Ausführungslog

kwi 14, 2016 8:25:02 AM org.jboss.arquillian.drone.webdriver.factory.remote.reusable.ReusedSessionPermanentFileStorage readStore 
INFO: Reused session store is not available at C:\Users\......\.drone-webdriver-session-store, a new one will be created. 
kwi 14, 2016 8:25:02 AM org.jboss.arquillian.container.test.impl.RunModeUtils isRunAsClient 
WARNING: The test method "InjectionTestCase groupSetter" will run on the client side - there is no running deployment yet. Please use the annotation @RunAsClient 
kwi 14, 2016 8:25:02 AM org.jboss.arquillian.container.test.impl.RunModeUtils isRunAsClient 
WARNING: The test method "InjectionTestCase groupSetter" will run on the client side - there is no running deployment yet. Please use the annotation @RunAsClient 
kwi 14, 2016 8:25:02 AM org.jboss.arquillian.container.test.impl.RunModeUtils isRunAsClient 
WARNING: The test method "InjectionTestCase groupSetter" will run on the client side - there is no running deployment yet. Please use the annotation @RunAsClient 
kwi 14, 2016 8:25:02 AM org.jboss.arquillian.container.test.impl.RunModeUtils isRunAsClient 
WARNING: The test method "InjectionTestCase groupSetter" will run on the client side - there is no running deployment yet. Please use the annotation @RunAsClient 
kwi 14, 2016 8:25:02 AM org.jboss.arquillian.container.test.impl.RunModeUtils isRunAsClient 
WARNING: The test method "InjectionTestCase groupSetter" will run on the client side - there is no running deployment yet. Please use the annotation @RunAsClient 
kwi 14, 2016 8:25:02 AM org.jboss.arquillian.container.test.impl.RunModeUtils isRunAsClient 
WARNING: The test method "InjectionTestCase groupSetter" will run on the client side - there is no running deployment yet. Please use the annotation @RunAsClient 



Neue Protokolle. Mit ShrinkWrap:

public static WebArchive createDeployment() { 
     File[] files = Maven.resolver().loadPomFromFile("pom.xml") 
       .importRuntimeDependencies().resolve().withTransitivity().asFile(); 


     WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war") 
       // add classes 
       .addPackages(true, "my.package") 
       // add configuration 
       .addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml") 
       .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") 
       .addAsWebInfResource(new File("src/test/webapp/WEB-INF/jboss-web.xml")) 
       // add pages 
       .addAsWebResource(new File("src/main/webapp/403.xhtml")) 
       .addAsWebResource(new File("src/main/webapp/404.xhtml")) 
       .addAsWebResource(new File("src/main/webapp/error.xhtml")) 
       .addAsWebResource(new File("src/main/webapp/login.xhtml")) 
       /** OTHER PAGES ADDED **/ 

       // add libraries 
       .addAsLibraries(files) 

       .setWebXML(new File("src/test/webapp/WEB-INF/web.xml"));     

     System.err.println(war.toString(true)); 

     return war; 
} 

@Deployment 
    public static Archive<?> createDeployment() { 
     return createDeployment(); 
    } 

Ich habe ein Problem gefunden. Tests versuchen, mit 0.0.0.0 statt meiner extrnal Wildfly Server "host"

Caused by: java.lang.IllegalStateException: Error launching request at http://0.0.0.0:8080/test/ArquillianServletRunner?outputMode=serializedObject&className=my.package.InjectionTestCase&methodName=groupSetter. No result returned 

On-Server verbinden ich sehe, dass die Anwendung

2016-04-15 11:20:55,986 INFO [org.jboss.as.server.deployment] (MSC service thread 1-14) JBAS015876: Starting deployment of "test.war" (runtime-name: "test.war") 
...... 
2016-04-15 11:21:00,884 INFO [org.jboss.as.server] (management-handler-thread - 1) JBAS018559: Deployed "test.war" (runtime-name : "test.war") 

Antwort

1

Sie müssen erfolgreich eingesetzt wird Arquillian sagen, dass Sie wollen Bereitstellung Ihren Testfalls auf einem Server:

Einfaches Beispiel (ohne addPackages() usw.)

@Deployment 
public static Archive<?> createDeployment() { 
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class).addAsManifestResource(EmptyAsset.INSTANCE, 
      "beans.xml"); 
    return archive; 
} 

an Ihrem Projekt Je können Sie einige zusätzliche deploy Operationen umfassen:

EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "TestProject.ear") 
      .addAsModule(archive); 
    archive.addAsResource("resources/MANIFEST.MF", "META-INF/MANIFEST.MF"); 
    archive.addAsResource("resources/beans.xml", "META-INF/beans.xml"); 
    archive.addAsResource("resources/persistence.xml", "META-INF/persistence.xml"); 

Und dann auf dem Server der ganze Injection Abhängigkeit sollte

EDIT mit einer entsprechenden Meldung zumindest sollte der Test-Einsatz arbeiten oder fehlschlagen:

In Bezug auf die

Error launching request at..... 

Fehler:

Nach dieser:

https://docs.jboss.org/author/display/ARQ/Container+configuration

try

 <property name="host">yourhost</property> 
     <property name="port">8181</property> 

auf die Konfiguration in Ihrem Arquillian hinzuzufügen.xml

+0

Ich habe ShrinkWrap hinzugefügt, aber es ist ein neues Problem aufgetreten. Protokolle und Code zum ersten Beitrag hinzugefügt. – skoczo

+0

Es sieht aus wie es funktioniert. Die jetzt injizierte Entität ist kein Nullwert. Danke @ Jan_Piel. Jetzt habe ich "Unerwartete Callable in Drone Context vorhanden, sollte in diesem Moment bereits instanziiert werden". Ich versuche eine Lösung dafür zu finden. Danke für die Hilfe. Es hat mich für ein paar Tage blockiert. Könnte ein Problem mit "Drone Context" sein, weil ich einen Remote-Server ohne grafisches env habe? – skoczo

+0

Tut mir leid, ich habe keine Erfahrung mit der Arquillian Drone Extension –

0

Stellen Sie sicher, die richtige Annotation importieren:

org.jboss.arquillian.container.test.api.Deployment 

Und nicht dieses:

org.jboss.arquillian.api.Deployment; 

Der zweite wird nicht auf und geben dem gleichen Fehler

there is no running deployment yet. Please use the annotation @RunAsClient 
abgeholt werden