2016-06-14 87 views
1

我想測試一個非常簡單的REST Web服務:@ArquillianResource返回null URL

  • 一個jboss-web.xml文件
  • Application類:

    @ApplicationPath("/") 
    public class Application extends javax.ws.rs.core.Application {} 
    
  • 一個Resource類:

    @Path("/") 
    public class Resource { 
        @GET String get() { return "OK"; } 
    } 
    

我的測試類使用@ArquillianResource註釋:

public class ResourceTest extends Arquillian { 

    @ArquillianResource URL baseURL; 

    @Deployment 
    public static WebArchive create() { 
    return ShrinkWrap.create(WebArchive.class) 
        .addClasses(Resource.class, Application.class); 
    } 

    @Test public void get() { /* test Resource here */ } 
} 

我試圖與@Deployment(testable = false)@Deployment(Testable = true),我也試圖@RunAsClient註釋添加到測試方法。

但我總是得到相同的異常:

java.lang.RuntimeException: Could not lookup value for field java.net.URL com.assylias.test.arquillian.ResourceTest.baseURL 

at org.jboss.arquillian.test.impl.enricher.resource.ArquillianResourceTestEnricher.enrich(ArquillianResourceTestEnricher.java:71) 
at org.jboss.arquillian.test.impl.TestInstanceEnricher.enrich(TestInstanceEnricher.java:55) 
at org.jboss.arquillian.container.test.impl.ClientTestInstanceEnricher.enrich(ClientTestInstanceEnricher.java:51) 

[...] 

Caused by: java.lang.RuntimeException: Provider for type class java.net.URL returned a null value: org.jboss.arqui[email protected]babafc2 
at org.jboss.arquillian.test.impl.enricher.resource.ArquillianResourceTestEnricher.lookup(ArquillianResourceTestEnricher.java:133) 
at org.jboss.arquillian.test.impl.enricher.resource.ArquillianResourceTestEnricher.enrich(ArquillianResourceTestEnricher.java:67) 

僅供參考,pom.xml中:

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

<dependencies> 
    <dependency> 
    <groupId>javax</groupId> 
    <artifactId>javaee-api</artifactId> 
    <version>7.0</version> 
    <scope>provided</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>org.jboss.arquillian.testng</groupId> 
    <artifactId>arquillian-testng-container</artifactId> 
    <scope>test</scope> 
    </dependency> 
    <dependency> 
    <groupId>org.jboss.weld</groupId> 
    <artifactId>weld-core</artifactId> 
    <version>2.2.16.Final</version> 
    <scope>test</scope> 
    </dependency> 

    <dependency> 
    <groupId>org.testng</groupId> 
    <artifactId>testng</artifactId> 
    <scope>test</scope> 
    </dependency> 
</dependencies> 
+0

難道是我正在使用嵌入式容器而不是遠程容器嗎? – assylias

回答

0

同樣的事情與工作:

<dependency> 
    <groupId>org.wildfly.arquillian</groupId> 
    <artifactId>wildfly-arquillian-container-remote</artifactId> 
    <version>2.0.0.Final</version> 
    <scope>test</scope> 
</dependency> 

和似乎問題在於嵌入式配置文件d不支持該功能。