Я реализовал некоторую службу Restful и использую Google App Engine для части базы данных.Все работает нормально, я проверил это с помощью cURL.Проблема в том, что мне нужно создать набор модульных тестов для аналогичных сервисов.
Вот ошибка, которую я получаю:
Jan 23, 2012 10:10:42 AM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Jan 23, 2012 10:10:42 AM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer <init>
INFO: Creating low level InMemory test container configured at the base URI http://localhost:9998/
Jan 23, 2012 10:10:42 AM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer start
INFO: Starting low level InMemory test container
Jan 23, 2012 10:10:42 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.11 12/09/2011 10:27 AM'
Jan 23, 2012 10:10:43 AM com.sun.jersey.spi.inject.Errors processErrorMessages
WARNING: The following warnings have been detected with resource and/or provider classes:
WARNING: A HTTP GET method, public void org.mycompany.myservices.Cache.flush(java.lang.String), MUST return a non-void type.
Jan 23, 2012 10:10:43 AM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer stop
INFO: Stopping low level InMemory test container
Моя реализация WS:
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Building put(@HeaderParam("Authorization") String token, Building building) {
try {
BuildingsDelegator td = new BuildingsDelegator(verifyCredentials(token));
return td.createBuilding(building);
} catch (AuthenticationException e) {
building = new Building();
building.setError("authentication did not succeed");
return building;
}
}
И контрольный пример, с которым я работаю:
public class BuildingTest extends JerseyTest {
private String token ="DQAAAMMAAAB9ApLCubrBvuac0Y6lF8TH8FPXY5WzAhkwrqZv6tL0l9pu_xcY_9mVa1Q-sqTDlMXWUGoo8coYZGh8H2L2b_597O6StOyZ7N3uD-6v5HLNgPDWjj6YXl_X_LyEGM97z3JbSFire3J2Aw5Rag09BEweSMEjV-7TX3lqvtipWYJwQNWlSKpDl4F3TxBj-bWQulvFQ_wonLKze227Le3D_gB0JRofe3L5RkxBClkR6VKIx5s9fEbzupFz6t9hmKoNUTdRa14CgrQSaxXiPMO7J6G9";
@Override
protected AppDescriptor configure() {
this.setTestContainerFactory(new InMemoryTestContainerFactory() );
return new WebAppDescriptor.Builder("org.mycompany.myservices")
.contextPath("/").build(); }
@Test
public void put() {
Building building = new Building();
building.setBuildingId("test_id_1.0x");
building.setTeamId("weakId");
building.setBuildingStatus(2);
building.setRunId((long) 1110705);
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:9998/");
RunBean resultBean = webResource
.path("rest/building")
.header("Authorization", token)
.type(MediaType.APPLICATION_JSON_TYPE)
.accept(MediaType.APPLICATION_JSON_TYPE)
.post(RunBean.class,building);
assertEquals(((Building)resultBean).getBuildingId(), building.getBuildingId());
}
}