Search in sources :

Example 1 with UserDto

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);
}
Also used : User(org.camunda.bpm.engine.identity.User) UserDto(org.camunda.bpm.engine.rest.dto.identity.UserDto) Test(org.junit.Test)

Example 2 with UserDto

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);
}
Also used : User(org.camunda.bpm.engine.identity.User) UserDto(org.camunda.bpm.engine.rest.dto.identity.UserDto) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test)

Example 3 with UserDto

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);
}
Also used : User(org.camunda.bpm.engine.identity.User) UserDto(org.camunda.bpm.engine.rest.dto.identity.UserDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with UserDto

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();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebApplicationException(javax.ws.rs.WebApplicationException) UserDto(org.camunda.bpm.engine.rest.dto.identity.UserDto) UserProfileDto(org.camunda.bpm.engine.rest.dto.identity.UserProfileDto) UserCredentialsDto(org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto) WebResource(com.sun.jersey.api.client.WebResource)

Example 5 with UserDto

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);
}
Also used : User(org.camunda.bpm.engine.identity.User) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) UserDto(org.camunda.bpm.engine.rest.dto.identity.UserDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

UserDto (org.camunda.bpm.engine.rest.dto.identity.UserDto)6 User (org.camunda.bpm.engine.identity.User)5 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)3 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 UserCredentialsDto (org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto)1 UserProfileDto (org.camunda.bpm.engine.rest.dto.identity.UserProfileDto)1