use of com.linkedin.restli.server.BatchUpdateRequest in project rest.li by linkedin.
the class TestBatchUpdateArgumentBuilder method testArgumentBuilderSuccess.
@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(ProtocolVersion version, Key primaryKey, Key[] associationKeys, String requestEntity, Object[] keys) throws Exception {
Set<Object> batchKeys = new HashSet<>(Arrays.asList(keys));
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(requestEntity, version);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, primaryKey, associationKeys, batchKeys);
@SuppressWarnings("rawtypes") Parameter<BatchUpdateRequest> param = new Parameter<>("", BatchUpdateRequest.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 3, Collections.singletonList(param), CollectionResourceAsyncTemplate.class.getMethod("batchUpdate", BatchUpdateRequest.class, Callback.class));
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, version, true, false);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
RestLiArgumentBuilder argumentBuilder = new BatchUpdateArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, DataMapUtils.readMapWithExceptions(request));
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
assertEquals(args.length, 1);
assertTrue(args[0] instanceof BatchUpdateRequest);
Map<?, ?> data = ((BatchUpdateRequest) args[0]).getData();
assertEquals(data.size(), 2);
MyComplexKey entity1 = (MyComplexKey) data.get(keys[0]);
MyComplexKey entity2 = (MyComplexKey) data.get(keys[1]);
assertEquals(entity1.getA(), "abc");
assertEquals((long) entity1.getB(), 123L);
assertEquals(entity2.getA(), "XY");
assertEquals((long) entity2.getB(), 456L);
verify(request, model, descriptor, context, routingResult);
}
use of com.linkedin.restli.server.BatchUpdateRequest in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testCustomCrudParamsCollectionBatchUpdate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "paramCollectionBatchUpdate")
public void testCustomCrudParamsCollectionBatchUpdate(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel model = buildResourceModel(CombinedResources.CollectionWithCustomCrudParams.class);
ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.BATCH_UPDATE);
CombinedResources.CollectionWithCustomCrudParams resource = getMockResource(CombinedResources.CollectionWithCustomCrudParams.class);
@SuppressWarnings("rawtypes") BatchUpdateRequest batchUpdateRequest = EasyMock.anyObject();
@SuppressWarnings("unchecked") BatchUpdateResult<String, CombinedTestDataModels.Foo> batchUpdateResult = resource.myBatchUpdate(batchUpdateRequest, eq(1), eq("baz"));
EasyMock.expect(batchUpdateResult).andReturn(null).once();
checkInvocation(resource, methodDescriptor, "PUT", version, uri, body, buildBatchPathKeys("foo", "bar"));
}
use of com.linkedin.restli.server.BatchUpdateRequest 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 = 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.BatchUpdateRequest in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseBatchUpdateCollection.
@Test
@SuppressWarnings({ "unchecked" })
public void testPromiseBatchUpdateCollection() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_UPDATE);
PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
@SuppressWarnings("rawtypes") BatchUpdateRequest batchUpdateRequest = EasyMock.anyObject();
EasyMock.expect(statusResource.batchUpdate(batchUpdateRequest)).andReturn(Promises.value(null)).once();
String body = RestLiTestHelper.doubleQuote("{'entities':{'1':{},'2':{}}}");
checkInvocation(statusResource, methodDescriptor, "PUT", version, "/promisestatuses?ids=List(1,2)", body, buildBatchPathKeys(1L, 2L));
}
use of com.linkedin.restli.server.BatchUpdateRequest in project rest.li by linkedin.
the class BatchUpdateArgumentBuilder method buildArguments.
@Override
public Object[] buildArguments(RestLiRequestData requestData, RoutingResult routingResult) {
@SuppressWarnings({ "unchecked", "rawtypes" }) BatchUpdateRequest batchRequest = new BatchUpdateRequest(requestData.getBatchKeyEntityMap());
Object[] positionalArgs = { batchRequest };
return ArgumentBuilder.buildArgs(positionalArgs, routingResult.getResourceMethod(), routingResult.getContext(), null, routingResult.getResourceMethodConfig());
}
Aggregations