}
@Test
public void testCreateUpdateAndDeleteGroupMembership() throws Exception {
LOG.info("Create, set default and delete group membership");
Group group = API.getGroups().createGroup("Test group 1").getGroup();
groupIds.add(group.getId());
User user = new User();
user.setName("Test user 1");
user.setEmail("test.user1@linxugrotto.org.uk");
user.setRole("agent");
User createdUser = API.getUsers().createUser(user).getUser();
GroupMembership groupMembership = new GroupMembership();
groupMembership.setUserId(createdUser.getId());
groupMembership.setGroupId(group.getId());
// Create
IndividualGroupMembershipResponse igmr = API.getGroups().createGroupMembership(groupMembership);
Assert.assertTrue(igmr.getGroupMembership().getId() > 0);
// Update
MultipleGroupMembershipResponse mgmr = API.getGroups().setGroupMembershipAsDefault(createdUser.getId(), igmr.getGroupMembership().getId());
Assert.assertEquals(mgmr.getGroupMemberships().size(), 2);
Assert.assertEquals(mgmr.getGroupMemberships().get(1).getId(), igmr.getGroupMembership().getId());
Assert.assertTrue(mgmr.getGroupMemberships().get(1).getDefaultGroup());
// Delete
Assert.assertTrue(API.getGroups().deleteGroupMembership(igmr.getGroupMembership().getId()));
Assert.assertTrue(API.getUsers().deleteUser(createdUser.getId()));
Assert.assertTrue(API.getGroups().deleteGroup(group.getId()));
}