|
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,23 @@ 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); |
| 237 | + // create a first collection with 2 configs (config1 aliases = a1,a2 ; config2 aliases = a1,a2,a3) |
| 238 | + SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigsWithAliases(), null); |
238 | 239 | UUID collectionUuid = postSpreadsheetConfigCollection(collectionToCreate); |
239 | | - List<UUID> configIds = getSpreadsheetConfigCollection(collectionUuid).spreadsheetConfigs().stream().map(SpreadsheetConfigInfos::id).toList(); |
| 240 | + List<SpreadsheetConfigInfos> sourceConfigs = getSpreadsheetConfigCollection(collectionUuid).spreadsheetConfigs(); |
| 241 | + List<UUID> configIds = sourceConfigs.stream().map(SpreadsheetConfigInfos::id).toList(); |
240 | 242 | assertThat(configIds).hasSize(2); |
| 243 | + List<String> expectedMergedUniqueAliases = sourceConfigs.stream().map (c -> c.nodeAliases()).flatMap(Collection::stream).collect(Collectors.toSet()).stream().toList(); |
| 244 | + |
241 | 245 | // create a second collection duplicating + merging these existing Configs |
242 | 246 | UUID mergedCollectionUuid = postMergeSpreadsheetConfigsIntoCollection(configIds); |
243 | | - List<UUID> duplicatedConfigIds = getSpreadsheetConfigCollection(mergedCollectionUuid).spreadsheetConfigs().stream().map(SpreadsheetConfigInfos::id).toList(); |
244 | 247 |
|
| 248 | + SpreadsheetConfigCollectionInfos mergedCollection = getSpreadsheetConfigCollection(mergedCollectionUuid); |
| 249 | + List<UUID> duplicatedConfigIds = mergedCollection.spreadsheetConfigs().stream().map(SpreadsheetConfigInfos::id).toList(); |
245 | 250 | assertThat(mergedCollectionUuid).isNotEqualTo(collectionUuid); |
246 | 251 | assertThat(duplicatedConfigIds).hasSameSizeAs(configIds); |
247 | 252 | assertThat(duplicatedConfigIds.stream().sorted().toList()).isNotEqualTo(configIds.stream().sorted().toList()); |
| 253 | + assertThat(mergedCollection.nodeAliases().stream().sorted().toList()).isEqualTo(expectedMergedUniqueAliases.stream().sorted().toList()); |
248 | 254 | } |
249 | 255 |
|
250 | 256 | @Test |
@@ -400,6 +406,18 @@ void testReplaceAllSpreadsheetConfigs() throws Exception { |
400 | 406 | .hasSize(sourceConfigIds.size()); |
401 | 407 | } |
402 | 408 |
|
| 409 | + private List<SpreadsheetConfigInfos> createSpreadsheetConfigsWithAliases() { |
| 410 | + List<ColumnInfos> columnInfos = Arrays.asList( |
| 411 | + new ColumnInfos(null, "cust_a", ColumnType.NUMBER, 1, "cust_b + cust_c", "[\"cust_b\", \"cust_c\"]", "idA", null, null, null, null, true), |
| 412 | + new ColumnInfos(null, "cust_b", ColumnType.TEXT, null, "var_minP + 1", null, "idB", null, null, null, null, true) |
| 413 | + ); |
| 414 | + |
| 415 | + return List.of( |
| 416 | + new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnInfos, null, List.of("a1", "a2")), |
| 417 | + new SpreadsheetConfigInfos(null, "TestSheet1", SheetType.GENERATOR, columnInfos, null, List.of("a1", "a2", "a3")) |
| 418 | + ); |
| 419 | + } |
| 420 | + |
403 | 421 | private List<SpreadsheetConfigInfos> createSpreadsheetConfigs() { |
404 | 422 | List<ColumnInfos> columnInfos = Arrays.asList( |
405 | 423 | new ColumnInfos(null, "cust_a", ColumnType.NUMBER, 1, "cust_b + cust_c", "[\"cust_b\", \"cust_c\"]", "idA", null, null, null, null, true), |
|
0 commit comments