use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class RestLiArgumentBuilderTestHelper method getMockRoutingResult.
public static RoutingResult getMockRoutingResult(ResourceMethodDescriptor descriptor, int getResourceMethodCount, ResourceContext context, int getContextCount) {
RoutingResult mockRoutingResult = createMock(RoutingResult.class);
if (descriptor != null) {
expect(mockRoutingResult.getResourceMethod()).andReturn(descriptor).times(getResourceMethodCount);
}
if (context != null) {
expect(mockRoutingResult.getContext()).andReturn(context).times(getContextCount);
}
replay(mockRoutingResult);
return mockRoutingResult;
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestBatchUpdateResponseBuilder method testUpdateStatusInstantiation.
@Test(dataProvider = "updateStatusInstantiation")
public void testUpdateStatusInstantiation(RestLiResponseData responseData, UpdateStatus expectedResult) {
ResourceContext mockContext = getMockResourceContext(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), null);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(null);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
PartialRestResponse response = new BatchUpdateResponseBuilder(new ErrorResponseBuilder()).buildResponse(routingResult, responseData);
Assert.assertEquals(((BatchResponse) response.getEntity()).getResults().get("key"), expectedResult);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestBatchUpdateResponseBuilder method unsupportedNullKeyMapTest.
/* Note that we use also need to test using java.util.concurrent.ConcurrentHashMap. This is because rest.li checks
* for the presence of nulls returned from maps which are returned from resource methods. The checking for nulls
* is prone to a NullPointerException since contains(null) can throw an NPE from certain map implementations such as
* java.util.concurrent.ConcurrentHashMap. We want to make sure our check for the presence of nulls is done in a
* way that doesn't throw an NullPointerException.
*/
@Test(dataProvider = "unsupportedNullKeyMapData")
@SuppressWarnings("unchecked")
public void unsupportedNullKeyMapTest(Object results, ProtocolVersion protocolVersion, Map<String, UpdateStatus> expectedResults) {
ResourceContext mockContext = getMockResourceContext(protocolVersion, null);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(null);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
BatchUpdateResponseBuilder batchUpdateResponseBuilder = new BatchUpdateResponseBuilder(new ErrorResponseBuilder());
RestLiResponseData responseData = batchUpdateResponseBuilder.buildRestLiResponseData(null, routingResult, results, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse restResponse = batchUpdateResponseBuilder.buildResponse(routingResult, responseData);
BatchResponse<UpdateStatus> batchResponse = (BatchResponse<UpdateStatus>) restResponse.getEntity();
EasyMock.verify(mockContext, mockDescriptor);
ResponseBuilderUtil.validateHeaders(restResponse, headers);
Assert.assertEquals(batchResponse.getResults(), expectedResults);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestCreateResponseBuilder method testProjectionInBuildRestliResponseData.
@Test
public void testProjectionInBuildRestliResponseData() throws URISyntaxException {
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);
ServerResourceContext mockContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockContext.getProjectionMask()).andReturn(maskTree);
EasyMock.expect(mockContext.getProjectionMode()).andReturn(ProjectionMode.AUTOMATIC);
EasyMock.replay(mockContext);
RoutingResult routingResult = new RoutingResult(mockContext, null);
Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
CreateKVResponse<Integer, Foo> values = new CreateKVResponse<Integer, Foo>(null, value);
CreateResponseBuilder responseBuilder = new CreateResponseBuilder();
RestLiResponseData envelope = responseBuilder.buildRestLiResponseData(new RestRequestBuilder(new URI("/foo")).build(), routingResult, values, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
RecordTemplate record = envelope.getRecordResponseEnvelope().getRecord();
Assert.assertEquals(record.data().size(), 1);
Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());
Assert.assertTrue(envelope.getCreateResponseEnvelope().isGetAfterCreate());
EasyMock.verify(mockContext);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestUpdateArgumentBuilder method testFailure.
@Test(dataProvider = "failureEntityData", dataProviderClass = RestLiArgumentBuilderTestHelper.class)
public void testFailure(String entity) {
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, entity, 1);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 1, null);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, null, 0);
RestLiArgumentBuilder argumentBuilder = new UpdateArgumentBuilder();
try {
argumentBuilder.extractRequestData(routingResult, request);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertTrue(e.getMessage().contains("Error parsing entity body"));
}
verify(request, model, descriptor, routingResult);
}
Aggregations