mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 03:01:05 +01:00
Add unit tests for user update
This commit is contained in:
@@ -73,6 +73,7 @@ public class UserRootResourceTest {
|
|||||||
when(userManager.getPage(any(), eq(0), eq(10))).thenReturn(new PageResult<>(singletonList(dummyUser), 1));
|
when(userManager.getPage(any(), eq(0), eq(10))).thenReturn(new PageResult<>(singletonList(dummyUser), 1));
|
||||||
when(userManager.get("Neo")).thenReturn(dummyUser);
|
when(userManager.get("Neo")).thenReturn(dummyUser);
|
||||||
doNothing().when(userManager).create(userCaptor.capture());
|
doNothing().when(userManager).create(userCaptor.capture());
|
||||||
|
doNothing().when(userManager).modify(userCaptor.capture());
|
||||||
|
|
||||||
UserCollectionToDtoMapper userCollectionToDtoMapper = new UserCollectionToDtoMapper(userToDtoMapper, uriInfoStore);
|
UserCollectionToDtoMapper userCollectionToDtoMapper = new UserCollectionToDtoMapper(userToDtoMapper, uriInfoStore);
|
||||||
UserCollectionResource userCollectionResource = new UserCollectionResource(userManager, dtoToUserMapper, userToDtoMapper,
|
UserCollectionResource userCollectionResource = new UserCollectionResource(userManager, dtoToUserMapper, userToDtoMapper,
|
||||||
@@ -134,6 +135,26 @@ public class UserRootResourceTest {
|
|||||||
assertEquals("encrypted123", createdUser.getPassword());
|
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
|
@Test
|
||||||
public void shouldFailForMissingContent() throws URISyntaxException {
|
public void shouldFailForMissingContent() throws URISyntaxException {
|
||||||
MockHttpRequest request = MockHttpRequest
|
MockHttpRequest request = MockHttpRequest
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"active": true,
|
"active": true,
|
||||||
"admin": false,
|
"admin": false,
|
||||||
"displayName": "rpf",
|
"displayName": "someone",
|
||||||
"mail": "x@abcde.cd",
|
"mail": "x@example.com",
|
||||||
"name": "rpf",
|
"name": "someone",
|
||||||
"password": "pwd123",
|
"password": "pwd123",
|
||||||
"type": "xml"
|
"type": "xml"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"active": true,
|
||||||
|
"admin": false,
|
||||||
|
"displayName": "Neo",
|
||||||
|
"mail": "neo@example.com",
|
||||||
|
"name": "Neo",
|
||||||
|
"password": "pwd123",
|
||||||
|
"type": "xml"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user