@Test(expectedExceptions = UnexpectedResponseException.class, expectedExceptionsMessageRegExp = "Expected application/json response from server but got text/plain; charset=utf-8") public void testNonJsonResponse() { handler.handle(null, mockResponse(OK, PLAIN_TEXT_UTF_8, "hello")); }
@Test(expectedExceptions = UnexpectedResponseException.class) public void testJsonErrorResponse() { String json = "{\"error\": true}"; handler.handle(null, mockResponse(INTERNAL_SERVER_ERROR, JSON_UTF_8, json)); } }
@Test(expectedExceptions = UnexpectedResponseException.class, expectedExceptionsMessageRegExp = "Expected application/json response from server but got text/plain; charset=utf-8") public void testNonJsonResponse() { handler.handle(null, mockResponse(OK, PLAIN_TEXT_UTF_8, "hello")); }
@Test(expectedExceptions = UnexpectedResponseException.class) public void testJsonErrorResponse() { String json = "{\"error\": true}"; handler.handle(null, mockResponse(INTERNAL_SERVER_ERROR, JSON_UTF_8, json)); } }
@Test(expectedExceptions = UnexpectedResponseException.class) public void testJsonErrorResponse() { String json = "{\"error\": true}"; handler.handle(null, mockResponse(INTERNAL_SERVER_ERROR, JSON_UTF_8, json)); } }
@Test(expectedExceptions = UnexpectedResponseException.class, expectedExceptionsMessageRegExp = "Expected application/json response from server but got text/plain; charset=utf-8") public void testNonJsonResponse() { handler.handle(null, mockResponse(OK, PLAIN_TEXT_UTF_8, "hello")); }
@Test public void testInvalidJson() { String json = "{\"age\": \"foo\"}"; try { handler.handle(null, mockResponse(OK, JSON_UTF_8, json)); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), format("Unable to create %s from JSON response:\n[%s]", User.class, json)); assertTrue(e.getCause() instanceof IllegalArgumentException); assertEquals(e.getCause().getMessage(), "Invalid JSON bytes for [simple type, class io.airlift.http.client.TestFullJsonResponseHandler$User]"); } }
@Test(expectedExceptions = UnexpectedResponseException.class, expectedExceptionsMessageRegExp = "Content-Type is not set for response") public void testMissingContentType() { handler.handle(null, new TestingResponse(OK, ImmutableListMultimap.<String, String>of(), "hello".getBytes(UTF_8))); }
@Test(expectedExceptions = UnexpectedResponseException.class, expectedExceptionsMessageRegExp = "Content-Type is not set for response") public void testMissingContentType() { handler.handle(null, new TestingResponse(OK, ImmutableListMultimap.<String, String>of(), "hello".getBytes(UTF_8))); }
@Test(expectedExceptions = UnexpectedResponseException.class, expectedExceptionsMessageRegExp = "Content-Type is not set for response") public void testMissingContentType() { handler.handle(null, new TestingResponse(OK, ImmutableListMultimap.<String, String>of(), "hello".getBytes(UTF_8))); }
@Test public void testInvalidJson() { String json = "{\"age\": \"foo\"}"; try { handler.handle(null, mockResponse(OK, JSON_UTF_8, json)); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), format("Unable to create %s from JSON response:\n[%s]", User.class, json)); assertTrue(e.getCause() instanceof IllegalArgumentException); assertEquals(e.getCause().getMessage(), "Invalid JSON bytes for [simple type, class io.airlift.http.client.TestFullJsonResponseHandler$User]"); } }
@Test public void testInvalidJson() { String json = "{\"age\": \"foo\"}"; try { handler.handle(null, mockResponse(OK, JSON_UTF_8, json)); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), "Unable to create " + User.class + " from JSON response:\n" + json); assertTrue(e.getCause() instanceof IllegalArgumentException); assertEquals(e.getCause().getMessage(), "Invalid [simple type, class io.airlift.http.client.TestFullJsonResponseHandler$User] json bytes"); } }
@Test public void testValidJson() { User user = new User("Joe", 25); User response = handler.handle(null, mockResponse(OK, JSON_UTF_8, codec.toJson(user))); assertEquals(response.getName(), user.getName()); assertEquals(response.getAge(), user.getAge()); }
@Test public void testValidJson() { User user = new User("Joe", 25); User response = handler.handle(null, mockResponse(OK, JSON_UTF_8, codec.toJson(user))); assertEquals(response.getName(), user.getName()); assertEquals(response.getAge(), user.getAge()); }
@Test public void testValidJson() { User user = new User("Joe", 25); User response = handler.handle(null, mockResponse(OK, JSON_UTF_8, codec.toJson(user))); assertEquals(response.getName(), user.getName()); assertEquals(response.getAge(), user.getAge()); }