Search in sources :

Example 1 with GroupMembershipsRequestBuilders

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

the class TestGroupsClient method testCollectionCreateGetUpdateDeleteId.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreateGetUpdateDeleteId(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    // find with optional params
    Group group = new Group();
    String name = "test";
    int memberID = 1;
    group.setName(name);
    group.setOwner(buildGroupMembership(memberID, "a@a.a", "f", "l"));
    GroupMembershipParam param = new GroupMembershipParam();
    param.setIntParameter(1);
    param.setStringParameter("String");
    final GroupsRequestBuilders groupBuilders = new GroupsRequestBuilders(requestOptions);
    final GroupMembershipsRequestBuilders membershipBuilders = new GroupMembershipsRequestBuilders(requestOptions);
    // Create
    Response<IdResponse<Integer>> response = getClient().sendRequest(groupBuilders.create().input(group).build()).getResponse();
    Assert.assertEquals(response.getStatus(), 201);
    Integer createdId = response.getEntity().getId();
    Assert.assertNotNull(createdId);
    @SuppressWarnings("deprecation") String stringId = response.getId();
    Assert.assertEquals(createdId.intValue(), Integer.parseInt(stringId));
    // Get newly created group and verify name
    Assert.assertEquals(getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse().getEntity().getName(), name);
    // Partial update - change name
    String newName = "new name";
    group.setName(newName);
    PatchRequest<Group> patch = PatchGenerator.diffEmpty(group);
    ResponseFuture<EmptyRecord> responseFuture = getClient().sendRequest(groupBuilders.partialUpdate().id(createdId).input(patch).build());
    Assert.assertEquals(204, responseFuture.getResponse().getStatus());
    // Get updated group and verify name
    Assert.assertEquals(getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse().getEntity().getName(), newName);
    // Delete
    responseFuture = getClient().sendRequest(groupBuilders.delete().id(createdId).build());
    Assert.assertEquals(204, responseFuture.getResponse().getStatus());
    // Verify deleted
    try {
        getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse();
        Assert.fail("Expected RestLiResponseException");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), 404);
    }
    // Cleanup - delete the owner's membership that was created along with the group
    responseFuture = getClient().sendRequest(membershipBuilders.delete().id(buildCompoundKey(memberID, createdId)).build());
    Assert.assertEquals(204, responseFuture.getResponse().getStatus());
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) EmptyRecord(com.linkedin.restli.common.EmptyRecord) IdResponse(com.linkedin.restli.common.IdResponse) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) GroupsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupsRequestBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 2 with GroupMembershipsRequestBuilders

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

the class TestGroupsClient method testCollectionCreateGetUpdateDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreateGetUpdateDelete(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    // find with optional params
    Group group = new Group();
    String name = "test";
    int memberID = 1;
    group.setName(name);
    group.setOwner(buildGroupMembership(memberID, "a@a.a", "f", "l"));
    GroupMembershipParam param = new GroupMembershipParam();
    param.setIntParameter(1);
    param.setStringParameter("String");
    final GroupsRequestBuilders groupBuilders = new GroupsRequestBuilders(requestOptions);
    final GroupMembershipsRequestBuilders membershipBuilders = new GroupMembershipsRequestBuilders(requestOptions);
    // Create
    Response<IdResponse<Integer>> response = getClient().sendRequest(groupBuilders.create().input(group).build()).getResponse();
    Assert.assertEquals(response.getStatus(), 201);
    @SuppressWarnings("unchecked") IdResponse<Integer> createResponse = response.getEntity();
    Assert.assertNotNull(createResponse.getId());
    @SuppressWarnings("deprecation") String stringId = response.getId();
    Assert.assertEquals(createResponse.getId().intValue(), Integer.parseInt(stringId));
    // Get newly created group and verify name
    Integer createdId = createResponse.getId();
    Assert.assertEquals(getClient().sendRequest(groupBuilders.get().id(createResponse.getId()).build()).getResponse().getEntity().getName(), name);
    // Partial update - change name
    String newName = "new name";
    group.setName(newName);
    PatchRequest<Group> patch = PatchGenerator.diffEmpty(group);
    ResponseFuture<EmptyRecord> responseFuture = getClient().sendRequest(groupBuilders.partialUpdate().id(createdId).input(patch).build());
    Assert.assertEquals(204, responseFuture.getResponse().getStatus());
    // Get updated group and verify name
    Assert.assertEquals(getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse().getEntity().getName(), newName);
    // Delete
    responseFuture = getClient().sendRequest(groupBuilders.delete().id(createdId).build());
    Assert.assertEquals(204, responseFuture.getResponse().getStatus());
    // Verify deleted
    try {
        getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse();
        Assert.fail("Expected RestLiResponseException");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), 404);
    }
    // Cleanup - delete the owner's membership that was created along with the group
    responseFuture = getClient().sendRequest(membershipBuilders.delete().id(buildCompoundKey(memberID, createdId)).build());
    Assert.assertEquals(204, responseFuture.getResponse().getStatus());
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) EmptyRecord(com.linkedin.restli.common.EmptyRecord) IdResponse(com.linkedin.restli.common.IdResponse) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) GroupsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupsRequestBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 3 with GroupMembershipsRequestBuilders

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

