33import  org .hamcrest .Matchers ;
44import  org .junit .jupiter .api .BeforeEach ;
55import  org .junit .jupiter .api .Test ;
6+ import  org .junit .jupiter .api .parallel .Isolated ;
67import  org .springframework .beans .factory .annotation .Autowired ;
78import  org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
89import  org .springframework .test .context .bean .override .mockito .MockitoBean ;
3738import  static  org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
3839
3940@ AutoConfigureMockMvc 
41+ @ Isolated 
4042class  PatchUserIntTest  extends  IntegrationBase  {
4143
4244    private  static  final  String  ORIGINAL_USERNAME  = "James Smith" ;
@@ -73,7 +75,7 @@ void setUp() {
7375    }
7476
7577    @ Test 
76-     void  patchUserShouldSucceedWhenProvidedWithValidValueForSubsetOfAllowableFields () throws  Exception  {
78+     void  patchUser_ShouldSucceed_WhenProvidedWithValidValueForSubsetOfAllowableFields () throws  Exception  {
7779        UserAccountEntity  user  = superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
7880
7981        UserAccountEntity  existingAccount  = createEnabledUserAccountEntity (user );
@@ -121,7 +123,7 @@ void patchUserShouldSucceedWhenProvidedWithValidValueForSubsetOfAllowableFields(
121123    }
122124
123125    @ Test 
124-     void  patchUserShouldSucceedWhenProvidedWithValidValuesForAllAllowableFields () throws  Exception  {
126+     void  patchUser_ShouldSucceed_WhenProvidedWithValidValuesForAllAllowableFields () throws  Exception  {
125127        UserAccountEntity  user  = superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
126128
127129        UserAccountEntity  existingAccount  = createEnabledUserAccountEntity (user );
@@ -168,7 +170,7 @@ void patchUserShouldSucceedWhenProvidedWithValidValuesForAllAllowableFields() th
168170
169171    // Regression test to cover bug DMP-2459 
170172    @ Test 
171-     void  patchUserShouldSucceedWhenAnExistingDescriptionIsRemoved () throws  Exception  {
173+     void  patchUser_ShouldSucceed_WhenAnExistingDescriptionIsRemoved () throws  Exception  {
172174        UserAccountEntity  user  = superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
173175
174176        UserAccountEntity  existingAccount  = createEnabledUserAccountEntity (user );
@@ -215,7 +217,7 @@ void patchUserShouldSucceedWhenAnExistingDescriptionIsRemoved() throws Exception
215217    }
216218
217219    @ Test 
218-     void  patchUserShouldFailIfChangeWithInvalidDataIsAttempted () throws  Exception  {
220+     void  patchUser_ShouldFail_IfChangeWithInvalidDataIsAttempted () throws  Exception  {
219221        UserAccountEntity  user  = superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
220222
221223        UserAccountEntity  existingAccount  = createEnabledUserAccountEntity (user );
@@ -234,7 +236,7 @@ void patchUserShouldFailIfChangeWithInvalidDataIsAttempted() throws Exception {
234236    }
235237
236238    @ Test 
237-     void  patchUserShouldFailIfProvidedUserIdDoesNotExistInDB () throws  Exception  {
239+     void  patchUser_ShouldFail_IfProvidedUserIdDoesNotExistInDB () throws  Exception  {
238240        superAdminUserStub .givenUserIsAuthorised (userIdentity );
239241
240242        MockHttpServletRequestBuilder  request  = buildRequest (818_231 )
@@ -249,7 +251,7 @@ void patchUserShouldFailIfProvidedUserIdDoesNotExistInDB() throws Exception {
249251    }
250252
251253    @ Test 
252-     void  patchUserShouldSucceedAndClearSecurityGroupsWhenAccountGetsDisabledAndNoSecurityGroupsAreExplicitlyProvided () throws  Exception  {
254+     void  patchUser_ShouldSucceedAndClearSecurityGroups_WhenAccountGetsDisabledAndNoSecurityGroupsAreExplicitlyProvided () throws  Exception  {
253255        UserAccountEntity  user  = superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
254256
255257        UserAccountEntity  existingAccount  = createEnabledUserAccountEntity (user );
@@ -283,7 +285,37 @@ void patchUserShouldSucceedAndClearSecurityGroupsWhenAccountGetsDisabledAndNoSec
283285    }
284286
285287    @ Test 
286-     void  patchUserShouldSucceedWhenAccountGetsEnabled () throws  Exception  {
288+     void  patchUser_ShouldFail_WhenAccountGetsDeactivatedBySameUser () throws  Exception  {
289+         UserAccountEntity  user  = superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
290+ 
291+         Integer  userId  = user .getId ();
292+ 
293+         MockHttpServletRequestBuilder  request  = buildRequest (userId )
294+             .content (""" 
295+                          { 
296+                            "active": false 
297+                          } 
298+                          """ );
299+         mockMvc .perform (request )
300+             .andExpect (status ().is4xxClientError ())
301+             .andExpect (jsonPath ("$.type" ).value ("AUTHORISATION_115" ))
302+             .andExpect (jsonPath ("$.title" ).value ("User is not authorised to modify own account" ))
303+             .andExpect (jsonPath ("$.status" ).value (403 ));
304+ 
305+         transactionTemplate .execute (status  -> {
306+             UserAccountEntity  latestUserAccountEntity  = dartsDatabase .getUserAccountRepository ()
307+                 .findById (userId )
308+                 .orElseThrow ();
309+ 
310+             assertEquals (true , latestUserAccountEntity .isActive ());
311+             assertThat (getSecurityGroupIds (latestUserAccountEntity ).size (), greaterThan (0 ));
312+ 
313+             return  null ;
314+         });
315+     }
316+ 
317+     @ Test 
318+     void  patchUser_ShouldSucceed_WhenAccountGetsEnabled () throws  Exception  {
287319        UserAccountEntity  user  = superAdminUserStub .givenUserIsAuthorised (userIdentity );
288320
289321        UserAccountEntity  existingAccount  = createDisabledUserAccountEntity (user );
@@ -317,7 +349,7 @@ void patchUserShouldSucceedWhenAccountGetsEnabled() throws Exception {
317349    }
318350
319351    @ Test 
320-     void  patchUserShouldSucceedWhenSecurityGroupsAreUpdated () throws  Exception  {
352+     void  patchUser_ShouldSucceed_WhenSecurityGroupsAreUpdated () throws  Exception  {
321353        UserAccountEntity  user  = superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
322354
323355        UserAccountEntity  existingAccount  = createEnabledUserAccountEntity (user );
@@ -361,7 +393,7 @@ void patchUserShouldSucceedWhenSecurityGroupsAreUpdated() throws Exception {
361393    }
362394
363395    @ Test 
364-     void  patchUserShouldSucceedIfEmailAddressChangeDifferent () throws  Exception  {
396+     void  patchUser_ShouldSucceed_IfEmailAddressChangeDifferent () throws  Exception  {
365397        UserAccountEntity  user  = superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
366398
367399        UserAccountEntity  existingAccount  = createEnabledUserAccountEntity (user );
@@ -382,7 +414,7 @@ void patchUserShouldSucceedIfEmailAddressChangeDifferent() throws Exception {
382414    }
383415
384416    @ Test 
385-     void  patchUserSameEmailShouldBeOkAndDataShouldRemainUnchanged () throws  Exception  {
417+     void  patchUser_ShouldRemainUnchanged_SameEmailShouldBeOkAndData () throws  Exception  {
386418        UserAccountEntity  user  = superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
387419
388420        UserAccountEntity  existingAccount  = createEnabledUserAccountEntity (user );
@@ -401,7 +433,7 @@ void patchUserSameEmailShouldBeOkAndDataShouldRemainUnchanged() throws Exception
401433    }
402434
403435    @ Test 
404-     void  patchUserDuplicateEmailShouldFail () throws  Exception  {
436+     void  patchUser_DuplicateEmailShouldFail () throws  Exception  {
405437        UserAccountEntity  user  = superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
406438
407439        createEnabledUserAccountEntity (user );
@@ -440,7 +472,7 @@ void patchUserShouldFailIfUserIsNotAuthorised() throws Exception {
440472    }
441473
442474    @ Test 
443-     void  patchUserShouldFailIfProvidedUserIsASystemUser () throws  Exception  {
475+     void  patchUser_ShouldFailIfProvidedUserIsASystemUser () throws  Exception  {
444476        superAdminUserStub .givenSystemAdminIsAuthorised (userIdentity );
445477
446478        UserAccountEntity  userAccountEntity  = accountStub .getSystemUserAccountEntity ();
0 commit comments