1313import org .junit .jupiter .api .extension .ExtendWith ;
1414import org .lfenergy .compas .core .commons .ElementConverter ;
1515import org .lfenergy .compas .core .commons .exception .CompasException ;
16+ import org .lfenergy .compas .scl .data .dto .LocationMetaData ;
1617import org .lfenergy .compas .scl .data .dto .ResourceMetaData ;
1718import org .lfenergy .compas .scl .data .dto .TypeEnum ;
1819import org .lfenergy .compas .scl .data .exception .CompasNoDataFoundException ;
@@ -546,11 +547,12 @@ void createLocation_WhenCalled_ThenReturnCreatedLocation() {
546547 ILocationMetaItem expectedLocation = new LocationMetaItem (UUID .randomUUID ().toString (), "locationKey" , "locationName" , null , 0 );
547548 when (compasSclDataRepository .createLocation ("locationKey" , "locationName" , null )).thenReturn (expectedLocation );
548549 when (compasSclDataRepository .hasDuplicateLocationValues ("locationKey" , "locationName" )).thenReturn (false );
549- Uni <ILocationMetaItem > actualLocation = compasSclDataService .createLocation ("locationKey" , "locationName" , null );
550+
551+ UniAssertSubscriber <ILocationMetaItem > result = compasSclDataService .createLocation ("locationKey" , "locationName" , null ).subscribe ().withSubscriber (UniAssertSubscriber .create ());
550552
551553 verify (compasSclDataRepository , times (1 )).createLocation (any (), any (), any ());
552- verify (compasSclDataArchivingServiceImpl , times (1 )).createLocation (any ());
553- assertEquals (expectedLocation , actualLocation );
554+ verify (compasSclDataRepository , times (1 )).addLocationTags (any ());
555+ assertEquals (expectedLocation , result . getItem () );
554556 }
555557
556558 @ Test
@@ -744,7 +746,26 @@ void archiveResource_WhenCalled_ThenResourceIsArchived() {
744746 null
745747 )
746748 );
747-
749+ LocationMetaItem locationMetaItem = new LocationMetaItem (
750+ locationId .toString (),
751+ "locationKey" ,
752+ "locationName" ,
753+ null ,
754+ 1
755+ );
756+ when (compasSclDataRepository .findLocationByUUID (locationId ))
757+ .thenReturn (
758+ locationMetaItem
759+ );
760+ when (compasSclDataArchivingServiceImpl .createLocation (locationMetaItem ))
761+ .thenReturn (Uni .createFrom ()
762+ .item (new LocationMetaData ()
763+ .uuid (locationId )
764+ .name ("locationName" )
765+ .key ("locationKey" )
766+ .description (null )
767+ .assignedResources (1 )
768+ ));
748769 when (compasSclDataArchivingServiceImpl .archiveData (any (), any (), any (), any (), any ())).thenReturn (Uni .createFrom ().item (
749770 new ResourceMetaData (
750771 TypeEnum .RESOURCE ,
@@ -789,14 +810,15 @@ void archiveResource_WhenFileIsNull_ThenFileIsNotWritten() {
789810
790811 UUID locationId = UUID .randomUUID ();
791812 when (compasSclDataRepository .listHistoryVersionsByUUID (resourceId )).thenReturn (List .of (historyMetaItem ));
813+ LocationMetaItem locationMetaItem = new LocationMetaItem (
814+ locationId .toString (),
815+ "someKey" ,
816+ "someName" ,
817+ "someDescription" ,
818+ 1
819+ );
792820 when (compasSclDataRepository .findLocationByUUID (UUID .fromString (locationId .toString ()))).thenReturn (
793- new LocationMetaItem (
794- locationId .toString (),
795- "someKey" ,
796- "someName" ,
797- "someDescription" ,
798- 1
799- )
821+ locationMetaItem
800822 );
801823 when (compasSclDataRepository .archiveResource (resourceId , new Version (version ), author , approver , contentType , filename ))
802824 .thenReturn (
@@ -816,7 +838,6 @@ void archiveResource_WhenFileIsNull_ThenFileIsNotWritten() {
816838 null
817839 )
818840 );
819-
820841 when (compasSclDataArchivingServiceImpl .archiveData (any (), any (), any (), any (), any ())).thenReturn (Uni .createFrom ().item (
821842 new ResourceMetaData (
822843 TypeEnum .RESOURCE ,
@@ -825,11 +846,19 @@ void archiveResource_WhenFileIsNull_ThenFileIsNotWritten() {
825846 List .of ()
826847 )
827848 ));
849+ when (compasSclDataArchivingServiceImpl .createLocation (locationMetaItem ))
850+ .thenReturn (Uni .createFrom ()
851+ .item (new LocationMetaData ()
852+ .uuid (locationId )
853+ .name ("locationName" )
854+ .key ("locationKey" )
855+ .description ("someDescription" )
856+ .assignedResources (1 )
857+ ));
828858
829859 UniAssertSubscriber <IAbstractArchivedResourceMetaItem > cut = compasSclDataService .archiveResource (resourceId , version , author , approver , contentType , filename , null ).subscribe ().withSubscriber (UniAssertSubscriber .create ());
830860
831861 cut .assertCompleted ();
832-
833862 verify (compasSclDataRepository , times (1 )).archiveResource (resourceId , new Version (version ), author , approver , contentType , filename );
834863 verify (compasSclDataArchivingService , times (0 )).archiveSclData (any (), any (), any (), any ());
835864 }
@@ -859,16 +888,16 @@ void archiveSclResource_WhenCalled_ThenResourceIsArchived() {
859888
860889 when (compasSclDataRepository .archiveSclResource (resourceId , new Version (version ), approver )).thenReturn (archivedResource );
861890 when (compasSclDataRepository .findByUUID (resourceId , new Version (version ))).thenReturn (sclData );
891+ LocationMetaItem locationMetaItem = new LocationMetaItem (
892+ locationId .toString (),
893+ "locationKey" ,
894+ "locationName" ,
895+ null ,
896+ 0
897+ );
862898 when (compasSclDataRepository .findLocationByUUID (locationId )).thenReturn (
863- new LocationMetaItem (
864- locationId .toString (),
865- "locationKey" ,
866- "locationName" ,
867- null ,
868- 0
869- )
899+ locationMetaItem
870900 );
871-
872901 when (compasSclDataArchivingServiceImpl .archiveSclData (any (), any (), any (), any ())).thenReturn (Uni .createFrom ().item (
873902 new ResourceMetaData (
874903 TypeEnum .RESOURCE ,
@@ -877,14 +906,22 @@ void archiveSclResource_WhenCalled_ThenResourceIsArchived() {
877906 List .of ()
878907 )
879908 ));
909+ when (compasSclDataArchivingServiceImpl .createLocation (locationMetaItem ))
910+ .thenReturn (Uni .createFrom ()
911+ .item (new LocationMetaData ()
912+ .uuid (locationId )
913+ .name ("locationName" )
914+ .key ("locationKey" )
915+ .description (null )
916+ .assignedResources (0 )
917+ ));
880918
881919 UniAssertSubscriber <IAbstractArchivedResourceMetaItem > result = compasSclDataService .archiveSclResource (resourceId , new Version (version ), approver ).subscribe ().withSubscriber (UniAssertSubscriber .create ());
882920
883921 result .assertCompleted ();
884-
885922 verify (compasSclDataRepository , times (1 )).archiveSclResource (resourceId , new Version (version ), approver );
886923 verify (compasSclDataRepository , times (1 )).findByUUID (resourceId , new Version (version ));
887- verify (compasSclDataArchivingServiceImpl , times (1 )).archiveSclData (resourceId , archivedResource , "locationName " , sclData );
924+ verify (compasSclDataArchivingServiceImpl , times (1 )).archiveSclData (resourceId , archivedResource , "locationKey " , sclData );
888925 }
889926
890927 @ Test
0 commit comments