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 = REST_CLIENT.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(REST_CLIENT.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 = REST_CLIENT.sendRequest(groupBuilders.partialUpdate()
.id(createdId)
.input(patch)
.build());
Assert.assertEquals(204, responseFuture.getResponse().getStatus());
// Get updated group and verify name
Assert.assertEquals(REST_CLIENT.sendRequest(groupBuilders.get()
.id(createdId)
.build())
.getResponse()
.getEntity()
.getName(),
newName);
// Delete
responseFuture = REST_CLIENT.sendRequest(groupBuilders.delete().id(createdId).build());
Assert.assertEquals(204, responseFuture.getResponse().getStatus());
// Verify deleted
try
{
REST_CLIENT.sendRequest(groupBuilders.get().id(createdId).build()).getResponse();
Assert.fail("Expected RestLiResponseException");
}
catch (RestLiResponseException e)
{
Assert.assertEquals(e.getStatus(), 404);