@Test
public void testNoError()
{
-// server
-// .enqueue(new MockResponse()
-// .setResponseCode(HttpStatus.CONTINUE.value())
-// .setHeader("Content-Type", "application/json")
-// .setBody("{ \"message\": \"Hello World!\" }"));
-//
-// try
-// {
-// String result = clientTemplate.getForObject(uri, String.class);
-// assertEquals("{ \"message\": \"Hello World!\" }", result);
-// }
-// catch(Exception e)
-// {
-// LOG.debug("{}", e.toString());
-// fail("Unexpected error: " + e);
-// }
+ server
+ .enqueue(new MockResponse()
+ .setResponseCode(HttpStatus.CONTINUE.value())
+ .setHeader("Content-Type", "application/json")
+ .setBody("{ \"message\": \"Hello World!\" }"));
+
+ try
+ {
+ SimpleMessage result = clientTemplate.getForObject(uri, SimpleMessage.class);
+ assertEquals("Hello World!", result.message);
+ }
+ catch(Exception e)
+ {
+ LOG.debug("{}", e.toString());
+ fail("Unexpected error: " + e);
+ }
server
try
{
- String result = clientTemplate.getForObject(uri, String.class);
- assertEquals("{ \"message\": \"Hello World!\" }", result);
+ SimpleMessage result = clientTemplate.getForObject(uri, SimpleMessage.class);
+ assertEquals("Hello World!", result.message);
}
catch(Exception e)
{
try
{
- String result = clientTemplate.getForObject(uri, String.class);
- assertEquals("{ \"message\": \"Hello World!\" }", result);
+ SimpleMessage result = clientTemplate.getForObject(uri, SimpleMessage.class);
+ assertEquals("Hello World!", result.message);
}
catch(Exception e)
{
try
{
- clientTemplate.getForObject(uri, String.class);
+ clientTemplate.getForObject(uri, SimpleMessage.class);
fail("The parent handler should have raised an exception!");
}
catch(HttpClientErrorException e)
try
{
- clientTemplate.getForObject(uri, String.class);
+ clientTemplate.getForObject(uri, SimpleMessage.class);
fail("The parent handler should have raised an exception!");
}
catch(HttpServerErrorException e)
try
{
- clientTemplate.getForObject(uri, String.class);
+ clientTemplate.getForObject(uri, SimpleMessage.class);
fail("The expected exception was not thrown");
}
catch(RateLimitExceededException e)
try
{
- clientTemplate.getForObject(uri, String.class);
+ clientTemplate.getForObject(uri, SimpleMessage.class);
fail("The expected exception was not thrown");
}
catch(GraphApiException e)
try
{
- clientTemplate.getForObject(uri, String.class);
+ clientTemplate.getForObject(uri, SimpleMessage.class);
fail("The expected exception was not thrown");
}
catch(HttpClientErrorException e)
fail("A wrong exception was thrown: " + e.toString());
}
}
+
+
+ static class SimpleMessage
+ {
+ String message;
+ }
}