use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testSubCollectionCreate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testSubCollectionCreate(RestliRequestOptions requestOptions) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("Hello there!");
greeting.setTone(Tone.FRIENDLY);
final SubgreetingsBuilders builders = new SubgreetingsBuilders(requestOptions);
//POST
Request<EmptyRecord> createRequest = builders.create().input(greeting).build();
Response<EmptyRecord> response = getClient().sendRequest(createRequest).getResponse();
Assert.assertNull(response.getHeader(RestConstants.HEADER_CONTENT_TYPE));
@SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
long id = createResponse.getId();
@SuppressWarnings("deprecation") String stringId = response.getId();
Assert.assertEquals(id, Long.parseLong(stringId));
//GET again to verify that the create has worked.
Request<Greeting> getRequest = builders.get().id(id).build();
Response<Greeting> getResponse = getClient().sendRequest(getRequest).getResponse();
Greeting responseGreeting = getResponse.getEntity();
Assert.assertEquals(responseGreeting.getMessage(), greeting.getMessage());
Assert.assertEquals(responseGreeting.getTone(), greeting.getTone());
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGroupsClient method testComplexKeyCreateGetUpdateDelete.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestComplexBuilderDataProvider")
public void testComplexKeyCreateGetUpdateDelete(ProtocolVersion version, RootBuilderWrapper<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> builders) throws RemoteInvocationException {
// Create a new complex key resource
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey = buildComplexKey(1, 1, 10, "String1");
ComplexKeyGroupMembership groupMembership = buildComplexKeyGroupMembership(complexKey.getKey(), "alfred@test.linkedin.com", "alfred", "hitchcock");
Request<EmptyRecord> createRequest = builders.create().input(groupMembership).build();
Response<EmptyRecord> createResponse = getClient().sendRequest(createRequest).getResponse();
Assert.assertEquals(createResponse.getStatus(), 201);
GroupMembershipParam param = new GroupMembershipParam();
param.setIntParameter(1);
param.setStringParameter("1");
GroupMembershipQueryParam groupMembershipQueryParam1 = new GroupMembershipQueryParam();
groupMembershipQueryParam1.setIntParameter(1);
groupMembershipQueryParam1.setStringParameter("1");
GroupMembershipQueryParam groupMembershipQueryParam2 = new GroupMembershipQueryParam();
groupMembershipQueryParam2.setIntParameter(2);
groupMembershipQueryParam2.setStringParameter("2");
GroupMembershipQueryParamArray queryParamArray = new GroupMembershipQueryParamArray(Arrays.asList(groupMembershipQueryParam1, groupMembershipQueryParam2));
// Get the resource back and check state
Request<ComplexKeyGroupMembership> request = builders.get().id(complexKey).fields(GroupMembership.fields().contactEmail()).setQueryParam("testParam", param).setQueryParam("testParamArray", queryParamArray).build();
ComplexKeyGroupMembership groupMembership1 = getClient().sendRequest(request).getResponse().getEntity();
Assert.assertNotNull(groupMembership1);
Assert.assertEquals(groupMembership1.getContactEmail(), "alfred@test.linkedin.com");
// Test the same with optional complex parameters
request = builders.get().id(complexKey).fields(GroupMembership.fields().contactEmail()).build();
groupMembership1 = getClient().sendRequest(request).getResponse().getEntity();
Assert.assertNotNull(groupMembership1);
Assert.assertEquals(groupMembership1.getContactEmail(), "alfred@test.linkedin.com");
// Update contact email and verify
groupMembership.setContactEmail("alphred@test.linkedin.com");
Request<EmptyRecord> updateRequest = builders.update().id(complexKey).input(groupMembership).build();
Response<EmptyRecord> updateResponse = getClient().sendRequest(updateRequest).getResponse();
Assert.assertEquals(updateResponse.getStatus(), 204);
groupMembership1 = getClient().sendRequest(request).getResponse().getEntity();
Assert.assertEquals(groupMembership1.getContactEmail(), "alphred@test.linkedin.com");
// Delete and verify
Request<EmptyRecord> deleteRequest = builders.delete().id(complexKey).build();
Response<EmptyRecord> deleteResponse = getClient().sendRequest(deleteRequest).getResponse();
Assert.assertEquals(deleteResponse.getStatus(), 204);
try {
getClient().sendRequest(request).getResponse().getEntity();
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), 404);
}
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGroupsClient method testCollectionCreateGetUpdateDelete.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreateGetUpdateDelete(RestliRequestOptions requestOptions) throws RemoteInvocationException {
// find with optional params
Group group = new Group();
String name = "test";
int memberID = 1;
group.setName(name);
group.setOwner(buildGroupMembership(memberID, "a@a.a", "f", "l"));
GroupMembershipParam param = new GroupMembershipParam();
param.setIntParameter(1);
param.setStringParameter("String");
final GroupsRequestBuilders groupBuilders = new GroupsRequestBuilders(requestOptions);
final GroupMembershipsRequestBuilders membershipBuilders = new GroupMembershipsRequestBuilders(requestOptions);
// Create
Response<IdResponse<Integer>> response = getClient().sendRequest(groupBuilders.create().input(group).build()).getResponse();
Assert.assertEquals(response.getStatus(), 201);
@SuppressWarnings("unchecked") IdResponse<Integer> createResponse = response.getEntity();
Assert.assertNotNull(createResponse.getId());
@SuppressWarnings("deprecation") String stringId = response.getId();
Assert.assertEquals(createResponse.getId().intValue(), Integer.parseInt(stringId));
// Get newly created group and verify name
Integer createdId = createResponse.getId();
Assert.assertEquals(getClient().sendRequest(groupBuilders.get().id(createResponse.getId()).build()).getResponse().getEntity().getName(), name);
// Partial update - change name
String newName = "new name";
group.setName(newName);
PatchRequest<Group> patch = PatchGenerator.diffEmpty(group);
ResponseFuture<EmptyRecord> responseFuture = getClient().sendRequest(groupBuilders.partialUpdate().id(createdId).input(patch).build());
Assert.assertEquals(204, responseFuture.getResponse().getStatus());
// Get updated group and verify name
Assert.assertEquals(getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse().getEntity().getName(), newName);
// Delete
responseFuture = getClient().sendRequest(groupBuilders.delete().id(createdId).build());
Assert.assertEquals(204, responseFuture.getResponse().getStatus());
// Verify deleted
try {
getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse();
Assert.fail("Expected RestLiResponseException");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), 404);
}
// Cleanup - delete the owner's membership that was created along with the group
responseFuture = getClient().sendRequest(membershipBuilders.delete().id(buildCompoundKey(memberID, createdId)).build());
Assert.assertEquals(204, responseFuture.getResponse().getStatus());
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestNullGreetingsClient method testNullCreateResponse.
/*
* Tests for nulls in CreateResponse
*/
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testNullCreateResponse(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
//Forces the server to return a null CreateResponse
final RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> methodBuilderWrapper = builders.create();
final Greeting illGreeting = new Greeting().setMessage("nullCreateResponse").setTone(Tone.INSULTING);
createAndAssertNullMessages(methodBuilderWrapper, illGreeting);
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestNullGreetingsClient method testNullHttpStatusCreateResponse.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testNullHttpStatusCreateResponse(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
//Forces the server to return a valid CreateResponse but with a null HttpStatus inside of it
final RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> methodBuilderWrapper = builders.create();
final Greeting illGreeting = new Greeting().setMessage("nullHttpStatus").setTone(Tone.INSULTING);
createAndAssertNullMessages(methodBuilderWrapper, illGreeting);
}
Aggregations