use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestBuilders method testAddMultipleValuesToHeader.
@Test
public void testAddMultipleValuesToHeader() {
final String headerName = "key";
final String headerVal1 = "value1";
final String headerVal2 = "value2";
final String headerValue = headerVal1 + ',' + headerVal2;
final MessageHeaders msg = new RestResponseBuilder().addHeaderValue(headerName, headerVal1).addHeaderValue(headerName, headerVal2).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 testSetHeaderNameWithSeparator.
@Test
public void testSetHeaderNameWithSeparator() {
final String headerBaseName = "invalidName";
final String headerValue = "testValue";
// Invalid chars per RFC 2616, section 2.2
final char[] separators = new char[] { '(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', 9 /* HT */
};
for (char separator : separators) {
final RestResponseBuilder builder = new RestResponseBuilder();
try {
builder.setHeader(headerBaseName + separator, headerValue);
Assert.fail("Should have thrown exception for invalid char (separator): " + separator);
} catch (IllegalArgumentException e) {
// expected
}
}
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestBuilders method testAddCookieSingleValue.
@Test
public void testAddCookieSingleValue() {
final String cookie = "cookie";
final RestResponse res = new RestResponseBuilder().addCookie(cookie).build();
Assert.assertNotNull(res.getHeaders());
Assert.assertNotNull(res.getCookies());
Assert.assertTrue(res.getHeaders().isEmpty());
Assert.assertEquals(res.getCookies().size(), 1);
Assert.assertEquals(res.getCookies().get(0), cookie);
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestBuilders method testGetHeaderCaseInsensitive.
@Test
public void testGetHeaderCaseInsensitive() {
final String headerName = "testName";
final String headerNameDifferentCase = "TestName";
final String headerValue = "testValue";
final RestResponse res = new RestResponseBuilder().setHeader(headerName, headerValue).build();
Assert.assertEquals(headerValue, res.getHeader(headerNameDifferentCase));
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestBuilders method testAddMultipleValuesToHeader2.
@Test
public void testAddMultipleValuesToHeader2() {
final String headerName = "key";
final String headerVal1a = "value1a";
final String headerVal1b = "value1b";
final String headerVal1 = headerVal1a + "," + headerVal1b;
final String headerVal2 = "value2";
final String headerValue = headerVal1 + ',' + headerVal2;
final MessageHeaders msg = new RestResponseBuilder().addHeaderValue(headerName, headerVal1).addHeaderValue(headerName, headerVal2).build();
Assert.assertEquals(headerValue, msg.getHeader(headerName));
Assert.assertEquals(Arrays.asList(headerVal1a, headerVal1b, headerVal2), msg.getHeaderValues(headerName));
}
Aggregations