@Test
public void testNoError()
{
- 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
+ // .enqueue(new MockResponse()
+ // .setResponseCode(HttpStatus.CONTINUE.value())
+ // .setHeader("Content-Type", "application/json")
+ // .setBody("Hallo Welt!"));
+ //
+ //try
+ //{
+ // String result = clientTemplate.getForObject(uri, String.class);
+ // assertEquals("Hallo Welt!", result);
+ //}
+ //catch(Exception e)
+ //{
+ // LOG.debug("{}", e.toString());
+ // fail("Unexpected error: " + e);
+ //}
server
.enqueue(new MockResponse()
.setResponseCode(HttpStatus.OK.value())
- .setHeader("Content-Type", "application/json")
- .setBody("{ \"message\": \"Hello World!\" }"));
+ .setHeader("Content-Type", "text/plain")
+ .setBody("Hallo Welt!"));
try
{
- SimpleMessage result = clientTemplate.getForObject(uri, SimpleMessage.class);
- assertEquals("Hello World!", result.message);
+ String result = clientTemplate.getForObject(uri, String.class);
+ assertEquals("Hallo Welt!", result);
}
catch(Exception e)
{
server
.enqueue(new MockResponse()
.setResponseCode(HttpStatus.TEMPORARY_REDIRECT.value())
- .setHeader("Content-Type", "application/json")
- .setBody("{ \"message\": \"Hello World!\" }"));
+ .setHeader("Content-Type", "text/plain")
+ .setBody("Hallo Welt!"));
try
{
- SimpleMessage result = clientTemplate.getForObject(uri, SimpleMessage.class);
- assertEquals("Hello World!", result.message);
+ String result = clientTemplate.getForObject(uri, String.class);
+ assertEquals("Hallo Welt!", result);
}
catch(Exception e)
{
server
.enqueue(new MockResponse()
.setResponseCode(HttpStatus.BAD_REQUEST.value())
- .setHeader("Content-Type", "application/json")
- .setBody("{ \"message\": \"Hello World!\" }"));
+ .setHeader("Content-Type", "text/plain")
+ .setBody("Hallo Welt!"));
try
{
- clientTemplate.getForObject(uri, SimpleMessage.class);
+ clientTemplate.getForObject(uri, String.class);
fail("The parent handler should have raised an exception!");
}
catch(HttpClientErrorException e)
server
.enqueue(new MockResponse()
.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value())
- .setHeader("Content-Type", "application/json")
- .setBody("{ \"message\": \"Hello World!\" }"));
+ .setHeader("Content-Type", "text/plain")
+ .setBody("Hallo Welt!"));
try
{
- clientTemplate.getForObject(uri, SimpleMessage.class);
+ clientTemplate.getForObject(uri, String.class);
fail("The parent handler should have raised an exception!");
}
catch(HttpServerErrorException e)
try
{
- clientTemplate.getForObject(uri, SimpleMessage.class);
+ clientTemplate.getForObject(uri, String.class);
fail("The expected exception was not thrown");
}
catch(RateLimitExceededException e)
.setResponseCode(HttpStatus.BAD_REQUEST.value())
.setHeader("Content-Type", "application/json")
.setBody(
- "{\n" +
- " \"error\":\n" +
- " {\n" +
- " \"message\": \"This error does not exist.\",\n" +
- " \"type\": \"NonexistentTypeException\",\n" +
- " \"code\": 999999999\n" +
- " }\n" +
- "}"));
+ "{\n" +
+ " \"error\":\n" +
+ " {\n" +
+ " \"message\": \"This error does not exist.\",\n" +
+ " \"type\": \"NonexistentTypeException\",\n" +
+ " \"code\": 999999999\n" +
+ " }\n" +
+ "}"));
try
{
- clientTemplate.getForObject(uri, SimpleMessage.class);
+ clientTemplate.getForObject(uri, String.class);
fail("The expected exception was not thrown");
}
catch(GraphApiException e)
.setResponseCode(HttpStatus.BAD_REQUEST.value())
.setHeader("Content-Type", "application/json")
.setBody(
- "{\n" +
- " \"error\":\n" +
- " {\n" +
- " \"message\": \"Not a Graph-Api-Exception.\",\n" +
- " \"type\": \"Whatever\",\n" +
- " \"code\": \"some string\"\n" +
- " }\n" +
- "}"));
+ "{\n" +
+ " \"error\":\n" +
+ " {\n" +
+ " \"message\": \"Not a Graph-Api-Exception.\",\n" +
+ " \"type\": \"Whatever\",\n" +
+ " \"code\": \"some string\"\n" +
+ " }\n" +
+ "}"));
try
{
- clientTemplate.getForObject(uri, SimpleMessage.class);
+ clientTemplate.getForObject(uri, String.class);
fail("The expected exception was not thrown");
}
catch(HttpClientErrorException e)
{
fail("A wrong exception was thrown: " + e.toString());
}
- }
- static class SimpleMessage
- {
- String message;
+ server
+ .enqueue(new MockResponse()
+ .setResponseCode(HttpStatus.BAD_REQUEST.value())
+ .setHeader("Content-Type", "text/plain")
+ .setBody("Hallo Welt!"));
+
+ try
+ {
+ clientTemplate.getForObject(uri, String.class);
+ fail("The expected exception was not thrown");
+ }
+ catch(HttpClientErrorException e)
+ {
+ LOG.debug("{}", e.toString());
+ }
+ catch(Exception e)
+ {
+ fail("A wrong exception was thrown: " + e.toString());
+ }
}
}