Я создаю тестовый пример jUnit для моей размещенной службы GAE, и у одного из методов возникают проблемы.
Вот интерфейс ресурса:
public interface BasketItemResource {
@Delete
public void removeBasketItem(String id);
@Get
public Representation listBasketItems();
@Put
public void addBasketItems(Representation items);
}
и вот мои тесты:
@Test
public void testListItems() {
Gson gson = new Gson();
List<BasketItem> items = null;
JsonRepresentation jRep = null;
Type collectionType = new TypeToken<List<BasketItem>>(){}.getType();
try {
jRep = new JsonRepresentation(resource.listBasketItems());
items = gson.fromJson(jRep.getJsonArray().toString(), collectionType);
} catch (JsonSyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertEquals(items.size(), 5);
}
@Test
public void testAddItem() {
Gson gson = new Gson();
BasketItem b = new BasketItem();
b.basketItemID = 123;
b.brandName = "Pepsi";
b.description = "Cola Beverage";
b.upc = "123123123";
List<BasketItem> items = new ArrayList<BasketItem>();
items.add(b);
JsonRepresentation jRep = null;
try {
jRep = new JsonRepresentation(new JSONArray(gson.toJson(items)));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
resource.addBasketItems(jRep);
}
Тест listItems выполняется нормально, но когда я запускаю testAddItems (), я сначала получаю это предупреждение:
INFO: Unable to register the helper org.restlet.client.ext.json.JsonConverter
java.lang.ClassNotFoundException: org.restlet.client.ext.json.JsonConverter
at org.restlet.engine.util.EngineClassLoader.findClass(EngineClassLoader.java:101)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.restlet.engine.Engine.registerHelper(Engine.java:723)
at org.restlet.engine.Engine.registerHelpers(Engine.java:761)
at org.restlet.engine.Engine.registerHelpers(Engine.java:801)
at org.restlet.engine.Engine.discoverConverters(Engine.java:509)
at org.restlet.engine.Engine.<init>(Engine.java:337)
at org.restlet.engine.Engine.register(Engine.java:248)
at org.restlet.engine.Engine.register(Engine.java:237)
at org.restlet.engine.Engine.getInstance(Engine.java:149)
at org.restlet.data.Method.<init>(Method.java:331)
at org.restlet.data.Method.<init>(Method.java:390)
at org.restlet.data.Method.<init>(Method.java:355)
at org.restlet.data.Method.<clinit>(Method.java:54)
at org.restlet.engine.resource.AnnotationUtils.addAnnotationDescriptors(AnnotationUtils.java:82)
at org.restlet.engine.resource.AnnotationUtils.addAnnotations(AnnotationUtils.java:132)
at org.restlet.engine.resource.AnnotationUtils.getAnnotations(AnnotationUtils.java:231)
at org.restlet.resource.ClientResource.wrap(ClientResource.java:1548)
at com.tests.tests.BasketItemUploadTests.setUp(BasketItemUploadTests.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
с последующей трассировкой стека в строке (resource.addBasketItems (jRep);):
Internal Server Error (500) - Internal Server Error
at org.restlet.resource.ClientResource$1.invoke(ClientResource.java:1655)
at $Proxy9.addBasketItems(Unknown Source)
at com.tests.tests.BasketItemUploadTests.testAddItem(BasketItemUploadTests.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)