Search in sources :

Example 6 with MockRestliResponseExceptionBuilder

use of com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder in project rest.li by linkedin.

the class TestMockRestliResponseExceptionBuilder method testNullErrorResponse.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testNullErrorResponse() {
    MockRestliResponseExceptionBuilder exceptionBuilder = new MockRestliResponseExceptionBuilder();
    exceptionBuilder.setErrorResponse(null);
}
Also used : MockRestliResponseExceptionBuilder(com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder) Test(org.testng.annotations.Test)

Example 7 with MockRestliResponseExceptionBuilder

use of com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder 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());
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) MockRestliResponseExceptionBuilder(com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder) Test(org.testng.annotations.Test)

Example 8 with MockRestliResponseExceptionBuilder

use of com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder 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);
}
Also used : RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) MockRestliResponseExceptionBuilder(com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 9 with MockRestliResponseExceptionBuilder

use of com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder 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);
}
Also used : RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) MockRestliResponseExceptionBuilder(com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder) Test(org.testng.annotations.Test)

Example 10 with MockRestliResponseExceptionBuilder

use of com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder 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");
}
Also used : HashMap(java.util.HashMap) RestResponse(com.linkedin.r2.message.rest.RestResponse) ArrayList(java.util.ArrayList) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) MockRestliResponseExceptionBuilder(com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map) HttpCookie(java.net.HttpCookie) Test(org.testng.annotations.Test)

Aggregations

MockRestliResponseExceptionBuilder (com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder)10 Test (org.testng.annotations.Test)10 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)3 ErrorResponse (com.linkedin.restli.common.ErrorResponse)1 ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)1 HttpCookie (java.net.HttpCookie)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1