use of org.activiti.engine.identity.Group in project Activiti by Activiti.
the class GroupCollectionResourceTest method testGetGroups.
/**
* Test getting all groups.
*/
@Deployment
public void testGetGroups() throws Exception {
List<Group> savedGroups = new ArrayList<Group>();
try {
Group group1 = identityService.newGroup("testgroup1");
group1.setName("Test group");
group1.setType("Test type");
identityService.saveGroup(group1);
savedGroups.add(group1);
Group group2 = identityService.newGroup("testgroup2");
group2.setName("Another group");
group2.setType("Another type");
identityService.saveGroup(group2);
savedGroups.add(group2);
Group group3 = identityService.createGroupQuery().groupId("admin").singleResult();
assertNotNull(group3);
// Test filter-less
String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION);
assertResultsPresentInDataResponse(url, group1.getId(), group2.getId(), group3.getId());
// Test based on name
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?name=" + encode("Test group");
assertResultsPresentInDataResponse(url, group1.getId());
// Test based on name like
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?nameLike=" + encode("% group");
assertResultsPresentInDataResponse(url, group2.getId(), group1.getId());
// Test based on type
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?type=" + encode("Another type");
assertResultsPresentInDataResponse(url, group2.getId());
// Test based on group member
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?member=kermit";
assertResultsPresentInDataResponse(url, group3.getId());
// Test based on potentialStarter
String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey("simpleProcess").singleResult().getId();
repositoryService.addCandidateStarterGroup(processDefinitionId, "admin");
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?potentialStarter=" + processDefinitionId;
assertResultsPresentInDataResponse(url, group3.getId());
} finally {
// Delete groups after test passes or fails
if (!savedGroups.isEmpty()) {
for (Group group : savedGroups) {
identityService.deleteGroup(group.getId());
}
}
}
}
use of org.activiti.engine.identity.Group in project Activiti by Activiti.
the class GroupResourceTest method testGetGroup.
/**
* Test getting a single group.
*/
public void testGetGroup() throws Exception {
try {
Group testGroup = identityService.newGroup("testgroup");
testGroup.setName("Test group");
testGroup.setType("Test type");
identityService.saveGroup(testGroup);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup")), HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("testgroup", responseNode.get("id").textValue());
assertEquals("Test group", responseNode.get("name").textValue());
assertEquals("Test type", responseNode.get("type").textValue());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId())));
Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
assertNotNull(createdGroup);
assertEquals("Test group", createdGroup.getName());
assertEquals("Test type", createdGroup.getType());
} finally {
try {
identityService.deleteGroup("testgroup");
} catch (Throwable ignore) {
// Ignore, since the group may not have been created in the test
// or already deleted
}
}
}
use of org.activiti.engine.identity.Group in project Activiti by Activiti.
the class GroupResourceTest method testUpdateGroupNullFields.
/**
* Test updating a single user passing in null-values.
*/
public void testUpdateGroupNullFields() throws Exception {
try {
Group testGroup = identityService.newGroup("testgroup");
testGroup.setName("Test group");
testGroup.setType("Test type");
identityService.saveGroup(testGroup);
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("name", (JsonNode) null);
requestNode.put("type", (JsonNode) null);
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup"));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("testgroup", responseNode.get("id").textValue());
assertNull(responseNode.get("name").textValue());
assertNull(responseNode.get("type").textValue());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId())));
Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
assertNotNull(createdGroup);
assertNull(createdGroup.getName());
assertNull(createdGroup.getType());
} finally {
try {
identityService.deleteGroup("testgroup");
} catch (Throwable ignore) {
// Ignore, since the group may not have been created in the test
// or already deleted
}
}
}
use of org.activiti.engine.identity.Group in project Activiti by Activiti.
the class GroupResourceTest method testUpdateGroup.
/**
* Test updating a single group.
*/
public void testUpdateGroup() throws Exception {
try {
Group testGroup = identityService.newGroup("testgroup");
testGroup.setName("Test group");
testGroup.setType("Test type");
identityService.saveGroup(testGroup);
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("name", "Updated group");
requestNode.put("type", "Updated type");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup"));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("testgroup", responseNode.get("id").textValue());
assertEquals("Updated group", responseNode.get("name").textValue());
assertEquals("Updated type", responseNode.get("type").textValue());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId())));
Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
assertNotNull(createdGroup);
assertEquals("Updated group", createdGroup.getName());
assertEquals("Updated type", createdGroup.getType());
} finally {
try {
identityService.deleteGroup("testgroup");
} catch (Throwable ignore) {
// Ignore, since the group may not have been created in the test
// or already deleted
}
}
}
use of org.activiti.engine.identity.Group in project Activiti by Activiti.
the class GroupResourceTest method testDeleteGroup.
/**
* Test deleting a single group.
*/
public void testDeleteGroup() throws Exception {
try {
Group testGroup = identityService.newGroup("testgroup");
testGroup.setName("Test group");
testGroup.setType("Test type");
identityService.saveGroup(testGroup);
closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup")), HttpStatus.SC_NO_CONTENT));
assertNull(identityService.createGroupQuery().groupId("testgroup").singleResult());
} finally {
try {
identityService.deleteGroup("testgroup");
} catch (Throwable ignore) {
// Ignore, since the group may not have been created in the test
// or already deleted
}
}
}
Aggregations