use of com.linkedin.restli.client.testutils.MockResponseBuilder in project rest.li by linkedin.
the class TestMockResponseBuilder method testBuild.
@Test
public void testBuild() {
MockResponseBuilder<Long, Greeting> mockResponseBuilder = new MockResponseBuilder<Long, Greeting>();
Greeting greeting = new Greeting().setId(1L).setMessage("message");
Map<String, String> headers = Collections.singletonMap("foo", "bar");
RestLiResponseException restLiResponseException = EasyMock.createMock(RestLiResponseException.class);
EasyMock.expect(restLiResponseException.getErrorSource()).andReturn("foo").once();
EasyMock.replay(restLiResponseException);
// build a response object using all the setters. This response does not make sense logically but the goal here
// is to test that the builder is working correctly.
mockResponseBuilder.setEntity(greeting).setHeaders(headers).setCookies(Collections.singletonList(new HttpCookie("cookie", "value"))).setStatus(200).setRestLiResponseException(restLiResponseException);
Response<Greeting> response = mockResponseBuilder.build();
// when we build the Response the ID is put into the headers
Map<String, String> builtHeaders = new HashMap<String, String>(headers);
builtHeaders.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, AllProtocolVersions.BASELINE_PROTOCOL_VERSION.toString());
Assert.assertEquals(response.getEntity(), greeting);
Assert.assertEquals(response.getHeaders(), builtHeaders);
Assert.assertEquals(response.getCookies(), Collections.singletonList(new HttpCookie("cookie", "value")));
Assert.assertEquals(response.getStatus(), 200);
Assert.assertEquals(response.getError().getErrorSource(), "foo");
}
Aggregations