Search in sources :

Example 1 with GroupsRequestBuilders

use of com.linkedin.restli.examples.groups.client.GroupsRequestBuilders 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 GroupsRequestBuilders

use of com.linkedin.restli.examples.groups.client.GroupsRequestBuilders 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 GroupsRequestBuilders

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

the class TestGroupsRequestBuilders method testEntityCreateId.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProviderNonEntity")
public void testEntityCreateId(URIDetails expectedURIDetails) throws IOException, RestException {
    CreateIdRequest<Integer, Group> request = new GroupsRequestBuilders().create().input(new Group()).build();
    checkRequestBuilder(request, ResourceMethod.CREATE, IdResponseDecoder.class, expectedURIDetails, new Group());
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) GroupsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupsRequestBuilders) Test(org.testng.annotations.Test)

Example 4 with GroupsRequestBuilders

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

the class TestGroupsRequestBuilders method requestGroupsBuilderDataProviderSearchWithOptional1.

@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProviderSearchWithOptional1")
private static Object[][] requestGroupsBuilderDataProviderSearchWithOptional1() {
    //Sample URIs:
    //"groups?keywords=linkedin&q=search"
    //"groups?keywords=linkedin&q=search"
    final Map<String, String> queryParamsMap = new HashMap<String, String>();
    queryParamsMap.put("keywords", "linkedin");
    queryParamsMap.put("q", "search");
    final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "groups", null, queryParamsMap, null);
    final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "groups", null, queryParamsMap, null);
    return new Object[][] { { new RootBuilderWrapper<Integer, Group>(new GroupsBuilders()), uriDetails1 }, { new RootBuilderWrapper<Integer, Group>(new GroupsBuilders()), uriDetails2 }, { new RootBuilderWrapper<Integer, Group>(new GroupsRequestBuilders()), uriDetails1 }, { new RootBuilderWrapper<Integer, Group>(new GroupsRequestBuilders()), uriDetails2 } };
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) URIDetails(com.linkedin.restli.internal.testutils.URIDetails) GroupsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupsRequestBuilders) HashMap(java.util.HashMap) GroupsBuilders(com.linkedin.restli.examples.groups.client.GroupsBuilders) DataProvider(org.testng.annotations.DataProvider)

Example 5 with GroupsRequestBuilders

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

the class TestGroupsRequestBuilders method requestGroupsBuilderDataProviderSearch.

@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProviderSearch")
private static Object[][] requestGroupsBuilderDataProviderSearch() {
    //Sample URIs:
    //"groups?groupID=1&keywords=linkedin&nameKeywords=test&q=search"
    //"groups?groupID=1&keywords=linkedin&nameKeywords=test&q=search"
    final Map<String, String> queryParamsMap = new HashMap<String, String>();
    queryParamsMap.put("groupID", "1");
    queryParamsMap.put("keywords", "linkedin");
    queryParamsMap.put("nameKeywords", "test");
    queryParamsMap.put("q", "search");
    final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "groups", null, queryParamsMap, null);
    final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "groups", null, queryParamsMap, null);
    return new Object[][] { { new RootBuilderWrapper<Integer, Group>(new GroupsBuilders()), uriDetails1 }, { new RootBuilderWrapper<Integer, Group>(new GroupsBuilders()), uriDetails2 }, { new RootBuilderWrapper<Integer, Group>(new GroupsRequestBuilders()), uriDetails1 }, { new RootBuilderWrapper<Integer, Group>(new GroupsRequestBuilders()), uriDetails2 } };
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) URIDetails(com.linkedin.restli.internal.testutils.URIDetails) GroupsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupsRequestBuilders) HashMap(java.util.HashMap) GroupsBuilders(com.linkedin.restli.examples.groups.client.GroupsBuilders) DataProvider(org.testng.annotations.DataProvider)

Aggregations

Group (com.linkedin.restli.examples.groups.api.Group)13 GroupsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupsRequestBuilders)13 GroupsBuilders (com.linkedin.restli.examples.groups.client.GroupsBuilders)10 URIDetails (com.linkedin.restli.internal.testutils.URIDetails)10 DataProvider (org.testng.annotations.DataProvider)10 HashMap (java.util.HashMap)7 Test (org.testng.annotations.Test)3 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 EmptyRecord (com.linkedin.restli.common.EmptyRecord)2 IdResponse (com.linkedin.restli.common.IdResponse)2 GroupMembershipParam (com.linkedin.restli.examples.groups.api.GroupMembershipParam)2 GroupMembershipsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders)2 HashSet (java.util.HashSet)2 GroupContact (com.linkedin.restli.examples.groups.api.GroupContact)1 ContactsBuilders (com.linkedin.restli.examples.groups.client.ContactsBuilders)1 ContactsRequestBuilders (com.linkedin.restli.examples.groups.client.ContactsRequestBuilders)1