use of com.linkedin.restli.client.RestLiResponseException 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.client.RestLiResponseException in project rest.li by linkedin.
the class TestGroupsClient method testCollectionCreateGetUpdateDeleteId.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreateGetUpdateDeleteId(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);
Integer createdId = response.getEntity().getId();
Assert.assertNotNull(createdId);
@SuppressWarnings("deprecation") String stringId = response.getId();
Assert.assertEquals(createdId.intValue(), Integer.parseInt(stringId));
// Get newly created group and verify name
Assert.assertEquals(getClient().sendRequest(groupBuilders.get().id(createdId).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.client.RestLiResponseException 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().setIntParameter(1).setStringParameter("1");
GroupMembershipQueryParam groupMembershipQueryParam1 = new GroupMembershipQueryParam().setIntParameter(1).setStringParameter("1");
GroupMembershipQueryParam groupMembershipQueryParam2 = new GroupMembershipQueryParam().setIntParameter(2).setStringParameter("2");
GroupMembershipQueryParamArray queryParamArray = new GroupMembershipQueryParamArray(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.client.RestLiResponseException in project rest.li by linkedin.
the class TestNullGreetingsClient method sendBatchUpdateAndAssert.
private void sendBatchUpdateAndAssert(final RootBuilderWrapper<Long, Greeting> builders, Long id) throws RemoteInvocationException {
try {
final Greeting someGreeting = new Greeting().setMessage("Hello").setTone(Tone.INSULTING);
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(id, someGreeting).build();
getClient().sendRequest(writeRequest).getResponse();
} catch (final RestLiResponseException responseException) {
assertCorrectInternalServerMessageForNull(responseException, "batch_update");
}
}
use of com.linkedin.restli.client.RestLiResponseException in project incubator-gobblin by apache.
the class GobblinServiceHATest method testBadGet.
@Test(dependsOnMethods = "testDelete")
public void testBadGet() throws Exception {
FlowId flowId = new FlowId().setFlowGroup(TEST_DUMMY_GROUP_NAME_1).setFlowName(TEST_DUMMY_FLOW_NAME_1);
try {
this.node1FlowConfigClient.getFlowConfig(flowId);
Assert.fail("Get should have raised a 404 error");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), HttpStatus.NOT_FOUND_404);
}
try {
this.node2FlowConfigClient.getFlowConfig(flowId);
Assert.fail("Get should have raised a 404 error");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), HttpStatus.NOT_FOUND_404);
}
}
Aggregations