use of org.camunda.bpm.engine.rest.dto.identity.UserDto in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testCreateNewUserWithCredentials.
@Test
public void testCreateNewUserWithCredentials() {
User newUser = MockProvider.createMockUser();
when(identityServiceMock.newUser(MockProvider.EXAMPLE_USER_ID)).thenReturn(newUser);
UserDto userDto = UserDto.fromUser(newUser, true);
given().body(userDto).contentType(ContentType.JSON).expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().post(USER_CREATE_URL);
verify(identityServiceMock).newUser(MockProvider.EXAMPLE_USER_ID);
verify(newUser).setFirstName(MockProvider.EXAMPLE_USER_FIRST_NAME);
verify(newUser).setLastName(MockProvider.EXAMPLE_USER_LAST_NAME);
verify(newUser).setEmail(MockProvider.EXAMPLE_USER_EMAIL);
verify(newUser).setPassword(MockProvider.EXAMPLE_USER_PASSWORD);
verify(identityServiceMock).saveUser(newUser);
}
use of org.camunda.bpm.engine.rest.dto.identity.UserDto in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testUserCreateExistingFails.
@Test
public void testUserCreateExistingFails() {
User newUser = MockProvider.createMockUser();
when(identityServiceMock.newUser(MockProvider.EXAMPLE_USER_ID)).thenReturn(newUser);
doThrow(new ProcessEngineException("")).when(identityServiceMock).saveUser(newUser);
UserDto userDto = UserDto.fromUser(newUser, true);
given().body(userDto).contentType(ContentType.JSON).then().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(ProcessEngineException.class.getSimpleName())).when().post(USER_CREATE_URL);
verify(identityServiceMock).newUser(MockProvider.EXAMPLE_USER_ID);
verify(identityServiceMock).saveUser(newUser);
}
use of org.camunda.bpm.engine.rest.dto.identity.UserDto in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testCreateNewUserWithoutCredentials.
@Test
public void testCreateNewUserWithoutCredentials() {
User newUser = MockProvider.createMockUser();
when(identityServiceMock.newUser(MockProvider.EXAMPLE_USER_ID)).thenReturn(newUser);
UserDto userDto = UserDto.fromUser(newUser, false);
given().body(userDto).contentType(ContentType.JSON).expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().post(USER_CREATE_URL);
verify(identityServiceMock).newUser(MockProvider.EXAMPLE_USER_ID);
verify(newUser).setFirstName(MockProvider.EXAMPLE_USER_FIRST_NAME);
verify(newUser).setLastName(MockProvider.EXAMPLE_USER_LAST_NAME);
verify(newUser).setEmail(MockProvider.EXAMPLE_USER_EMAIL);
// no password was set
verify(newUser, never()).setPassword(any(String.class));
verify(identityServiceMock).saveUser(newUser);
}
use of org.camunda.bpm.engine.rest.dto.identity.UserDto in project camunda-bpm-platform by camunda.
the class TestUtil method createInitialUser.
public void createInitialUser(String id, String password, String firstName, String lastName) {
UserDto user = new UserDto();
UserCredentialsDto credentials = new UserCredentialsDto();
credentials.setPassword(password);
user.setCredentials(credentials);
UserProfileDto profile = new UserProfileDto();
profile.setId(id);
profile.setFirstName(firstName);
profile.setLastName(lastName);
user.setProfile(profile);
WebResource webResource = client.resource(testProperties.getApplicationPath("/camunda/api/admin/setup/default/user/create"));
ClientResponse clientResponse = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, user);
try {
if (clientResponse.getResponseStatus() != Response.Status.NO_CONTENT) {
throw new WebApplicationException(clientResponse.getResponseStatus());
}
} finally {
clientResponse.close();
}
}
use of org.camunda.bpm.engine.rest.dto.identity.UserDto in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testUserCreateThrowsAuthorizationException.
@Test
public void testUserCreateThrowsAuthorizationException() {
User newUser = MockProvider.createMockUser();
String message = "exception expected";
when(identityServiceMock.newUser(MockProvider.EXAMPLE_USER_ID)).thenThrow(new AuthorizationException(message));
UserDto userDto = UserDto.fromUser(newUser, true);
given().body(userDto).contentType(ContentType.JSON).then().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().post(USER_CREATE_URL);
}
Aggregations