use of com.linkedin.restli.server.twitter.StatusCollectionResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPagingContextBadCount.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusPagingContextBadCount")
public void testPagingContextBadCount(ProtocolVersion version, String query) throws Exception {
ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findNamedMethod("public_timeline");
StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
expectRoutingException(methodDescriptor, statusResource, "GET", "/statuses" + query, version);
}
use of com.linkedin.restli.server.twitter.StatusCollectionResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testBatchPatchCollection.
@Test
@SuppressWarnings({ "unchecked" })
public void testBatchPatchCollection() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
@SuppressWarnings("rawtypes") BatchPatchRequest batchPatchRequest = (BatchPatchRequest) EasyMock.anyObject();
EasyMock.expect(statusResource.batchUpdate(batchPatchRequest)).andReturn(null).once();
String body = RestLiTestHelper.doubleQuote("{'entities':{'1':{},'2':{}}}");
checkInvocation(statusResource, methodDescriptor, "POST", version, "/statuses?ids=List(1,2)", body, buildBatchPathKeys(1L, 2L));
}
use of com.linkedin.restli.server.twitter.StatusCollectionResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testBatchUpdateCollection.
@Test
@SuppressWarnings({ "unchecked" })
public void testBatchUpdateCollection() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_UPDATE);
StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
@SuppressWarnings("rawtypes") BatchUpdateRequest batchUpdateRequest = (BatchUpdateRequest) EasyMock.anyObject();
EasyMock.expect(statusResource.batchUpdate(batchUpdateRequest)).andReturn(null).once();
String body = RestLiTestHelper.doubleQuote("{'entities':{'1':{},'2':{}}}");
checkInvocation(statusResource, methodDescriptor, "PUT", version, "/statuses?ids=List(1,2)", body, buildBatchPathKeys(1L, 2L));
}
use of com.linkedin.restli.server.twitter.StatusCollectionResource in project rest.li by linkedin.
the class TestRestLiServer method testPostProcessingException.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "protocolVersions")
public void testPostProcessingException(final ProtocolVersion protocolVersion, final String errorResponseHeaderName, final RestOrStream restOrStream) throws Exception {
//request for nested projection within string field will generate error
final StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.get(eq(1L))).andReturn(buildStatusRecord()).once();
EasyMock.replay(statusResource);
Callback<RestResponse> restResponseCallback = new Callback<RestResponse>() {
@Override
public void onSuccess(RestResponse restResponse) {
fail();
}
@Override
public void onError(Throwable e) {
assertTrue(e instanceof RestException);
RestException restException = (RestException) e;
RestResponse restResponse = restException.getResponse();
try {
assertEquals(restResponse.getStatus(), 500);
assertTrue(restResponse.getEntity().length() > 0);
assertEquals(restResponse.getHeader(errorResponseHeaderName), RestConstants.HEADER_VALUE_ERROR);
EasyMock.verify(statusResource);
EasyMock.reset(statusResource);
} catch (Exception e2) {
fail(e2.toString());
}
}
};
if (restOrStream == RestOrStream.REST) {
RestRequest request = new RestRequestBuilder(new URI("/statuses/1?fields=text:(invalid)")).setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString()).build();
_server.handleRequest(request, new RequestContext(), restResponseCallback);
} else {
StreamRequest streamRequest = new StreamRequestBuilder(new URI("/statuses/1?fields=text:(invalid)")).setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString()).build(EntityStreams.emptyStream());
Callback<StreamResponse> callback = new Callback<StreamResponse>() {
@Override
public void onSuccess(StreamResponse streamResponse) {
fail();
}
@Override
public void onError(Throwable e) {
Messages.toRestException((StreamException) e, new Callback<RestException>() {
@Override
public void onError(Throwable e) {
Assert.fail();
}
@Override
public void onSuccess(RestException result) {
restResponseCallback.onError(result);
}
});
}
};
_server.handleRequest(streamRequest, new RequestContext(), callback);
}
}
use of com.linkedin.restli.server.twitter.StatusCollectionResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testDelete.
@Test
public void testDelete() throws Exception {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(StatusCollectionResource.class, LocationResource.class, DiscoveredItemsResource.class);
ResourceModel statusResourceModel = resourceModelMap.get("/statuses");
ResourceModel locationResourceModel = statusResourceModel.getSubResource("location");
ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/discovereditems");
ResourceMethodDescriptor methodDescriptor;
StatusCollectionResource statusResource;
LocationResource locationResource;
DiscoveredItemsResource discoveredItemsResource;
// #1 Delete on collection resource
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.DELETE);
statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.delete(eq(1L))).andReturn(null).once();
checkInvocation(statusResource, methodDescriptor, "DELETE", version, "/statuses/1", buildPathKeys("statusID", 1L));
// #2 Delete on simple resource
methodDescriptor = locationResourceModel.findMethod(ResourceMethod.DELETE);
locationResource = getMockResource(LocationResource.class);
EasyMock.expect(locationResource.delete()).andReturn(null).once();
checkInvocation(locationResource, methodDescriptor, "DELETE", version, "/statuses/1/location", buildPathKeys("statusID", 1L));
// #3 Delete on complex-key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.DELETE);
discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key = getDiscoveredItemComplexKey(1L, 2, 3L);
EasyMock.expect(discoveredItemsResource.delete(eq(key))).andReturn(null).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "DELETE", version, "/discovereditems/(itemId:1,type:2,userId:3)", buildPathKeys("discoveredItemId", key));
}
Aggregations