@@ -250,6 +250,11 @@ void registerNewUserThrows() {
250
250
ex = assertThrows (UserNotRegisteredException .class , () ->
251
251
userBusinessService .registerNewUser (userRegisterForm ));
252
252
assertEquals ("User could not be registered. One or more groups do not exist." , ex .getMessage ());
253
+
254
+ userRegisterForm .setGroupIds (new long []{Groups .SYSTEM .getGroupId ()});
255
+ ex = assertThrows (UserNotRegisteredException .class , () ->
256
+ userBusinessService .registerNewUser (userRegisterForm ));
257
+ assertEquals ("User could not be registered. New users cannot be in group '" + Groups .SYSTEM .getDisplayName () + "'." , ex .getMessage ());
253
258
}
254
259
255
260
@ Test
@@ -299,6 +304,11 @@ void updateUserThrows() {
299
304
userBusinessService .updateUser (userId , userRegisterForm1 , authenticatedUser ));
300
305
assertEquals ("User could not get updated. User does not exist, use register endpoint." , ex .getMessage ());
301
306
307
+ when (userRepositoryMock .findByUserId (userId )).thenReturn (UserEntity .builder ().groupIds (new long []{Groups .SYSTEM .getGroupId ()}).build ());
308
+ ex = assertThrows (UserNotUpdatedException .class , () ->
309
+ userBusinessService .updateUser (userId , userRegisterForm1 , authenticatedUser ));
310
+ assertEquals ("User could not get updated. Runtime users cannot be modified." , ex .getMessage ());
311
+
302
312
when (userRepositoryMock .findByUserId (userId )).thenReturn (userEntityMock );
303
313
ex = assertThrows (UserNotUpdatedException .class , () ->
304
314
userBusinessService .updateUser (userId , userRegisterForm1 , authenticatedUser ));
@@ -414,6 +424,13 @@ void updateGroupsThrows() {
414
424
ex = assertThrows (UserNotUpdatedException .class , () ->
415
425
userBusinessService .updateUser (userId , userRegisterForm , authenticatedUser ));
416
426
assertEquals ("User could not get updated. One or more groups do not exist." , ex .getMessage ());
427
+
428
+ long [] systemUser = new long []{Groups .SYSTEM .getGroupId ()};
429
+ userRegisterForm .setGroupIds (systemUser );
430
+ when (groupRepositoryMock .getGroupsByIds (systemUser )).thenReturn (new Groups []{Groups .SYSTEM });
431
+ ex = assertThrows (UserNotUpdatedException .class , () ->
432
+ userBusinessService .updateUser (userId , userRegisterForm , authenticatedUser ));
433
+ assertEquals ("User could not get updated. Users cannot be added to the '" + Groups .SYSTEM .getDisplayName () + "' Group" , ex .getMessage ());
417
434
}
418
435
419
436
@ Test
0 commit comments