From a6ccb293ec962528c8712d2a75f309de638e1031 Mon Sep 17 00:00:00 2001 From: Matthew Dunsdon Date: Tue, 15 Dec 2020 15:49:19 +0000 Subject: [PATCH] fix(#1710): Create file specific instance of distributed list ... to try and detangle where an common distributed list is actually needed. --- .../features/operators/general/InMap.feature | 2 +- .../utils/CucumberFileReader.java | 8 ++++--- .../profile/reader/CsvFileInputReader.java | 9 +++---- .../profile/reader/CsvInputReader.java | 8 ++++--- .../profile/reader/CsvStreamInputReader.java | 18 +++++++------- .../generator/profile/reader/FileReader.java | 24 ++++--------------- .../serialisation/ConstraintDeserializer.java | 6 ++--- .../profile/services/ConstraintService.java | 7 +++--- .../services/NameRetrievalService.java | 23 +++++++++--------- .../reader/JsonProfileReaderTests.java | 13 ++++++---- .../reader/file/CsvStreamInputReaderTest.java | 15 +++++++----- .../file/names/NameRetrievalServiceTest.java | 21 +++++++++------- .../AtomicConstraintDeserialiserTests.java | 7 +++--- .../FieldDeserialiserTests.java | 2 +- ...rammaticalConstraintDeserialiserTests.java | 3 +-- .../{ => serialisation}/TestFileReader.java | 20 ++++++++-------- 16 files changed, 92 insertions(+), 94 deletions(-) rename profile/src/test/java/com/scottlogic/datahelix/generator/profile/{ => serialisation}/AtomicConstraintDeserialiserTests.java (98%) rename profile/src/test/java/com/scottlogic/datahelix/generator/profile/{ => serialisation}/FieldDeserialiserTests.java (98%) rename profile/src/test/java/com/scottlogic/datahelix/generator/profile/{ => serialisation}/GrammaticalConstraintDeserialiserTests.java (98%) rename profile/src/test/java/com/scottlogic/datahelix/generator/profile/{ => serialisation}/TestFileReader.java (68%) diff --git a/orchestrator/src/test/java/com/scottlogic/datahelix/generator/orchestrator/cucumber/features/operators/general/InMap.feature b/orchestrator/src/test/java/com/scottlogic/datahelix/generator/orchestrator/cucumber/features/operators/general/InMap.feature index 49731e7f1..96d5ca03c 100644 --- a/orchestrator/src/test/java/com/scottlogic/datahelix/generator/orchestrator/cucumber/features/operators/general/InMap.feature +++ b/orchestrator/src/test/java/com/scottlogic/datahelix/generator/orchestrator/cucumber/features/operators/general/InMap.feature @@ -96,7 +96,7 @@ Feature: User can specify that a field value belongs to a set of predetermined o | "Wales" | "Cardiff" | 2 | "two" | - Scenario: Running an 'inMap' with text a restriction + Scenario: Running an 'inMap' with invalid typed data Given the following non nullable fields exist: | HomeNation | | Population | diff --git a/orchestrator/src/test/java/com/scottlogic/datahelix/generator/orchestrator/cucumber/testframework/utils/CucumberFileReader.java b/orchestrator/src/test/java/com/scottlogic/datahelix/generator/orchestrator/cucumber/testframework/utils/CucumberFileReader.java index 386100fca..ba4a97730 100644 --- a/orchestrator/src/test/java/com/scottlogic/datahelix/generator/orchestrator/cucumber/testframework/utils/CucumberFileReader.java +++ b/orchestrator/src/test/java/com/scottlogic/datahelix/generator/orchestrator/cucumber/testframework/utils/CucumberFileReader.java @@ -15,12 +15,14 @@ */ package com.scottlogic.datahelix.generator.orchestrator.cucumber.testframework.utils; -import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; +import com.scottlogic.datahelix.generator.common.whitelist.WeightedElement; import com.scottlogic.datahelix.generator.profile.reader.CsvInputStreamReaderFactory; import com.scottlogic.datahelix.generator.profile.reader.FileReader; import javax.inject.Inject; import java.io.File; +import java.util.List; +import java.util.stream.Collectors; public class CucumberFileReader extends FileReader { private final CucumberTestState testState; @@ -32,8 +34,8 @@ public CucumberFileReader(CucumberTestState testState) { } @Override - public DistributedList listFromMapFile(File file, String key) { - return DistributedList.uniform(testState.getValuesFromMap(file.getName(), key)); + public List listFromMapFile(File file, String key) { + return testState.getValuesFromMap(file.getName(), key); } } diff --git a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvFileInputReader.java b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvFileInputReader.java index 76e948f04..e7c4b7907 100644 --- a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvFileInputReader.java +++ b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvFileInputReader.java @@ -17,9 +17,10 @@ package com.scottlogic.datahelix.generator.profile.reader; import com.scottlogic.datahelix.generator.common.ValidationException; -import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; +import com.scottlogic.datahelix.generator.common.whitelist.WeightedElement; import java.io.*; +import java.util.List; public class CsvFileInputReader implements CsvInputReader { private final File path; @@ -28,7 +29,7 @@ public CsvFileInputReader(File path) { this.path = path; } - public DistributedList retrieveLines() { + public List> retrieveLines() { try (InputStream stream = createStream()) { return new CsvStreamInputReader(stream, path.getName()).retrieveLines(); } catch (IOException exc){ @@ -36,9 +37,9 @@ public DistributedList retrieveLines() { } } - public DistributedList retrieveLines(String key) { + public List retrieveLinesForColumn(String key) { try (InputStream stream = createStream()) { - return new CsvStreamInputReader(stream, path.getName()).retrieveLines(key); + return new CsvStreamInputReader(stream, path.getName()).retrieveLinesForColumn(key); } catch (IOException exc){ throw new UncheckedIOException(exc); } diff --git a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvInputReader.java b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvInputReader.java index 074c71074..a6705187b 100644 --- a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvInputReader.java +++ b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvInputReader.java @@ -16,9 +16,11 @@ package com.scottlogic.datahelix.generator.profile.reader; -import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; +import com.scottlogic.datahelix.generator.common.whitelist.WeightedElement; + +import java.util.List; public interface CsvInputReader{ - DistributedList retrieveLines(); - DistributedList retrieveLines(String key); + List> retrieveLines(); + List retrieveLinesForColumn(String key); } diff --git a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvStreamInputReader.java b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvStreamInputReader.java index 817d1146a..1bee2b844 100644 --- a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvStreamInputReader.java +++ b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/CsvStreamInputReader.java @@ -17,13 +17,14 @@ package com.scottlogic.datahelix.generator.profile.reader; import com.scottlogic.datahelix.generator.common.ValidationException; -import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; import com.scottlogic.datahelix.generator.common.whitelist.WeightedElement; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVRecord; -import java.io.*; +import java.io.IOException; +import java.io.InputStream; +import java.io.UncheckedIOException; import java.nio.charset.Charset; import java.util.List; import java.util.Optional; @@ -38,14 +39,14 @@ public CsvStreamInputReader(InputStream stream, String file) { this.file = file; } - public DistributedList retrieveLines() { + public List> retrieveLines() { List records = parse(stream); - return new DistributedList<>(records.stream() + return records.stream() .map(this::createWeightedElementFromRecord) - .collect(Collectors.toList())); + .collect(Collectors.toList()); } - public DistributedList retrieveLines(String key) { + public List retrieveLinesForColumn(String key) { List records = parse(stream); int index = getIndexForKey(records.get(0), key); @@ -53,10 +54,9 @@ public DistributedList retrieveLines(String key) { //Remove the header records.remove(0); - return new DistributedList<>(records.stream() + return records.stream() .map(record -> record.get(index)) - .map(record -> createWeightedElement(record, Optional.empty())) - .collect(Collectors.toList())); + .collect(Collectors.toList()); } private static int getIndexForKey(CSVRecord header, String key) { diff --git a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/FileReader.java b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/FileReader.java index 817f6d4b0..a12273ffa 100644 --- a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/FileReader.java +++ b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/reader/FileReader.java @@ -16,11 +16,10 @@ package com.scottlogic.datahelix.generator.profile.reader; import com.google.inject.Inject; -import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; import com.scottlogic.datahelix.generator.common.whitelist.WeightedElement; import java.io.File; -import java.util.stream.Collectors; +import java.util.List; public class FileReader { private final CsvInputStreamReaderFactory csvReaderFactory; @@ -30,24 +29,11 @@ public FileReader(CsvInputStreamReaderFactory csvReaderFactory) { this.csvReaderFactory = csvReaderFactory; } - public DistributedList setFromFile(File file) { - CsvInputReader reader = csvReaderFactory.getReaderForFile(file); - DistributedList names = reader.retrieveLines(); - - return new DistributedList<>( - names.distributedList().stream() - .map(holder -> new WeightedElement<>((Object) holder.element(), holder.weight())) - .distinct() - .collect(Collectors.toList())); + public List> setFromFile(File file) { + return csvReaderFactory.getReaderForFile(file).retrieveLines(); } - public DistributedList listFromMapFile(File file, String key) { - CsvInputReader reader = csvReaderFactory.getReaderForFile(file); - DistributedList names = reader.retrieveLines(key); - - return new DistributedList<>( - names.distributedList().stream() - .map(holder -> new WeightedElement<>(holder.element(), holder.weight())) - .collect(Collectors.toList())); + public List listFromMapFile(File file, String key) { + return csvReaderFactory.getReaderForFile(file).retrieveLinesForColumn(key); } } diff --git a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/serialisation/ConstraintDeserializer.java b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/serialisation/ConstraintDeserializer.java index e45f6c306..e552265db 100644 --- a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/serialisation/ConstraintDeserializer.java +++ b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/serialisation/ConstraintDeserializer.java @@ -38,7 +38,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; public class ConstraintDeserializer extends JsonDeserializer { private final FileReader fileReader; @@ -75,7 +74,8 @@ public ConstraintDTO deserialize(JsonParser jsonParser, DeserializationContext c private InMapConstraintDTO map(InMapFromFileConstraintDTO dto) { - List values = fileReader.listFromMapFile(getFile(dto.file), dto.key).stream().collect(Collectors.toList()); + List values = new ArrayList<>(fileReader.listFromMapFile(getFile(dto.file), dto.key)); + InMapConstraintDTO inMapConstraintDTO = new InMapConstraintDTO(); inMapConstraintDTO.field = dto.field; inMapConstraintDTO.otherField = dto.file; @@ -85,7 +85,7 @@ private InMapConstraintDTO map(InMapFromFileConstraintDTO dto) private InSetConstraintDTO map(InSetFromFileConstraintDTO dto) { - List values = new ArrayList<>(fileReader.setFromFile(getFile(dto.file)).distributedList()); + List values = new ArrayList<>(fileReader.setFromFile(getFile(dto.file))); InSetConstraintDTO inSetConstraintDTO = new InSetConstraintDTO(); inSetConstraintDTO.field = dto.field; inSetConstraintDTO.values = values; diff --git a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/services/ConstraintService.java b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/services/ConstraintService.java index baf6314f3..fe10151a8 100644 --- a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/services/ConstraintService.java +++ b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/services/ConstraintService.java @@ -18,6 +18,7 @@ import com.google.inject.Inject; import com.scottlogic.datahelix.generator.common.profile.*; +import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; import com.scottlogic.datahelix.generator.core.profile.constraints.Constraint; import com.scottlogic.datahelix.generator.core.profile.constraints.atomic.*; import com.scottlogic.datahelix.generator.core.profile.constraints.grammatical.AndConstraint; @@ -88,13 +89,13 @@ public ConstraintService(CustomConstraintFactory customConstraintFactory, NameRe field -> new MatchesStandardConstraint(field, StandardConstraintTypes.RIC)); fieldTypeToConstraint.put( StandardSpecificFieldType.FIRST_NAME.getType(), - field -> new InSetConstraint(field, nameRetrievalService.loadNamesFromFile(NameConstraintTypes.FIRST))); + field -> new InSetConstraint(field, new DistributedList(nameRetrievalService.loadNamesFromFile(NameConstraintTypes.FIRST)))); fieldTypeToConstraint.put( StandardSpecificFieldType.LAST_NAME.getType(), - field -> new InSetConstraint(field, nameRetrievalService.loadNamesFromFile(NameConstraintTypes.LAST))); + field -> new InSetConstraint(field, new DistributedList(nameRetrievalService.loadNamesFromFile(NameConstraintTypes.LAST)))); fieldTypeToConstraint.put( StandardSpecificFieldType.FULL_NAME.getType(), - field -> new InSetConstraint(field, nameRetrievalService.loadNamesFromFile(NameConstraintTypes.FULL))); + field -> new InSetConstraint(field, new DistributedList(nameRetrievalService.loadNamesFromFile(NameConstraintTypes.FULL)))); fieldTypeToConstraint.put( StandardSpecificFieldType.FAKER.getType(), field -> new FakerConstraint(field, field.getSpecificType().getFakerMethod())); diff --git a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/services/NameRetrievalService.java b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/services/NameRetrievalService.java index 0b0c0f5a2..49e66fcad 100644 --- a/profile/src/main/java/com/scottlogic/datahelix/generator/profile/services/NameRetrievalService.java +++ b/profile/src/main/java/com/scottlogic/datahelix/generator/profile/services/NameRetrievalService.java @@ -17,7 +17,6 @@ package com.scottlogic.datahelix.generator.profile.services; import com.google.inject.Inject; -import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; import com.scottlogic.datahelix.generator.common.whitelist.WeightedElement; import com.scottlogic.datahelix.generator.core.profile.constraints.atomic.NameConstraintTypes; import com.scottlogic.datahelix.generator.profile.reader.CsvInputStreamReaderFactory; @@ -25,6 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; +import java.util.List; import java.util.stream.Collectors; import static com.scottlogic.datahelix.generator.core.profile.constraints.atomic.NameConstraintTypes.*; @@ -38,7 +38,7 @@ public NameRetrievalService(CsvInputStreamReaderFactory csvReaderFactory) { this.csvReaderFactory = csvReaderFactory; } - public DistributedList loadNamesFromFile(NameConstraintTypes configuration) { + public List> loadNamesFromFile(NameConstraintTypes configuration) { if (configuration == FULL) { return downcastToObject(combineFirstWithLastNames( generateNamesFromSingleFile(FIRST.getFilePath()), @@ -48,15 +48,14 @@ public DistributedList loadNamesFromFile(NameConstraintTypes configurati } } - private static DistributedList downcastToObject(DistributedList higher) { - return new DistributedList<>( - higher.distributedList().stream() + private static List> downcastToObject(List> higher) { + return higher.stream() .map(holder -> new WeightedElement(holder.element(), holder.weight())) .distinct() - .collect(Collectors.toList())); + .collect(Collectors.toList()); } - private DistributedList generateNamesFromSingleFile(String source) { + private List> generateNamesFromSingleFile(String source) { try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(source)) { return csvReaderFactory.getReaderForStream(stream, source).retrieveLines(); @@ -65,14 +64,14 @@ private DistributedList generateNamesFromSingleFile(String source) { } } - private static DistributedList combineFirstWithLastNames(DistributedList firstNames, - DistributedList lastNames) { - return new DistributedList<>(firstNames.distributedList().stream() + private static List> combineFirstWithLastNames(List> firstNames, + List> lastNames) { + return firstNames.stream() .flatMap( - first -> lastNames.distributedList().stream() + first -> lastNames.stream() .map(last -> mergeFrequencies(first, last))) .distinct() - .collect(Collectors.toList())); + .collect(Collectors.toList()); } private static WeightedElement mergeFrequencies(WeightedElement first, diff --git a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/JsonProfileReaderTests.java b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/JsonProfileReaderTests.java index b35d99ee7..28abeca78 100644 --- a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/JsonProfileReaderTests.java +++ b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/JsonProfileReaderTests.java @@ -23,7 +23,7 @@ import com.scottlogic.datahelix.generator.common.profile.FieldType; import com.scottlogic.datahelix.generator.common.profile.NumericGranularity; import com.scottlogic.datahelix.generator.common.util.FileUtils; -import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; +import com.scottlogic.datahelix.generator.common.whitelist.WeightedElement; import com.scottlogic.datahelix.generator.core.profile.Profile; import com.scottlogic.datahelix.generator.core.profile.constraints.Constraint; import com.scottlogic.datahelix.generator.core.profile.constraints.atomic.*; @@ -52,17 +52,20 @@ import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.Iterator; +import java.util.List; import java.util.function.Consumer; import static com.scottlogic.datahelix.generator.common.util.Defaults.DEFAULT_DATE_FORMATTING; +import static com.scottlogic.datahelix.generator.common.whitelist.WeightedElement.withDefaultWeight; +import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.core.IsNull.nullValue; public class JsonProfileReaderTests { - private DistributedList inSetReaderReturnValue = DistributedList.singleton("test"); - private DistributedList fromFileReaderReturnValue = DistributedList.singleton("test"); + private final List> inSetReaderReturnValue = singletonList(withDefaultWeight("test")); + private final List fromFileReaderReturnValue = singletonList("test"); private class MockFromFileReader extends FileReader { public MockFromFileReader() { @@ -70,13 +73,13 @@ public MockFromFileReader() { } @Override - public DistributedList setFromFile(File file) + public List> setFromFile(File file) { return inSetReaderReturnValue; } @Override - public DistributedList listFromMapFile(File file, String Key) + public List listFromMapFile(File file, String Key) { return fromFileReaderReturnValue; } diff --git a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/file/CsvStreamInputReaderTest.java b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/file/CsvStreamInputReaderTest.java index c71a5a362..deed50e64 100644 --- a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/file/CsvStreamInputReaderTest.java +++ b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/file/CsvStreamInputReaderTest.java @@ -15,13 +15,13 @@ */ package com.scottlogic.datahelix.generator.profile.reader.file; -import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; import com.scottlogic.datahelix.generator.common.whitelist.WeightedElement; import com.scottlogic.datahelix.generator.profile.reader.CsvInputReader; import com.scottlogic.datahelix.generator.profile.reader.CsvStreamInputReader; import org.junit.jupiter.api.Test; import java.io.InputStream; +import java.util.List; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -35,11 +35,14 @@ public void testReadingLinesFromNames() { final InputStream is = loader.getResourceAsStream("names/firstname.csv"); final CsvInputReader reader = new CsvStreamInputReader(is, "names/firstname.csv"); - final DistributedList names = reader.retrieveLines(); + final List> nameElements = reader.retrieveLines(); + final Set names = nameElements.stream() + .map(WeightedElement::element) + .collect(Collectors.toSet()); final Set sampleNames = Stream.of("Rory", "Kyle", "Grace").collect(Collectors.toSet()); - assertTrue(names.list().containsAll(sampleNames)); + assertTrue(names.containsAll(sampleNames)); } @Test @@ -48,13 +51,13 @@ public void testReadingLinesFromFileWithoutFrequencies() { final InputStream is = loader.getResourceAsStream("csv/without-frequencies.csv"); final CsvInputReader reader = new CsvStreamInputReader(is, "csv/without-frequencies.csv"); - final DistributedList set = reader.retrieveLines(); + final List> set = reader.retrieveLines(); assertTrue(checkAllWeightsAreEquals(set)); } - private boolean checkAllWeightsAreEquals(DistributedList set) { - return set.distributedList().stream() + private boolean checkAllWeightsAreEquals(List> set) { + return set.stream() .map(WeightedElement::weight) .distinct() .limit(2).count() <= 1; diff --git a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/file/names/NameRetrievalServiceTest.java b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/file/names/NameRetrievalServiceTest.java index e27cfec13..d3e84540c 100644 --- a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/file/names/NameRetrievalServiceTest.java +++ b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/reader/file/names/NameRetrievalServiceTest.java @@ -17,15 +17,18 @@ package com.scottlogic.datahelix.generator.profile.reader.file.names; +import com.scottlogic.datahelix.generator.common.whitelist.WeightedElement; import com.scottlogic.datahelix.generator.core.profile.constraints.atomic.NameConstraintTypes; -import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; import com.scottlogic.datahelix.generator.profile.reader.CsvInputStreamReaderFactory; import com.scottlogic.datahelix.generator.profile.services.NameRetrievalService; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import static org.junit.jupiter.api.Assertions.*; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class NameRetrievalServiceTest { @@ -34,9 +37,9 @@ public void testLoadingFirstNames() { CsvInputStreamReaderFactory csvReaderFactory = new CsvInputStreamReaderFactory(); NameRetrievalService service = new NameRetrievalService(csvReaderFactory); - DistributedList names = service.loadNamesFromFile(NameConstraintTypes.FIRST); + List> names = service.loadNamesFromFile(NameConstraintTypes.FIRST); - assertEquals(704, names.distributedList().size()); + assertEquals(704, names.size()); } @Test @@ -44,9 +47,9 @@ public void testLoadingLastNames() { CsvInputStreamReaderFactory csvReaderFactory = new CsvInputStreamReaderFactory(); NameRetrievalService service = new NameRetrievalService(csvReaderFactory); - DistributedList names = service.loadNamesFromFile(NameConstraintTypes.LAST); + List> names = service.loadNamesFromFile(NameConstraintTypes.LAST); - assertEquals(280, names.distributedList().size()); + assertEquals(280, names.size()); } @Test @@ -54,9 +57,9 @@ public void testLoadingFullNames() { CsvInputStreamReaderFactory csvReaderFactory = new CsvInputStreamReaderFactory(); NameRetrievalService service = new NameRetrievalService(csvReaderFactory); - DistributedList names = service.loadNamesFromFile(NameConstraintTypes.FULL); + List> names = service.loadNamesFromFile(NameConstraintTypes.FULL); - assertEquals(197120, names.distributedList().size()); + assertEquals(197120, names.size()); } @ParameterizedTest @@ -65,7 +68,7 @@ public void testAllValuesGiveValidResult(NameConstraintTypes config) { CsvInputStreamReaderFactory csvReaderFactory = new CsvInputStreamReaderFactory(); NameRetrievalService service = new NameRetrievalService(csvReaderFactory); - DistributedList result = service.loadNamesFromFile(config); + List> result = service.loadNamesFromFile(config); assertNotNull(result); } diff --git a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/AtomicConstraintDeserialiserTests.java b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/AtomicConstraintDeserialiserTests.java similarity index 98% rename from profile/src/test/java/com/scottlogic/datahelix/generator/profile/AtomicConstraintDeserialiserTests.java rename to profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/AtomicConstraintDeserialiserTests.java index ff5616197..849711c11 100644 --- a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/AtomicConstraintDeserialiserTests.java +++ b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/AtomicConstraintDeserialiserTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.datahelix.generator.profile; +package com.scottlogic.datahelix.generator.profile.serialisation; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -37,7 +37,6 @@ import com.scottlogic.datahelix.generator.profile.dtos.constraints.atomic.textual.MatchesRegexConstraintDTO; import com.scottlogic.datahelix.generator.profile.dtos.constraints.relations.*; import com.scottlogic.datahelix.generator.profile.reader.FileReader; -import com.scottlogic.datahelix.generator.profile.serialisation.ConstraintDeserializer; import org.junit.Assert; import org.junit.Rule; import org.junit.jupiter.api.Test; @@ -127,8 +126,8 @@ public void shouldDeserialiseWeightedInSetCsvFile() throws IOException { InSetConstraintDTO expected = new InSetConstraintDTO(); expected.field = "country"; expected.values = Arrays.asList( - new WeightedElement<>("test1", 0.2), - new WeightedElement<>("test2", 0.8) + new WeightedElement<>("test1", 20.0), + new WeightedElement<>("test2", 80.0) ); assertThat(actual, sameBeanAs(expected)); diff --git a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/FieldDeserialiserTests.java b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/FieldDeserialiserTests.java similarity index 98% rename from profile/src/test/java/com/scottlogic/datahelix/generator/profile/FieldDeserialiserTests.java rename to profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/FieldDeserialiserTests.java index 6f8e573b7..d5b56abb8 100644 --- a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/FieldDeserialiserTests.java +++ b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/FieldDeserialiserTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.datahelix.generator.profile; +package com.scottlogic.datahelix.generator.profile.serialisation; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; diff --git a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/GrammaticalConstraintDeserialiserTests.java b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/GrammaticalConstraintDeserialiserTests.java similarity index 98% rename from profile/src/test/java/com/scottlogic/datahelix/generator/profile/GrammaticalConstraintDeserialiserTests.java rename to profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/GrammaticalConstraintDeserialiserTests.java index 163d755d9..0b20155dd 100644 --- a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/GrammaticalConstraintDeserialiserTests.java +++ b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/GrammaticalConstraintDeserialiserTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.datahelix.generator.profile; +package com.scottlogic.datahelix.generator.profile.serialisation; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -32,7 +32,6 @@ import com.scottlogic.datahelix.generator.profile.dtos.constraints.grammatical.NotConstraintDTO; import com.scottlogic.datahelix.generator.profile.reader.CsvInputStreamReaderFactory; import com.scottlogic.datahelix.generator.profile.reader.FileReader; -import com.scottlogic.datahelix.generator.profile.serialisation.ConstraintDeserializer; import org.junit.Assert; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/TestFileReader.java b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/TestFileReader.java similarity index 68% rename from profile/src/test/java/com/scottlogic/datahelix/generator/profile/TestFileReader.java rename to profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/TestFileReader.java index f163df6d3..ea0428f52 100644 --- a/profile/src/test/java/com/scottlogic/datahelix/generator/profile/TestFileReader.java +++ b/profile/src/test/java/com/scottlogic/datahelix/generator/profile/serialisation/TestFileReader.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.scottlogic.datahelix.generator.profile; +package com.scottlogic.datahelix.generator.profile.serialisation; -import com.scottlogic.datahelix.generator.common.whitelist.DistributedList; import com.scottlogic.datahelix.generator.common.whitelist.WeightedElement; import com.scottlogic.datahelix.generator.profile.reader.FileReader; import java.io.File; import java.util.Arrays; -import java.util.Collections; import java.util.List; +import static com.scottlogic.datahelix.generator.common.whitelist.WeightedElement.withDefaultWeight; +import static java.util.Collections.singletonList; + public class TestFileReader extends FileReader { private final boolean weighted; @@ -38,22 +39,21 @@ public TestFileReader(boolean weighted) { } @Override - public DistributedList setFromFile(File file) { + public List> setFromFile(File file) { return weighted ? this.getDistributedListWithWeights() - : DistributedList.uniform(Collections.singleton("test")); + : singletonList(withDefaultWeight("test")); } @Override - public DistributedList listFromMapFile(File file, String key) { - return DistributedList.uniform(Collections.singleton("test")); + public List listFromMapFile(File file, String key) { + return singletonList("test"); } - private static DistributedList getDistributedListWithWeights() { - List elements = Arrays.asList( + private static List> getDistributedListWithWeights() { + return Arrays.asList( new WeightedElement<>("test1", 20), new WeightedElement<>("test2", 80) ); - return DistributedList.weightedOrDefault(elements); } }