use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestHttpBridge method testHttpToRestErrorMessage.
@Test
public void testHttpToRestErrorMessage() throws TimeoutException, InterruptedException, ExecutionException {
FutureCallback<RestResponse> futureCallback = new FutureCallback<RestResponse>();
TransportCallback<RestResponse> callback = new TransportCallbackAdapter<RestResponse>(futureCallback);
TransportCallback<RestResponse> bridgeCallback = HttpBridge.httpToRestCallback(callback);
RestResponse restResponse = new RestResponseBuilder().build();
// Note: FutureCallback will fail if called twice. An exception would be raised on the current
// thread because we begin the callback sequence here in onResponse.
// (test originally added due to bug with double callback invocation)
bridgeCallback.onResponse(TransportResponseImpl.<RestResponse>error(new RestException(restResponse)));
RestResponse resp = futureCallback.get(30, TimeUnit.SECONDS);
// should have unpacked restResponse from the RestException that we passed in without
// propagating the actual exception
Assert.assertSame(resp, restResponse);
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestBuilders method testSetHeaderNameWithControlChar.
@Test
public void testSetHeaderNameWithControlChar() {
final String headerBaseName = "invalidName";
final String headerValue = "testValue";
for (char i = 0; i <= 31; i++) {
final RestResponseBuilder builder = new RestResponseBuilder();
try {
builder.setHeader(headerBaseName + i, headerValue);
Assert.fail("Should have thrown exception for invalid char (control char): " + i);
} catch (IllegalArgumentException e) {
// expected
}
}
for (char i = 127; i <= 255; i++) {
final RestResponseBuilder builder = new RestResponseBuilder();
try {
builder.setHeader(headerBaseName + i, headerValue);
Assert.fail("Should have thrown exception for invalid char (control char): " + i);
} catch (IllegalArgumentException e) {
// expected
}
}
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestBuilders method testSetMultiValueHeader.
@Test
public void testSetMultiValueHeader() {
final String headerName = "key";
final String headerVal1 = "value1";
final String headerVal2 = "value2";
final String headerValue = headerVal1 + ',' + headerVal2;
final MessageHeaders msg = new RestResponseBuilder().setHeader(headerName, headerValue).build();
Assert.assertEquals(headerValue, msg.getHeader(headerName));
Assert.assertEquals(Arrays.asList(headerVal1, headerVal2), msg.getHeaderValues(headerName));
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestBuilders method testSetHeaderWithCookieFails.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testSetHeaderWithCookieFails() {
final String headerName = "set-cookie";
final String headerValue = "value";
final RestResponse res = new RestResponseBuilder().setHeader(headerName, headerValue).build();
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestBuilders method testSetCookiesMultipleValues.
@Test
public void testSetCookiesMultipleValues() {
final String cookie1 = "cookie1";
final String cookie2 = "cookie2";
final String cookie3 = "cookie3";
List<String> cookies = new ArrayList<String>();
cookies.add(cookie2);
cookies.add(cookie3);
final RestResponse res = new RestResponseBuilder().addCookie(cookie1).setCookies(cookies).build();
Assert.assertNotNull(res.getHeaders());
Assert.assertNotNull(res.getCookies());
Assert.assertTrue(res.getHeaders().isEmpty());
Assert.assertEquals(res.getCookies().size(), 2);
Assert.assertEquals(res.getCookies().get(0), cookie2);
Assert.assertEquals(res.getCookies().get(1), cookie3);
}
Aggregations