3
我有一组类可以在项目中使用REST方法。他们是这样的:如何使用Arquillian测试RESTful方法?
@Path("customer/")
@RequestScoped
public class CustomerCollectionResource {
@EJB
private AppManager manager; // working with DB
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response list(@QueryParam("email") String email) {
final List<Customer> entities = manager.listCustomers(email);
// adding customers to result
return Response.ok(result).build();
}
}
,我已经写了测试方法后:
@RunWith(Arquillian.class)
public class CustomerResourceTest {
@Deployment
public static WebArchive createTestArchive() {
return ShrinkWrap.create(WebArchive.class, "test.war")
// Adding omitted
//.addClasses(....)
}
@Test @GET @Path("projectName/customer") @Consumes(MediaType.APPLICATION_JSON)
public void test(ClientResponse<List<Customer>> response) throws Exception {
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
}
,并试图运行这个测试时,我得到NullPointerException异常。这是因为在测试案例中空洞的回应。为什么发生这种情况?数据库配置正确。