use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.
the class TestRestLiResponseHandler method testSetResponseCookies.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicData")
public void testSetResponseCookies(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
String testHeaderName = "XXX";
String testHeaderValue = "head";
ResourceModel resourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = resourceModel.findNamedMethod("search");
ResourceContextImpl context = new ResourceContextImpl();
context.setResponseHeader(testHeaderName, testHeaderValue);
context.addResponseCookie(new HttpCookie("cook1", "value1"));
context.addResponseCookie(new HttpCookie("cook2", "value2"));
RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptTypeData.acceptHeaders, context);
RoutingResult routingResult = new RoutingResult(context, methodDescriptor);
// this is a valid response
RestResponse response = _responseHandler.buildResponse(buildRequest(acceptTypeData.acceptHeaders, protocolVersion), routingResult, buildStatusList(1));
List<HttpCookie> cookies = Arrays.asList(new HttpCookie("cook1", "value1"), new HttpCookie("cook2", "value2"));
Assert.assertEquals(CookieUtil.decodeSetCookies(response.getCookies()), cookies);
response = _responseHandler.buildResponse(buildRequest(acceptTypeData.acceptHeaders, protocolVersion), routingResult, // this is an invalid response
new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
//but the cookie should still be valid
Assert.assertEquals(CookieUtil.decodeSetCookies(response.getCookies()), cookies);
}
use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.
the class TestRestLiResponseHandler method testApplicationSpecifiedHeaders.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicData")
public void testApplicationSpecifiedHeaders(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
String testHeaderName = "X-LI-TEST-HEADER";
String testHeaderValue = "test";
ResourceModel resourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = resourceModel.findNamedMethod("search");
ResourceContextImpl context = new ResourceContextImpl();
context.setResponseHeader(testHeaderName, testHeaderValue);
RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptTypeData.acceptHeaders, context);
RoutingResult routingResult = new RoutingResult(context, methodDescriptor);
RestResponse response;
response = _responseHandler.buildResponse(buildRequest(acceptTypeData.acceptHeaders, protocolVersion), routingResult, buildStatusList(3));
Assert.assertEquals(response.getHeader(testHeaderName), testHeaderValue);
}
use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.
the class TestRestUtils method testValidateRequestHeadersWithValidAcceptHeaderAndMatch.
@Test()
public void testValidateRequestHeadersWithValidAcceptHeaderAndMatch() throws Exception {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "application/json");
ServerResourceContext resourceContext = new ResourceContextImpl();
RestUtils.validateRequestHeadersAndUpdateResourceContext(headers, resourceContext);
Assert.assertEquals(resourceContext.getResponseMimeType(), "application/json");
}
Aggregations