Search in sources :

Example 66 with CompoundKey

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

the class TestPatchArgumentBuilder method argumentData.

@DataProvider(name = "argumentData")
private Object[][] argumentData() {
    @SuppressWarnings("rawtypes") Parameter<?> patchParam = new Parameter<PatchRequest>("", PatchRequest.class, null, 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(patchParam);
    List<Parameter<?>> simpleResourceParams = new ArrayList<Parameter<?>>();
    simpleResourceParams.add(patchParam);
    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(patchParam);
    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(patchParam);
    return new Object[][] { { collectionResourceParams, new Key("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema()), "myComplexKeyCollectionId", 1234 }, { 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()) } };
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) CompoundKey(com.linkedin.restli.common.CompoundKey) ArrayList(java.util.ArrayList) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Parameter(com.linkedin.restli.internal.server.model.Parameter) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) DataProvider(org.testng.annotations.DataProvider)

Example 67 with CompoundKey

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

the class TestBatchUpdateArgumentBuilder method failureData.

@DataProvider(name = "failureData")
private Object[][] failureData() {
    Object[] compoundKeys = new Object[] { new CompoundKey().append("string1", "XXX").append("string2", "oranges"), new CompoundKey().append("string1", "coffee").append("string2", "tea") };
    Object[] complexResourceKeys = new Object[] { new ComplexResourceKey<MyComplexKey, EmptyRecord>(new MyComplexKey().setA("A1").setB(111L), new EmptyRecord()), new ComplexResourceKey<MyComplexKey, EmptyRecord>(new MyComplexKey().setA("A2").setB(222L), new EmptyRecord()) };
    return new Object[][] { { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("integerKey", Integer.class, new IntegerDataSchema()), null, "{\"entities\":{\"10001\":{\"b\":123,\"a\":\"abc\"}," + "\"10002\":{\"b\":456,\"a\":\"XY\"}}}", new Object[] { 10001, 99999 }, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("integerKey", Integer.class, new IntegerDataSchema()), null, "{\"entities\":{\"10001\":{\"b\":123,\"a\":\"abc\"}," + "\"99999\":{\"b\":456,\"a\":\"XY\"}}}", new Object[] { 10001, 10002 }, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("integerKey", Integer.class, new IntegerDataSchema()), null, "{\"entities\":{\"10001\":{\"b\":123,\"a\":\"abc\"}," + "\"10002\":{\"b\":456,\"a\":\"XY\"}}}", new Object[] { 10001, 10002, 10003 }, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"string1=apples&string2=oranges\":{\"b\":123,\"a\":\"abc\"}," + "\"string1=coffee&string2=tea\":{\"b\":456,\"a\":\"XY\"}}}", compoundKeys, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { // Duplicate key in the entities body
    AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"string1=coffee&string2=tea\":{\"b\":123,\"a\":\"abc\"}," + "\"string2=tea&string1=coffee\":{\"b\":456,\"a\":\"XY\"}}}", compoundKeys, ERROR_MESSAGE_DUPLICATE_BATCH_KEYS }, { AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"(string1:coffee,string2:tea)\":{\"b\":456,\"a\":\"XY\"}," + "\"(string1:apples,string2:oranges)\":{\"b\":123,\"a\":\"abc\"}}}", compoundKeys, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { // Duplicate key in the entities body
    AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"(string1:coffee,string2:tea)\":{\"b\":456,\"a\":\"XY\"}," + "\"(string2:tea,string1:coffee)\":{\"b\":123,\"a\":\"abc\"}}}", compoundKeys, ERROR_MESSAGE_DUPLICATE_BATCH_KEYS }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("complexKey", ComplexResourceKey.class, null), null, "{\"entities\":{\"a=A1&b=999\":{\"b\":123,\"a\":\"abc\"}," + "\"a=A2&b=222\":{\"b\":456,\"a\":\"XY\"}}}", complexResourceKeys, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { // Duplicate key in the entities body
    AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("complexKey", ComplexResourceKey.class, null), null, "{\"entities\":{\"a=A1&b=111\":{\"b\":123,\"a\":\"abc\"}," + "\"b=111&a=A1\":{\"b\":456,\"a\":\"XY\"}}}", complexResourceKeys, ERROR_MESSAGE_DUPLICATE_BATCH_KEYS } };
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) CompoundKey(com.linkedin.restli.common.CompoundKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) DataProvider(org.testng.annotations.DataProvider)

Example 68 with CompoundKey

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

the class TestGroupsClient method testAssociationCreateGetDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProvider")
public void testAssociationCreateGetDelete(ProtocolVersion version, RootBuilderWrapper<CompoundKey, GroupMembership> membershipBuilders) throws RemoteInvocationException {
    // Setup - create group memberships
    CompoundKey key1 = buildCompoundKey(1, 1);
    GroupMembership groupMembership1 = buildGroupMembership(null, "alfred@test.linkedin.com", "Alfred", "Hitchcock");
    Response<EmptyRecord> response = getClient().sendRequest(membershipBuilders.update().id(key1).input(groupMembership1).build()).getResponse();
    Assert.assertEquals(response.getStatus(), 204);
    // Get membership
    Request<GroupMembership> getRequest = membershipBuilders.get().id(key1).fields(GroupMembership.fields().contactEmail()).build();
    GroupMembership groupMembership = getClient().sendRequest(getRequest).getResponse().getEntity();
    Assert.assertEquals(groupMembership.getContactEmail(), "alfred@test.linkedin.com");
    // Delete the newly created group membership
    Response<EmptyRecord> deleteResponse = getClient().sendRequest(membershipBuilders.delete().id(key1).build()).getResponse();
    Assert.assertEquals(deleteResponse.getStatus(), 204);
    // Make sure it is gone
    try {
        getClient().sendRequest(getRequest).getResponse();
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), 404);
    }
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 69 with CompoundKey

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

the class TestGroupsClient method testAssociationBatchGetEntityCompoundKeyResponse.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testAssociationBatchGetEntityCompoundKeyResponse(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    CompoundKey key1 = buildCompoundKey(1, 1);
    CompoundKey key2 = buildCompoundKey(2, 1);
    Set<CompoundKey> allRequestedKeys = new HashSet<CompoundKey>(Arrays.asList(key1, key2));
    Request<BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>>> request = new GroupMembershipsRequestBuilders(requestOptions).batchGet().ids(key1, key2).fields(GroupMembership.fields().contactEmail()).build();
    BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>> groupMemberships = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertTrue(allRequestedKeys.containsAll(groupMemberships.getResults().keySet()));
    Assert.assertTrue(allRequestedKeys.containsAll(groupMemberships.getErrors().keySet()));
    Set<CompoundKey> allResponseKeys = new HashSet<CompoundKey>(groupMemberships.getResults().keySet());
    allResponseKeys.addAll(groupMemberships.getErrors().keySet());
    Assert.assertEquals(allResponseKeys, allRequestedKeys);
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) EntityResponse(com.linkedin.restli.common.EntityResponse) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 70 with CompoundKey

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

the class TestGroupsClient method testAssociationBatchCreateGetUpdatePatchDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProvider")
public void testAssociationBatchCreateGetUpdatePatchDelete(ProtocolVersion version, RootBuilderWrapper<CompoundKey, GroupMembership> membershipBuilders) throws RemoteInvocationException {
    // Setup - batch create two group memberships
    CompoundKey key1 = buildCompoundKey(1, 1);
    CompoundKey key2 = buildCompoundKey(2, 1);
    GroupMembership groupMembership1 = buildGroupMembership(null, "alfred@test.linkedin.com", "Alfred", "Hitchcock");
    GroupMembership groupMembership2 = buildGroupMembership(null, "bruce@test.linkedin.com", "Bruce", "Willis");
    Map<CompoundKey, UpdateStatus> results = getClient().sendRequest(membershipBuilders.batchUpdate().input(key1, groupMembership1).input(key2, groupMembership2).build()).getResponse().getEntity().getResults();
    Assert.assertEquals(results.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(results.get(key2).getStatus().intValue(), 204);
    // BatchGet memberships
    final RestliRequestOptions requestOptions = membershipBuilders.getRequestOptions();
    Request<BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>>> request = new GroupMembershipsRequestBuilders(requestOptions).batchGet().ids(key1, key2).fields(GroupMembership.fields().contactEmail()).build();
    Map<CompoundKey, EntityResponse<GroupMembership>> groupMemberships = getClient().sendRequest(request).getResponse().getEntity().getResults();
    Assert.assertTrue(groupMemberships.containsKey(key1));
    Assert.assertEquals(groupMemberships.get(key1).getEntity().getContactEmail(), "alfred@test.linkedin.com");
    Assert.assertTrue(groupMemberships.containsKey(key2));
    Assert.assertEquals(groupMemberships.get(key2).getEntity().getContactEmail(), "bruce@test.linkedin.com");
    // Batch partial update
    GroupMembership patchedGroupMembership1 = buildGroupMembership(null, "ALFRED@test.linkedin.com", "ALFRED", "Hitchcock");
    GroupMembership patchedGroupMembership2 = buildGroupMembership(null, "BRUCE@test.linkedin.com", "BRUCE", "Willis");
    Map<CompoundKey, PatchRequest<GroupMembership>> patchInputs = new HashMap<CompoundKey, PatchRequest<GroupMembership>>();
    patchInputs.put(key1, PatchGenerator.diff(groupMembership1, patchedGroupMembership1));
    patchInputs.put(key2, PatchGenerator.diff(groupMembership2, patchedGroupMembership2));
    Map<CompoundKey, UpdateStatus> patchResults = getClient().sendRequest(membershipBuilders.batchPartialUpdate().patchInputs(patchInputs).build()).getResponse().getEntity().getResults();
    Assert.assertEquals(patchResults.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(patchResults.get(key2).getStatus().intValue(), 204);
    // Batch get to make sure our patch applied
    Request<BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>>> batchGetRequest = new GroupMembershipsRequestBuilders(requestOptions).batchGet().ids(key1, key2).fields(GroupMembership.fields().contactEmail(), GroupMembership.fields().firstName()).build();
    BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>> entity = getClient().sendRequest(batchGetRequest).getResponse().getEntity();
    Assert.assertEquals(entity.getErrors().size(), 0);
    Assert.assertEquals(entity.getResults().size(), 2);
    Assert.assertEquals(entity.getResults().get(key1).getEntity().getContactEmail(), "ALFRED@test.linkedin.com");
    Assert.assertEquals(entity.getResults().get(key1).getEntity().getFirstName(), "ALFRED");
    Assert.assertEquals(entity.getResults().get(key2).getEntity().getContactEmail(), "BRUCE@test.linkedin.com");
    Assert.assertEquals(entity.getResults().get(key2).getEntity().getFirstName(), "BRUCE");
    // GetAll memberships
    Request<CollectionResponse<GroupMembership>> getAllRequest = membershipBuilders.getAll().paginate(1, 2).fields(GroupMembership.fields().contactEmail()).build();
    List<GroupMembership> elements = getClient().sendRequest(getAllRequest).getResponse().getEntity().getElements();
    Assert.assertEquals(elements.size(), 1);
    // Delete the newly created group memberships
    Map<CompoundKey, UpdateStatus> deleteResult = getClient().sendRequest(membershipBuilders.batchDelete().ids(key1, key2).build()).getResponse().getEntity().getResults();
    Assert.assertEquals(deleteResult.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(deleteResult.get(key2).getStatus().intValue(), 204);
    // Make sure they are gone
    BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>> getResponse = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertEquals(getResponse.getResults().size(), getResponse.getErrors().size());
    Assert.assertTrue(getResponse.getErrors().containsKey(key1));
    Assert.assertTrue(getResponse.getErrors().containsKey(key2));
    Assert.assertEquals(getResponse.getErrors().get(key1).getStatus().intValue(), 404);
    Assert.assertEquals(getResponse.getErrors().get(key2).getStatus().intValue(), 404);
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) RestliRequestOptions(com.linkedin.restli.client.RestliRequestOptions) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) CollectionResponse(com.linkedin.restli.common.CollectionResponse) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) Test(org.testng.annotations.Test)

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