2626import org .springframework .test .web .servlet .MvcResult ;
2727
2828import java .util .*;
29+ import java .util .stream .Collectors ;
2930
3031import static org .assertj .core .api .Assertions .assertThat ;
3132import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
@@ -233,18 +234,31 @@ void testDuplicateCollection() throws Exception {
233234
234235 @ Test
235236 void testMergeModelsIntoNewCollection () throws Exception {
236- // create a first collection with 2 configs
237- SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos (null , createSpreadsheetConfigs (), null );
238- UUID collectionUuid = postSpreadsheetConfigCollection (collectionToCreate );
239- List <UUID > configIds = getSpreadsheetConfigCollection (collectionUuid ).spreadsheetConfigs ().stream ().map (SpreadsheetConfigInfos ::id ).toList ();
240- assertThat (configIds ).hasSize (2 );
241- // create a second collection duplicating + merging these existing Configs
242- UUID mergedCollectionUuid = postMergeSpreadsheetConfigsIntoCollection (configIds );
243- List <UUID > duplicatedConfigIds = getSpreadsheetConfigCollection (mergedCollectionUuid ).spreadsheetConfigs ().stream ().map (SpreadsheetConfigInfos ::id ).toList ();
237+ // create a source collection to create N configs
238+ SpreadsheetConfigCollectionInfos sourceCollection = new SpreadsheetConfigCollectionInfos (null , createSpreadsheetConfigsWithAliases (), List .of ("sourceAlias" ));
239+ UUID collectionUuid = postSpreadsheetConfigCollection (sourceCollection );
240+ List <SpreadsheetConfigInfos > sourceConfigs = getSpreadsheetConfigCollection (collectionUuid ).spreadsheetConfigs ();
241+ List <UUID > configIds = sourceConfigs .stream ().map (SpreadsheetConfigInfos ::id ).toList ();
244242
243+ // create a second collection, duplicating and merging these N source Configs
244+ UUID mergedCollectionUuid = postMergeSpreadsheetConfigsIntoCollection (configIds );
245245 assertThat (mergedCollectionUuid ).isNotEqualTo (collectionUuid );
246+
247+ SpreadsheetConfigCollectionInfos mergedCollection = getSpreadsheetConfigCollection (mergedCollectionUuid );
248+ List <UUID > duplicatedConfigIds = mergedCollection .spreadsheetConfigs ().stream ().map (SpreadsheetConfigInfos ::id ).toList ();
246249 assertThat (duplicatedConfigIds ).hasSameSizeAs (configIds );
247250 assertThat (duplicatedConfigIds .stream ().sorted ().toList ()).isNotEqualTo (configIds .stream ().sorted ().toList ());
251+
252+ // dont compare aliases, merged collection aliases are computed
253+ assertThat (mergedCollection )
254+ .usingRecursiveComparison ()
255+ .ignoringFields ("id" , "nodeAliases" , "spreadsheetConfigs.columns.uuid" , "spreadsheetConfigs.id" )
256+ .ignoringExpectedNullFields ()
257+ .isEqualTo (sourceCollection );
258+
259+ // merged aliases must be unique
260+ List <String > expectedUniqueAliases = sourceConfigs .stream ().map (SpreadsheetConfigInfos ::nodeAliases ).flatMap (Collection ::stream ).collect (Collectors .toSet ()).stream ().toList ();
261+ assertThat (mergedCollection .nodeAliases ()).isEqualTo (expectedUniqueAliases );
248262 }
249263
250264 @ Test
@@ -267,7 +281,7 @@ void testAddSpreadsheetConfigToCollection() throws Exception {
267281 List <ColumnInfos > columnInfos = List .of (
268282 new ColumnInfos (null , "new_col" , ColumnType .NUMBER , 1 , "formula" , "[\" dep\" ]" , "idNew" , null , null , null , null , true )
269283 );
270- SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos (null , "NewSheet" , SheetType .BATTERY , columnInfos , null );
284+ SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos (null , "NewSheet" , SheetType .BATTERY , columnInfos , null , List . of () );
271285
272286 String newConfigJson = mapper .writeValueAsString (newConfig );
273287 MvcResult mvcResult = mockMvc .perform (post (URI_SPREADSHEET_CONFIG_COLLECTION_BASE + "/" + collectionUuid + "/spreadsheet-configs" )
@@ -305,7 +319,7 @@ void testRemoveSpreadsheetConfigFromCollection() throws Exception {
305319 @ Test
306320 void testAddSpreadsheetConfigToNonExistentCollection () throws Exception {
307321 UUID nonExistentUuid = UUID .randomUUID ();
308- SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos (null , "TestSheet" , SheetType .GENERATOR , List .of (), null );
322+ SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos (null , "TestSheet" , SheetType .GENERATOR , List .of (), null , List . of () );
309323
310324 String newConfigJson = mapper .writeValueAsString (newConfig );
311325 mockMvc .perform (post (URI_SPREADSHEET_CONFIG_COLLECTION_BASE + "/" + nonExistentUuid + "/spreadsheet-configs" )
@@ -400,15 +414,30 @@ void testReplaceAllSpreadsheetConfigs() throws Exception {
400414 .hasSize (sourceConfigIds .size ());
401415 }
402416
417+ private List <SpreadsheetConfigInfos > createSpreadsheetConfigsWithAliases () {
418+ List <ColumnInfos > columnInfos = Arrays .asList (
419+ new ColumnInfos (null , "cust_a" , ColumnType .NUMBER , 1 , "cust_b + cust_c" , "[\" cust_b\" , \" cust_c\" ]" , "idA" , null , null , null , null , true ),
420+ new ColumnInfos (null , "cust_b" , ColumnType .TEXT , null , "var_minP + 1" , null , "idB" , null , null , null , null , true )
421+ );
422+
423+ return List .of (
424+ new SpreadsheetConfigInfos (null , "TestSheet" , SheetType .GENERATOR , columnInfos , null , List .of ("a1" , "a2" )),
425+ new SpreadsheetConfigInfos (null , "TestSheet1" , SheetType .GENERATOR , columnInfos , null , List .of ("a1" , "a2" , "a3" )),
426+ new SpreadsheetConfigInfos (null , "TestSheet2" , SheetType .GENERATOR , columnInfos , null , List .of ("a2" , "a4" )),
427+ new SpreadsheetConfigInfos (null , "TestSheet3" , SheetType .GENERATOR , columnInfos , null , List .of ()),
428+ new SpreadsheetConfigInfos (null , "TestSheet4" , SheetType .GENERATOR , columnInfos , null , List .of ("alias" ))
429+ );
430+ }
431+
403432 private List <SpreadsheetConfigInfos > createSpreadsheetConfigs () {
404433 List <ColumnInfos > columnInfos = Arrays .asList (
405434 new ColumnInfos (null , "cust_a" , ColumnType .NUMBER , 1 , "cust_b + cust_c" , "[\" cust_b\" , \" cust_c\" ]" , "idA" , null , null , null , null , true ),
406435 new ColumnInfos (null , "cust_b" , ColumnType .TEXT , null , "var_minP + 1" , null , "idB" , null , null , null , null , true )
407436 );
408437
409438 return List .of (
410- new SpreadsheetConfigInfos (null , "TestSheet" , SheetType .GENERATOR , columnInfos , null ),
411- new SpreadsheetConfigInfos (null , "TestSheet1" , SheetType .GENERATOR , columnInfos , null )
439+ new SpreadsheetConfigInfos (null , "TestSheet" , SheetType .GENERATOR , columnInfos , null , List . of () ),
440+ new SpreadsheetConfigInfos (null , "TestSheet1" , SheetType .GENERATOR , columnInfos , null , List . of () )
412441 );
413442 }
414443
@@ -443,8 +472,8 @@ private List<SpreadsheetConfigInfos> createSpreadsheetConfigsWithFilters() {
443472 );
444473
445474 return List .of (
446- new SpreadsheetConfigInfos (null , "TestSheet" , SheetType .GENERATOR , columnsConfig1 , globalFiltersConfig1 ),
447- new SpreadsheetConfigInfos (null , "TestSheet2" , SheetType .LOAD , columnsConfig2 , globalFiltersConfig2 )
475+ new SpreadsheetConfigInfos (null , "TestSheet" , SheetType .GENERATOR , columnsConfig1 , globalFiltersConfig1 , List . of () ),
476+ new SpreadsheetConfigInfos (null , "TestSheet2" , SheetType .LOAD , columnsConfig2 , globalFiltersConfig2 , List . of () )
448477 );
449478 }
450479
@@ -457,9 +486,9 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigs() {
457486 );
458487
459488 return List .of (
460- new SpreadsheetConfigInfos (null , "Generator" , SheetType .GENERATOR , columnInfos , null ),
461- new SpreadsheetConfigInfos (null , "TestSheet" , SheetType .GENERATOR , columnInfos , null ),
462- new SpreadsheetConfigInfos (null , "TestSheet (1)" , SheetType .BATTERY , columnInfos , null )
489+ new SpreadsheetConfigInfos (null , "Generator" , SheetType .GENERATOR , columnInfos , null , List . of () ),
490+ new SpreadsheetConfigInfos (null , "TestSheet" , SheetType .GENERATOR , columnInfos , null , List . of () ),
491+ new SpreadsheetConfigInfos (null , "TestSheet (1)" , SheetType .BATTERY , columnInfos , null , List . of () )
463492 );
464493 }
465494
@@ -500,9 +529,9 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigsWithFilters(
500529 );
501530
502531 return List .of (
503- new SpreadsheetConfigInfos (null , "Updated1" , SheetType .BATTERY , columnsConfig1 , globalFiltersConfig1 ),
504- new SpreadsheetConfigInfos (null , "Updated2" , SheetType .LINE , columnsConfig2 , globalFiltersConfig2 ),
505- new SpreadsheetConfigInfos (null , "Added3" , SheetType .BUS , columnsConfig3 , globalFiltersConfig3 )
532+ new SpreadsheetConfigInfos (null , "Updated1" , SheetType .BATTERY , columnsConfig1 , globalFiltersConfig1 , List . of () ),
533+ new SpreadsheetConfigInfos (null , "Updated2" , SheetType .LINE , columnsConfig2 , globalFiltersConfig2 , List . of () ),
534+ new SpreadsheetConfigInfos (null , "Added3" , SheetType .BUS , columnsConfig3 , globalFiltersConfig3 , List . of () )
506535 );
507536 }
508537
0 commit comments