use of com.linkedin.restli.examples.groups.api.GroupMembershipQueryParam 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);
}
}
Aggregations