Search in sources :

Example 6 with CollectionResponse

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

the class TestGreetingsClient method testGetAll.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testGetAll(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    List<Greeting> greetings = generateBatchTestData(3, "GetAll", Tone.FRIENDLY);
    @SuppressWarnings("unchecked") List<Long> createdIds = createBatchTestDataSerially(builders, greetings);
    addIdsToGeneratedGreetings(createdIds, greetings);
    Request<CollectionResponse<Greeting>> getAllRequest = builders.getAll().build();
    List<Greeting> getAllReturnedGreetings = getClient().sendRequest(getAllRequest).getResponse().getEntity().getElements();
    // the current implementation of getAll should return all those Greetings with the String "GetAll"
    // in them. Thus, fetchedGreetings and getAllGreetings should be the same
    Assert.assertEquals(getAllReturnedGreetings.size(), greetings.size());
    for (int i = 0; i < greetings.size(); i++) {
        Greeting getAllReturnedGreeting = getAllReturnedGreetings.get(i);
        Greeting greeting = greetings.get(i);
        // Make sure the types of the fetched Greeting match the types in the schema. This happens as a side effect of the
        // validate method
        // This is why we can't do Assert.assertEquals(getAllReturnedGreetings, greetings) directly
        ValidateDataAgainstSchema.validate(getAllReturnedGreeting.data(), getAllReturnedGreeting.schema(), new ValidationOptions());
        Assert.assertEquals(getAllReturnedGreeting, greeting);
    }
    deleteAndVerifyBatchTestDataSerially(builders, createdIds);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) ValidationOptions(com.linkedin.data.schema.validation.ValidationOptions) Test(org.testng.annotations.Test)

Example 7 with CollectionResponse

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

the class TestGreetingsClientAcceptTypes method testFinder.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataDataProvider")
public void testFinder(RestClient restClient, String expectedContentType, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Request<CollectionResponse<Greeting>> request = builders.findBy("Search").setQueryParam("tone", Tone.SINCERE).paginate(1, 2).build();
    Response<CollectionResponse<Greeting>> response = restClient.sendRequest(request).getResponse();
    Assert.assertEquals(response.getHeader("Content-Type"), expectedContentType);
    CollectionResponse<Greeting> collectionResponse = response.getEntity();
    List<Greeting> greetings = collectionResponse.getElements();
    for (Greeting g : greetings) {
        Assert.assertEquals(g.getTone(), Tone.SINCERE);
    }
    collectionResponse.getPaging().getLinks();
    for (Link link : collectionResponse.getPaging().getLinks()) {
        Assert.assertEquals(link.getType(), expectedContentType);
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Link(com.linkedin.restli.common.Link) Test(org.testng.annotations.Test)

Example 8 with CollectionResponse

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

the class TestGroupsClient method testComplexKeyBatchCreateGetUpdateDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestComplexBuilderDataProvider")
public void testComplexKeyBatchCreateGetUpdateDelete(ProtocolVersion version, RootBuilderWrapper<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> builders) throws RemoteInvocationException {
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey1 = buildComplexKey(1, 1, 10, "String1");
    ComplexKeyGroupMembership groupMembership1 = buildComplexKeyGroupMembership(complexKey1.getKey(), "alfred@test.linkedin.com", "alfred", "hitchcock");
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey2 = buildComplexKey(2, 1, 20, "String2");
    ComplexKeyGroupMembership groupMembership2 = buildComplexKeyGroupMembership(complexKey2.getKey(), "bruce@test.linkedin.com", "bruce", "willis");
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey3 = buildComplexKey(3, 1, 30, "String3");
    ComplexKeyGroupMembership groupMembership3 = buildComplexKeyGroupMembership(complexKey3.getKey(), "carole@test.linkedin.com", "carole", "bouquet");
    Request<CollectionResponse<CreateStatus>> createRequest = builders.batchCreate().input(groupMembership1).input(groupMembership2).input(groupMembership3).build();
    Response<CollectionResponse<CreateStatus>> createResponse = getClient().sendRequest(createRequest).getResponse();
    Assert.assertEquals(createResponse.getStatus(), 200);
    final RestliRequestOptions requestOptions = builders.getRequestOptions();
    @SuppressWarnings("unchecked") Request<BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>>> request = new GroupMembershipsComplexRequestBuilders(requestOptions).batchGet().ids(complexKey1, complexKey2, complexKey3).fields(GroupMembership.fields().contactEmail()).build();
    BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>> groupMemberships = getClient().sendRequest(request).getResponse().getEntity();
    Map<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>> results = groupMemberships.getResults();
    ComplexKeyGroupMembership groupMembership1_ = results.get(complexKey1).getEntity();
    ComplexKeyGroupMembership groupMembership2_ = results.get(complexKey2).getEntity();
    ComplexKeyGroupMembership groupMembership3_ = results.get(complexKey3).getEntity();
    Assert.assertNotNull(groupMembership1_);
    Assert.assertEquals(groupMembership1_.getContactEmail(), "alfred@test.linkedin.com");
    Assert.assertNotNull(groupMembership2_);
    Assert.assertEquals(groupMembership2_.getContactEmail(), "bruce@test.linkedin.com");
    Assert.assertNotNull(groupMembership3_);
    Assert.assertEquals(groupMembership3_.getContactEmail(), "carole@test.linkedin.com");
    // Update and verify
    groupMembership1.setContactEmail("alfred+@test.linkedin.com");
    groupMembership2.setContactEmail("bruce+@test.linkedin.com");
    groupMembership3.setContactEmail("carole+@test.linkedin.com");
    Request<BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, UpdateStatus>> updateRequest = builders.batchUpdate().input(complexKey1, groupMembership1).input(complexKey2, groupMembership2).input(complexKey3, groupMembership3).build();
    int status = getClient().sendRequest(updateRequest).getResponse().getStatus();
    Assert.assertEquals(status, 200);
}
Also used : RestliRequestOptions(com.linkedin.restli.client.RestliRequestOptions) GroupMembershipsComplexRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsComplexRequestBuilders) GroupMembershipKey(com.linkedin.restli.examples.groups.api.GroupMembershipKey) CollectionResponse(com.linkedin.restli.common.CollectionResponse) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) EntityResponse(com.linkedin.restli.common.EntityResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) Test(org.testng.annotations.Test)

