I tried to test a single action:
public class ListsController extends APIController {
public void index(){
view("lists", List.findAll().orderBy("id"));
render().contentType("application/json");
}
}
public abstract class APIController extends AppController {
@Override
protected String getContentType() {
return "application/json";
}
@Override
protected String getLayout() {
return null;
}
}
Here is a test:
public class ListsControllerSpec extends DBControllerSpec {
@Test
public void shouldRenderLists(){
app.models.List list = new app.models.List();
list.set("id", 1);
list.set("code", "some code");
list.set("name", "some name");
list.set("item_code", "some item code");
list.saveIt();
request().integrateViews().get("index");
the(contentType()).shouldBeEqual("application/json");
Map[] listsMaps = JsonHelper.toMaps(responseContent());
the(listsMaps.length).shouldBeEqual(1);
Map listEntry = listsMaps[0];
the(listEntry.get("code")).shouldBeEqual("some code");
the(listEntry.get("name")).shouldBeEqual("some name");
}
}
and it failed:
[main] INFO FreeMarkerTemplateManager - rendering template: '/lists/index' with layout: 'null', session: 1
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.498 sec <<< FAILURE! - in app.controllers.ListsControllerSpec
shouldRenderLists(app.controllers.ListsControllerSpec) Time elapsed: 0.411 sec <<< ERROR!
java.lang.RuntimeException: java.io.EOFException: No content to map to Object due to end of input
at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2775)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2718)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)
at org.javalite.common.JsonHelper.toMaps(JsonHelper.java:50)
at app.controllers.ListsControllerSpec.shouldRenderLists(ListsControllerSpec.java:22)
Results :
Tests in error:
ListsControllerSpec.shouldRenderLists:22 » Runtime java.io.EOFException: No co...
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0