Search in sources :

Example 51 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestGreetingsClient method testSearchWithPostFilter.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderWithResourceNameDataProvider")
public void testSearchWithPostFilter(RootBuilderWrapper<Long, Greeting> builders, String resourceName, ProtocolVersion protocolVersion) throws RemoteInvocationException {
    Request<CollectionResponse<Greeting>> findRequest = builders.findBy("SearchWithPostFilter").paginate(0, 5).build();
    CollectionResponse<Greeting> entity = getClient().sendRequest(findRequest).getResponse().getEntity();
    CollectionMetadata paging = entity.getPaging();
    Assert.assertEquals(paging.getStart().intValue(), 0);
    Assert.assertEquals(paging.getCount().intValue(), 5);
    // expected to be 4 instead of 5 because of post filter
    Assert.assertEquals(entity.getElements().size(), 4);
    // to accommodate post filtering, even though 4 are returned, next page should be 5-10.
    Link next = paging.getLinks().get(0);
    Assert.assertEquals(next.getRel(), "next");
    //Query parameter order is non deterministic
    //"/" + resourceName + "?count=5&start=5&q=searchWithPostFilter";
    final Map<String, String> queryParamsMap = new HashMap<String, String>();
    queryParamsMap.put("count", "5");
    queryParamsMap.put("start", "5");
    queryParamsMap.put("q", "searchWithPostFilter");
    final URIDetails uriDetails = new URIDetails(protocolVersion, "/" + resourceName, null, queryParamsMap, null);
    URIDetails.testUriGeneration(next.getHref(), uriDetails);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) URIDetails(com.linkedin.restli.internal.testutils.URIDetails) HashMap(java.util.HashMap) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Link(com.linkedin.restli.common.Link) Test(org.testng.annotations.Test)

Example 52 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestGreetingsClient method testSearchFacets.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testSearchFacets(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Request<CollectionResponse<Greeting>> req = builders.findBy("SearchWithFacets").setQueryParam("tone", Tone.SINCERE).build();
    ResponseFuture<CollectionResponse<Greeting>> future = getClient().sendRequest(req);
    Response<CollectionResponse<Greeting>> response = future.getResponse();
    SearchMetadata metadata = new SearchMetadata(response.getEntity().getMetadataRaw());
    Assert.assertTrue(metadata.getFacets().size() > 0);
// "randomly" generated data is guaranteed to have positive number of each tone
}
Also used : CollectionResponse(com.linkedin.restli.common.CollectionResponse) SearchMetadata(com.linkedin.restli.examples.greetings.api.SearchMetadata) Test(org.testng.annotations.Test)

