POJOResourceFactory noDefaults = new POJOResourceFactory(LocatingResource.class);
dispatcher.getRegistry().addResourceFactory(noDefaults);
{
MockHttpRequest request = MockHttpRequest.get("/locating/basic");
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
Assert.assertEquals("basic", response.getContentAsString());
}
{
MockHttpRequest request = MockHttpRequest.put("/locating/basic");
request.content("basic".getBytes());
request.contentType("text/plain");
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
Assert.assertEquals(204, response.getStatus());
}
{
MockHttpRequest request = MockHttpRequest.get("/locating/queryParam?" + "param=" + URLEncoder.encode("hello world", "UTF-8"));
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
Assert.assertEquals("hello world", response.getContentAsString());
}
{
MockHttpRequest request = MockHttpRequest.get("/locating/uriParam/1234");
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
Assert.assertEquals("1234", response.getContentAsString());
}
}