@@ -152,7 +152,6 @@ void shouldCreateFile() throws Exception {
152152
153153 CdsCreateResponseDto ret = new CdsCreateResponseDto ();
154154 ret .setStatusOk (true );
155- ArgumentCaptor <URI > captor = ArgumentCaptor .forClass (URI .class );
156155 Mockito .when (cdsRemoteCaller .executePostCall (any (),
157156 eq ("/sub-path-testy/myfilename" ),
158157 eq (false ),
@@ -558,7 +557,74 @@ void shouldEditFile() throws Exception {
558557 eq (false ));
559558
560559 }
561-
560+
561+ @ Test
562+ void shouldMoveFile () throws Exception {
563+ this .initTenantForMovement ();
564+ this .setExistingFileForMovement ("source_file.txt" , false , "test" , false );
565+ this .setExistingFileForMovement ("dest_file.txt" , true , "test_dest" , true );
566+ CdsCreateResponseDto ret = new CdsCreateResponseDto ();
567+ ret .setStatusOk (true );
568+ Mockito .when (cdsRemoteCaller .executePostCall (any (),
569+ eq ("test_dest/dest_file.txt" ),
570+ eq (true ),
571+ any (),
572+ any (),
573+ eq (false ))).thenReturn (ret );
574+ boolean result = this .cdsStorageManager .move ("test/source_file.txt" , false , "test_dest/dest_file.txt" , true );
575+ Assertions .assertThat (result ).isTrue ();
576+ Mockito .verify (this .cdsRemoteCaller , Mockito .times (3 )).getFileAttributeView (Mockito .any (URI .class ), Mockito .any ());
577+ Mockito .verify (this .cdsRemoteCaller , Mockito .times (1 )).getFile (Mockito .any (URI .class ), Mockito .any (), Mockito .anyBoolean ());
578+ }
579+
580+ @ Test
581+ void shouldFailMovementDueMissingSource () throws Exception {
582+ this .initTenantForMovement ();
583+ boolean result = this .cdsStorageManager .move ("test/source_file.txt" , false , "test_dest/dest_file.txt" , false );
584+ Assertions .assertThat (result ).isFalse ();
585+ Mockito .verify (this .cdsRemoteCaller , Mockito .times (1 )).getFileAttributeView (Mockito .any (URI .class ), Mockito .any ());
586+ Mockito .verify (this .cdsRemoteCaller , Mockito .times (0 )).getFile (Mockito .any (URI .class ), Mockito .any (), Mockito .anyBoolean ());
587+ }
588+
589+ @ Test
590+ void shouldFailMovementDueExistingDestination () throws Exception {
591+ this .initTenantForMovement ();
592+ this .setExistingFileForMovement ("source_file.txt" , false , "test" , false );
593+ this .setExistingFileForMovement ("dest_file.txt" , true , "test_dest" , false );
594+ boolean result = this .cdsStorageManager .move ("test/source_file.txt" , false , "test_dest/dest_file.txt" , true );
595+ Assertions .assertThat (result ).isFalse ();
596+ Mockito .verify (this .cdsRemoteCaller , Mockito .times (2 )).getFileAttributeView (Mockito .any (URI .class ), Mockito .any ());
597+ Mockito .verify (this .cdsRemoteCaller , Mockito .times (0 )).getFile (Mockito .any (URI .class ), Mockito .any (), Mockito .anyBoolean ());
598+ }
599+
600+ private void initTenantForMovement () {
601+ Map <String ,String > configMap = Map .of ("cdsPublicUrl" ,"http://my-server/tenant1/cms-resources" ,
602+ "cdsPrivateUrl" ,"http://cds-kube-service:8081/" ,
603+ "cdsPath" ,"/mytenant/api/v1/" );
604+ TenantConfig tc = new TenantConfig (configMap );
605+ Mockito .when (tenantManager .getConfig ("my-tenant" )).thenReturn (Optional .ofNullable (tc ));
606+ ApsTenantApplicationUtils .setTenant ("my-tenant" );
607+ }
608+
609+ private void setExistingFileForMovement (String existingFileName , boolean isProtected , String path , boolean returnEmpty ) {
610+ String subPath = ((isProtected ) ? "protected/" : "" ) + path ;
611+ if (returnEmpty ) {
612+ Mockito .when (cdsRemoteCaller .getFileAttributeView (eq (URI .create (
613+ "http://cds-kube-service:8081/mytenant/api/v1/list/" + subPath )),
614+ any ())).thenReturn (Optional .empty ());
615+ return ;
616+ }
617+ CdsFileAttributeViewDto file = new CdsFileAttributeViewDto ();
618+ file .setName (existingFileName );
619+ file .setDirectory (false );
620+ CdsFileAttributeViewDto dir = new CdsFileAttributeViewDto ();
621+ dir .setName ("test-folder" );
622+ dir .setDirectory (true );
623+ Mockito .when (cdsRemoteCaller .getFileAttributeView (eq (URI .create (
624+ "http://cds-kube-service:8081/mytenant/api/v1/list/" + subPath )),
625+ any ())).thenReturn (Optional .ofNullable (new CdsFileAttributeViewDto []{file , dir }));
626+ }
627+
562628 //@Test
563629 void testListAttributes () throws Throwable {
564630 Map <String ,String > configMap = Map .of ("cdsPublicUrl" ,"http://my-server/tenant1/cms-resources" ,
0 commit comments