use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class MockFailedResponseFutureBuilder method buildWithEntity.
private ResponseFuture<V> buildWithEntity() {
int status = getStatus();
byte[] entity = mapToBytes(getEntity().data());
Response<V> decodedResponse = new MockResponseBuilder<K, V>().setEntity(getEntity()).setStatus(status).setHeaders(getHeaders()).setCookies(getCookies()).setProtocolVersion(getProtocolVersion()).build();
RestResponse restResponse = new RestResponseBuilder().setEntity(entity).setStatus(status).setHeaders(decodedResponse.getHeaders()).setCookies(CookieUtil.encodeCookies(decodedResponse.getCookies())).build();
RestLiResponseException restLiResponseException = new RestLiResponseException(restResponse, decodedResponse, new ErrorResponse());
ExecutionException executionException = new ExecutionException(restLiResponseException);
Future<Response<V>> responseFuture = buildFuture(null, executionException);
return new ResponseFutureImpl<>(responseFuture, _errorHandlingBehavior);
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestMockRestliResponseExceptionBuilder method testOldProtocolVersion.
@Test
public void testOldProtocolVersion() {
ProtocolVersion expectedProtocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();
RestLiResponseException exception = new MockRestliResponseExceptionBuilder().setProtocolVersion(expectedProtocolVersion).build();
RestResponse errorResponse = exception.getResponse();
assertEquals(errorResponse.getHeader(RestConstants.HEADER_LINKEDIN_ERROR_RESPONSE), "true");
assertEquals(errorResponse.getHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION), expectedProtocolVersion.toString());
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestMockRestliResponseExceptionBuilder method testOverwriteStatus.
@Test
public void testOverwriteStatus() {
ErrorResponse noStatusErrorResponse = new ErrorResponse();
RestLiResponseException exception = new MockRestliResponseExceptionBuilder().setErrorResponse(noStatusErrorResponse).build();
assertEquals(exception.getStatus(), 500);
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestMockRestliResponseExceptionBuilder method testSetStatus.
@Test
public void testSetStatus() {
RestLiResponseException exception = new MockRestliResponseExceptionBuilder().setStatus(HttpStatus.S_403_FORBIDDEN).build();
assertEquals(exception.getStatus(), 403);
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestMockRestliResponseExceptionBuilder method testAddCookiesAndHeaders.
@Test
public void testAddCookiesAndHeaders() {
Map.Entry<String, String> expectedEntry = new AbstractMap.SimpleEntry<>("foo", "bar");
HttpCookie expectedCookie = new HttpCookie("bar", "foo");
Map<String, String> headers = new HashMap<>();
headers.put(expectedEntry.getKey(), expectedEntry.getValue());
List<HttpCookie> cookies = new ArrayList<>();
cookies.add(expectedCookie);
RestLiResponseException exception = new MockRestliResponseExceptionBuilder().setHeaders(headers).setCookies(cookies).build();
RestResponse errorResponse = exception.getResponse();
assertEquals(errorResponse.getHeader(expectedEntry.getKey()), expectedEntry.getValue());
assertEquals(errorResponse.getCookies().get(0), "bar=foo");
}
Aggregations