*/
public class GroupMembershipResourceTest extends BaseSpringRestTestCase {
public void testCreatemembership() throws Exception {
try {
Group testGroup = identityService.newGroup("testgroup");
testGroup.setName("Test group");
testGroup.setType("Test type");
identityService.saveGroup(testGroup);
User testUser = identityService.newUser("testuser");
identityService.saveUser(testUser);
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("userId", "testuser");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX +
RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_MEMBERSHIP_COLLECTION, "testgroup"));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("testuser", responseNode.get("userId").textValue());
assertEquals("testgroup", responseNode.get("groupId").textValue());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(
RestUrls.URL_GROUP_MEMBERSHIP, testGroup.getId(), testUser.getId())));
Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
assertNotNull(createdGroup);
assertEquals("Test group", createdGroup.getName());
assertEquals("Test type", createdGroup.getType());
assertNotNull(identityService.createUserQuery().memberOfGroup("testgroup").singleResult());
assertEquals("testuser", identityService.createUserQuery().memberOfGroup("testgroup").singleResult().getId());
} finally {
try {