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());
}
}
}
}
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());
}
}
}
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());
}
}
}
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());
}
}
}
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());
}
}
}
Aggregations