【发布时间】:2020-09-15 19:59:16
【问题描述】:
我需要 Arquillian 测试方面的帮助。
添加情况的代码示例。 此代码在真实环境中运行正常。只有在使用 arquillian 制作的测试用例中,才会出现预期结果
代码:
@Stateless
public class CustomerResourceImpl implements CustomerResource{
@Override
public Response findOne(String id) {
String res = "Un cliente";
return Response.ok(res).build();
}
}
@Path("customer")
@Produces(MediaType.APPLICATION_JSON)
public interface CustomerResource {
@GET
@Path("/findOne")
public javax.ws.rs.core.Response findOne(@QueryParam("id") String id);
}
还有这个测试用例
@RunWith(Arquillian.class)
public class CustomerResourceTest {
@Deployment (testable = false)
public static Archive createTestArchive() {
return ShrinkWrap
..... (mas)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
@ArquillianResource
private URL deploymentURL;
@Test
@RunAsClient
public void findOne(@ArquillianResteasyResource CustomerResource resource) throws Exception {
final Response response = resource.findOne("1");
System.out.println(response.getEntity()); // IS NULL ??
System.out.println(response.getStatus()); // 200 OK
assertNotNull(response);
}
}
问题是 response.getEntity() 总是 NULL 。为什么?状态响应 OK = 200 ,没问题。此服务在带有 Java 8 的 jboss 7.2 中运行正常。
谢谢!
【问题讨论】:
-
我在这个链接中找到了解决方案:stackoverflow.com/questions/48781860/…Slds!
标签: jax-rs