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);
}
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);
}
}
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);
}
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");
}
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);
}
Aggregations