Skip to content

Commit 123512e

Browse files
committed
add tests
Signed-off-by: David BRAQUART <[email protected]>
1 parent 105c5d1 commit 123512e

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigCollectionIntegrationTest.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.test.web.servlet.MvcResult;
2727

2828
import java.util.*;
29+
import java.util.stream.Collectors;
2930

3031
import static org.assertj.core.api.Assertions.assertThat;
3132
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
@@ -233,18 +234,23 @@ 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);
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);
238239
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();
240242
assertThat(configIds).hasSize(2);
243+
List<String> expectedMergedUniqueAliases = sourceConfigs.stream().map (c -> c.nodeAliases()).flatMap(Collection::stream).collect(Collectors.toSet()).stream().toList();
244+
241245
// create a second collection duplicating + merging these existing Configs
242246
UUID mergedCollectionUuid = postMergeSpreadsheetConfigsIntoCollection(configIds);
243-
List<UUID> duplicatedConfigIds = getSpreadsheetConfigCollection(mergedCollectionUuid).spreadsheetConfigs().stream().map(SpreadsheetConfigInfos::id).toList();
244247

248+
SpreadsheetConfigCollectionInfos mergedCollection = getSpreadsheetConfigCollection(mergedCollectionUuid);
249+
List<UUID> duplicatedConfigIds = mergedCollection.spreadsheetConfigs().stream().map(SpreadsheetConfigInfos::id).toList();
245250
assertThat(mergedCollectionUuid).isNotEqualTo(collectionUuid);
246251
assertThat(duplicatedConfigIds).hasSameSizeAs(configIds);
247252
assertThat(duplicatedConfigIds.stream().sorted().toList()).isNotEqualTo(configIds.stream().sorted().toList());
253+
assertThat(mergedCollection.nodeAliases().stream().sorted().toList()).isEqualTo(expectedMergedUniqueAliases.stream().sorted().toList());
248254
}
249255

250256
@Test
@@ -400,6 +406,18 @@ void testReplaceAllSpreadsheetConfigs() throws Exception {
400406
.hasSize(sourceConfigIds.size());
401407
}
402408

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+
403421
private List<SpreadsheetConfigInfos> createSpreadsheetConfigs() {
404422
List<ColumnInfos> columnInfos = Arrays.asList(
405423
new ColumnInfos(null, "cust_a", ColumnType.NUMBER, 1, "cust_b + cust_c", "[\"cust_b\", \"cust_c\"]", "idA", null, null, null, null, true),

src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void tearDown() {
6363

6464
@Test
6565
void testCreate() throws Exception {
66-
SpreadsheetConfigInfos configToCreate = new SpreadsheetConfigInfos(null, "Battery", SheetType.BATTERY, createColumnsWithFilters(), createGlobalFilters(), List.of());
66+
SpreadsheetConfigInfos configToCreate = new SpreadsheetConfigInfos(null, "Battery", SheetType.BATTERY, createColumnsWithFilters(), createGlobalFilters(), List.of("alias1", "alias2"));
6767

6868
UUID configUuid = postSpreadsheetConfig(configToCreate);
6969
SpreadsheetConfigInfos createdConfig = getSpreadsheetConfig(configUuid);
@@ -89,7 +89,7 @@ void testCreateWithInvalidData() throws Exception {
8989

9090
@Test
9191
void testRead() throws Exception {
92-
SpreadsheetConfigInfos configToRead = new SpreadsheetConfigInfos(null, "Battery", SheetType.BUS, createColumnsWithFilters(), createGlobalFilters(), List.of());
92+
SpreadsheetConfigInfos configToRead = new SpreadsheetConfigInfos(null, "Battery", SheetType.BUS, createColumnsWithFilters(), createGlobalFilters(), List.of("alias"));
9393

9494
UUID configUuid = saveAndReturnId(configToRead);
9595

@@ -153,11 +153,11 @@ void testUpdateWithInvalidData() throws Exception {
153153

154154
@Test
155155
void testUpdate() throws Exception {
156-
SpreadsheetConfigInfos configToUpdate = new SpreadsheetConfigInfos(null, "Battery", SheetType.BATTERY, createColumnsWithFilters(), createGlobalFilters(), List.of());
156+
SpreadsheetConfigInfos configToUpdate = new SpreadsheetConfigInfos(null, "Battery", SheetType.BATTERY, createColumnsWithFilters(), createGlobalFilters(), List.of("alias1"));
157157

158158
UUID configUuid = saveAndReturnId(configToUpdate);
159159

160-
SpreadsheetConfigInfos updatedConfig = new SpreadsheetConfigInfos(configUuid, "Bus", SheetType.BUS, createUpdatedColumnsWithFilters(), createUpdatedGlobalFilters(), List.of());
160+
SpreadsheetConfigInfos updatedConfig = new SpreadsheetConfigInfos(configUuid, "Bus", SheetType.BUS, createUpdatedColumnsWithFilters(), createUpdatedGlobalFilters(), List.of("newAlias"));
161161

162162
String updatedConfigJson = mapper.writeValueAsString(updatedConfig);
163163

@@ -211,7 +211,7 @@ void testGetAll() throws Exception {
211211

212212
@Test
213213
void testDuplicate() throws Exception {
214-
SpreadsheetConfigInfos configToCreate = new SpreadsheetConfigInfos(null, "Battery", SheetType.BATTERY, createColumnsWithFilters(), createGlobalFilters(), List.of());
214+
SpreadsheetConfigInfos configToCreate = new SpreadsheetConfigInfos(null, "Battery", SheetType.BATTERY, createColumnsWithFilters(), createGlobalFilters(), List.of("alias1,", "alias2"));
215215
UUID configUuid = postSpreadsheetConfig(configToCreate);
216216

217217
UUID duplicatedConfigUuid = duplicateSpreadsheetConfig(configUuid);

0 commit comments

Comments
 (0)