Search in sources :

Example 1 with GroupMembershipsComplexRequestBuilders

use of com.linkedin.restli.examples.groups.client.GroupMembershipsComplexRequestBuilders in project rest.li by linkedin.

the class TestGroupsClient method testComplexKeyBatchCreateGetUpdateDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestComplexBuilderDataProvider")
public void testComplexKeyBatchCreateGetUpdateDelete(ProtocolVersion version, RootBuilderWrapper<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> builders) throws RemoteInvocationException {
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey1 = buildComplexKey(1, 1, 10, "String1");
    ComplexKeyGroupMembership groupMembership1 = buildComplexKeyGroupMembership(complexKey1.getKey(), "alfred@test.linkedin.com", "alfred", "hitchcock");
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey2 = buildComplexKey(2, 1, 20, "String2");
    ComplexKeyGroupMembership groupMembership2 = buildComplexKeyGroupMembership(complexKey2.getKey(), "bruce@test.linkedin.com", "bruce", "willis");
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey3 = buildComplexKey(3, 1, 30, "String3");
    ComplexKeyGroupMembership groupMembership3 = buildComplexKeyGroupMembership(complexKey3.getKey(), "carole@test.linkedin.com", "carole", "bouquet");
    Request<CollectionResponse<CreateStatus>> createRequest = builders.batchCreate().input(groupMembership1).input(groupMembership2).input(groupMembership3).build();
    Response<CollectionResponse<CreateStatus>> createResponse = getClient().sendRequest(createRequest).getResponse();
    Assert.assertEquals(createResponse.getStatus(), 200);
    final RestliRequestOptions requestOptions = builders.getRequestOptions();
    @SuppressWarnings("unchecked") Request<BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>>> request = new GroupMembershipsComplexRequestBuilders(requestOptions).batchGet().ids(complexKey1, complexKey2, complexKey3).fields(GroupMembership.fields().contactEmail()).build();
    BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>> groupMemberships = getClient().sendRequest(request).getResponse().getEntity();
    Map<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>> results = groupMemberships.getResults();
    ComplexKeyGroupMembership groupMembership1_ = results.get(complexKey1).getEntity();
    ComplexKeyGroupMembership groupMembership2_ = results.get(complexKey2).getEntity();
    ComplexKeyGroupMembership groupMembership3_ = results.get(complexKey3).getEntity();
    Assert.assertNotNull(groupMembership1_);
    Assert.assertEquals(groupMembership1_.getContactEmail(), "alfred@test.linkedin.com");
    Assert.assertNotNull(groupMembership2_);
    Assert.assertEquals(groupMembership2_.getContactEmail(), "bruce@test.linkedin.com");
    Assert.assertNotNull(groupMembership3_);
    Assert.assertEquals(groupMembership3_.getContactEmail(), "carole@test.linkedin.com");
    // Update and verify
    groupMembership1.setContactEmail("alfred+@test.linkedin.com");
    groupMembership2.setContactEmail("bruce+@test.linkedin.com");
    groupMembership3.setContactEmail("carole+@test.linkedin.com");
    Request<BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, UpdateStatus>> updateRequest = builders.batchUpdate().input(complexKey1, groupMembership1).input(complexKey2, groupMembership2).input(complexKey3, groupMembership3).build();
    int status = getClient().sendRequest(updateRequest).getResponse().getStatus();
    Assert.assertEquals(status, 200);
}
Also used : RestliRequestOptions(com.linkedin.restli.client.RestliRequestOptions) GroupMembershipsComplexRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsComplexRequestBuilders) GroupMembershipKey(com.linkedin.restli.examples.groups.api.GroupMembershipKey) CollectionResponse(com.linkedin.restli.common.CollectionResponse) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) EntityResponse(com.linkedin.restli.common.EntityResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) Test(org.testng.annotations.Test)

Aggregations

RestliRequestOptions (com.linkedin.restli.client.RestliRequestOptions)1 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1 EntityResponse (com.linkedin.restli.common.EntityResponse)1 ComplexKeyGroupMembership (com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership)1 GroupMembershipKey (com.linkedin.restli.examples.groups.api.GroupMembershipKey)1 GroupMembershipParam (com.linkedin.restli.examples.groups.api.GroupMembershipParam)1 GroupMembershipsComplexRequestBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsComplexRequestBuilders)1 Test (org.testng.annotations.Test)1