Arquillian,Runclient测试为远程

时间:2018-09-06 09:14:25

标签: java-ee jboss jboss-arquillian

我想知道如何将Arquillian rest客户端测试作为jboss远程配置文件启动。

这是我的测试课:

@RunAsClient
@RunWith(Arquillian.class)
public class MemberRegistrationClientTest {

    @Deployment
    public static Archive<?> createTestArchive() {
        return ShrinkWrap.create(WebArchive.class, "test.war").addPackage(Member.class.getPackage())
                .addClasses(Resources.class, MemberResourceRESTService.class, MemberRepository.class, JaxRsActivator.class)
                //.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
                .addAsResource("import.sql")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

    }

    final String RESOURCE_PREFIX = "rest";

    @ArquillianResource
    URL deploymentUrl;

    @Test
    public void testGetCustomerByIdUsingClientRequest() throws Exception {
        //deploymentUrl = new URL("http://localhost:8180/test/");
        // GET http://localhost:8080/test/rest/customer/1
        System.out.println("deployementUrl: " + deploymentUrl.toString() +  RESOURCE_PREFIX + "/members/0");

        ClientRequest request = new ClientRequest(deploymentUrl.toString() + RESOURCE_PREFIX + "/members/0");
        request.header("Accept", MediaType.APPLICATION_XML);

        // we're expecting a String back
        ClientResponse<String> responseObj = request.get(String.class);

        Assert.assertEquals(200, responseObj.getStatus());
        System.out.println("GET /members/0 HTTP/1.1\n\n" + responseObj.getEntity());


    }

}

首先,我使用已安装的应用程序启动我的Jboss,然后使用以下命令启动测试:

mvn clean test -Parq-jbossas-remote.

问题在于部署URL错误,因为它指向localhost:8080 / test,而正确的URL应该是localhost:8080 / myproject。

是否有任何简单的方法来设置包应指向的上下文根?

1 个答案:

答案 0 :(得分:0)

如果要使部署上下文为myproject,最简单的选择是将测试部署命名为myproject.war。您可以将ShrinkWrap.create(WebArchive.class, "test.war")更改为ShrinkWrap.create(WebArchive.class, "myproject.war")

另一种选择是添加一个jboss-web.xml

<?xml version="1.0"?>
<jboss-web>
   <context-root>/myproject</context-root>
</jboss-web>