Add unit tests for user update

This commit is contained in:
René Pfeuffer
2018-06-25 14:16:20 +02:00
parent e156ef1964
commit 15acd69562
3 changed files with 33 additions and 3 deletions

View File

@@ -73,6 +73,7 @@ public class UserRootResourceTest {
when(userManager.getPage(any(), eq(0), eq(10))).thenReturn(new PageResult<>(singletonList(dummyUser), 1));
when(userManager.get("Neo")).thenReturn(dummyUser);
doNothing().when(userManager).create(userCaptor.capture());
doNothing().when(userManager).modify(userCaptor.capture());
UserCollectionToDtoMapper userCollectionToDtoMapper = new UserCollectionToDtoMapper(userToDtoMapper, uriInfoStore);
UserCollectionResource userCollectionResource = new UserCollectionResource(userManager, dtoToUserMapper, userToDtoMapper,
@@ -134,6 +135,26 @@ public class UserRootResourceTest {
assertEquals("encrypted123", createdUser.getPassword());
}
@Test
public void shouldUpdateChangedUserWithEncryptedPassword() throws URISyntaxException, IOException {
URL url = Resources.getResource("sonia/scm/api/v2/user-test-update.json");
byte[] userJson = Resources.toByteArray(url);
MockHttpRequest request = MockHttpRequest
.put("/" + UserRootResource.USERS_PATH_V2 + "Neo")
.contentType(VndMediaType.USER)
.content(userJson);
MockHttpResponse response = new MockHttpResponse();
when(passwordService.encryptPassword("pwd123")).thenReturn("encrypted123");
dispatcher.invoke(request, response);
assertEquals(204, response.getStatus());
User updatedUser = userCaptor.getValue();
assertNotNull(updatedUser);
assertEquals("encrypted123", updatedUser.getPassword());
}
@Test
public void shouldFailForMissingContent() throws URISyntaxException {
MockHttpRequest request = MockHttpRequest