use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestCollectionResponseBuilder method testBuilderExceptions.
@Test(dataProvider = "exceptionTestData")
public void testBuilderExceptions(Object results, String expectedErrorMessage) throws URISyntaxException {
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
ResourceContext mockContext = getMockResourceContext(null, null, null, null, null);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
CollectionResponseBuilder responseBuilder = new CollectionResponseBuilder();
try {
responseBuilder.buildRestLiResponseData(getRestRequest(), routingResult, results, headers, Collections.<HttpCookie>emptyList());
Assert.fail("An exception should have been thrown because of null elements!");
} catch (RestLiServiceException e) {
Assert.assertTrue(e.getMessage().contains(expectedErrorMessage));
}
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestCollectionResponseBuilder method getMockResourceMethodDescriptor.
private static ResourceMethodDescriptor getMockResourceMethodDescriptor() {
ResourceMethodDescriptor mockDescriptor = EasyMock.createMock(ResourceMethodDescriptor.class);
EasyMock.expect(mockDescriptor.getParametersWithType(EasyMock.<Parameter.ParamType>anyObject())).andReturn(Collections.<Parameter<?>>emptyList()).once();
EasyMock.replay(mockDescriptor);
return mockDescriptor;
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestCollectionResponseBuilder method getMockResourceMethodDescriptor.
private static ResourceMethodDescriptor getMockResourceMethodDescriptor(ResourceMethod resourceMethod) {
ResourceMethodDescriptor mockDescriptor = EasyMock.createMock(ResourceMethodDescriptor.class);
EasyMock.expect(mockDescriptor.getParametersWithType(EasyMock.<Parameter.ParamType>anyObject())).andReturn(Collections.<Parameter<?>>emptyList()).once();
EasyMock.expect(mockDescriptor.getType()).andReturn(resourceMethod);
EasyMock.replay(mockDescriptor);
return mockDescriptor;
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestCreateResponseBuilder method testBuilder.
@Test(dataProvider = "testData")
public void testBuilder(ProtocolVersion protocolVersion, Object expectedId, String expectedLocation, String expectedHeaderId, String altKeyName, Map<String, AlternativeKey<?, ?>> alternativeKeyMap) throws URISyntaxException {
CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
CreateResponse createResponse = new CreateResponse(compoundKey);
IdResponse<?> expectedIdResponse = new IdResponse<Object>(expectedId);
RestRequest restRequest = new RestRequestBuilder(new URI("/foo")).build();
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
// the headers passed in are modified
Map<String, String> expectedHeaders = new HashMap<String, String>(headers);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(alternativeKeyMap);
ResourceContext mockContext = getMockResourceContext(protocolVersion, altKeyName);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
CreateResponseBuilder createResponseBuilder = new CreateResponseBuilder();
RestLiResponseData responseData = createResponseBuilder.buildRestLiResponseData(restRequest, routingResult, createResponse, headers, Collections.<HttpCookie>emptyList());
Assert.assertFalse(responseData.getCreateResponseEnvelope().isGetAfterCreate());
PartialRestResponse partialRestResponse = createResponseBuilder.buildResponse(routingResult, responseData);
expectedHeaders.put(RestConstants.HEADER_LOCATION, expectedLocation);
if (protocolVersion.equals(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion())) {
expectedHeaders.put(RestConstants.HEADER_ID, expectedHeaderId);
} else {
expectedHeaders.put(RestConstants.HEADER_RESTLI_ID, expectedHeaderId);
}
EasyMock.verify(mockContext, mockDescriptor);
ResponseBuilderUtil.validateHeaders(partialRestResponse, expectedHeaders);
Assert.assertEquals(partialRestResponse.getStatus(), HttpStatus.S_201_CREATED);
Assert.assertEquals(partialRestResponse.getEntity(), expectedIdResponse);
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestCreateResponseBuilder method testBuilderException.
@Test
public void testBuilderException() throws URISyntaxException {
CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
CreateResponse createResponse = new CreateResponse(compoundKey, null);
RestRequest restRequest = new RestRequestBuilder(new URI("/foo")).build();
ProtocolVersion protocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(null);
ResourceContext mockContext = getMockResourceContext(protocolVersion, null);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
CreateResponseBuilder createResponseBuilder = new CreateResponseBuilder();
try {
createResponseBuilder.buildRestLiResponseData(restRequest, routingResult, createResponse, headers, Collections.<HttpCookie>emptyList());
Assert.fail("buildRestLiResponseData should have thrown an exception because the status is null!");
} catch (RestLiServiceException e) {
Assert.assertTrue(e.getMessage().contains("Unexpected null encountered. HttpStatus is null inside of a CreateResponse from the resource method: "));
}
}
Aggregations