Search in sources :

Example 56 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserCollectionResourceTest method testGetUsers.

/**
   * Test getting all users.
   */
@Deployment
public void testGetUsers() throws Exception {
    List<User> savedUsers = new ArrayList<User>();
    try {
        User user1 = identityService.newUser("testuser");
        user1.setFirstName("Fred");
        user1.setLastName("McDonald");
        user1.setEmail("no-reply@activiti.org");
        identityService.saveUser(user1);
        savedUsers.add(user1);
        User user2 = identityService.newUser("anotherUser");
        user2.setFirstName("Tijs");
        user2.setLastName("Barrez");
        user2.setEmail("no-reply@alfresco.org");
        identityService.saveUser(user2);
        savedUsers.add(user2);
        User user3 = identityService.createUserQuery().userId("kermit").singleResult();
        assertNotNull(user3);
        // Test filter-less
        String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION);
        assertResultsPresentInDataResponse(url, user1.getId(), user2.getId(), user3.getId());
        // Test based on userId
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?id=testuser";
        assertResultsPresentInDataResponse(url, user1.getId());
        // Test based on firstName
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?firstName=Tijs";
        assertResultsPresentInDataResponse(url, user2.getId());
        // Test based on lastName
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?lastName=Barrez";
        assertResultsPresentInDataResponse(url, user2.getId());
        // Test based on email
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?email=no-reply@activiti.org";
        assertResultsPresentInDataResponse(url, user1.getId());
        // Test based on firstNameLike
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?firstNameLike=" + encode("%ij%");
        assertResultsPresentInDataResponse(url, user2.getId());
        // Test based on lastNameLike
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?lastNameLike=" + encode("%rez");
        assertResultsPresentInDataResponse(url, user2.getId());
        // Test based on emailLike
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?emailLike=" + encode("no-reply@activiti.org%");
        assertResultsPresentInDataResponse(url, user1.getId());
        // Test based on memberOfGroup
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?memberOfGroup=admin";
        assertResultsPresentInDataResponse(url, user3.getId());
        // Test based on potentialStarter
        String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey("simpleProcess").singleResult().getId();
        repositoryService.addCandidateStarterUser(processDefinitionId, "kermit");
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?potentialStarter=" + processDefinitionId;
        assertResultsPresentInDataResponse(url, user3.getId());
    } finally {
        // Delete user after test passes or fails
        if (!savedUsers.isEmpty()) {
            for (User user : savedUsers) {
                identityService.deleteUser(user.getId());
            }
        }
    }
}
Also used : User(org.activiti.engine.identity.User) ArrayList(java.util.ArrayList) Deployment(org.activiti.engine.test.Deployment)

Example 57 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserInfoResourceTest method testCreateUserInfo.

public void testCreateUserInfo() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setEmail("no-reply@activiti.org");
        identityService.saveUser(newUser);
        savedUser = newUser;
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("value", "Value 1");
        requestNode.put("key", "key1");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO_COLLECTION, "testuser"));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertEquals("key1", responseNode.get("key").textValue());
        assertEquals("Value 1", responseNode.get("value").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1")));
    } finally {
        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) User(org.activiti.engine.identity.User) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 58 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserInfoResourceTest method testGetUserInfo.

/**
   * Test getting info for a user.
   */
public void testGetUserInfo() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setEmail("no-reply@activiti.org");
        identityService.saveUser(newUser);
        savedUser = newUser;
        identityService.setUserInfo(newUser.getId(), "key1", "Value 1");
        CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1")), HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertEquals("key1", responseNode.get("key").textValue());
        assertEquals("Value 1", responseNode.get("value").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1")));
    } finally {
        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
Also used : User(org.activiti.engine.identity.User) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 59 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserInfoResourceTest method testUpdateUserInfo.

/**
   * Test update info for a user.
   */
public void testUpdateUserInfo() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setEmail("no-reply@activiti.org");
        identityService.saveUser(newUser);
        savedUser = newUser;
        identityService.setUserInfo(newUser.getId(), "key1", "Value 1");
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("value", "Updated value");
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1"));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertEquals("key1", responseNode.get("key").textValue());
        assertEquals("Updated value", responseNode.get("value").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1")));
        // Check if info is actually updated
        assertEquals("Updated value", identityService.getUserInfo(newUser.getId(), "key1"));
    } finally {
        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) User(org.activiti.engine.identity.User) 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 60 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserInfoResourceTest method testCreateUserInfoExceptions.

public void testCreateUserInfoExceptions() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setEmail("no-reply@activiti.org");
        identityService.saveUser(newUser);
        savedUser = newUser;
        // Test creating without value
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("key", "key1");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO_COLLECTION, "testuser"));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
        // Test creating without key
        requestNode = objectMapper.createObjectNode();
        requestNode.put("value", "The value");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
        // Test creating an already existing info 
        identityService.setUserInfo(newUser.getId(), "key1", "The value");
        requestNode = objectMapper.createObjectNode();
        requestNode.put("key", "key1");
        requestNode.put("value", "The value");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT));
        // Test creating info for unexisting user
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO_COLLECTION, "unexistinguser"));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_NOT_FOUND));
    } finally {
        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) User(org.activiti.engine.identity.User) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Aggregations

User (org.activiti.engine.identity.User)94 Group (org.activiti.engine.identity.Group)22 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 Task (org.activiti.engine.task.Task)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)9 Picture (org.activiti.engine.identity.Picture)9 StringEntity (org.apache.http.entity.StringEntity)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ArrayList (java.util.ArrayList)7 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)7 HttpPut (org.apache.http.client.methods.HttpPut)7 HttpGet (org.apache.http.client.methods.HttpGet)6 UserQuery (org.activiti.engine.identity.UserQuery)5 HttpDelete (org.apache.http.client.methods.HttpDelete)5 HttpPost (org.apache.http.client.methods.HttpPost)4 Item (com.vaadin.data.Item)3 ActivitiException (org.activiti.engine.ActivitiException)3 IdentityService (org.activiti.engine.IdentityService)3