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異常。這是因爲在測試案例中空洞的迴應。爲什麼發生這種情況?數據庫配置正確。