Search in sources :

Example 6 with GroupMembershipKey

use of com.linkedin.restli.examples.groups.api.GroupMembershipKey in project rest.li by linkedin.

the class TestGroupsClient method testComplexKeyCreateGetUpdateDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestComplexBuilderDataProvider")
public void testComplexKeyCreateGetUpdateDelete(ProtocolVersion version, RootBuilderWrapper<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> builders) throws RemoteInvocationException {
    // Create a new complex key resource
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey = buildComplexKey(1, 1, 10, "String1");
    ComplexKeyGroupMembership groupMembership = buildComplexKeyGroupMembership(complexKey.getKey(), "alfred@test.linkedin.com", "alfred", "hitchcock");
    Request<EmptyRecord> createRequest = builders.create().input(groupMembership).build();
    Response<EmptyRecord> createResponse = getClient().sendRequest(createRequest).getResponse();
    Assert.assertEquals(createResponse.getStatus(), 201);
    GroupMembershipParam param = new GroupMembershipParam().setIntParameter(1).setStringParameter("1");
    GroupMembershipQueryParam groupMembershipQueryParam1 = new GroupMembershipQueryParam().setIntParameter(1).setStringParameter("1");
    GroupMembershipQueryParam groupMembershipQueryParam2 = new GroupMembershipQueryParam().setIntParameter(2).setStringParameter("2");
    GroupMembershipQueryParamArray queryParamArray = new GroupMembershipQueryParamArray(groupMembershipQueryParam1, groupMembershipQueryParam2);
    // Get the resource back and check state
    Request<ComplexKeyGroupMembership> request = builders.get().id(complexKey).fields(GroupMembership.fields().contactEmail()).setQueryParam("testParam", param).setQueryParam("testParamArray", queryParamArray).build();
    ComplexKeyGroupMembership groupMembership1 = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertNotNull(groupMembership1);
    Assert.assertEquals(groupMembership1.getContactEmail(), "alfred@test.linkedin.com");
    // Test the same with optional complex parameters
    request = builders.get().id(complexKey).fields(GroupMembership.fields().contactEmail()).build();
    groupMembership1 = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertNotNull(groupMembership1);
    Assert.assertEquals(groupMembership1.getContactEmail(), "alfred@test.linkedin.com");
    // Update contact email and verify
    groupMembership.setContactEmail("alphred@test.linkedin.com");
    Request<EmptyRecord> updateRequest = builders.update().id(complexKey).input(groupMembership).build();
    Response<EmptyRecord> updateResponse = getClient().sendRequest(updateRequest).getResponse();
    Assert.assertEquals(updateResponse.getStatus(), 204);
    groupMembership1 = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertEquals(groupMembership1.getContactEmail(), "alphred@test.linkedin.com");
    // Delete and verify
    Request<EmptyRecord> deleteRequest = builders.delete().id(complexKey).build();
    Response<EmptyRecord> deleteResponse = getClient().sendRequest(deleteRequest).getResponse();
    Assert.assertEquals(deleteResponse.getStatus(), 204);
    try {
        getClient().sendRequest(request).getResponse().getEntity();
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), 404);
    }
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) GroupMembershipKey(com.linkedin.restli.examples.groups.api.GroupMembershipKey) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) GroupMembershipQueryParamArray(com.linkedin.restli.examples.groups.api.GroupMembershipQueryParamArray) GroupMembershipQueryParam(com.linkedin.restli.examples.groups.api.GroupMembershipQueryParam) Test(org.testng.annotations.Test)

Example 7 with GroupMembershipKey

use of com.linkedin.restli.examples.groups.api.GroupMembershipKey in project rest.li by linkedin.

the class TestGroupsClient method buildComplexKey.

private static ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> buildComplexKey(int memberID, int groupID, int intParam, String stringParam) {
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey = new ComplexResourceKey<>(new GroupMembershipKey(), new GroupMembershipParam());
    complexKey.getKey().setMemberID(memberID);
    complexKey.getKey().setGroupID(groupID);
    complexKey.getParams().setIntParameter(intParam);
    complexKey.getParams().setStringParameter(stringParam);
    return complexKey;
}
Also used : GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) GroupMembershipKey(com.linkedin.restli.examples.groups.api.GroupMembershipKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey)

Example 8 with GroupMembershipKey

use of com.linkedin.restli.examples.groups.api.GroupMembershipKey in project rest.li by linkedin.

the class GroupMembershipsResource3 method fromGroupMembership.

private static ComplexKeyGroupMembership fromGroupMembership(GroupMembership groupMembership) {
    if (groupMembership == null) {
        return null;
    }
    ComplexKeyGroupMembership complexKeyGroupMembership = new ComplexKeyGroupMembership(groupMembership.data());
    GroupMembershipKey groupMembershipKey = new GroupMembershipKey();
    groupMembershipKey.setGroupID(groupMembership.getGroupID());
    groupMembershipKey.setMemberID(groupMembership.getMemberID());
    complexKeyGroupMembership.setId(groupMembershipKey);
    return complexKeyGroupMembership;
}
Also used : GroupMembershipKey(com.linkedin.restli.examples.groups.api.GroupMembershipKey) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership)

Aggregations

GroupMembershipKey (com.linkedin.restli.examples.groups.api.GroupMembershipKey)8 ComplexKeyGroupMembership (com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership)5 GroupMembershipParam (com.linkedin.restli.examples.groups.api.GroupMembershipParam)5 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)4 CompoundKey (com.linkedin.restli.common.CompoundKey)2 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)2 Test (org.testng.annotations.Test)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)1 RestliRequestOptions (com.linkedin.restli.client.RestliRequestOptions)1 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 EntityResponse (com.linkedin.restli.common.EntityResponse)1 GroupMembership (com.linkedin.restli.examples.groups.api.GroupMembership)1 GroupMembershipQueryParam (com.linkedin.restli.examples.groups.api.GroupMembershipQueryParam)1 GroupMembershipQueryParamArray (com.linkedin.restli.examples.groups.api.GroupMembershipQueryParamArray)1 GroupMembershipsComplexRequestBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsComplexRequestBuilders)1 BatchResult (com.linkedin.restli.server.BatchResult)1 CreateResponse (com.linkedin.restli.server.CreateResponse)1 HashMap (java.util.HashMap)1