@ArquillianResource返回空URL

时间:2016-06-14 11:31:08

标签: java-ee jboss testng wildfly jboss-arquillian

我正在尝试测试一个非常简单的REST Web服务:

  • 一个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.arquillian.container.test.impl.enricher.resource.URLResourceProvider@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>

1 个答案:

答案 0 :(得分:0)

同样适用于:

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

似乎问题是嵌入式配置文件不支持该功能。