我有一组类可以在项目中使用 REST 方法。它们看起来像这样:
@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。这是因为测试用例中的空响应。为什么会这样?数据库配置正确。