2016-04-14 3 views
0

Я пишу wildfly Java EE app, но у меня проблема с вставкой bean-блока в тестовые. Он не работает в автономных тестах, а также в ShrinkWrap.Arquillian bean and dao @ Injection не работает

import org.jboss.arquillian.junit.Arquillian; 
import org.junit.Assert; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import javax.inject.Inject; 
... 


@RunWith(Arquillian.class) 
public class InjectionTestCase { 
    @org.jboss.arquillian.core.api.annotation.Inject 
    private ProjectStatusDao proStatusDao; 

    @Inject 
    private ClientsCtrl clients; 

    @Test 
    public void groupSetter() { 
     ManageUser user = new ManageUser(); 

     String g = "group"; 
     user.setGroup(g); 

     Assert.assertEquals(g, user.getGroup()); 
    } 
} 

Простой тест, но оба введенных объекта равны нулю. Я попробовал инъекцию из пакета org.jboss.arquillian.core.api.annotation.Inject, но тот же эффект.

Вы можете мне помочь? Я понятия не имею, что с этим делать.

SRC/тест/ресурсы/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> 

журнала Execution

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 



Новые журналы. With 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(); 
    } 

Я нашел одну проблему. Тесты пытаются соединиться с 0.0.0.0 вместо моего extrnal wildfly сервера «хозяина»

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 

На сервере я вижу, что приложение развернуто успешно

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

ответ

1

Вы должны Arquillian сказать, что вы хотите развернуть TestCase на сервере:

Простой пример (без addPackages() и так далее)

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

В зависимости от вашего проекта, могут включать в себя некоторые дополнительные операциях развёртывания:

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

, а затем на сервере всего Dependency Injection должен работать или, по крайней мере, тест-развертывание должно завершиться с соответствующим сообщением

EDIT:

Что касается ошибки

Error launching request at..... 

:

В соответствии с этим:

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

пытаются добавить

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

конфигурации в вашем arquillian.XML

+0

Я добавил ShrinkWrap, но возникла новая проблема. Журналы и код добавлены в первый пост. – skoczo

+0

Похоже, это работает. Теперь введенный объект не является нулевым. Спасибо @Jan_Piel. Теперь у меня есть «Неожиданный вызываемый, присутствующий в Drone Context, должен быть уже создан в данный момент». Я пытаюсь найти решение для этого. Спасибо за помощь. Он заблокировал меня на несколько дней. Может ли проблема с «Drone Context» быть, потому что у меня есть удаленный сервер без графического env? – skoczo

+0

Извините, у меня нет опыта с расширением Arquillian Drone –

0

Убедитесь, что вы импортировать правильный Аннотация:

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

И не это одно:

org.jboss.arquillian.api.Deployment; 

Второй не будет подобран и дают ту же самую ошибку

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