use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGroupsRequestBuilders method testSubResourceCreate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestContactsBuilderDataProviderNonEntity")
public void testSubResourceCreate(URIDetails expectedURIDetails) throws IOException, RestException {
GroupContact contact = new GroupContact();
contact.setContactID(3);
contact.setGroupID(1);
contact.setMemberID(3);
contact.setFirstName("Laura");
contact.setLastName("Smith");
contact.setIsPreapproved(true);
contact.setIsInvited(true);
Request<EmptyRecord> oldRequest = new ContactsBuilders().create().groupIdKey(1).input(contact).build();
checkRequestBuilder(oldRequest, ResourceMethod.CREATE, CreateResponseDecoder.class, expectedURIDetails, contact);
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestComplexKeysResource method testBatchDeleteMain.
private void testBatchDeleteMain(RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> requestBuilder, RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, EmptyRecord> createRequestBuilder, BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGetRequestBuilder) throws RemoteInvocationException {
String messageText = "m1";
Message message = new Message();
message.setMessage(messageText);
Request<EmptyRecord> createRequest = createRequestBuilder.input(message).build();
ResponseFuture<EmptyRecord> createFuture = getClient().sendRequest(createRequest);
Response<EmptyRecord> createResponse = createFuture.getResponse();
Assert.assertEquals(createResponse.getStatus(), 201);
String messageText2 = "m2";
message.setMessage(messageText2);
createRequest = createRequestBuilder.input(message).build();
createFuture = getClient().sendRequest(createRequest);
createResponse = createFuture.getResponse();
Assert.assertEquals(createResponse.getStatus(), 201);
ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(messageText, messageText);
ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(messageText2, messageText2);
ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>> ids = new ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>>();
ids.add(key1);
ids.add(key2);
final Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> request = requestBuilder.ids(ids).build();
final ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> future = getClient().sendRequest(request);
final BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> response = future.getResponse().getEntity();
for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> resp : response.getResults().entrySet()) {
Assert.assertEquals(resp.getValue().getStatus().intValue(), 204);
}
Assert.assertNotNull(response.getResults().get(key1));
Assert.assertNotNull(response.getResults().get(key2));
Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetRequest = batchGetRequestBuilder.ids(ids).build();
ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetFuture = getClient().sendRequest(batchGetRequest);
BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> batchGetResponse = batchGetFuture.getResponse().getEntity();
Assert.assertEquals(batchGetResponse.getResults().size(), batchGetResponse.getErrors().size());
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGreetingClientContentTypes method testUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataDataProvider")
public void testUpdate(RestClient restClient, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException {
// GET
Request<Greeting> request = builders.get().id(1L).build();
Response<Greeting> greetingResponse1 = restClient.sendRequest(request).getResponse();
String response1 = greetingResponse1.getEntity().getMessage();
Assert.assertNotNull(response1);
// POST
Greeting greeting = new Greeting(greetingResponse1.getEntity().data().copy());
greeting.setMessage(response1 + "Again");
Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).build();
Response<EmptyRecord> updateResponse = restClient.sendRequest(writeRequest).getResponse();
Assert.assertNull(updateResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE));
// GET again, to verify that our POST worked.
Request<Greeting> request2 = builders.get().id(1L).build();
Response<Greeting> greetingResponse2 = restClient.sendRequest(request2).getResponse();
String response2 = greetingResponse2.getEntity().getMessage();
Assert.assertEquals(response2, response1 + "Again");
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGreetingClientContentTypes method testPostsWithCharset.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testPostsWithCharset(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Request<Greeting> request = builders.<Greeting>action("SomeAction").id(1L).setActionParam("A", 1).setActionParam("B", "").setActionParam("C", new TransferOwnershipRequest()).setActionParam("D", new TransferOwnershipRequest()).setActionParam("E", 3).setHeader("Content-Type", "application/json; charset=UTF-8").build();
Response<Greeting> response = getClient().sendRequest(request).getResponse();
Greeting actionGreeting = response.getEntity();
Assert.assertEquals(actionGreeting.getMessage(), "This is a newly created greeting");
Greeting createGreeting = new Greeting();
createGreeting.setMessage("Hello there!");
createGreeting.setTone(Tone.FRIENDLY);
Request<EmptyRecord> createRequest = builders.create().input(createGreeting).setHeader("Content-Type", "application/json; charset=UTF-8").build();
Response<EmptyRecord> emptyRecordResponse = getClient().sendRequest(createRequest).getResponse();
Assert.assertNull(emptyRecordResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE));
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestCustomTypesClient method testCollectionCreate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreate(RestliRequestOptions requestOptions) throws RemoteInvocationException {
CreateRequest<Greeting> request = new CustomTypes2Builders(requestOptions).create().input(new Greeting().setId(10)).build();
Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("unchecked") CreateResponse<CustomLong> createResponse = (CreateResponse<CustomLong>) response.getEntity();
Assert.assertEquals(createResponse.getId(), new CustomLong(10L));
}
Aggregations