use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGroupsClient method testAssociationCreateGetDelete.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProvider")
public void testAssociationCreateGetDelete(ProtocolVersion version, RootBuilderWrapper<CompoundKey, GroupMembership> membershipBuilders) throws RemoteInvocationException {
// Setup - create group memberships
CompoundKey key1 = buildCompoundKey(1, 1);
GroupMembership groupMembership1 = buildGroupMembership(null, "alfred@test.linkedin.com", "Alfred", "Hitchcock");
Response<EmptyRecord> response = getClient().sendRequest(membershipBuilders.update().id(key1).input(groupMembership1).build()).getResponse();
Assert.assertEquals(response.getStatus(), 204);
// Get membership
Request<GroupMembership> getRequest = membershipBuilders.get().id(key1).fields(GroupMembership.fields().contactEmail()).build();
GroupMembership groupMembership = getClient().sendRequest(getRequest).getResponse().getEntity();
Assert.assertEquals(groupMembership.getContactEmail(), "alfred@test.linkedin.com");
// Delete the newly created group membership
Response<EmptyRecord> deleteResponse = getClient().sendRequest(membershipBuilders.delete().id(key1).build()).getResponse();
Assert.assertEquals(deleteResponse.getStatus(), 204);
// Make sure it is gone
try {
getClient().sendRequest(getRequest).getResponse();
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), 404);
}
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGreetingsClient method createBatchTestDataSerially.
/**
* Creates batch data.
*
* @param greetings the greetings that we want to create
*
* @return the ids of the created Greetings
* @throws RemoteInvocationException
*/
private List<Long> createBatchTestDataSerially(RootBuilderWrapper<Long, Greeting> builders, List<Greeting> greetings) throws RemoteInvocationException {
List<Long> createdIds = new ArrayList<Long>();
for (Greeting greeting : greetings) {
RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> createBuilder = builders.create();
Long createdId;
if (createBuilder.isRestLi2Builder()) {
Object objBuilder = createBuilder.getBuilder();
@SuppressWarnings("unchecked") CreateIdRequestBuilder<Long, Greeting> createIdRequestBuilder = (CreateIdRequestBuilder<Long, Greeting>) objBuilder;
CreateIdRequest<Long, Greeting> request = createIdRequestBuilder.input(greeting).build();
Response<IdResponse<Long>> response = getClient().sendRequest(request).getResponse();
createdId = response.getEntity().getId();
} else {
Request<EmptyRecord> request = createBuilder.input(greeting).build();
Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
@SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
createdId = createResponse.getId();
}
createdIds.add(createdId);
}
return createdIds;
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGreetingsClientAcceptTypes method testUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataDataProvider")
public void testUpdate(RestClient restClient, String expectedContentType, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException {
// GET
Request<Greeting> request = builders.get().id(1L).build();
Response<Greeting> greetingResponse1 = restClient.sendRequest(request).getResponse();
Assert.assertEquals(greetingResponse1.getHeader("Content-Type"), expectedContentType);
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();
Assert.assertEquals(greetingResponse2.getHeader("Content-Type"), expectedContentType);
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 TestExceptionsResource3 method testUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
public void testUpdate(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws Exception {
Response<EmptyRecord> response = null;
RestLiResponseException exception = null;
try {
Request<EmptyRecord> request = builders.update().id(11L).input(new Greeting().setId(11L).setMessage("@#$%@!$%").setTone(Tone.INSULTING)).build();
ResponseFuture<EmptyRecord> future;
if (explicit) {
future = getClient().sendRequest(request, errorHandlingBehavior);
} else {
future = getClient().sendRequest(request);
}
response = future.getResponse();
if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR) {
Assert.fail("expected exception");
}
} catch (RestLiResponseException e) {
if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR) {
exception = e;
} else {
Assert.fail("not expected exception");
}
}
if (explicit && errorHandlingBehavior == ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS) {
Assert.assertNotNull(response);
Assert.assertTrue(response.hasError());
exception = response.getError();
Assert.assertEquals(response.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
Assert.assertNull(response.getEntity());
}
Assert.assertNotNull(exception);
Assert.assertTrue(exception.hasDecodedResponse());
Assert.assertEquals(exception.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestCustomCrudParams method testCookbookCrudParams.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testCookbookCrudParams(RootBuilderWrapper<Long, Greeting> builders) throws Exception {
try {
Request<Greeting> request = builders.get().id(1L).build();
ResponseFuture<Greeting> future = getClient().sendRequest(request);
@SuppressWarnings("unused") Response<Greeting> greetingResponse = future.getResponse();
Assert.fail("expected response exception");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getServiceErrorMessage(), "Invalid auth token");
}
// GET
Request<Greeting> request = builders.get().id(1L).setQueryParam("auth", "PLEASE").build();
ResponseFuture<Greeting> future = getClient().sendRequest(request);
Response<Greeting> greetingResponse = future.getResponse();
// POST
Greeting greeting = new Greeting(greetingResponse.getEntity().data().copy());
greeting.setMessage("This is a new message!");
Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).setQueryParam("auth", "PLEASE").build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<Greeting> request2 = builders.get().id(1L).setQueryParam("auth", "PLEASE").build();
ResponseFuture<Greeting> future2 = getClient().sendRequest(request2);
greetingResponse = future2.get();
Assert.assertEquals(greetingResponse.getEntity().getMessage(), "This is a new message!");
}
Aggregations