Search in sources :

Example 1 with UserInput

use of io.gravitee.rest.api.portal.rest.model.UserInput in project gravitee-management-rest-api by gravitee-io.

the class UserResourceTest method shouldUpdateCurrentUser.

@Test
public void shouldUpdateCurrentUser() {
    UserInput userInput = new UserInput();
    final String newAvatar = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
    final String expectedAvatar = "data:image/gif;base64,R0lGODlhyADIAPAAAAAAAP///ywAAAAAyADIAEAC/4SPqcvtD6OctNqL" + "s968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+" + "f0uv2Oz+v3/L7/DxgoOEhYaHiImKi4yNjo+AgZKTlJWWl5iZmpucnZ6fkJGio6SlpqeoqaqrrK2ur6ChsrO0tba3uLm6u7y9vr" + "+wscLDxMXGx8jJysvMzc7PwMHS09TV1tfY2drb3N3e39DR4uPk5ebn6Onq6+zt7u/g4fLz9PX29/j5+vv8/f7/8PMKDAgQQLGj" + "yIMKHChQwbOnwIMaLEiRQrWryIMaPGjQYcO3osUwAAOw==";
    userInput.setAvatar(newAvatar);
    userInput.setId(USER_NAME);
    when(userService.update(eq(USER_NAME), any())).thenReturn(new UserEntity());
    final Response response = target().request().put(Entity.json(userInput));
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    ArgumentCaptor<UpdateUserEntity> user = ArgumentCaptor.forClass(UpdateUserEntity.class);
    Mockito.verify(userService).update(eq(USER_NAME), user.capture());
    final UpdateUserEntity updateUserEntity = user.getValue();
    assertNotNull(updateUserEntity);
    assertEquals(expectedAvatar, updateUserEntity.getPicture());
    assertNull(updateUserEntity.getStatus());
    User updateUser = response.readEntity(User.class);
    assertNotNull(updateUser);
}
Also used : Response(javax.ws.rs.core.Response) User(io.gravitee.rest.api.portal.rest.model.User) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserInput(io.gravitee.rest.api.portal.rest.model.UserInput) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 2 with UserInput

use of io.gravitee.rest.api.portal.rest.model.UserInput in project gravitee-management-rest-api by gravitee-io.

the class UserResourceTest method shouldHaveUnauthorizedAccessWhileUpdatingWithWrongId.

@Test
public void shouldHaveUnauthorizedAccessWhileUpdatingWithWrongId() {
    UserInput user = new UserInput();
    user.setId("anotherId");
    user.setAvatar("");
    final Response response = target().request().put(Entity.json(user));
    assertEquals(HttpStatusCode.UNAUTHORIZED_401, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) UserInput(io.gravitee.rest.api.portal.rest.model.UserInput) Test(org.junit.Test)

Aggregations

UserInput (io.gravitee.rest.api.portal.rest.model.UserInput)2 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 UpdateUserEntity (io.gravitee.rest.api.model.UpdateUserEntity)1 UserEntity (io.gravitee.rest.api.model.UserEntity)1 User (io.gravitee.rest.api.portal.rest.model.User)1