Example 9 with CollectionResponse

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

the class TestPagingProjection method testMetadataAutomaticPagingFullyAutomaticSingleMetaPagingTotal.

/**
   * Calls the resource method metadataAutomaticPagingFullyAutomatic with a single metadata field and a single paging
   * field for 'total'.
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testMetadataAutomaticPagingFullyAutomaticSingleMetaPagingTotal(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.findBy("metadataAutomaticPagingFullyAutomatic").metadataFields(Greeting.fields().message()).pagingFields(CollectionMetadata.fields().total()).build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    assertGreeting(metadataGreeting, false, /*hasTone*/
    true, /*hasMessage*/
    false);
    Assert.assertTrue(response.getEntity().hasPaging(), "We must have paging!");
    assertPaging(response.getEntity().getPaging(), true, /*hasTotal*/
    false, /*hasStart*/
    false, /*hasCount*/
    false);
    final int totalCount = response.getEntity().getPaging().getTotal();
    Assert.assertEquals(totalCount, 2, "We must have 2 in our count");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 10 with CollectionResponse

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

the class TestPagingProjection method testMetadataAutomaticPagingFullyAutomaticNoFields.

/**
   * Calls the resource method metadataAutomaticPagingFullyAutomatic without any projection fields specified
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testMetadataAutomaticPagingFullyAutomaticNoFields(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.findBy("metadataAutomaticPagingFullyAutomatic").metadataFields().pagingFields().build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    //nothing should be sent back for both below
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    assertGreeting(metadataGreeting, false, /*hasTone*/
    false, /*hasMessage*/
    false);
    assertPaging(response.getEntity().getPaging(), false, /*hasTotal*/
    false, /*hasStart*/
    false, /*hasCount*/
    false);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) 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