Search in sources :

Example 11 with Group

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());
            }
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) ArrayList(java.util.ArrayList) Deployment(org.activiti.engine.test.Deployment)

Example 12 with Group

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
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 13 with Group

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
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut)

Example 14 with Group

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
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut)

Example 15 with Group

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
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) HttpDelete(org.apache.http.client.methods.HttpDelete)

Aggregations

Group (org.activiti.engine.identity.Group)61 User (org.activiti.engine.identity.User)22 ArrayList (java.util.ArrayList)12 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 StringEntity (org.apache.http.entity.StringEntity)5 Item (com.vaadin.data.Item)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 PropertysetItem (com.vaadin.data.util.PropertysetItem)3 Deployment (org.activiti.engine.test.Deployment)3 HttpDelete (org.apache.http.client.methods.HttpDelete)3 HttpPut (org.apache.http.client.methods.HttpPut)3 HashSet (java.util.HashSet)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 IdentityService (org.activiti.engine.IdentityService)2 GroupQuery (org.activiti.engine.identity.GroupQuery)2 LoggedInUser (org.activiti.explorer.identity.LoggedInUser)2 ActivitiConflictException (org.activiti.rest.exception.ActivitiConflictException)2