Example 53 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestGreetingsClient method testSearchWithTones.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testSearchWithTones(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Request<CollectionResponse<Greeting>> req = builders.findBy("SearchWithTones").setQueryParam("tones", Arrays.asList(Tone.SINCERE, Tone.INSULTING)).build();
    ResponseFuture<CollectionResponse<Greeting>> future = getClient().sendRequest(req);
    Response<CollectionResponse<Greeting>> response = future.getResponse();
    List<Greeting> greetings = response.getEntity().getElements();
    for (Greeting greeting : greetings) {
        Assert.assertTrue(greeting.hasTone());
        Tone tone = greeting.getTone();
        Assert.assertTrue(Tone.SINCERE.equals(tone) || Tone.INSULTING.equals(tone));
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) Tone(com.linkedin.restli.examples.greetings.api.Tone) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 54 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestGreetingsClient method TestPagination.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void TestPagination(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Request<CollectionResponse<Greeting>> findRequest = builders.findBy("SearchWithPostFilter").paginateStart(1).build();
    CollectionResponse<Greeting> entity = getClient().sendRequest(findRequest).getResponse().getEntity();
    CollectionMetadata paging = entity.getPaging();
    Assert.assertEquals(paging.getStart().intValue(), 1);
    Assert.assertEquals(paging.getCount().intValue(), 10);
    // expected to be 9 instead of 10 because of post filter
    Assert.assertEquals(entity.getElements().size(), 9);
    findRequest = builders.findBy("SearchWithPostFilter").paginateCount(5).build();
    entity = getClient().sendRequest(findRequest).getResponse().getEntity();
    paging = entity.getPaging();
    Assert.assertEquals(paging.getStart().intValue(), 0);
    Assert.assertEquals(paging.getCount().intValue(), 5);
    // expected to be 4 instead of 5 because of post filter
    Assert.assertEquals(entity.getElements().size(), 4);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 55 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestGroupsClient method testAssociationBatchCreateGetUpdatePatchDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProvider")
public void testAssociationBatchCreateGetUpdatePatchDelete(ProtocolVersion version, RootBuilderWrapper<CompoundKey, GroupMembership> membershipBuilders) throws RemoteInvocationException {
    // Setup - batch create two group memberships
    CompoundKey key1 = buildCompoundKey(1, 1);
    CompoundKey key2 = buildCompoundKey(2, 1);
    GroupMembership groupMembership1 = buildGroupMembership(null, "alfred@test.linkedin.com", "Alfred", "Hitchcock");
    GroupMembership groupMembership2 = buildGroupMembership(null, "bruce@test.linkedin.com", "Bruce", "Willis");
    Map<CompoundKey, UpdateStatus> results = getClient().sendRequest(membershipBuilders.batchUpdate().input(key1, groupMembership1).input(key2, groupMembership2).build()).getResponse().getEntity().getResults();
    Assert.assertEquals(results.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(results.get(key2).getStatus().intValue(), 204);
    // BatchGet memberships
    final RestliRequestOptions requestOptions = membershipBuilders.getRequestOptions();
    Request<BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>>> request = new GroupMembershipsRequestBuilders(requestOptions).batchGet().ids(key1, key2).fields(GroupMembership.fields().contactEmail()).build();
    Map<CompoundKey, EntityResponse<GroupMembership>> groupMemberships = getClient().sendRequest(request).getResponse().getEntity().getResults();
    Assert.assertTrue(groupMemberships.containsKey(key1));
    Assert.assertEquals(groupMemberships.get(key1).getEntity().getContactEmail(), "alfred@test.linkedin.com");
    Assert.assertTrue(groupMemberships.containsKey(key2));
    Assert.assertEquals(groupMemberships.get(key2).getEntity().getContactEmail(), "bruce@test.linkedin.com");
    // Batch partial update
    GroupMembership patchedGroupMembership1 = buildGroupMembership(null, "ALFRED@test.linkedin.com", "ALFRED", "Hitchcock");
    GroupMembership patchedGroupMembership2 = buildGroupMembership(null, "BRUCE@test.linkedin.com", "BRUCE", "Willis");
    Map<CompoundKey, PatchRequest<GroupMembership>> patchInputs = new HashMap<CompoundKey, PatchRequest<GroupMembership>>();
    patchInputs.put(key1, PatchGenerator.diff(groupMembership1, patchedGroupMembership1));
    patchInputs.put(key2, PatchGenerator.diff(groupMembership2, patchedGroupMembership2));
    Map<CompoundKey, UpdateStatus> patchResults = getClient().sendRequest(membershipBuilders.batchPartialUpdate().patchInputs(patchInputs).build()).getResponse().getEntity().getResults();
    Assert.assertEquals(patchResults.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(patchResults.get(key2).getStatus().intValue(), 204);
    // Batch get to make sure our patch applied
    Request<BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>>> batchGetRequest = new GroupMembershipsRequestBuilders(requestOptions).batchGet().ids(key1, key2).fields(GroupMembership.fields().contactEmail(), GroupMembership.fields().firstName()).build();
    BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>> entity = getClient().sendRequest(batchGetRequest).getResponse().getEntity();
    Assert.assertEquals(entity.getErrors().size(), 0);
    Assert.assertEquals(entity.getResults().size(), 2);
    Assert.assertEquals(entity.getResults().get(key1).getEntity().getContactEmail(), "ALFRED@test.linkedin.com");
    Assert.assertEquals(entity.getResults().get(key1).getEntity().getFirstName(), "ALFRED");
    Assert.assertEquals(entity.getResults().get(key2).getEntity().getContactEmail(), "BRUCE@test.linkedin.com");
    Assert.assertEquals(entity.getResults().get(key2).getEntity().getFirstName(), "BRUCE");
    // GetAll memberships
    Request<CollectionResponse<GroupMembership>> getAllRequest = membershipBuilders.getAll().paginate(1, 2).fields(GroupMembership.fields().contactEmail()).build();
    List<GroupMembership> elements = getClient().sendRequest(getAllRequest).getResponse().getEntity().getElements();
    Assert.assertEquals(elements.size(), 1);
    // Delete the newly created group memberships
    Map<CompoundKey, UpdateStatus> deleteResult = getClient().sendRequest(membershipBuilders.batchDelete().ids(key1, key2).build()).getResponse().getEntity().getResults();
    Assert.assertEquals(deleteResult.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(deleteResult.get(key2).getStatus().intValue(), 204);
    // Make sure they are gone
    BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>> getResponse = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertEquals(getResponse.getResults().size(), getResponse.getErrors().size());
    Assert.assertTrue(getResponse.getErrors().containsKey(key1));
    Assert.assertTrue(getResponse.getErrors().containsKey(key2));
    Assert.assertEquals(getResponse.getErrors().get(key1).getStatus().intValue(), 404);
    Assert.assertEquals(getResponse.getErrors().get(key2).getStatus().intValue(), 404);
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) RestliRequestOptions(com.linkedin.restli.client.RestliRequestOptions) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) CollectionResponse(com.linkedin.restli.common.CollectionResponse) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) Test(org.testng.annotations.Test)

Aggregations

CollectionResponse (com.linkedin.restli.common.CollectionResponse)85 Test (org.testng.annotations.Test)77 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)58 CreateStatus (com.linkedin.restli.common.CreateStatus)11 ArrayList (java.util.ArrayList)7 DataMap (com.linkedin.data.DataMap)6 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)6 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)5 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)5 UpdateStatus (com.linkedin.restli.common.UpdateStatus)5 HttpStatus (com.linkedin.restli.common.HttpStatus)4 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)4 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)4 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)4 HashMap (java.util.HashMap)4 RestResponse (com.linkedin.r2.message.rest.RestResponse)3 Link (com.linkedin.restli.common.Link)3 Message (com.linkedin.restli.examples.greetings.api.Message)3 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)3 URIDetails (com.linkedin.restli.internal.testutils.URIDetails)3