Search in sources :

Example 26 with CompoundKey

use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.

the class TestBatchUpdateResponseBuilder method unsupportedNullKeyMapData.

@DataProvider(name = "unsupportedNullKeyMapData")
public Object[][] unsupportedNullKeyMapData() {
    final CompoundKey c1 = new CompoundKey().append("a", "a1").append("b", 1);
    final Map<CompoundKey, UpdateResponse> results = new ConcurrentHashMap<CompoundKey, UpdateResponse>();
    results.put(c1, new UpdateResponse(HttpStatus.S_202_ACCEPTED));
    final BatchUpdateResult<CompoundKey, Foo> batchUpdateResult = new BatchUpdateResult<CompoundKey, Foo>(results, new ConcurrentHashMap<CompoundKey, RestLiServiceException>());
    final UpdateStatus updateStatus = new UpdateStatus().setStatus(202);
    final Map<String, UpdateStatus> expectedProtocol1Results = new HashMap<String, UpdateStatus>();
    expectedProtocol1Results.put("a=a1&b=1", updateStatus);
    final Map<String, UpdateStatus> expectedProtocol2Results = new HashMap<String, UpdateStatus>();
    expectedProtocol2Results.put("(a:a1,b:1)", updateStatus);
    return new Object[][] { { batchUpdateResult, AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), expectedProtocol1Results }, { batchUpdateResult, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), expectedProtocol2Results } };
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Foo(com.linkedin.pegasus.generator.examples.Foo) UpdateResponse(com.linkedin.restli.server.UpdateResponse) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DataProvider(org.testng.annotations.DataProvider)

Example 27 with CompoundKey

use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testDataMapToCompoundKey.

@Test(dataProvider = "dataMapToCompoundKey")
public void testDataMapToCompoundKey(CompoundKey expectedCompoundKey, DataMap dataMap, Set<Key> keys) {
    CompoundKey compoundKey = ArgumentUtils.dataMapToCompoundKey(dataMap, keys);
    Assert.assertEquals(compoundKey, expectedCompoundKey);
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 28 with CompoundKey

use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.

the class TestRestLiMethodInvocation method buildFollowsCompoundKey.

/**
   * Helper method to return a Compound Key for the FollowsAssociativeResource and AsyncFollowsAssociativeResource
   * Sets the "followerID" to id1
   * Sets the "followeeID" to id2
   *
   * @param id1 the "followerID".
   * @param id2 the "followeeID"
   *
   * @return
   */
private CompoundKey buildFollowsCompoundKey(Long id1, Long id2) {
    CompoundKey key = new CompoundKey();
    key.append("followerID", id1);
    key.append("followeeID", id2);
    return key;
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey)

Example 29 with CompoundKey

use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testAsyncBatchUpdateAssociativeResource.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchUpdateCompoundKey")
public void testAsyncBatchUpdateAssociativeResource(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_UPDATE);
    resource = getMockResource(AsyncFollowsAssociativeResource.class);
    @SuppressWarnings("unchecked") BatchUpdateRequest<CompoundKey, Followed> mockBatchUpdateReq = (BatchUpdateRequest<CompoundKey, Followed>) EasyMock.anyObject();
    resource.batchUpdate(mockBatchUpdateReq, 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, "PUT", version, uri, body, buildBatchPathKeys(buildFollowsCompoundKey(1L, 2L), buildFollowsCompoundKey(3L, 4L), buildFollowsCompoundKey(5L, 6L)));
}
Also used : BatchUpdateRequest(com.linkedin.restli.server.BatchUpdateRequest) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Followed(com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed) AsyncFollowsAssociativeResource(com.linkedin.restli.server.twitter.AsyncFollowsAssociativeResource) Callback(com.linkedin.common.callback.Callback) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) RequestExecutionCallback(com.linkedin.restli.server.RequestExecutionCallback) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 30 with CompoundKey

use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testPromiseGetAssociativeResource.

@Test
public void testPromiseGetAssociativeResource() throws Exception {
    ResourceModel followsResourceModel = buildResourceModel(PromiseFollowsAssociativeResource.class);
    ResourceMethodDescriptor methodDescriptor;
    PromiseFollowsAssociativeResource resource;
    // #1: get
    methodDescriptor = followsResourceModel.findMethod(ResourceMethod.GET);
    resource = getMockResource(PromiseFollowsAssociativeResource.class);
    CompoundKey rawKey = new CompoundKey();
    rawKey.append("followerID", 1L);
    rawKey.append("followeeID", 2L);
    CompoundKey key = eq(rawKey);
    EasyMock.expect(resource.get(key)).andReturn(Promises.value(new Followed(new DataMap()))).once();
    checkInvocation(resource, methodDescriptor, "GET", version, "/promisefollows/(followerID:1,followeeID:2)", buildPathKeys("followerID", 1L, "followeeID", 2L, followsResourceModel.getKeyName(), rawKey));
}
Also used : PromiseFollowsAssociativeResource(com.linkedin.restli.server.twitter.PromiseFollowsAssociativeResource) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Followed(com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

CompoundKey (com.linkedin.restli.common.CompoundKey)94 Test (org.testng.annotations.Test)48 HashMap (java.util.HashMap)26 DataProvider (org.testng.annotations.DataProvider)20 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)17 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)16 GroupMembership (com.linkedin.restli.examples.groups.api.GroupMembership)15 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)14 AfterTest (org.testng.annotations.AfterTest)13 BeforeTest (org.testng.annotations.BeforeTest)13 DataMap (com.linkedin.data.DataMap)12 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)12 Key (com.linkedin.restli.server.Key)11 Followed (com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed)10 HashSet (java.util.HashSet)10 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)9 TestRecord (com.linkedin.restli.client.test.TestRecord)9 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)9 AsyncFollowsAssociativeResource (com.linkedin.restli.server.twitter.AsyncFollowsAssociativeResource)9 EmptyRecord (com.linkedin.restli.common.EmptyRecord)8