use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncGetAssociativeResource.
@Test
public void testAsyncGetAssociativeResource() throws Exception {
ResourceModel followsResourceModel = buildResourceModel(AsyncFollowsAssociativeResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncFollowsAssociativeResource resource;
// #1: get
methodDescriptor = followsResourceModel.findMethod(ResourceMethod.GET);
resource = getMockResource(AsyncFollowsAssociativeResource.class);
CompoundKey rawKey = new CompoundKey();
rawKey.append("followerID", 1L);
rawKey.append("followeeID", 2L);
CompoundKey key = eq(rawKey);
resource.get(key, EasyMock.<Callback<Followed>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<Followed> callback = (Callback<Followed>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(resource);
checkAsyncInvocation(resource, callback, methodDescriptor, "GET", version, "/asyncfollows/(followerID:1,followeeID:2)", buildPathKeys("followerID", 1L, "followeeID", 2L, followsResourceModel.getKeyName(), rawKey));
}
use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncBatchPatchAssociativeResource.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchUpdateCompoundKey")
public void testAsyncBatchPatchAssociativeResource(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel followsResourceModel = buildResourceModel(AsyncFollowsAssociativeResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncFollowsAssociativeResource resource;
methodDescriptor = followsResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
resource = getMockResource(AsyncFollowsAssociativeResource.class);
@SuppressWarnings("unchecked") BatchPatchRequest<CompoundKey, Followed> mockBatchPatchReq = (BatchPatchRequest<CompoundKey, Followed>) EasyMock.anyObject();
resource.batchUpdate(mockBatchPatchReq, EasyMock.<Callback<BatchUpdateResult<CompoundKey, Followed>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<BatchUpdateResult<CompoundKey, Followed>> callback = (Callback<BatchUpdateResult<CompoundKey, Followed>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(resource);
checkAsyncInvocation(resource, callback, methodDescriptor, "POST", version, uri, body, buildBatchPathKeys(buildFollowsCompoundKey(1L, 2L), buildFollowsCompoundKey(3L, 4L), buildFollowsCompoundKey(5L, 6L)));
}
use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class TestRestLiRouting method testRoutingDetailsAssociationBatchGet.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsAssociationBatch")
public void testRoutingDetailsAssociationBatchGet(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(FollowsAssociativeResource.class);
_router = new RestLiRouter(pathRootResourceMap);
RestRequest request = createRequest(uri, "GET", version);
RoutingResult result = _router.process(request, new RequestContext(), null);
assertNotNull(result);
ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
assertNotNull(resourceMethodDescriptor);
assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.BATCH_GET);
assertNull(resourceMethodDescriptor.getActionName());
assertNull(resourceMethodDescriptor.getFinderName());
assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), FollowsAssociativeResource.class);
assertEquals(resourceMethodDescriptor.getMethod().getName(), "batchGet");
assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Set.class });
assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "follows");
assertNotNull(result.getContext());
PathKeys keys = result.getContext().getPathKeys();
assertNull(keys.getAsString("followerID"));
assertNull(keys.getAsString("followeeID"));
CompoundKey key1 = new CompoundKey();
key1.append("followerID", 1L);
key1.append("followeeID", 2L);
CompoundKey key2 = new CompoundKey();
key2.append("followerID", 3L);
key2.append("followeeID", 4L);
Set<CompoundKey> expectedBatchKeys = new HashSet<CompoundKey>();
expectedBatchKeys.add(key1);
expectedBatchKeys.add(key2);
assertEquals(keys.getBatchIds().size(), 2);
for (CompoundKey batchKey : keys.<CompoundKey>getBatchIds()) {
assertTrue(expectedBatchKeys.contains(batchKey));
expectedBatchKeys.remove(batchKey);
}
assertEquals(expectedBatchKeys.size(), 0);
}
use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class TestUriParamUtils method testCompoundKeyToString.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "compoundKey")
public void testCompoundKeyToString(ProtocolVersion version, String expected) {
CompoundKey compoundKey = new CompoundKey();
compoundKey.append("key1", "stringVal");
compoundKey.append("key2", 5);
compoundKey.append("key3", TestEnum.VALUE_1);
String compoundKeyString = URIParamUtils.keyToString(compoundKey, NO_ESCAPING, null, true, version);
Assert.assertEquals(compoundKeyString, expected);
}
use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class TestUpdateArgumentBuilder method argumentData.
@DataProvider(name = "argumentData")
private Object[][] argumentData() {
Parameter<?> myComplexKeyParam = new Parameter<MyComplexKey>("", MyComplexKey.class, DataTemplateUtil.getSchema(MyComplexKey.class), false, null, Parameter.ParamType.POST, false, new AnnotationSet(new Annotation[] {}));
List<Parameter<?>> collectionResourceParams = new ArrayList<Parameter<?>>();
collectionResourceParams.add(new Parameter<Integer>("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema(), false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {})));
collectionResourceParams.add(myComplexKeyParam);
List<Parameter<?>> simpleResourceParams = new ArrayList<Parameter<?>>();
simpleResourceParams.add(myComplexKeyParam);
List<Parameter<?>> associationResourceParams = new ArrayList<Parameter<?>>();
associationResourceParams.add(new Parameter<CompoundKey>("myComplexKeyAssociationId", CompoundKey.class, null, false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {})));
associationResourceParams.add(myComplexKeyParam);
List<Parameter<?>> complexResourceKeyParams = new ArrayList<Parameter<?>>();
@SuppressWarnings("rawtypes") Parameter<ComplexResourceKey> complexResourceKeyParam = new Parameter<ComplexResourceKey>("complexKeyTestId", ComplexResourceKey.class, null, false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {}));
complexResourceKeyParams.add(complexResourceKeyParam);
complexResourceKeyParams.add(myComplexKeyParam);
return new Object[][] { { collectionResourceParams, new Key("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema()), "myComplexKeyCollectionId", 4545 }, { simpleResourceParams, null, null, null }, { associationResourceParams, new Key("myComplexKeyAssociationId", CompoundKey.class, null), "myComplexKeyAssociationId", new CompoundKey().append("string1", "apples").append("string2", "oranges") }, { complexResourceKeyParams, new Key("complexKeyTestId", ComplexResourceKey.class, null), "complexKeyTestId", new ComplexResourceKey<MyComplexKey, EmptyRecord>(new MyComplexKey().setA("keyString").setB(1234L), new EmptyRecord()) } };
}
Aggregations