the class TestGroupsRequestBuilders method testAssociationBatchGetEntityByAssociationMultipleCompoundKeys2.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBatchDataProvider")
public void testAssociationBatchGetEntityByAssociationMultipleCompoundKeys2(URIDetails expectedURIDetails) throws IOException, RestException, URISyntaxException {
    GroupMembershipsBuilders.Key key1 = new GroupMembershipsBuilders.Key().setGroupId(1).setMemberId(1);
    GroupMembershipsBuilders.Key key2 = new GroupMembershipsBuilders.Key().setGroupId(2).setMemberId(1);
    GroupMembershipsBuilders.Key key3 = new GroupMembershipsBuilders.Key().setGroupId(2).setMemberId(2);
    Request<BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>>> request = new GroupMembershipsRequestBuilders().batchGet().ids(key1, key2, key3).build();
    checkRequestBuilder(request, ResourceMethod.BATCH_GET, BatchEntityResponseDecoder.class, expectedURIDetails, null);
}
Also used : GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) GroupMembershipsBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsBuilders) CompoundKey(com.linkedin.restli.common.CompoundKey) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 4 with GroupMembershipsRequestBuilders

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

the class TestGroupsRequestBuilders method requestMembershipsBuilderDataProviderEntity.

@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProviderEntity")
private static Object[][] requestMembershipsBuilderDataProviderEntity() {
    //Sample URIs:
    //"groupMemberships/groupID=7&memberID=1"
    //"groupMemberships/(groupID:7,memberID:1)"
    final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "groupMemberships/groupID=7&memberID=1", null, null, null);
    final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "groupMemberships/(groupID:7,memberID:1)", null, null, null);
    return new Object[][] { { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsBuilders()), uriDetails1 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsBuilders()), uriDetails2 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsRequestBuilders()), uriDetails1 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsRequestBuilders()), uriDetails2 } };
}
Also used : URIDetails(com.linkedin.restli.internal.testutils.URIDetails) CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) GroupMembershipsBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsBuilders) DataProvider(org.testng.annotations.DataProvider)

Example 5 with GroupMembershipsRequestBuilders

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

the class TestGroupsRequestBuilders method requestMembershipsBuilderDataProviderEntityFinderByGroupWithOptional.

@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProviderEntityFinderByGroupWithOptional")
private static Object[][] requestMembershipsBuilderDataProviderEntityFinderByGroupWithOptional() {
    //Sample URIs:
    //"groupMemberships/groupID=1?firstName=Bruce&q=group"
    //"groupMemberships/(groupID:1)?firstName=Bruce&q=group"
    final Map<String, String> queryParamsMap = new HashMap<String, String>();
    queryParamsMap.put("firstName", "Bruce");
    queryParamsMap.put("q", "group");
    final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "groupMemberships/groupID=1", null, queryParamsMap, null);
    final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "groupMemberships/(groupID:1)", null, queryParamsMap, null);
    return new Object[][] { { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsBuilders()), uriDetails1 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsBuilders()), uriDetails2 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsRequestBuilders()), uriDetails1 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsRequestBuilders()), uriDetails2 } };
}
Also used : URIDetails(com.linkedin.restli.internal.testutils.URIDetails) HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) GroupMembershipsBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsBuilders) DataProvider(org.testng.annotations.DataProvider)

Aggregations

GroupMembershipsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders)9 CompoundKey (com.linkedin.restli.common.CompoundKey)7 GroupMembership (com.linkedin.restli.examples.groups.api.GroupMembership)7 GroupMembershipsBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsBuilders)5 Test (org.testng.annotations.Test)5 URIDetails (com.linkedin.restli.internal.testutils.URIDetails)4 HashMap (java.util.HashMap)4 DataProvider (org.testng.annotations.DataProvider)4 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)3 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 EmptyRecord (com.linkedin.restli.common.EmptyRecord)2 EntityResponse (com.linkedin.restli.common.EntityResponse)2 IdResponse (com.linkedin.restli.common.IdResponse)2 ComplexKeyGroupMembership (com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership)2 Group (com.linkedin.restli.examples.groups.api.Group)2 GroupMembershipParam (com.linkedin.restli.examples.groups.api.GroupMembershipParam)2 GroupsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupsRequestBuilders)2 RestliRequestOptions (com.linkedin.restli.client.RestliRequestOptions)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1 PatchRequest (com.linkedin.restli.common.PatchRequest)1