2014-11-12 3 views
0

Я пытаюсь получить тесты Arquillian, запущенные на Websphere 8.5 Remote. Инъекции не работает: pom.xmlArquillian ApplicationDescriptor issues

<?xml version="1.0" encoding="UTF-8"?> 
<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>org.arquillian.example</groupId> 
    <artifactId>arquillian-tutorial</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>arquillian-tutorial</name> 
    <url>http://maven.apache.org</url> 


    <!-- Properties --> 



    <properties> 
     <was_home>C:/usr_local2/IBM/WebSphere/AppServer</was_home> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <profiles> 
     <profile> 
      <id>build-server</id> 
      <properties> 
       <was_home>${WAS85_HOME}</was_home> 
      </properties> 
     </profile> 
    </profiles> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.jboss.arquillian</groupId> 
       <artifactId>arquillian-bom</artifactId> 
       <version>1.1.5.Final</version> 
       <scope>import</scope> 
       <type>pom</type> 
      </dependency> 
      <dependency> 
       <groupId>org.jboss.shrinkwrap.descriptors</groupId> 
       <artifactId>shrinkwrap-descriptors-bom</artifactId> 
       <version>2.0.0-alpha-6</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>org.jboss.arquillian.junit</groupId> 
      <artifactId>arquillian-junit-container</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.1</version> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.jboss.arquillian.container</groupId> 
      <artifactId>arquillian-was-remote-8.5</artifactId> 
      <version>1.0.0.Final-SNAPSHOT</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.shrinkwrap.descriptors</groupId> 
      <artifactId>shrinkwrap-descriptors-depchain</artifactId> 
      <version>2.0.0-alpha-6</version> 
      <type>pom</type> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.jboss.weld</groupId> 
      <artifactId>weld-core</artifactId> 
      <version>1.1.5.Final</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-simple</artifactId> 
      <version>1.6.4</version> 
      <scope>test</scope> 
     </dependency> 
     <!-- com.ibm.websphere --> 

     <dependency> 
      <groupId>com.ibm.websphere</groupId> 
      <artifactId>was-public</artifactId> 
      <version>8.5.0</version> 
      <scope>system</scope> 
      <systemPath>${was_home}/dev/was_public.jar</systemPath> 
     </dependency> 

     <dependency> 
      <groupId>com.ibm.websphere</groupId> 
      <artifactId>ws-admin-client</artifactId> 
      <version>8.5.0</version> 
      <scope>system</scope> 
      <systemPath>${was_home}/runtimes/com.ibm.ws.admin.client_8.5.0.jar</systemPath> 
     </dependency> 
    </dependencies> 
</project> 

У меня есть EJB:

package org.arquillian.example; 

import javax.inject.Inject; 
import javax.inject.Singleton; 
import java.io.PrintStream; 

/** 
* A component for creating personal greetings. 
*/ 
@Singleton 
public class Greeter { 
    private PhraseBuilder phraseBuilder; 

    @Inject 
    public Greeter(PhraseBuilder phraseBuilder) { 
     this.phraseBuilder = phraseBuilder; 
    } 

    public void greet(PrintStream to, String name) { 
     to.println(createGreeting(name)); 
    } 

    public String createGreeting(String name) { 
     return phraseBuilder.buildPhrase("hello", name); 
    } 
} 

И у меня Arquillian тест:

package org.arquillian.example; 

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.ShrinkWrap; 
import org.jboss.shrinkwrap.api.asset.EmptyAsset; 
import org.jboss.shrinkwrap.api.asset.StringAsset; 
import org.jboss.shrinkwrap.api.spec.WebArchive; 
import org.junit.Assert; 
import org.junit.Test; 
import org.junit.runner.RunWith; 

import javax.ejb.EJB; 
import javax.inject.Inject; 

@RunWith(Arquillian.class) 
public class GreeterTest { 

    @Deployment 
    public static Archive<?> createDeployment() { 
     WebArchive war = ShrinkWrap.create(WebArchive.class).addClass(Greeter.class).addClass(PhraseBuilder.class) 
       .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 
     System.out.println(war.toString(true)); 
     return war; 

    } 

    @Inject 
    Greeter greeter; 

    @EJB 
    Greeter greeter2; 

    @Test 
    public void shouldBeInjectedCDI() { 
     Assert.assertNotNull("CDI injection is not working", greeter); 
    } 

    @Test 
    public void shouldBeInjectedEJB() { 
     Assert.assertNotNull("EJB injection is not working", greeter2); 
    } 

    @Test 
    public void should_create_greeting() { 
     Assert.assertEquals("Hello, Earthling!", 
       greeter.createGreeting("Earthling")); 
     greeter.greet(System.out, "Earthling"); 
    } 
} 

, но как только я начинаю тесты все они потерпели неудачу.

java.lang.NullPointerException 
at org.arquillian.example.GreeterTest.should_create_greeting(GreeterTest.java:50) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:301) 
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:94) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) 
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:94) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) 
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:94) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) 
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:94) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) 
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:102) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) 
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:84) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) 
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:65) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) 
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:111) 
at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:294) 
at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:269) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) 
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:193) 
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:345) 
at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:49) 
at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:207) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:155) 
at org.junit.runner.JUnitCore.run(JUnitCore.java:157) 
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) 
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) 
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 

Я пробовал много вещей. @ApplicationScoped, @SessionScoped в классе Greeter. Может ли кто-нибудь помочь мне?

Edit: Вот архив

2adbe911-ddef-42b5-bbfe-4d13fe620acd.war: 
/META-INF/ 
/META-INF/beans.xml 
/WEB-INF/ 
/WEB-INF/beans.xml 
/WEB-INF/classes/ 
/WEB-INF/classes/org/ 
/WEB-INF/classes/org/arquillian/ 
/WEB-INF/classes/org/arquillian/example/ 
/WEB-INF/classes/org/arquillian/example/Greeter.class 
/WEB-INF/classes/org/arquillian/example/PhraseBuilder.class 

ответ

0

Вы должны иметь beans.xml файл, чтобы включить CDI. Для веб-модулей он должен быть в WEB-INF, для модулей ejb в папке META-INF.

+0

Не следует ли следовать этой линии? .addAsWebInfResource (EmptyAsset.INSTANCE, "beans.xml") – user831217

+0

@ user831217 Да, он должен. Извините, этого не заметил. И из ваших утверждений работает '@ EJB'? Или оба '@ EJB' и' @ Inject' не работают? – Gas

+0

Ничего не работает на Websphere. Я тестировал его с помощью Weld, и это идет без проблем. – user831217