Search in sources :

Example 6 with UserCredentialsDto

use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto in project camunda-bpm-platform by camunda.

the class UserRestServiceInteractionTest method testPutCredentialsThrowsAuthorizationException.

@Test
public void testPutCredentialsThrowsAuthorizationException() {
    User initialUser = MockProvider.createMockUser();
    UserQuery sampleUserQuery = mock(UserQuery.class);
    when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
    when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
    when(sampleUserQuery.singleResult()).thenReturn(initialUser);
    String message = "exception expected";
    doThrow(new AuthorizationException(message)).when(identityServiceMock).saveUser(any(User.class));
    UserCredentialsDto dto = new UserCredentialsDto();
    dto.setPassword("new-password");
    given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(dto).contentType(ContentType.JSON).then().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().put(USER_CREDENTIALS_URL);
}
Also used : User(org.camunda.bpm.engine.identity.User) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) UserQuery(org.camunda.bpm.engine.identity.UserQuery) UserCredentialsDto(org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

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