Search in sources :

Example 6 with GroupMembershipParam

use of com.linkedin.restli.examples.groups.api.GroupMembershipParam 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 7 with GroupMembershipParam

use of com.linkedin.restli.examples.groups.api.GroupMembershipParam 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<GroupMembershipKey, GroupMembershipParam>(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 GroupMembershipParam

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

the class TestGroupsClient method testDefaultValue.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProvider")
public void testDefaultValue(RootBuilderWrapper<Integer, Group> groupBuilders) throws RemoteInvocationException {
    // use server side default value for the RecordTemplate
    getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").build()).getResponse();
    try {
        // specifying an instance of the RecordTemplate which mismatches the default will fail the request
        final GroupMembershipParam newValue = new GroupMembershipParam();
        newValue.setIntParameter(0);
        newValue.setStringParameter("fail");
        getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").setQueryParam("record", newValue).build()).getResponse();
        Assert.fail("Expect exception when specifying the \"record\" query parameter different from the default");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), 500);
    }
}
Also used : GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 9 with GroupMembershipParam

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

the class TestGroupsClient method testComplexArrayParameter.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProvider")
public void testComplexArrayParameter(RootBuilderWrapper<Integer, Group> groupBuilders) throws RemoteInvocationException {
    final GroupMembershipParam elem = new GroupMembershipParam();
    elem.setIntParameter(7);
    elem.setStringParameter("success");
    final Collection<GroupMembershipParam> array = Arrays.asList(elem, elem);
    getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").setQueryParam("records", Arrays.asList(elem)).build()).getResponse();
    getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").setQueryParam("records", array).build()).getResponse();
    getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").setQueryParam("records", new GroupMembershipParamArray(array)).build()).getResponse();
    getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").addQueryParam("Records", elem).build()).getResponse();
    getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").addQueryParam("Records", elem).addQueryParam("Records", elem).build()).getResponse();
}
Also used : GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) GroupMembershipParamArray(com.linkedin.restli.examples.groups.api.GroupMembershipParamArray) Test(org.testng.annotations.Test)

Aggregations

GroupMembershipParam (com.linkedin.restli.examples.groups.api.GroupMembershipParam)9 Test (org.testng.annotations.Test)6 GroupMembershipKey (com.linkedin.restli.examples.groups.api.GroupMembershipKey)5 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)4 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)4 EmptyRecord (com.linkedin.restli.common.EmptyRecord)3 ComplexKeyGroupMembership (com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership)3 IdResponse (com.linkedin.restli.common.IdResponse)2 Group (com.linkedin.restli.examples.groups.api.Group)2 GroupMembershipsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders)2 GroupsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupsRequestBuilders)2 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)2 RestliRequestOptions (com.linkedin.restli.client.RestliRequestOptions)1 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1 EntityResponse (com.linkedin.restli.common.EntityResponse)1 GroupMembershipParamArray (com.linkedin.restli.examples.groups.api.GroupMembershipParamArray)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