use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.
the class TestClientBuilders method testCrudBuilderParams8.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "noEntityWithParam")
public void testCrudBuilderParams8(URIDetails expectedURIDetails) {
Request<CollectionResponse<CreateStatus>> request = new BatchCreateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS).input(new TestRecord()).setParam("foo", "bar").build();
URIDetails.testUriGeneration(request, expectedURIDetails);
}
use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.
the class TestExamplesGenerator method validateCollectionResponse.
private <T extends RecordTemplate> ValidationResult validateCollectionResponse(RestResponse response, Class<T> recordClass, ValidationOptions options) throws IOException {
final DataMap respData = _codec.bytesToMap(response.getEntity().copyBytes());
final CollectionResponse<T> collResp = new CollectionResponse<T>(respData, recordClass);
final DataSchema recordSchema = DataTemplateUtil.getSchema(recordClass);
for (T record : collResp.getElements()) {
final ValidationResult valRet = ValidateDataAgainstSchema.validate(record.data(), recordSchema, options);
if (!valRet.isValid()) {
return valRet;
}
}
return null;
}
use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.
the class BatchCreateHelper method batchCreateOldBuilders.
private static <K, V extends RecordTemplate> List<CreateIdStatus<K>> batchCreateOldBuilders(RestClient restClient, BatchCreateRequestBuilder<K, V> builder, List<V> entities) throws RemoteInvocationException {
BatchCreateRequest<V> request = builder.inputs(entities).build();
Response<CollectionResponse<CreateStatus>> response = restClient.sendRequest(request).getResponse();
List<CreateStatus> elements = response.getEntity().getElements();
List<CreateIdStatus<K>> result = new ArrayList<CreateIdStatus<K>>(elements.size());
for (CreateStatus status : elements) {
@SuppressWarnings("unchecked") CreateIdStatus<K> createIdStatus = (CreateIdStatus<K>) status;
result.add(createIdStatus);
}
return result;
}
use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.
the class TestAssociationsResource method testSubresourceFinder.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubBuilderDataProvider")
public void testSubresourceFinder(RootBuilderWrapper<String, Message> builders) throws RemoteInvocationException {
Request<CollectionResponse<Message>> request = builders.findBy("Tone").setPathKey("dest", "dest").setPathKey("src", "src").setQueryParam("tone", Tone.FRIENDLY).build();
List<Message> messages = getClient().sendRequest(request).getResponse().getEntity().getElements();
for (Message message : messages) {
Assert.assertEquals(message.getTone(), Tone.FRIENDLY);
}
}
use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.
the class TestGreetingsClient method testOldCookbookInBatch.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testOldCookbookInBatch(RestliRequestOptions requestOptions) throws Exception {
final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
// GET
final BatchGetRequestBuilder<Long, Greeting> batchGetBuilder = builders.batchGet();
Request<BatchResponse<Greeting>> request = batchGetBuilder.ids(1L).build();
ResponseFuture<BatchResponse<Greeting>> future = getClient().sendRequest(request);
Response<BatchResponse<Greeting>> greetingResponse = future.getResponse();
// PUT
Greeting greeting = new Greeting(greetingResponse.getEntity().getResults().get("1").data().copy());
greeting.setMessage("This is a new message!");
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<BatchResponse<Greeting>> request2 = builders.batchGet().ids(1L).build();
ResponseFuture<BatchResponse<Greeting>> future2 = getClient().sendRequest(request2);
greetingResponse = future2.get();
Greeting repeatedGreeting = new Greeting();
repeatedGreeting.setMessage("Hello Hello");
repeatedGreeting.setTone(Tone.SINCERE);
Request<CollectionResponse<CreateStatus>> request3 = builders.batchCreate().inputs(Arrays.asList(repeatedGreeting, repeatedGreeting)).build();
CollectionResponse<CreateStatus> statuses = getClient().sendRequest(request3).getResponse().getEntity();
for (CreateStatus status : statuses.getElements()) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("deprecation") String id = status.getId();
Assert.assertNotNull(id);
}
}
Aggregations