2626import javax .ws .rs .ext .RuntimeDelegate ;
2727
2828import org .apache .commons .lang3 .StringUtils ;
29+ import org .exoplatform .portal .config .UserACL ;
30+ import org .exoplatform .services .security .MembershipEntry ;
2931import org .junit .AfterClass ;
3032import org .junit .Assert ;
3133import org .junit .Before ;
@@ -130,7 +132,7 @@ public class ProcessesStorageImplTest {
130132 private FileService fileService ;
131133
132134 @ Mock
133- private OrganizationService organizationService ;
135+ private UserACL userACL ;
134136
135137 private ProcessesStorage processesStorage ;
136138
@@ -158,7 +160,7 @@ public void setUp() throws Exception {
158160 listenerService ,
159161 processesAttachmentService ,
160162 fileService ,
161- organizationService );
163+ userACL );
162164
163165 }
164166
@@ -213,7 +215,7 @@ public void saveWorkflow() throws EntityNotFoundException {
213215 Throwable exception1 = assertThrows (IllegalArgumentException .class , () -> this .processesStorage .saveWorkFlow (null , 1l ));
214216 assertEquals ("workflow argument is null" , exception1 .getMessage ());
215217
216- when (identityManager .getIdentity ("1" )).thenReturn (null );
218+ when (identityManager .getIdentity (1 )).thenReturn (null );
217219 Throwable exception2 = assertThrows (IllegalArgumentException .class , () -> this .processesStorage .saveWorkFlow (workFlow , 1l ));
218220 assertEquals ("identity is not exist" , exception2 .getMessage ());
219221
@@ -222,7 +224,7 @@ public void saveWorkflow() throws EntityNotFoundException {
222224 when (workFlow .getProjectId ()).thenReturn (0L );
223225 when (workFlow .getSpaceId ()).thenReturn ("1" );
224226 when (projectService .getProject (workFlow .getProjectId ())).thenReturn (projectDto );
225- when (identityManager .getIdentity ("1" )).thenReturn (identity );
227+ when (identityManager .getIdentity (1 )).thenReturn (identity );
226228 when (space .getGroupId ()).thenReturn ("/spaces/processes_space" );
227229 when (space .getId ()).thenReturn ("2" );
228230 when (spaceService .getSpaceByGroupId ("/spaces/processes_space" )).thenReturn (space );
@@ -319,12 +321,12 @@ public void saveWork() throws EntityNotFoundException, IllegalAccessException, O
319321 when (statusDto .getProject ()).thenReturn (projectDto );
320322 Throwable exception1 = assertThrows (IllegalArgumentException .class , () -> this .processesStorage .saveWork (null , 1l ));
321323 assertEquals ("work argument is null" , exception1 .getMessage ());
322- when (identityManager .getIdentity ("1" )).thenReturn (null );
324+ when (identityManager .getIdentity (1 )).thenReturn (null );
323325 Throwable exception2 = assertThrows (IllegalArgumentException .class , () -> this .processesStorage .saveWork (work , 1l ));
324326 assertEquals ("identity is not exist" , exception2 .getMessage ());
325327 work .setId (0L );
326328 work .setProjectId (1L );
327- when (identityManager .getIdentity ("1" )).thenReturn (identity );
329+ when (identityManager .getIdentity (1 )).thenReturn (identity );
328330 when (projectService .getProject (work .getProjectId ())).thenReturn (projectDto );
329331 ENTITY_MAPPER .when (() -> EntityMapper .workToTask (work )).thenReturn (taskDto );
330332 ENTITY_MAPPER .when (() -> EntityMapper .taskToWork (taskDto )).thenReturn (work );
@@ -385,11 +387,11 @@ public void saveWorkDraft() {
385387 workEntity .equals (workEntity );
386388 workEntity .toString ();
387389 Identity identity = mock (Identity .class );
388- when (identityManager .getIdentity ("1" )).thenReturn (null );
390+ when (identityManager .getIdentity (1 )).thenReturn (null );
389391 Throwable exception1 = assertThrows (IllegalArgumentException .class , () -> this .processesStorage .saveWorkDraft (work , 1l ));
390392 assertEquals ("identity is not exist" , exception1 .getMessage ());
391393 ENTITY_MAPPER .when (() -> EntityMapper .toEntity (work )).thenReturn (workEntity );
392- when (identityManager .getIdentity ("1" )).thenReturn (identity );
394+ when (identityManager .getIdentity (1 )).thenReturn (identity );
393395 work .setWorkFlow (workFlow );
394396 when (workDraftDAO .create (workEntity )).thenReturn (workEntity );
395397 processesStorage .saveWorkDraft (work , 1L );
@@ -420,10 +422,10 @@ public void getWorkById() throws Exception {
420422 List <TaskDto > list = new ArrayList <>();
421423 list .add (taskDto );
422424 when (identity .getRemoteId ()).thenReturn ("root" );
423- when (identityManager .getIdentity ("1" )).thenReturn (null );
425+ when (identityManager .getIdentity (1 )).thenReturn (null );
424426 Throwable exception1 = assertThrows (IllegalArgumentException .class , () -> this .processesStorage .getWorkById (1L , 1L ));
425427 assertEquals ("identity is not exist" , exception1 .getMessage ());
426- when (identityManager .getIdentity ("1" )).thenReturn (identity );
428+ when (identityManager .getIdentity (1 )).thenReturn (identity );
427429 when (taskService .findTasks (any (), ArgumentMatchers .anyInt (), ArgumentMatchers .anyInt ())).thenReturn (list );
428430 processesStorage .getWorkById (1L , 1L );
429431 EntityMapper .taskToWork (taskDto );
@@ -435,7 +437,6 @@ public void getWorkById() throws Exception {
435437
436438 @ Test
437439 public void updateWorkCompleted () throws EntityNotFoundException {
438- COMMONS_UTILS .when (() -> CommonsUtils .getService (OrganizationService .class )).thenReturn (organizationService );
439440 COMMONS_UTILS .when (() -> CommonsUtils .getService (SpaceService .class )).thenReturn (spaceService );
440441 TaskDto taskDto = new TaskDto ();
441442 StatusDto statusDto = new StatusDto ();
@@ -533,7 +534,7 @@ public void getWorks() throws Exception {
533534 currentProfile .setProperty (Profile .FULL_NAME , username );
534535 currentIdentity .setProfile (currentProfile );
535536
536- when (identityManager .getIdentity (( String . valueOf ( currentOwnerId )) )).thenReturn (currentIdentity );
537+ when (identityManager .getIdentity (currentOwnerId )).thenReturn (currentIdentity );
537538
538539 PROCESSES_UTILS .when (() -> ProcessesUtils .getUserNameByIdentityId (any (), anyLong ())).thenCallRealMethod ();
539540 String user = ProcessesUtils .getUserNameByIdentityId (identityManager , 1l );
@@ -598,7 +599,7 @@ public void getIllustrationImageById() throws Exception {
598599 }
599600
600601 @ Test
601- public void findWorkflow () throws Exception {
602+ public void testFindWorkflow () throws Exception {
602603 IllustrativeAttachment illustrativeAttachment = new IllustrativeAttachment (null ,
603604 "image.png" ,
604605 "image/png" ,
@@ -623,9 +624,11 @@ public void findWorkflow() throws Exception {
623624 when (workFlow .getProjectId ()).thenReturn (0L );
624625 when (workFlow .getSpaceId ()).thenReturn ("1" );
625626
626- when (identityManager .getIdentity ("1" )).thenReturn (identity );
627+ when (identityManager .getIdentity (1 )).thenReturn (identity );
627628 when (identity .getRemoteId ()).thenReturn ("user" );
628629 when (identity .getId ()).thenReturn ("1" );
630+ org .exoplatform .services .security .Identity aclIdentity = mock (org .exoplatform .services .security .Identity .class );
631+ when (userACL .getUserIdentity ("user" )).thenReturn (aclIdentity );
629632 when (space .getGroupId ()).thenReturn ("/spaces/processes_space" );
630633 when (spaceService .getSpaceByGroupId ("/spaces/processes_space" )).thenReturn (space );
631634 when (spaceService .getSpaceById ("1" )).thenReturn (space );
@@ -664,7 +667,6 @@ public void findWorkflow() throws Exception {
664667 when (workFlowDAO .findWorkFlows (filter , memberships , 0 , 0 )).thenReturn (workFlowEntities );
665668 when (workFlow .getIllustrativeAttachment ()).thenReturn (illustrativeAttachment );
666669 this .processesStorage .saveWorkFlow (workFlow , 1L );
667- when (organizationService .getMembershipHandler ()).thenReturn (membershipHandler );
668670 assertEquals (null , this .processesStorage .getWorkFlowById (1 ));
669671
670672 Collection <Membership > memberships_ = new ArrayList ();
@@ -688,8 +690,7 @@ public void findWorkflow() throws Exception {
688690
689691 PROCESSES_UTILS .when (() -> ProcessesUtils .getProjectParentSpace (workFlow .getProjectId ())).thenReturn (space );
690692 ENTITY_MAPPER .when (() -> EntityMapper .fromEntity (newWorkFlowEntity1 , null )).thenReturn (workFlow );
691-
692- when (organizationService .getMembershipHandler ().findMembershipsByUser (identity .getRemoteId ())).thenReturn (memberships_ );
693+ when (aclIdentity .getMemberships ()).thenReturn (memberships_ .stream ().map (m -> new MembershipEntry (m .getGroupId (), m .getMembershipType ())).toList ());
693694 assertEquals (1 , this .processesStorage .findWorkFlows (filter , Long .parseLong (identity .getId ()), 0 , 0 ).size ());
694695
695696 MembershipImpl adminProcesses = new MembershipImpl ();
@@ -701,7 +702,7 @@ public void findWorkflow() throws Exception {
701702 PROCESSES_UTILS .when (() -> ProcessesUtils .getProjectParentSpace (workFlow .getProjectId ())).thenReturn (space );
702703 ENTITY_MAPPER .when (() -> EntityMapper .fromEntity (newWorkFlowEntity1 , null )).thenReturn (workFlow );
703704
704- when (organizationService . getMembershipHandler (). findMembershipsByUser ( identity . getRemoteId ())). thenReturn ( memberships_ );
705+ when (aclIdentity . getMemberships ()). thenReturn ( memberships_ . stream (). map ( m -> new MembershipEntry ( m . getGroupId (), m . getMembershipType ())). toList () );
705706 assertEquals (0 , this .processesStorage .findWorkFlows (filter , Long .parseLong (identity .getId ()), 0 , 0 ).size ());
706707 }
707708
@@ -731,7 +732,7 @@ public void countWorkflow() {
731732 when (workFlow .getProjectId ()).thenReturn (0L );
732733 when (workFlow .getSpaceId ()).thenReturn ("1" );
733734
734- when (identityManager .getIdentity ("1" )).thenReturn (identity );
735+ when (identityManager .getIdentity (1 )).thenReturn (identity );
735736 when (space .getGroupId ()).thenReturn ("/spaces/processes_space" );
736737 when (spaceService .getSpaceByGroupId ("/spaces/processes_space" )).thenReturn (space );
737738 when (spaceService .getSpaceById ("1" )).thenReturn (space );
0 commit comments