Search in sources :

Example 71 with RestResponseBuilder

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));
}
Also used : RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) MessageHeaders(com.linkedin.r2.message.MessageHeaders) Test(org.testng.annotations.Test)

Example 72 with RestResponseBuilder

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
        }
    }
}
Also used : RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) Test(org.testng.annotations.Test)

Example 73 with RestResponseBuilder

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);
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) Test(org.testng.annotations.Test)

Example 74 with RestResponseBuilder

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));
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) Test(org.testng.annotations.Test)

Example 75 with RestResponseBuilder

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));
}
Also used : RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) MessageHeaders(com.linkedin.r2.message.MessageHeaders) Test(org.testng.annotations.Test)

Aggregations

RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)87 RestResponse (com.linkedin.r2.message.rest.RestResponse)55 Test (org.testng.annotations.Test)53 RestRequest (com.linkedin.r2.message.rest.RestRequest)22 RestException (com.linkedin.r2.message.rest.RestException)18 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)17 RequestContext (com.linkedin.r2.message.RequestContext)15 ByteString (com.linkedin.data.ByteString)13 Map (java.util.Map)10 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)8 HashMap (java.util.HashMap)8 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)6 RoutingException (com.linkedin.restli.server.RoutingException)6 DataMap (com.linkedin.data.DataMap)5 FilterChain (com.linkedin.r2.filter.FilterChain)5 CaptureLastCallFilter (com.linkedin.r2.testutils.filter.CaptureLastCallFilter)5 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)5 FilterResponseContext (com.linkedin.restli.server.filter.FilterResponseContext)5 IOException (java.io.IOException)5 URI (java.net.URI)5