use of org.activiti.engine.identity.User in project Activiti by Activiti.
the class UserInfoResourceTest method testUpdateUnexistingInfo.
/**
* Test deleting the info for a user who doesn't have that info set
*/
public void testUpdateUnexistingInfo() 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", "Updated value");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, "testuser", "key1"));
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
} 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 UserPictureResourceTest method testGetPictureForUserWithoutPicture.
/**
* Test getting the picture for a user who doesn't have a îcture set
*/
public void testGetPictureForUserWithoutPicture() 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;
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId())), HttpStatus.SC_NOT_FOUND);
// response content type application/json;charset=UTF-8
assertEquals("application/json", response.getEntity().getContentType().getValue().split(";")[0]);
closeResponse(response);
} 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 UserPictureResourceTest method testUpdatePicture.
public void testUpdatePicture() 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;
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId()));
httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("myPicture.png", "image/png", new ByteArrayInputStream("this is the picture raw byte stream".getBytes()), null));
closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));
Picture picture = identityService.getUserPicture(newUser.getId());
assertNotNull(picture);
assertEquals("image/png", picture.getMimeType());
assertEquals("this is the picture raw byte stream", new String(picture.getBytes()));
} 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 UserPictureResourceTest method testGetUserPicture.
/**
* Test getting the picture for a user.
*/
public void testGetUserPicture() 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;
// Create picture for user
Picture thePicture = new Picture("this is the picture raw byte stream".getBytes(), "image/png");
identityService.setUserPicture(newUser.getId(), thePicture);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId())), HttpStatus.SC_OK);
assertEquals("this is the picture raw byte stream", IOUtils.toString(response.getEntity().getContent()));
// Check if media-type is correct
assertEquals("image/png", response.getEntity().getContentType().getValue());
closeResponse(response);
} 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 GroupMembershipResourceTest method testCreateMembershipAlreadyExisting.
public void testCreateMembershipAlreadyExisting() 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);
identityService.createMembership("testuser", "testgroup");
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()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT));
} finally {
try {
identityService.deleteGroup("testgroup");
} catch (Throwable ignore) {
// Ignore, since the group may not have been created in the test
// or already deleted
}
try {
identityService.deleteUser("testuser");
} catch (Throwable ignore) {
// Ignore, since the group may not have been created in the test
// or already deleted
}
}
}
Aggregations