26
26
import org .springframework .test .web .servlet .MvcResult ;
27
27
28
28
import java .util .*;
29
+ import java .util .stream .Collectors ;
29
30
30
31
import static org .assertj .core .api .Assertions .assertThat ;
31
32
import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
@@ -233,18 +234,31 @@ void testDuplicateCollection() throws Exception {
233
234
234
235
@ Test
235
236
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 ();
244
242
243
+ // create a second collection, duplicating and merging these N source Configs
244
+ UUID mergedCollectionUuid = postMergeSpreadsheetConfigsIntoCollection (configIds );
245
245
assertThat (mergedCollectionUuid ).isNotEqualTo (collectionUuid );
246
+
247
+ SpreadsheetConfigCollectionInfos mergedCollection = getSpreadsheetConfigCollection (mergedCollectionUuid );
248
+ List <UUID > duplicatedConfigIds = mergedCollection .spreadsheetConfigs ().stream ().map (SpreadsheetConfigInfos ::id ).toList ();
246
249
assertThat (duplicatedConfigIds ).hasSameSizeAs (configIds );
247
250
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 );
248
262
}
249
263
250
264
@ Test
@@ -267,7 +281,7 @@ void testAddSpreadsheetConfigToCollection() throws Exception {
267
281
List <ColumnInfos > columnInfos = List .of (
268
282
new ColumnInfos (null , "new_col" , ColumnType .NUMBER , 1 , "formula" , "[\" dep\" ]" , "idNew" , null , null , null , null , true )
269
283
);
270
- SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos (null , "NewSheet" , SheetType .BATTERY , columnInfos , null );
284
+ SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos (null , "NewSheet" , SheetType .BATTERY , columnInfos , null , List . of () );
271
285
272
286
String newConfigJson = mapper .writeValueAsString (newConfig );
273
287
MvcResult mvcResult = mockMvc .perform (post (URI_SPREADSHEET_CONFIG_COLLECTION_BASE + "/" + collectionUuid + "/spreadsheet-configs" )
@@ -305,7 +319,7 @@ void testRemoveSpreadsheetConfigFromCollection() throws Exception {
305
319
@ Test
306
320
void testAddSpreadsheetConfigToNonExistentCollection () throws Exception {
307
321
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 () );
309
323
310
324
String newConfigJson = mapper .writeValueAsString (newConfig );
311
325
mockMvc .perform (post (URI_SPREADSHEET_CONFIG_COLLECTION_BASE + "/" + nonExistentUuid + "/spreadsheet-configs" )
@@ -400,15 +414,30 @@ void testReplaceAllSpreadsheetConfigs() throws Exception {
400
414
.hasSize (sourceConfigIds .size ());
401
415
}
402
416
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
+
403
432
private List <SpreadsheetConfigInfos > createSpreadsheetConfigs () {
404
433
List <ColumnInfos > columnInfos = Arrays .asList (
405
434
new ColumnInfos (null , "cust_a" , ColumnType .NUMBER , 1 , "cust_b + cust_c" , "[\" cust_b\" , \" cust_c\" ]" , "idA" , null , null , null , null , true ),
406
435
new ColumnInfos (null , "cust_b" , ColumnType .TEXT , null , "var_minP + 1" , null , "idB" , null , null , null , null , true )
407
436
);
408
437
409
438
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 () )
412
441
);
413
442
}
414
443
@@ -443,8 +472,8 @@ private List<SpreadsheetConfigInfos> createSpreadsheetConfigsWithFilters() {
443
472
);
444
473
445
474
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 () )
448
477
);
449
478
}
450
479
@@ -457,9 +486,9 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigs() {
457
486
);
458
487
459
488
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 () )
463
492
);
464
493
}
465
494
@@ -500,9 +529,9 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigsWithFilters(
500
529
);
501
530
502
531
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 () )
506
535
);
507
536
}
508
537
0 commit comments