From d0397b5a55103c0261dbc5e4c5dbd9b130b33a31 Mon Sep 17 00:00:00 2001 From: Zachary Bischoff <116595361+bischoffz@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:28:27 -0500 Subject: [PATCH 01/15] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 59de761..d751996 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ - 3.2.0 + 4.0.0-SNAPSHOT UTF-8 From bbb2d66dabd9b0f07f3e9e2aa3f45ec868f43829 Mon Sep 17 00:00:00 2001 From: Zachary Bischoff <116595361+bischoffz@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:17:34 -0500 Subject: [PATCH 02/15] remove output files from controller builder (#38) --- .../ms/taskit/core/TranslationController.java | 415 ++++-------------- .../ms/taskit/core/TranslationEngine.java | 49 --- .../testsupport/TestTranslationEngine.java | 7 - .../taskit/core/AT_TranslationController.java | 391 +++-------------- .../core/TranslationEngineTestHelper.java | 25 -- .../testsupport/AT_TestTranslationEngine.java | 7 - .../protobuf/ProtobufTranslationEngine.java | 7 - .../ProtobufTranslationEngineTestHelper.java | 24 - .../AT_ProtobufTranslationEngine.java | 28 +- 9 files changed, 158 insertions(+), 795 deletions(-) diff --git a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java index b3a899b..27dce53 100644 --- a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java +++ b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java @@ -12,8 +12,6 @@ import java.util.Optional; import java.util.Set; -import org.apache.commons.math3.util.Pair; - import gov.hhs.aspr.ms.util.errors.ContractException; /** @@ -36,9 +34,6 @@ final static class Data { protected final List translators = new ArrayList<>(); protected final Map> inputFilePathMap = new LinkedHashMap<>(); protected final Map inputFilePathEngine = new LinkedHashMap<>(); - protected final Map outputFilePathMap = new LinkedHashMap<>(); - protected final Map outputFilePathEngine = new LinkedHashMap<>(); - protected final Map, Class> parentChildClassRelationshipMap = new LinkedHashMap<>(); Data() { } @@ -63,14 +58,10 @@ private void validateFilePathNotNull(Path filePath) { } } - private void validatePathNotDuplicate(Path filePath, boolean in, boolean out) { - if (in && this.data.inputFilePathMap.containsKey(filePath)) { + private void validatePathNotDuplicate(Path filePath) { + if (this.data.inputFilePathMap.containsKey(filePath)) { throw new ContractException(CoreTranslationError.DUPLICATE_INPUT_PATH); } - - if (out && this.data.outputFilePathMap.values().contains(filePath)) { - throw new ContractException(CoreTranslationError.DUPLICATE_OUTPUT_PATH); - } } private void validateTranslationEngineNotNull(TranslationEngine translationEngine) { @@ -133,7 +124,7 @@ TranslationController buildWithoutInitAndChecks() { public Builder addInputFilePath(Path filePath, Class classRef, TranslationEngineType translationEngineType) { validateFilePathNotNull(filePath); validateClassRefNotNull(classRef); - validatePathNotDuplicate(filePath, true, false); + validatePathNotDuplicate(filePath); if (!filePath.toFile().exists()) { throw new ContractException(CoreTranslationError.INVALID_INPUT_PATH); @@ -144,129 +135,6 @@ public Builder addInputFilePath(Path filePath, Class classRef, TranslationEng return this; } - /** - * Adds the path and class ref to be written to after building via - * {@link TranslationController#writeOutput} with the given classRef and - * scenario id of 0 as the key - * - * @throws ContractException - *
    - *
  • {@linkplain CoreTranslationError#NULL_PATH} if - * filePath is null
  • - *
  • {@linkplain CoreTranslationError#NULL_CLASS_REF} - * if classRef is null
  • - *
  • {@linkplain CoreTranslationError#DUPLICATE_OUTPUT_PATH} - * if filePath has already been added
  • - *
  • {@linkplain CoreTranslationError#DUPLICATE_OUTPUT_PATH_KEY} - * if the classRef and scenarioId pair has already - * been added
  • - *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_PATH} - * if filePath does not exist on the system. Note this - * check is for the folder, not the file. The file - * will be created if necessary by the writer
  • - *
- */ - public Builder addOutputFilePath(Path filePath, Class classRef, - TranslationEngineType translationEngineType) { - return this.addOutputFilePath(filePath, classRef, 0, translationEngineType); - } - - /** - * Adds the path and class ref to be written to after building via - * {@link TranslationController#writeOutput} with the given classRef and - * scenarioId as the key - * - * @throws ContractException - *
    - *
  • {@linkplain CoreTranslationError#NULL_PATH} if - * filePath is null
  • - *
  • {@linkplain CoreTranslationError#NULL_CLASS_REF} - * if classRef is null
  • - *
  • {@linkplain CoreTranslationError#DUPLICATE_OUTPUT_PATH} - * if filePath has already been added
  • - *
  • {@linkplain CoreTranslationError#DUPLICATE_OUTPUT_PATH_KEY} - * if the classRef and scenarioId pair has already - * been added
  • - *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_PATH} - * if filePath does not exist on the system. Note this - * check is for the folder, not the file. The file - * will be created if necessary by the writer
  • - *
- */ - public Builder addOutputFilePath(Path filePath, Class classRef, Integer scenarioId, - TranslationEngineType translationEngineType) { - validateClassRefNotNull(classRef); - - return this.addOutputFilePath(filePath, classRef.getName() + ":" + scenarioId, translationEngineType); - } - - /** - * Adds the path and class ref to be written to after building via - * {@link TranslationController#writeOutput} with the given key - * - * @throws ContractException - *
    - *
  • {@linkplain CoreTranslationError#NULL_PATH} if - * filePath is null
  • - *
  • {@linkplain CoreTranslationError#DUPLICATE_OUTPUT_PATH} - * if filePath has already been added
  • - *
  • {@linkplain CoreTranslationError#DUPLICATE_OUTPUT_PATH_KEY} - * if the classRef and scenarioId pair has already - * been added
  • - *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_PATH} - * if filePath does not exist on the system. Note this - * check is for the folder, not the file. The file - * will be created if necessary by the writer
  • - *
- */ - public Builder addOutputFilePath(Path filePath, String key, TranslationEngineType translationEngineType) { - validateFilePathNotNull(filePath); - validatePathNotDuplicate(filePath, false, true); - - if (this.data.outputFilePathMap.containsKey(key)) { - throw new ContractException(CoreTranslationError.DUPLICATE_OUTPUT_PATH_KEY); - } - - if (!filePath.getParent().toFile().exists()) { - throw new ContractException(CoreTranslationError.INVALID_OUTPUT_PATH); - } - - this.data.outputFilePathMap.put(key, filePath); - this.data.outputFilePathEngine.put(filePath, translationEngineType); - return this; - } - - /** - * Adds the given classRef markerInterace mapping. - *

- * explicitly used when calling {@link TranslationController#writeOutput} with a - * class for which a classRef ScenarioId pair does not exist and/or the need to - * output the given class as the markerInterface instead of the concrete class - * - * @param the childClass - * @param the parentClass/MarkerInterfaceClass - * @throws ContractException - *

    - *
  • {@linkplain CoreTranslationError#NULL_CLASS_REF} - * if classRef is null or if markerInterface is - * null
  • - *
  • {@linkplain CoreTranslationError#DUPLICATE_CLASSREF} - * if child parent relationship has already been - * added
  • - *
- */ - public Builder addParentChildClassRelationship(Class classRef, Class parentClassRef) { - validateClassRefNotNull(classRef); - validateClassRefNotNull(parentClassRef); - - if (this.data.parentChildClassRelationshipMap.containsKey(classRef)) { - throw new ContractException(CoreTranslationError.DUPLICATE_CLASSREF); - } - - this.data.parentChildClassRelationshipMap.put(classRef, parentClassRef); - return this; - } - /** * Adds a {@link TranslationEngine.Builder} * @@ -281,22 +149,6 @@ public Builder addTranslationEngine(TranslationEngine translationEngine) { this.data.translationEngines.add(translationEngine); - Map, Class> childToParentClassMap = translationEngine.getChildParentClassMap(); - - for (Class childClassRef : childToParentClassMap.keySet()) { - // Need to duplicate code here because the map doesn't provide the type safety - // that is required by the addParentChildClassRelationship method - Class parentClassRef = childToParentClassMap.get(childClassRef); - - // Note: no 'class is not null' validation here because it was validated prior - // to being put into the engine - if (this.data.parentChildClassRelationshipMap.containsKey(childClassRef)) { - throw new ContractException(CoreTranslationError.DUPLICATE_CLASSREF); - } - - this.data.parentChildClassRelationshipMap.put(childClassRef, parentClassRef); - } - return this; } @@ -309,38 +161,6 @@ public static Builder builder() { return new Builder(new Data()); } - /** - * Passes the given reader and inputClassRef to the built - * {@link TranslationEngine} to read, parse and translate the inputData. - * - * @param the classType associated with the reader - */ - void readInput(Path path, Class inputClassRef, TranslationEngine translationEngine) { - Object appObject; - try { - appObject = translationEngine.readInput(path, inputClassRef); - this.objects.add(appObject); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - /** - * Passes the given writer object and optional superClass to the built - * {@link TranslationEngine} to translate and write to the outputFile - * - * @param the class of the object to write to the outputFile - * @param the optional parent class of the object to write to the outputFile - */ - void writeOutput(Path path, M object, Optional> superClass, - TranslationEngine translationEngine) { - try { - translationEngine.writeOutput(path, object, superClass); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - void initTranslationEngines() { for (TranslationEngine translationEngine : this.data.translationEngines) { translationEngine.translationSpecsAreInitialized(); @@ -412,200 +232,117 @@ public TranslationController readInput() { } /** - * Given the classRef and scenarioId, find the given outputFilePath. If the - * classRef Scenario pair has been added, that is returned. Otherwise, checks to - * see if the classRef exists in the parentChildClassRelationshipMap and if so, - * returns - * the resulting classRef scenarioId pair - * - * @param the childClass - * @param the optional parentClass/MarkerInterfaceClass - */ - Pair>> getOutputPathKey(Class classRef, Integer scenarioId) { - String key = classRef.getName() + ":" + scenarioId; - - if (this.data.outputFilePathMap.containsKey(key)) { - return new Pair<>(key, Optional.empty()); - } - - if (this.data.parentChildClassRelationshipMap.containsKey(classRef)) { - // can safely cast because of type checking when adding to the - // parentChildClassRelationshipMap - @SuppressWarnings("unchecked") - Class parentClass = (Class) this.data.parentChildClassRelationshipMap.get(classRef); - - key = parentClass.getName() + ":" + scenarioId; - - if (this.data.outputFilePathMap.containsKey(key)) { - return new Pair<>(key, Optional.of(parentClass)); - } - } - - throw new ContractException(CoreTranslationError.INVALID_OUTPUT_CLASSREF, - "No path was provided for " + classRef.getName()); - } - - /** - * Given the classRef and scenarioId, find the given outputFilePath. If the - * classRef Scenario pair has been added, that is returned. Otherwise, checks to - * see if the classRef exists in the parentChildClassRelationshipMap and if so, - * returns - * the resulting classRef scenarioId pair + * Passes the given reader and inputClassRef to the built + * {@link TranslationEngine} to read, parse and translate the inputData. * - * @param the childClass - * @param the optional parentClass/MarkerInterfaceClass + * @param the classType associated with the reader */ - Path getOutputPath(String key) { - if (this.data.outputFilePathMap.containsKey(key)) { - return this.data.outputFilePathMap.get(key); + void readInput(Path path, Class inputClassRef, TranslationEngine translationEngine) { + Object appObject; + try { + appObject = translationEngine.readInput(path, inputClassRef); + this.objects.add(appObject); + } catch (IOException e) { + throw new RuntimeException(e); } - - throw new ContractException(CoreTranslationError.INVALID_OUTPUT_CLASSREF, - "No path was provided for " + key); } /** - * takes the list of objects and writes each object out to it's corresponding - * outputFilePath, if it exists - *

- * internally calls {@link TranslationController#writeOutput(Object)} + * writes the given object to the given path using the given translation engine + * type * - * @param the type of the list of obects to write to output + * @param the classType of the object * @throws ContractException *

    - *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_CLASSREF} - * if the class of the object paired with the - * scenarioId does not have a associated - * outputFilePath
  • + *
  • {@linkplain CoreTranslationError#NULL_OBJECT_FOR_TRANSLATION} + * if the object is null
  • + *
  • {@linkplain CoreTranslationError#NULL_PATH} + * if the path is null
  • + *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_PATH} + * if the path does not exist (specifically the parent + * directory of the path ie. a/b/c/foo.txt throws this + * if a/b/c doesn't exist
  • *
  • {@linkplain CoreTranslationError#NULL_TRANSLATION_ENGINE} * if translationEngine is null
  • *
*/ - public void writeOutput(List objects) { - for (T object : objects) { - this.writeOutput(object); - } + public void writeOutput(M object, Path path, + TranslationEngineType translationEngineType) { + + this.writeOutput(object, Optional.empty(), path, translationEngineType); } /** - * takes the list of objects and writes each object out to it's corresponding - * outputFilePath using the supplied key, if it exists - *

- * internally calls {@link TranslationController#writeOutput(Object)} + * writes the given object to the given path using the given translation engine + * type using the parent class as the actual output type * - * @param the type of the list of obects to write to output + * @param the classType of the object * @throws ContractException *

    - *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_CLASSREF} - * if the supplied key has no valid outputFilePath - * mapping
  • + *
  • {@linkplain CoreTranslationError#NULL_CLASS_REF} + * if the parent classref is null
  • + *
  • {@linkplain CoreTranslationError#NULL_OBJECT_FOR_TRANSLATION} + * if the object is null
  • + *
  • {@linkplain CoreTranslationError#NULL_PATH} + * if the path is null
  • + *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_PATH} + * if the path does not exist (specifically the parent + * directory of the path ie. a/b/c/foo.txt throws this + * if a/b/c doesn't exist
  • *
  • {@linkplain CoreTranslationError#NULL_TRANSLATION_ENGINE} * if translationEngine is null
  • *
*/ - public void writeOutput(Map objects) { - for (String key : objects.keySet()) { - this.writeOutput(objects.get(key), key); + public void writeOutput(M object, Class parentClassRef, Path path, + TranslationEngineType translationEngineType) { + + if (parentClassRef == null) { + throw new ContractException(CoreTranslationError.NULL_CLASS_REF); } + + this.writeOutput(object, Optional.of(parentClassRef), path, translationEngineType); } - /** - * takes the list of objects with the specified scenarioId and writes each - * object out to it's corresponding outputFilePath, if it exists - *

- * internally calls {@link TranslationController#writeOutput(Object, Integer)} - * - * @param the type of the list of obects to write to output - * @throws ContractException - *

    - *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_CLASSREF} - * if the class of the object paired with the - * scenarioId does not have a associated - * outputFilePath
  • - *
  • {@linkplain CoreTranslationError#NULL_TRANSLATION_ENGINE} - * if translationEngine is null
  • - *
- */ - public void writeOutput(List objects, Integer scenarioId) { - for (T object : objects) { - this.writeOutput(object, scenarioId); + void writeOutput(M object, Optional> parentClassRef, Path path, + TranslationEngineType translationEngineType) { + + if (object == null) { + throw new ContractException(CoreTranslationError.NULL_OBJECT_FOR_TRANSLATION); } - } - /** - * takes the given object and writes it out to it's corresponding - * outputFilePath, if it exists - *

- * internally calls {@link TranslationController#writeOutput(Object, Integer)} - * with a scenarioId of 0 - * - * @param the type of the list of obects to write to output - * @throws ContractException - *

    - *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_CLASSREF} - * if the class of the object paired with the - * scenarioId does not have a associated - * outputFilePath
  • - *
  • {@linkplain CoreTranslationError#NULL_TRANSLATION_ENGINE} - * if translationEngine is null
  • - *
- */ - public void writeOutput(T object) { - this.writeOutput(object, 0); - } + if (path == null) { + throw new ContractException(CoreTranslationError.NULL_PATH); + } - /** - * takes the given object and scenarioId pair and writes it out to it's - * corresponding outputFilePath, if it exists - * - * @param the classType of the object - * @param the optional type of the parent class of the object - * @throws ContractException - *
    - *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_CLASSREF} - * if the class of the object paired with the - * scenarioId does not have a associated - * outputFilePath
  • - *
  • {@linkplain CoreTranslationError#NULL_TRANSLATION_ENGINE} - * if translationEngine is null
  • - *
- */ - @SuppressWarnings("unchecked") - public void writeOutput(M object, Integer scenarioId) { - // this gives an unchecked warning, surprisingly - Class classRef = (Class) object.getClass(); + if (!path.getParent().toFile().exists()) { + throw new ContractException(CoreTranslationError.INVALID_OUTPUT_PATH); + } + + TranslationEngine translationEngine = this.translationEngines.get(translationEngineType); - Pair>> keyPair = getOutputPathKey(classRef, scenarioId); + if (translationEngine == null) { + throw new ContractException(CoreTranslationError.NULL_TRANSLATION_ENGINE); + } - this.writeOutput(object, keyPair.getFirst(), keyPair.getSecond()); + this.writeOutput(path, object, parentClassRef, translationEngine); } /** - * takes the given object and scenarioId pair and writes it out to it's - * corresponding outputFilePath, if it exists + * Passes the given writer object and optional superClass to the built + * {@link TranslationEngine} to translate and write to the outputFile * - * @param the classType of the object - * @throws ContractException - *
    - *
  • {@linkplain CoreTranslationError#INVALID_OUTPUT_CLASSREF} - * if the supplied key has no valid outputFilePath - * mapping
  • - *
  • {@linkplain CoreTranslationError#NULL_TRANSLATION_ENGINE} - * if translationEngine is null
  • - *
+ * @param the class of the object to write to the outputFile + * @param the optional parent class of the object to write to the outputFile */ - public void writeOutput(M object, String key) { - this.writeOutput(object, key, Optional.empty()); + void writeOutput(Path path, M object, Optional> superClass, + TranslationEngine translationEngine) { + try { + translationEngine.writeOutput(path, object, superClass); + } catch (IOException e) { + throw new RuntimeException(e); + } } - void writeOutput(M object, String key, Optional> parentClassRef) { - Path path = getOutputPath(key); - - TranslationEngineType type = this.data.outputFilePathEngine.get(path); - TranslationEngine translationEngine = this.translationEngines.get(type); - - this.writeOutput(path, object, parentClassRef, translationEngine); - } /** * Searches the list of read in objects and returns the first Object found of * the given classRef diff --git a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java index 327a1c5..2c4827d 100644 --- a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java +++ b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java @@ -37,7 +37,6 @@ protected TranslationEngine(Data data) { protected static class Data { protected final Map, BaseTranslationSpec> classToTranslationSpecMap = new LinkedHashMap<>(); protected final Set translationSpecs = new LinkedHashSet<>(); - protected Map, Class> childToParentClassMap = new LinkedHashMap<>(); protected TranslationEngineType translationEngineType = TranslationEngineType.UNKNOWN; protected boolean translatorsInitialized = false; @@ -112,12 +111,6 @@ private void validateTranslatorNotNull(Translator translator) { } } - private void validateClassRefNotNull(Class classRef) { - if (classRef == null) { - throw new ContractException(CoreTranslationError.NULL_CLASS_REF); - } - } - void clearBuilder() { this.data = new Data(); } @@ -193,38 +186,6 @@ protected final void _addTranslator(Translator translator) { this.translators.add(translator); } - /** - * Adds the given classRef markerInterace mapping. - *

- * explicitly used when calling {@link TranslationController#writeOutput} with a - * class for which a classRef ScenarioId pair does not exist and/or the need to - * output the given class as the markerInterface instead of the concrete class - * - * @param the childClass - * @param the parentClass/MarkerInterfaceClass - * @throws ContractException - *

    - *
  • {@linkplain CoreTranslationError#NULL_CLASS_REF} - * if classRef is null or if markerInterface is - * null
  • - *
  • {@linkplain CoreTranslationError#DUPLICATE_CLASSREF} - * if child parent relationship has already been - * added
  • - *
- */ - public abstract Builder addParentChildClassRelationship(Class classRef, Class markerInterface); - - protected final void _addParentChildClassRelationship(Class classRef, Class markerInterface) { - validateClassRefNotNull(classRef); - validateClassRefNotNull(markerInterface); - - if (this.data.childToParentClassMap.containsKey(classRef)) { - throw new ContractException(CoreTranslationError.DUPLICATE_CLASSREF); - } - - this.data.childToParentClassMap.put(classRef, markerInterface); - } - /* * Goes through the list of translators and orders them based on their * dependencies @@ -386,16 +347,6 @@ private void validateTranslatorsInitialized() { } } - // This is package access so the TranslationController can access it but nothing - // else. - Map, Class> getChildParentClassMap() { - Map, Class> copyMap = new LinkedHashMap<>(this.data.childToParentClassMap); - - this.data.childToParentClassMap = null; - - return copyMap; - } - /** * returns the {@link TranslationEngineType} of this TranslationEngine * diff --git a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/testsupport/TestTranslationEngine.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/testsupport/TestTranslationEngine.java index 8fd5373..e0863fa 100644 --- a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/testsupport/TestTranslationEngine.java +++ b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/testsupport/TestTranslationEngine.java @@ -98,13 +98,6 @@ public Builder addTranslator(Translator translator) { return this; } - - @Override - public Builder addParentChildClassRelationship(Class classRef, Class markerInterface) { - _addParentChildClassRelationship(classRef, markerInterface); - - return this; - } } public static Builder builder() { diff --git a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java index 8bae610..9713bce 100644 --- a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java +++ b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java @@ -8,19 +8,16 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.Optional; -import org.apache.commons.math3.util.Pair; import org.junit.jupiter.api.Test; import gov.hhs.aspr.ms.taskit.core.testsupport.TestObjectUtil; import gov.hhs.aspr.ms.taskit.core.testsupport.TestTranslationEngine; import gov.hhs.aspr.ms.taskit.core.testsupport.testcomplexobject.TestComplexAppObject; import gov.hhs.aspr.ms.taskit.core.testsupport.testcomplexobject.TestComplexObjectTranslator; +import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestAppChildObject; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestAppObject; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestObjectTranslator; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.input.TestInputObject; @@ -170,13 +167,12 @@ public void testReadInput() { TranslationController translationController = TranslationController.builder() .addInputFilePath(filePath.resolve(fileName), TestInputObject.class, TranslationEngineType.CUSTOM) - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, - TranslationEngineType.CUSTOM) .addTranslationEngine(testTranslationEngine).build(); TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); - translationController.writeOutput(expectedAppObject); + translationController.writeOutput(expectedAppObject, filePath.resolve(fileName), + TranslationEngineType.CUSTOM); translationController.readInput(); @@ -223,112 +219,23 @@ public void testWriteOutput_Engine() { } @Test - @UnitTestForCoverage - public void testGetOutputPathKey() { - String fileName = "GetOutputPath_1-testOutput.json"; - String fileName2 = "GetOutputPath_2-testOutput.json"; - - ResourceHelper.createOutputFile(filePath, fileName); - ResourceHelper.createOutputFile(filePath, fileName2); - - TranslationController translationController = TranslationController.builder() - .addTranslationEngine(TestTranslationEngine.builder().build()) - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, - TranslationEngineType.CUSTOM) - .addOutputFilePath(filePath.resolve(fileName2), Object.class, 1, - TranslationEngineType.CUSTOM) - .addParentChildClassRelationship(TestAppObject.class, Object.class).build(); - - Pair>> expectedPair1 = new Pair<>( - TestAppObject.class.getName() + ":" + 0, - Optional.empty()); - Pair>> expectedPair2 = new Pair<>(Object.class.getName() + ":" + 1, - Optional.of(Object.class)); - - Pair>> actualPair1 = translationController - .getOutputPathKey(TestAppObject.class, 0); - Pair>> actualPair2 = translationController - .getOutputPathKey(TestAppObject.class, 1); - - assertEquals(expectedPair1, actualPair1); - assertEquals(expectedPair2, actualPair2); - // preconditions - - // if the class scenarioId pair does not exist and there is no parent child - // class relationship - ContractException contractException = assertThrows(ContractException.class, () -> { - translationController.getOutputPathKey(TestInputObject.class, 1); - }); - - assertEquals(CoreTranslationError.INVALID_OUTPUT_CLASSREF, contractException.getErrorType()); - - // if the class and scenarioID pair does not exist AND there is a parent child - // class relationship AND the parentClass scenarioId pair does not exists - contractException = assertThrows(ContractException.class, () -> { - translationController.getOutputPathKey(TestAppObject.class, 4); - }); - - assertEquals(CoreTranslationError.INVALID_OUTPUT_CLASSREF, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = TranslationController.class, name = "writeOutput", args = { List.class }) - public void testWriteOutput_List() { - String fileName = "WriteOutput_List_1-testOutput.json"; - String fileName2 = "WriteOutput_List_2-testOutput.json"; - - ResourceHelper.createOutputFile(filePath, fileName); - ResourceHelper.createOutputFile(filePath, fileName2); - - TestTranslationEngine testTranslationEngine = TestTranslationEngine.builder() - .addTranslator(TestObjectTranslator.getTranslator()) - .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); - - TranslationController translationController = TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, - TranslationEngineType.CUSTOM) - .addOutputFilePath(filePath.resolve(fileName2), TestComplexAppObject.class, - TranslationEngineType.CUSTOM) - .addTranslationEngine(testTranslationEngine).build(); - - List outputObjects = new ArrayList<>(); - - outputObjects.add(TestObjectUtil.generateTestAppObject()); - outputObjects.add(TestObjectUtil.generateTestComplexAppObject()); - translationController.writeOutput(outputObjects); - - // preconditions - // the runtime exception is covered by the test - testMakeFileWriter() - // the contract exception for CoreTranslationError.INVALID_OUTPUT_CLASSREF is - // covered by the test - testGetOutputPath() - // the contract exception for CoreTranslationError.NULL_TRANSLATION_ENGINE is - // covered by the test - testValidateTranslationEngine() - } - - @Test - @UnitTestMethod(target = TranslationController.class, name = "writeOutput", args = { Map.class }) - public void testWriteOutput_Map() { - String fileName = "WriteOutput_List_1-testOutput.json"; - String fileName2 = "WriteOutput_List_2-testOutput.json"; + @UnitTestMethod(target = TranslationController.class, name = "writeOutput", args = { Object.class, + Path.class, TranslationEngineType.class }) + public void testWriteOutput() { + String fileName = "writeOutput-testOutput.json"; ResourceHelper.createOutputFile(filePath, fileName); - ResourceHelper.createOutputFile(filePath, fileName2); TestTranslationEngine testTranslationEngine = TestTranslationEngine.builder() .addTranslator(TestObjectTranslator.getTranslator()) .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); TranslationController translationController = TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), "key1", TranslationEngineType.CUSTOM) - .addOutputFilePath(filePath.resolve(fileName2), "key2", - TranslationEngineType.CUSTOM) .addTranslationEngine(testTranslationEngine).build(); - Map outputObjects = new LinkedHashMap<>(); + TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); - outputObjects.put("key1", TestObjectUtil.generateTestAppObject()); - outputObjects.put("key2", TestObjectUtil.generateTestComplexAppObject()); - translationController.writeOutput(outputObjects); + translationController.writeOutput(expectedAppObject, filePath.resolve(fileName), TranslationEngineType.CUSTOM); // preconditions // the runtime exception is covered by the test - testMakeFileWriter() @@ -339,73 +246,47 @@ public void testWriteOutput_Map() { } @Test - @UnitTestMethod(target = TranslationController.class, name = "writeOutput", args = { List.class, - Integer.class }) - public void testWriteOutput_List_ScenarioId() throws IOException { - String fileName = "WriteOutput_List_ScenarioId_1-testOutput.json"; - String fileName2 = "WriteOutput_List_ScenarioId_2-testOutput.json"; + @UnitTestMethod(target = TranslationController.class, name = "writeOutput", args = { Object.class, Class.class, + Path.class, TranslationEngineType.class }) + public void testWriteOutput_ParentClass() { + String fileName = "writeOutput_ParentClass-testOutput.json"; ResourceHelper.createOutputFile(filePath, fileName); - ResourceHelper.createOutputFile(filePath, fileName2); TestTranslationEngine testTranslationEngine = TestTranslationEngine.builder() .addTranslator(TestObjectTranslator.getTranslator()) .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); TranslationController translationController = TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, 1, - TranslationEngineType.CUSTOM) - .addOutputFilePath(filePath.resolve(fileName2), TestComplexAppObject.class, 1, - TranslationEngineType.CUSTOM) .addTranslationEngine(testTranslationEngine).build(); - List outputObjects = new ArrayList<>(); + TestAppObject appObject = TestObjectUtil.generateTestAppObject(); + TestAppChildObject expectedAppObject = TestObjectUtil.getChildAppFromApp(appObject); - outputObjects.add(TestObjectUtil.generateTestAppObject()); - outputObjects.add(TestObjectUtil.generateTestComplexAppObject()); - translationController.writeOutput(outputObjects, 1); + translationController.writeOutput(expectedAppObject, TestAppObject.class, filePath.resolve(fileName), + TranslationEngineType.CUSTOM); // preconditions - // the runtime exception is covered by the test - testMakeFileWriter() - // the contract exception for CoreTranslationError.INVALID_OUTPUT_CLASSREF is - // covered by the test - testGetOutputPath() - // the contract exception for CoreTranslationError.NULL_TRANSLATION_ENGINE is - // covered by the test - testValidateTranslationEngine() - } - - @Test - @UnitTestMethod(target = TranslationController.class, name = "writeOutput", args = { Object.class }) - public void testWriteOutput() throws IOException { - String fileName = "writeOutput-testOutput.json"; - - ResourceHelper.createOutputFile(filePath, fileName); - - TestTranslationEngine testTranslationEngine = TestTranslationEngine.builder() - .addTranslator(TestObjectTranslator.getTranslator()) - .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); - - TranslationController translationController = TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, - TranslationEngineType.CUSTOM) - .addTranslationEngine(testTranslationEngine).build(); - - TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); - - translationController.writeOutput(expectedAppObject); + // the given parent classref is null + ContractException contractException = assertThrows(ContractException.class, () -> { + Class badClassRef = null; + translationController.writeOutput(expectedAppObject, badClassRef, filePath.resolve(fileName), + TranslationEngineType.CUSTOM); + }); - // preconditions - // the runtime exception is covered by the test - testMakeFileWriter() - // the contract exception for CoreTranslationError.INVALID_OUTPUT_CLASSREF is - // covered by the test - testGetOutputPath() - // the contract exception for CoreTranslationError.NULL_TRANSLATION_ENGINE is - // covered by the test - testValidateTranslationEngine() + assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); + // CoreTranslationError.NULL_OBJECT_FOR_TRANSLATION is tested by + // testWriteOutput_Base() + // CoreTranslationError#NULL_PATH is tested by testWriteOutput_Base() + // CoreTranslationError#INVALID_OUTPUT_PATH is tested by testWriteOutput_Base() + // CoreTranslationError#NULL_TRANSLATION_ENGINE is tested by + // testWriteOutput_Base() } @Test - @UnitTestMethod(target = TranslationController.class, name = "writeOutput", args = { Object.class, - Integer.class }) - public void testWriteOutput_ScenarioId() throws IOException { - String fileName = "writeOutput_ScenarioId-testOutput.json"; + @UnitTestForCoverage + public void testWriteOutput_Base() { + String fileName = "writeOutput_Base-testOutput.json"; ResourceHelper.createOutputFile(filePath, fileName); @@ -414,55 +295,43 @@ public void testWriteOutput_ScenarioId() throws IOException { .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); TranslationController translationController = TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, 1, - TranslationEngineType.CUSTOM) .addTranslationEngine(testTranslationEngine).build(); - TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); - - translationController.writeOutput(expectedAppObject, 1); + TestAppObject appObject = TestObjectUtil.generateTestAppObject(); + TestAppChildObject expectedAppObject = TestObjectUtil.getChildAppFromApp(appObject); // preconditions - // the runtime exception is covered by the test - testMakeFileWriter() - // the contract exception for CoreTranslationError.INVALID_OUTPUT_CLASSREF is - // covered by the test - testGetOutputPath() - // the contract exception for CoreTranslationError.NULL_TRANSLATION_ENGINE is - // covered by the test - testValidateTranslationEngine() - } - - @Test - @UnitTestMethod(target = TranslationController.class, name = "writeOutput", args = { Object.class, - String.class }) - public void testWriteOutput_Key() throws IOException { - String fileName = "writeOutput_Key-testOutput.json"; + // the given object is null + ContractException contractException = assertThrows(ContractException.class, () -> { + translationController.writeOutput(null, Optional.empty(), filePath.resolve(fileName), + TranslationEngineType.CUSTOM); + }); - ResourceHelper.createOutputFile(filePath, fileName); + assertEquals(CoreTranslationError.NULL_OBJECT_FOR_TRANSLATION, contractException.getErrorType()); - TestTranslationEngine testTranslationEngine = TestTranslationEngine.builder() - .addTranslator(TestObjectTranslator.getTranslator()) - .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); + // the path is null + contractException = assertThrows(ContractException.class, () -> { + translationController.writeOutput(expectedAppObject, Optional.empty(), null, + TranslationEngineType.CUSTOM); + }); - String key = "TEST_KEY"; - TranslationController translationController = TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), key, TranslationEngineType.CUSTOM) - .addTranslationEngine(testTranslationEngine).build(); + assertEquals(CoreTranslationError.NULL_PATH, contractException.getErrorType()); - TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); + // if the path is invalid + contractException = assertThrows(ContractException.class, () -> { + translationController.writeOutput(expectedAppObject, Optional.empty(), filePath.resolve("badPath").resolve(fileName), + TranslationEngineType.CUSTOM); + }); - translationController.writeOutput(expectedAppObject, key); + assertEquals(CoreTranslationError.INVALID_OUTPUT_PATH, contractException.getErrorType()); - // preconditions - // the given key is not valid - ContractException contractException = assertThrows(ContractException.class, () -> { - translationController.writeOutput(expectedAppObject, "BAD_KEY"); + // if the translation engine is null + contractException = assertThrows(ContractException.class, () -> { + translationController.writeOutput(expectedAppObject, Optional.empty(), filePath.resolve(fileName), + TranslationEngineType.UNKNOWN); }); - assertEquals(CoreTranslationError.INVALID_OUTPUT_CLASSREF, contractException.getErrorType()); - // the runtime exception is covered by the test - testMakeFileWriter() - // the contract exception for CoreTranslationError.INVALID_OUTPUT_CLASSREF is - // covered by the test - testGetOutputPath() - // the contract exception for CoreTranslationError.NULL_TRANSLATION_ENGINE is - // covered by the test - testValidateTranslationEngine() + assertEquals(CoreTranslationError.NULL_TRANSLATION_ENGINE, contractException.getErrorType()); } @Test @@ -479,13 +348,11 @@ public void testGetFirstObject() throws IOException { TranslationController translationController = TranslationController.builder() .addInputFilePath(filePath.resolve(fileName), TestInputObject.class, TranslationEngineType.CUSTOM) - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, - TranslationEngineType.CUSTOM) .addTranslationEngine(testTranslationEngine).build(); TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); - translationController.writeOutput(expectedAppObject); + translationController.writeOutput(expectedAppObject, filePath.resolve(fileName), TranslationEngineType.CUSTOM); translationController.readInput(); @@ -518,10 +385,6 @@ public void testGetObjects_OfClass() throws IOException { .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); TranslationController translationController = TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, 1, - TranslationEngineType.CUSTOM) - .addOutputFilePath(filePath.resolve(fileName2), TestAppObject.class, 2, - TranslationEngineType.CUSTOM) .addInputFilePath(filePath.resolve(fileName), TestInputObject.class, TranslationEngineType.CUSTOM) .addInputFilePath(filePath.resolve(fileName2), TestInputObject.class, @@ -530,8 +393,10 @@ public void testGetObjects_OfClass() throws IOException { List expectedObjects = TestObjectUtil.getListOfAppObjects(2); - translationController.writeOutput(expectedObjects.get(0), 1); - translationController.writeOutput(expectedObjects.get(1), 2); + translationController.writeOutput(expectedObjects.get(0), filePath.resolve(fileName), + TranslationEngineType.CUSTOM); + translationController.writeOutput(expectedObjects.get(1), filePath.resolve(fileName2), + TranslationEngineType.CUSTOM); translationController.readInput(); @@ -562,10 +427,6 @@ public void testGetObjects() throws IOException { .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); TranslationController translationController = TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, 1, - TranslationEngineType.CUSTOM) - .addOutputFilePath(filePath.resolve(fileName2), TestAppObject.class, 2, - TranslationEngineType.CUSTOM) .addInputFilePath(filePath.resolve(fileName), TestInputObject.class, TranslationEngineType.CUSTOM) .addInputFilePath(filePath.resolve(fileName2), TestInputObject.class, @@ -574,8 +435,10 @@ public void testGetObjects() throws IOException { List expectedObjects = TestObjectUtil.getListOfAppObjects(2); - translationController.writeOutput(expectedObjects.get(0), 1); - translationController.writeOutput(expectedObjects.get(1), 2); + translationController.writeOutput(expectedObjects.get(0), filePath.resolve(fileName), + TranslationEngineType.CUSTOM); + translationController.writeOutput(expectedObjects.get(1), filePath.resolve(fileName2), + TranslationEngineType.CUSTOM); translationController.readInput(); @@ -658,118 +521,13 @@ public void testAddInputFilePath() { } - @Test - @UnitTestMethod(target = TranslationController.Builder.class, name = "addOutputFilePath", args = { Path.class, - Class.class, TranslationEngineType.class }) - public void testAddOutputFilePath() { - String fileName = "addOutputFilePath1-testOutput.json"; - String fileName2 = "addOutputFilePath2-testOutput.json"; - - ResourceHelper.createOutputFile(filePath, fileName); - - assertDoesNotThrow(() -> TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, - TranslationEngineType.CUSTOM) - .addTranslationEngine(TestTranslationEngine.builder().build()).build()); - - // preconditions - ContractException contractException = assertThrows(ContractException.class, () -> { - TranslationController.builder().addOutputFilePath(null, TestAppObject.class, - TranslationEngineType.CUSTOM); - }); - - assertEquals(CoreTranslationError.NULL_PATH, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - Class classRef = null; - TranslationController.builder().addOutputFilePath(filePath.resolve(fileName), classRef, - TranslationEngineType.CUSTOM); - }); - - assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, - TranslationEngineType.CUSTOM) - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, - TranslationEngineType.CUSTOM); - }); - - assertEquals(CoreTranslationError.DUPLICATE_OUTPUT_PATH, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - TranslationController.builder() - .addOutputFilePath(filePath.resolve(fileName), TestAppObject.class, - TranslationEngineType.CUSTOM) - .addOutputFilePath(filePath.resolve(fileName2), TestAppObject.class, - TranslationEngineType.CUSTOM); - }); - - assertEquals(CoreTranslationError.DUPLICATE_OUTPUT_PATH_KEY, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - TranslationController.builder().addOutputFilePath( - filePath.resolve("badpath").resolve(fileName2), - TestAppObject.class, TranslationEngineType.CUSTOM); - }); - - assertEquals(CoreTranslationError.INVALID_OUTPUT_PATH, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = TranslationController.Builder.class, name = "addOutputFilePath", args = { Path.class, - Class.class, Integer.class, TranslationEngineType.class }) - public void testAddOutputFilePath_ScenarioId() { - // Tested by testAddOutputFilePath, which internally calls - // addOutputFilePath(path, classRef, 0, engineType) - } - - @Test - @UnitTestMethod(target = TranslationController.Builder.class, name = "addOutputFilePath", args = { Path.class, - String.class, TranslationEngineType.class }) - public void testAddOutputFilePath_Key() { - // Tested by testAddOutputFilePath, which internally calls - // addOutputFilePath(path, classRef, 0, engineType) which calls - // addOutputFilePath(path, "classRef.name():0", engineType) - } - - @Test - @UnitTestMethod(target = TranslationController.Builder.class, name = "addParentChildClassRelationship", args = { - Class.class, Class.class }) - public void testAddParentChildClassRelationship() { - TranslationController.builder().addParentChildClassRelationship(TestAppObject.class, Object.class); - - // preconditions - ContractException contractException = assertThrows(ContractException.class, () -> { - TranslationController.builder().addParentChildClassRelationship(null, Object.class); - }); - - assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - TranslationController.builder().addParentChildClassRelationship(TestAppObject.class, null); - }); - - assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - TranslationController.builder() - .addParentChildClassRelationship(TestAppObject.class, Object.class) - .addParentChildClassRelationship(TestAppObject.class, Object.class); - }); - - assertEquals(CoreTranslationError.DUPLICATE_CLASSREF, contractException.getErrorType()); - } - @Test @UnitTestMethod(target = TranslationController.Builder.class, name = "addTranslationEngine", args = { TranslationEngine.class }) public void testAddTransationEngine() { TestTranslationEngine translationEngine = TestTranslationEngine.builder() .addTranslator(TestObjectTranslator.getTranslator()) - .addTranslator(TestComplexObjectTranslator.getTranslator()) - .addParentChildClassRelationship(TestAppObject.class, Object.class).build(); + .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); TranslationController.builder().addTranslationEngine(translationEngine).build(); @@ -779,18 +537,5 @@ public void testAddTransationEngine() { }); assertEquals(CoreTranslationError.NULL_TRANSLATION_ENGINE, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - TestTranslationEngine translationEngine2 = TestTranslationEngine.builder() - .addTranslator(TestObjectTranslator.getTranslator()) - .addTranslator(TestComplexObjectTranslator.getTranslator()) - .addParentChildClassRelationship(TestAppObject.class, Object.class).build(); - - TranslationController.builder() - .addParentChildClassRelationship(TestAppObject.class, Object.class) - .addTranslationEngine(translationEngine2); - }); - - assertEquals(CoreTranslationError.DUPLICATE_CLASSREF, contractException.getErrorType()); } } diff --git a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/TranslationEngineTestHelper.java b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/TranslationEngineTestHelper.java index bce8f9e..5eac2d2 100644 --- a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/TranslationEngineTestHelper.java +++ b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/TranslationEngineTestHelper.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import gov.hhs.aspr.ms.taskit.core.testsupport.testcomplexobject.translationSpecs.TestComplexObjectTranslationSpec; -import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestAppObject; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestObjectTranslator; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestObjectWrapper; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.translationSpecs.TestObjectTranslationSpec; @@ -149,28 +148,4 @@ public static void testAddTranslator(TranslationEngine.Builder builder) { assertEquals(CoreTranslationError.DUPLICATE_TRANSLATOR, contractException.getErrorType()); } - - public static void testAddParentChildClassRelationship(TranslationEngine.Builder builder) { - builder.addParentChildClassRelationship(TestAppObject.class, Object.class); - - // preconditions - ContractException contractException = assertThrows(ContractException.class, () -> { - builder.addParentChildClassRelationship(null, Object.class); - }); - - assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - builder.addParentChildClassRelationship(TestAppObject.class, null); - }); - - assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - builder.addParentChildClassRelationship(TestAppObject.class, Object.class) - .addParentChildClassRelationship(TestAppObject.class, Object.class); - }); - - assertEquals(CoreTranslationError.DUPLICATE_CLASSREF, contractException.getErrorType()); - } } diff --git a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/testsupport/AT_TestTranslationEngine.java b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/testsupport/AT_TestTranslationEngine.java index d0936c1..2043b3e 100644 --- a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/testsupport/AT_TestTranslationEngine.java +++ b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/testsupport/AT_TestTranslationEngine.java @@ -122,13 +122,6 @@ public void testAddTranslator() { TranslationEngineTestHelper.testAddTranslator(TestTranslationEngine.builder()); } - @Test - @UnitTestMethod(target = TestTranslationEngine.Builder.class, name = "addParentChildClassRelationship", args = { - Class.class, Class.class }) - public void testAddParentChildClassRelationship() { - TranslationEngineTestHelper.testAddParentChildClassRelationship(TestTranslationEngine.builder()); - } - @Test @UnitTestMethod(target = TestTranslationEngine.class, name = "hashCode", args = {}) public void testHashCode() { diff --git a/protobuf/src/main/java/gov/hhs/aspr/ms/taskit/protobuf/ProtobufTranslationEngine.java b/protobuf/src/main/java/gov/hhs/aspr/ms/taskit/protobuf/ProtobufTranslationEngine.java index ec0a158..4bbb709 100644 --- a/protobuf/src/main/java/gov/hhs/aspr/ms/taskit/protobuf/ProtobufTranslationEngine.java +++ b/protobuf/src/main/java/gov/hhs/aspr/ms/taskit/protobuf/ProtobufTranslationEngine.java @@ -194,13 +194,6 @@ public Builder addTranslator(Translator translator) { return this; } - @Override - public Builder addParentChildClassRelationship(Class classRef, Class markerInterface) { - _addParentChildClassRelationship(classRef, markerInterface); - - return this; - } - /** * checks the class to determine if it is a ProtocolMessageEnum or a Message and * if so, gets the Descriptor (which is akin to a class but for a Protobuf diff --git a/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/core/ProtobufTranslationEngineTestHelper.java b/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/core/ProtobufTranslationEngineTestHelper.java index 82c790c..c1aa93c 100644 --- a/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/core/ProtobufTranslationEngineTestHelper.java +++ b/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/core/ProtobufTranslationEngineTestHelper.java @@ -3,7 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestAppObject; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestObjectTranslator; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestObjectWrapper; import gov.hhs.aspr.ms.taskit.protobuf.testsupport.testcomplexobject.translationSpecs.TestProtobufComplexObjectTranslationSpec; @@ -150,27 +149,4 @@ public static void testAddTranslator(TranslationEngine.Builder builder) { assertEquals(CoreTranslationError.DUPLICATE_TRANSLATOR, contractException.getErrorType()); } - public static void testAddParentChildClassRelationship(TranslationEngine.Builder builder) { - builder.addParentChildClassRelationship(TestAppObject.class, Object.class); - - // preconditions - ContractException contractException = assertThrows(ContractException.class, () -> { - builder.addParentChildClassRelationship(null, Object.class); - }); - - assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - builder.addParentChildClassRelationship(TestAppObject.class, null); - }); - - assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> { - builder.addParentChildClassRelationship(TestAppObject.class, Object.class) - .addParentChildClassRelationship(TestAppObject.class, Object.class); - }); - - assertEquals(CoreTranslationError.DUPLICATE_CLASSREF, contractException.getErrorType()); - } } diff --git a/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/protobuf/AT_ProtobufTranslationEngine.java b/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/protobuf/AT_ProtobufTranslationEngine.java index c469380..ca6b5a6 100644 --- a/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/protobuf/AT_ProtobufTranslationEngine.java +++ b/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/protobuf/AT_ProtobufTranslationEngine.java @@ -160,7 +160,8 @@ public void testDebugPrint() throws IOException { TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); protobufTranslationEngine.writeOutput(filePath.resolve(fileName), expectedAppObject, Optional.empty()); - TestAppObject actualAppObject = protobufTranslationEngine.readInput(filePath.resolve(fileName), TestInputObject.class); + TestAppObject actualAppObject = protobufTranslationEngine.readInput(filePath.resolve(fileName), + TestInputObject.class); assertEquals(expectedAppObject, actualAppObject); } @@ -239,12 +240,15 @@ public void testReadInput() throws IOException { TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); protobufTranslationEngine.writeOutput(filePath.resolve(fileName), expectedAppObject, Optional.empty()); - TestAppObject actualAppObject = protobufTranslationEngine.readInput(filePath.resolve(fileName), TestInputObject.class); + TestAppObject actualAppObject = protobufTranslationEngine.readInput(filePath.resolve(fileName), + TestInputObject.class); assertEquals(expectedAppObject, actualAppObject); - protobufTranslationEngine.writeOutput(filePath.resolve(fileName2), TestObjectUtil.getChildAppFromApp(expectedAppObject), + protobufTranslationEngine.writeOutput(filePath.resolve(fileName2), + TestObjectUtil.getChildAppFromApp(expectedAppObject), Optional.of(TestAppObject.class)); - TestAppObject actualAppChildObject = protobufTranslationEngine.readInput(filePath.resolve(fileName2), TestInputObject.class); + TestAppObject actualAppChildObject = protobufTranslationEngine.readInput(filePath.resolve(fileName2), + TestInputObject.class); assertEquals(expectedAppObject, actualAppChildObject); // preconditions @@ -275,12 +279,15 @@ public void testWriteOutput() throws IOException { TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); protobufTranslationEngine.writeOutput(filePath.resolve(fileName), expectedAppObject, Optional.empty()); - TestAppObject actualAppObject = protobufTranslationEngine.readInput(filePath.resolve(fileName), TestInputObject.class); + TestAppObject actualAppObject = protobufTranslationEngine.readInput(filePath.resolve(fileName), + TestInputObject.class); assertEquals(expectedAppObject, actualAppObject); - protobufTranslationEngine.writeOutput(filePath.resolve(fileName2), TestObjectUtil.getChildAppFromApp(expectedAppObject), + protobufTranslationEngine.writeOutput(filePath.resolve(fileName2), + TestObjectUtil.getChildAppFromApp(expectedAppObject), Optional.of(TestAppObject.class)); - TestAppObject actualAppChildObject = protobufTranslationEngine.readInput(filePath.resolve(fileName2), TestInputObject.class); + TestAppObject actualAppChildObject = protobufTranslationEngine.readInput(filePath.resolve(fileName2), + TestInputObject.class); assertEquals(expectedAppObject, actualAppChildObject); // this test is just for coverage, but this method should never be directly @@ -441,13 +448,6 @@ public void testAddTranslator() { ProtobufTranslationEngineTestHelper.testAddTranslator(ProtobufTranslationEngine.builder()); } - @Test - @UnitTestMethod(target = ProtobufTranslationEngine.Builder.class, name = "addParentChildClassRelationship", args = { - Class.class, Class.class }) - public void testAddParentChildClassRelationship() { - ProtobufTranslationEngineTestHelper.testAddParentChildClassRelationship(ProtobufTranslationEngine.builder()); - } - @Test @UnitTestMethod(target = ProtobufTranslationEngine.Builder.class, name = "setIgnoringUnknownFields", args = { boolean.class }) From 00092c90fa414a2b567bfd55027a20f49eb68254 Mon Sep 17 00:00:00 2001 From: Zachary Bischoff <116595361+bischoffz@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:01:40 -0500 Subject: [PATCH 03/15] Readd Parent Child Class Relationship (#39) * readd parentclass relationship --- .../ms/taskit/core/TranslationController.java | 45 ++++++++++++++++++- .../taskit/core/AT_TranslationController.java | 40 +++++++++++++++-- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java index 27dce53..52e3e09 100644 --- a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java +++ b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java @@ -34,6 +34,7 @@ final static class Data { protected final List translators = new ArrayList<>(); protected final Map> inputFilePathMap = new LinkedHashMap<>(); protected final Map inputFilePathEngine = new LinkedHashMap<>(); + protected final Map, Class> parentChildClassRelationshipMap = new LinkedHashMap<>(); Data() { } @@ -135,6 +136,37 @@ public Builder addInputFilePath(Path filePath, Class classRef, TranslationEng return this; } + /** + * Adds the given classRef markerInterace mapping. + *

+ * explicitly used when calling {@link TranslationController#writeOutput} with a + * class for which a classRef ScenarioId pair does not exist and/or the need to + * output the given class as the markerInterface instead of the concrete class + * + * @param the childClass + * @param the parentClass/MarkerInterfaceClass + * @throws ContractException + *

    + *
  • {@linkplain CoreTranslationError#NULL_CLASS_REF} + * if classRef is null or if markerInterface is + * null
  • + *
  • {@linkplain CoreTranslationError#DUPLICATE_CLASSREF} + * if child parent relationship has already been + * added
  • + *
+ */ + public Builder addParentChildClassRelationship(Class classRef, Class parentClassRef) { + validateClassRefNotNull(classRef); + validateClassRefNotNull(parentClassRef); + + if (this.data.parentChildClassRelationshipMap.containsKey(classRef)) { + throw new ContractException(CoreTranslationError.DUPLICATE_CLASSREF); + } + + this.data.parentChildClassRelationshipMap.put(classRef, parentClassRef); + return this; + } + /** * Adds a {@link TranslationEngine.Builder} * @@ -151,7 +183,6 @@ public Builder addTranslationEngine(TranslationEngine translationEngine) { return this; } - } /** @@ -269,7 +300,17 @@ void readInput(Path path, Class inputClassRef, TranslationEngine translat public void writeOutput(M object, Path path, TranslationEngineType translationEngineType) { - this.writeOutput(object, Optional.empty(), path, translationEngineType); + Optional> parentClassRef = Optional.empty(); + + if (this.data.parentChildClassRelationshipMap.containsKey(object.getClass())) { + // can safely cast because of type checking when adding to the + // parentChildClassRelationshipMap + @SuppressWarnings("unchecked") + Class parentClass = (Class) this.data.parentChildClassRelationshipMap.get(object.getClass()); + + parentClassRef = Optional.of(parentClass); + } + this.writeOutput(object, parentClassRef, path, translationEngineType); } /** diff --git a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java index 9713bce..3f6768e 100644 --- a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java +++ b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java @@ -235,7 +235,8 @@ public void testWriteOutput() { TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); - translationController.writeOutput(expectedAppObject, filePath.resolve(fileName), TranslationEngineType.CUSTOM); + translationController.writeOutput(expectedAppObject, filePath.resolve(fileName), + TranslationEngineType.CUSTOM); // preconditions // the runtime exception is covered by the test - testMakeFileWriter() @@ -319,7 +320,8 @@ public void testWriteOutput_Base() { // if the path is invalid contractException = assertThrows(ContractException.class, () -> { - translationController.writeOutput(expectedAppObject, Optional.empty(), filePath.resolve("badPath").resolve(fileName), + translationController.writeOutput(expectedAppObject, Optional.empty(), + filePath.resolve("badPath").resolve(fileName), TranslationEngineType.CUSTOM); }); @@ -327,7 +329,8 @@ public void testWriteOutput_Base() { // if the translation engine is null contractException = assertThrows(ContractException.class, () -> { - translationController.writeOutput(expectedAppObject, Optional.empty(), filePath.resolve(fileName), + translationController.writeOutput(expectedAppObject, Optional.empty(), + filePath.resolve(fileName), TranslationEngineType.UNKNOWN); }); @@ -352,7 +355,8 @@ public void testGetFirstObject() throws IOException { TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); - translationController.writeOutput(expectedAppObject, filePath.resolve(fileName), TranslationEngineType.CUSTOM); + translationController.writeOutput(expectedAppObject, filePath.resolve(fileName), + TranslationEngineType.CUSTOM); translationController.readInput(); @@ -521,6 +525,34 @@ public void testAddInputFilePath() { } + @Test + @UnitTestMethod(target = TranslationController.Builder.class, name = "addParentChildClassRelationship", args = { + Class.class, Class.class }) + public void testAddParentChildClassRelationship() { + TranslationController.builder().addParentChildClassRelationship(TestAppObject.class, Object.class); + + // preconditions + ContractException contractException = assertThrows(ContractException.class, () -> { + TranslationController.builder().addParentChildClassRelationship(null, Object.class); + }); + + assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); + + contractException = assertThrows(ContractException.class, () -> { + TranslationController.builder().addParentChildClassRelationship(TestAppObject.class, null); + }); + + assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); + + contractException = assertThrows(ContractException.class, () -> { + TranslationController.builder() + .addParentChildClassRelationship(TestAppObject.class, Object.class) + .addParentChildClassRelationship(TestAppObject.class, Object.class); + }); + + assertEquals(CoreTranslationError.DUPLICATE_CLASSREF, contractException.getErrorType()); + } + @Test @UnitTestMethod(target = TranslationController.Builder.class, name = "addTranslationEngine", args = { TranslationEngine.class }) From 72604c257d90ecaa1ff4fd476601f044bf782150 Mon Sep 17 00:00:00 2001 From: bischoffz Date: Mon, 4 Mar 2024 18:21:43 -0500 Subject: [PATCH 04/15] readd parent child class relationship --- .../ms/taskit/core/TranslationController.java | 16 +++++++ .../ms/taskit/core/TranslationEngine.java | 48 +++++++++++++++++++ .../testsupport/TestTranslationEngine.java | 7 +++ .../taskit/core/AT_TranslationController.java | 37 +++++++++++--- .../core/TranslationEngineTestHelper.java | 25 ++++++++++ .../testsupport/AT_TestTranslationEngine.java | 7 +++ .../protobuf/ProtobufTranslationEngine.java | 7 +++ .../ProtobufTranslationEngineTestHelper.java | 24 ++++++++++ 8 files changed, 164 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java index 52e3e09..1dc7737 100644 --- a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java +++ b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java @@ -181,6 +181,22 @@ public Builder addTranslationEngine(TranslationEngine translationEngine) { this.data.translationEngines.add(translationEngine); + Map, Class> childToParentClassMap = translationEngine.getChildParentClassMap(); + + for (Class childClassRef : childToParentClassMap.keySet()) { + // Need to duplicate code here because the map doesn't provide the type safety + // that is required by the addParentChildClassRelationship method + Class parentClassRef = childToParentClassMap.get(childClassRef); + + // Note: no 'class is not null' validation here because it was validated prior + // to being put into the engine + if (this.data.parentChildClassRelationshipMap.containsKey(childClassRef)) { + throw new ContractException(CoreTranslationError.DUPLICATE_CLASSREF); + } + + this.data.parentChildClassRelationshipMap.put(childClassRef, parentClassRef); + } + return this; } } diff --git a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java index 2c4827d..f08f223 100644 --- a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java +++ b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java @@ -37,6 +37,7 @@ protected TranslationEngine(Data data) { protected static class Data { protected final Map, BaseTranslationSpec> classToTranslationSpecMap = new LinkedHashMap<>(); protected final Set translationSpecs = new LinkedHashSet<>(); + protected Map, Class> childToParentClassMap = new LinkedHashMap<>(); protected TranslationEngineType translationEngineType = TranslationEngineType.UNKNOWN; protected boolean translatorsInitialized = false; @@ -111,6 +112,12 @@ private void validateTranslatorNotNull(Translator translator) { } } + private void validateClassRefNotNull(Class classRef) { + if (classRef == null) { + throw new ContractException(CoreTranslationError.NULL_CLASS_REF); + } + } + void clearBuilder() { this.data = new Data(); } @@ -186,6 +193,37 @@ protected final void _addTranslator(Translator translator) { this.translators.add(translator); } + /** + * Adds the given classRef markerInterace mapping. + *

+ * explicitly used when calling {@link TranslationController#writeOutput} with a + * class for which a classRef ScenarioId pair does not exist and/or the need to + * output the given class as the markerInterface instead of the concrete class + * + * @param the childClass + * @param the parentClass/MarkerInterfaceClass + * @throws ContractException + *

    + *
  • {@linkplain CoreTranslationError#NULL_CLASS_REF} + * if classRef is null or if markerInterface is + * null
  • + *
  • {@linkplain CoreTranslationError#DUPLICATE_CLASSREF} + * if child parent relationship has already been + * added
  • + *
+ */ + public abstract Builder addParentChildClassRelationship(Class classRef, Class parentClassRef); + + protected final void _addParentChildClassRelationship(Class classRef, Class parentClassRef) { + validateClassRefNotNull(classRef); + validateClassRefNotNull(parentClassRef); + + if (this.data.childToParentClassMap.containsKey(classRef)) { + throw new ContractException(CoreTranslationError.DUPLICATE_CLASSREF); + } + + this.data.childToParentClassMap.put(classRef, parentClassRef); + } /* * Goes through the list of translators and orders them based on their * dependencies @@ -347,6 +385,16 @@ private void validateTranslatorsInitialized() { } } + // This is package access so the TranslationController can access it but nothing + // else. + Map, Class> getChildParentClassMap() { + Map, Class> copyMap = new LinkedHashMap<>(this.data.childToParentClassMap); + + this.data.childToParentClassMap = null; + + return copyMap; + } + /** * returns the {@link TranslationEngineType} of this TranslationEngine * diff --git a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/testsupport/TestTranslationEngine.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/testsupport/TestTranslationEngine.java index e0863fa..8fd5373 100644 --- a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/testsupport/TestTranslationEngine.java +++ b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/testsupport/TestTranslationEngine.java @@ -98,6 +98,13 @@ public Builder addTranslator(Translator translator) { return this; } + + @Override + public Builder addParentChildClassRelationship(Class classRef, Class markerInterface) { + _addParentChildClassRelationship(classRef, markerInterface); + + return this; + } } public static Builder builder() { diff --git a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java index 3f6768e..554f1db 100644 --- a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java +++ b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java @@ -228,7 +228,9 @@ public void testWriteOutput() { TestTranslationEngine testTranslationEngine = TestTranslationEngine.builder() .addTranslator(TestObjectTranslator.getTranslator()) - .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); + .addTranslator(TestComplexObjectTranslator.getTranslator()) + .addParentChildClassRelationship(TestAppChildObject.class, TestAppObject.class) + .build(); TranslationController translationController = TranslationController.builder() .addTranslationEngine(testTranslationEngine).build(); @@ -238,12 +240,17 @@ public void testWriteOutput() { translationController.writeOutput(expectedAppObject, filePath.resolve(fileName), TranslationEngineType.CUSTOM); + TestAppChildObject testAppChildObject = TestObjectUtil.getChildAppFromApp(expectedAppObject); + + translationController.writeOutput(testAppChildObject, filePath.resolve(fileName), + TranslationEngineType.CUSTOM); // preconditions - // the runtime exception is covered by the test - testMakeFileWriter() - // the contract exception for CoreTranslationError.INVALID_OUTPUT_CLASSREF is - // covered by the test - testGetOutputPath() - // the contract exception for CoreTranslationError.NULL_TRANSLATION_ENGINE is - // covered by the test - testValidateTranslationEngine() + // CoreTranslationError.NULL_OBJECT_FOR_TRANSLATION is tested by + // testWriteOutput_Base() + // CoreTranslationError#NULL_PATH is tested by testWriteOutput_Base() + // CoreTranslationError#INVALID_OUTPUT_PATH is tested by testWriteOutput_Base() + // CoreTranslationError#NULL_TRANSLATION_ENGINE is tested by + // testWriteOutput_Base() } @Test @@ -276,6 +283,8 @@ public void testWriteOutput_ParentClass() { }); assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); + + // preconditions // CoreTranslationError.NULL_OBJECT_FOR_TRANSLATION is tested by // testWriteOutput_Base() // CoreTranslationError#NULL_PATH is tested by testWriteOutput_Base() @@ -559,7 +568,8 @@ public void testAddParentChildClassRelationship() { public void testAddTransationEngine() { TestTranslationEngine translationEngine = TestTranslationEngine.builder() .addTranslator(TestObjectTranslator.getTranslator()) - .addTranslator(TestComplexObjectTranslator.getTranslator()).build(); + .addTranslator(TestComplexObjectTranslator.getTranslator()) + .addParentChildClassRelationship(TestAppObject.class, Object.class).build(); TranslationController.builder().addTranslationEngine(translationEngine).build(); @@ -569,5 +579,18 @@ public void testAddTransationEngine() { }); assertEquals(CoreTranslationError.NULL_TRANSLATION_ENGINE, contractException.getErrorType()); + + contractException = assertThrows(ContractException.class, () -> { + TestTranslationEngine translationEngine2 = TestTranslationEngine.builder() + .addTranslator(TestObjectTranslator.getTranslator()) + .addTranslator(TestComplexObjectTranslator.getTranslator()) + .addParentChildClassRelationship(TestAppObject.class, Object.class).build(); + + TranslationController.builder() + .addParentChildClassRelationship(TestAppObject.class, Object.class) + .addTranslationEngine(translationEngine2); + }); + + assertEquals(CoreTranslationError.DUPLICATE_CLASSREF, contractException.getErrorType()); } } diff --git a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/TranslationEngineTestHelper.java b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/TranslationEngineTestHelper.java index 5eac2d2..bce8f9e 100644 --- a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/TranslationEngineTestHelper.java +++ b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/TranslationEngineTestHelper.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import gov.hhs.aspr.ms.taskit.core.testsupport.testcomplexobject.translationSpecs.TestComplexObjectTranslationSpec; +import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestAppObject; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestObjectTranslator; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestObjectWrapper; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.translationSpecs.TestObjectTranslationSpec; @@ -148,4 +149,28 @@ public static void testAddTranslator(TranslationEngine.Builder builder) { assertEquals(CoreTranslationError.DUPLICATE_TRANSLATOR, contractException.getErrorType()); } + + public static void testAddParentChildClassRelationship(TranslationEngine.Builder builder) { + builder.addParentChildClassRelationship(TestAppObject.class, Object.class); + + // preconditions + ContractException contractException = assertThrows(ContractException.class, () -> { + builder.addParentChildClassRelationship(null, Object.class); + }); + + assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); + + contractException = assertThrows(ContractException.class, () -> { + builder.addParentChildClassRelationship(TestAppObject.class, null); + }); + + assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); + + contractException = assertThrows(ContractException.class, () -> { + builder.addParentChildClassRelationship(TestAppObject.class, Object.class) + .addParentChildClassRelationship(TestAppObject.class, Object.class); + }); + + assertEquals(CoreTranslationError.DUPLICATE_CLASSREF, contractException.getErrorType()); + } } diff --git a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/testsupport/AT_TestTranslationEngine.java b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/testsupport/AT_TestTranslationEngine.java index 2043b3e..c04ba79 100644 --- a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/testsupport/AT_TestTranslationEngine.java +++ b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/testsupport/AT_TestTranslationEngine.java @@ -122,6 +122,13 @@ public void testAddTranslator() { TranslationEngineTestHelper.testAddTranslator(TestTranslationEngine.builder()); } + @Test + @UnitTestMethod(target = TestTranslationEngine.Builder.class, name = "addParentChildClassRelationship", args = { + Class.class, Class.class }) + public void testAddParentChildClassRelationship() { + TranslationEngineTestHelper.testAddParentChildClassRelationship(TestTranslationEngine.builder()); + } + @Test @UnitTestMethod(target = TestTranslationEngine.class, name = "hashCode", args = {}) public void testHashCode() { diff --git a/protobuf/src/main/java/gov/hhs/aspr/ms/taskit/protobuf/ProtobufTranslationEngine.java b/protobuf/src/main/java/gov/hhs/aspr/ms/taskit/protobuf/ProtobufTranslationEngine.java index 4bbb709..db9f190 100644 --- a/protobuf/src/main/java/gov/hhs/aspr/ms/taskit/protobuf/ProtobufTranslationEngine.java +++ b/protobuf/src/main/java/gov/hhs/aspr/ms/taskit/protobuf/ProtobufTranslationEngine.java @@ -194,6 +194,13 @@ public Builder addTranslator(Translator translator) { return this; } + @Override + public Builder addParentChildClassRelationship(Class classRef, Class markerInterface) { + _addParentChildClassRelationship(classRef, markerInterface); + + return this; + } + /** * checks the class to determine if it is a ProtocolMessageEnum or a Message and * if so, gets the Descriptor (which is akin to a class but for a Protobuf diff --git a/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/core/ProtobufTranslationEngineTestHelper.java b/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/core/ProtobufTranslationEngineTestHelper.java index c1aa93c..82c790c 100644 --- a/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/core/ProtobufTranslationEngineTestHelper.java +++ b/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/core/ProtobufTranslationEngineTestHelper.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestAppObject; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestObjectTranslator; import gov.hhs.aspr.ms.taskit.core.testsupport.testobject.TestObjectWrapper; import gov.hhs.aspr.ms.taskit.protobuf.testsupport.testcomplexobject.translationSpecs.TestProtobufComplexObjectTranslationSpec; @@ -149,4 +150,27 @@ public static void testAddTranslator(TranslationEngine.Builder builder) { assertEquals(CoreTranslationError.DUPLICATE_TRANSLATOR, contractException.getErrorType()); } + public static void testAddParentChildClassRelationship(TranslationEngine.Builder builder) { + builder.addParentChildClassRelationship(TestAppObject.class, Object.class); + + // preconditions + ContractException contractException = assertThrows(ContractException.class, () -> { + builder.addParentChildClassRelationship(null, Object.class); + }); + + assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); + + contractException = assertThrows(ContractException.class, () -> { + builder.addParentChildClassRelationship(TestAppObject.class, null); + }); + + assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); + + contractException = assertThrows(ContractException.class, () -> { + builder.addParentChildClassRelationship(TestAppObject.class, Object.class) + .addParentChildClassRelationship(TestAppObject.class, Object.class); + }); + + assertEquals(CoreTranslationError.DUPLICATE_CLASSREF, contractException.getErrorType()); + } } From d0947ef4868367a8a64ac3e6ec17fb2d08ef081e Mon Sep 17 00:00:00 2001 From: bischoffz Date: Mon, 4 Mar 2024 18:23:33 -0500 Subject: [PATCH 05/15] add test for jacoco coverage --- .../ms/taskit/protobuf/AT_ProtobufTranslationEngine.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/protobuf/AT_ProtobufTranslationEngine.java b/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/protobuf/AT_ProtobufTranslationEngine.java index ca6b5a6..3758c0c 100644 --- a/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/protobuf/AT_ProtobufTranslationEngine.java +++ b/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/protobuf/AT_ProtobufTranslationEngine.java @@ -448,6 +448,13 @@ public void testAddTranslator() { ProtobufTranslationEngineTestHelper.testAddTranslator(ProtobufTranslationEngine.builder()); } + @Test + @UnitTestMethod(target = ProtobufTranslationEngine.Builder.class, name = "addParentChildClassRelationship", args = { + Class.class, Class.class }) + public void testAddParentChildClassRelationship() { + ProtobufTranslationEngineTestHelper.testAddParentChildClassRelationship(ProtobufTranslationEngine.builder()); + } + @Test @UnitTestMethod(target = ProtobufTranslationEngine.Builder.class, name = "setIgnoringUnknownFields", args = { boolean.class }) From e5d8e16077d40b8b5328e61e78bd80cd284d0049 Mon Sep 17 00:00:00 2001 From: Zachary Bischoff <116595361+bischoffz@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:31:23 -0400 Subject: [PATCH 06/15] Add Contract Error (#40) * Add Contract Error Remove unused Errors --- .../ms/taskit/core/CoreTranslationError.java | 86 +++++++++---------- .../ms/taskit/core/TranslationEngine.java | 21 +++-- .../aspr/ms/taskit/core/TranslationSpec.java | 2 +- .../ms/taskit/core/AT_TranslationSpec.java | 2 +- 4 files changed, 56 insertions(+), 55 deletions(-) diff --git a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/CoreTranslationError.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/CoreTranslationError.java index a586bfc..965eb7c 100644 --- a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/CoreTranslationError.java +++ b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/CoreTranslationError.java @@ -4,54 +4,48 @@ public enum CoreTranslationError implements ContractError { - CIRCULAR_TRANSLATOR_DEPENDENCIES("Circular translator dependencies: "), - DUPLICATE_CLASSREF("Duplicate ClassRef"), - DUPLICATE_OUTPUT_PATH_KEY("Duplicate ClassRef and Scenario Pair"), - DUPLICATE_DEPENDENCY("Duplicate Dependency"), - DUPLICATE_INPUT_PATH("Duplicate Input Path"), - DUPLICATE_OUTPUT_PATH("Duplicate Output Path"), - DUPLICATE_TRANSLATOR("Duplicate Translator"), - DUPLICATE_TRANSLATION_SPEC("Duplicate TranslationSpec"), - INVALID_TRANSLATION_ENGINE_CLASS_REF( - "The given Translation Engine classRef does not match the class of the actual Translation Engine"), - INVALID_TRANSLATION_ENGINE_BUILDER_CLASS_REF( - "The given Translation Engine Builder classRef does not match the class of the actual Translation Engine Builder"), - INVALID_OUTPUT_CLASSREF("The given class does not have a output file path associated with it."), - INVALID_OUTPUT_PATH( + CIRCULAR_TRANSLATOR_DEPENDENCIES("Circular translator dependencies: "), + DUPLICATE_CLASSREF("Duplicate ClassRef"), + DUPLICATE_DEPENDENCY("Duplicate Dependency"), + DUPLICATE_INPUT_PATH("Duplicate Input Path"), + DUPLICATE_TRANSLATOR("Duplicate Translator"), + DUPLICATE_TRANSLATION_SPEC("Duplicate TranslationSpec"), + INVALID_INPUT_PATH("The given input file path does not exist"), + INVALID_OUTPUT_PATH( "The given output file path does not exist. While the file will be created on write, the directory will not."), - INVALID_INPUT_PATH("The given input file path does not exist"), - MISSING_TRANSLATOR("Missing Translator: "), - NO_TRANSLATION_ENGINES("There are no translation engines added to this controller."), - NULL_TRANSLATOR_ID("Null TranslatorId"), - NULL_TRANSLATOR("Null Translator"), - NULL_TRANSLATION_ENGINE_BUILDER("Null Translation Engine Builder"), - NULL_TRANSLATION_ENGINE("Null Translation Engine"), - NULL_OBJECT_FOR_TRANSLATION("The object to be translated was null"), - NULL_INIT_CONSUMER("Null Initilizer Consumer"), - NULL_DEPENDENCY("Null dependency"), - NULL_PATH("Null Path"), - NULL_CLASS_REF("Null Class Ref"), - NULL_TRANSLATION_SPEC("Null TranslationSpec"), - NULL_TRANSLATION_SPEC_APP_CLASS("Null TranslationSpec App Class"), - NULL_TRANSLATION_SPEC_INPUT_CLASS("Null TranslationSpec Input Class"), - UNKNOWN_TRANSLATION_SPEC("No translation spec was provided for the given class"), - UNITIALIZED_TRANSLATION_SPEC("TranslationSpec not initialized"), - UNINITIALIZED_TRANSLATORS( - "Translators were added to the builder but were not initialized. Make sure to call super.initTranslators() during your custom engine build method"), - UNKNOWN_OBJECT("Object is not Translatable by this TranslationSpec"), - UNKNWON_TRANSLATION_ENGINE_TYPE("Translation Engine Type was not set"), - UNKNOWN_CLASSREF("No object has been read in with the specified classRef"), - UNKNOWN_OUTPUT_PATH_KEY("The provided key does not exist"), - MISSING_OUTPUT_PATH_KEYS("The number of keys provided does not match the number of objects to be written"); + INVALID_TRANSLATION_ENGINE_BUILDER_CLASS_REF( + "The given Translation Engine Builder classRef does not match the class of the actual Translation Engine Builder"), + MISSING_TRANSLATOR("Missing Translator: "), + NO_TRANSLATION_ENGINES("There are no translation engines added to this controller."), + NULL_CLASS_REF("Null Class Ref"), + NULL_DEPENDENCY("Null dependency"), + NULL_INIT_CONSUMER("Null Initilizer Consumer"), + NULL_OBJECT_FOR_TRANSLATION("The object to be translated was null"), + NULL_PATH("Null Path"), + NULL_TRANSLATION_ENGINE("Null Translation Engine"), + NULL_TRANSLATION_ENGINE_BUILDER("Null Translation Engine Builder"), + NULL_TRANSLATION_SPEC("Null TranslationSpec"), + NULL_TRANSLATION_SPEC_APP_CLASS("Null TranslationSpec App Class"), + NULL_TRANSLATION_SPEC_INPUT_CLASS("Null TranslationSpec Input Class"), + NULL_TRANSLATOR("Null Translator"), + NULL_TRANSLATOR_ID("Null TranslatorId"), + UNINITIALIZED_TRANSLATION_SPEC("TranslationSpec not initialized"), + UNINITIALIZED_TRANSLATORS( + "Translators were added to the builder but were not initialized. Make sure to call super.initTranslators() during your custom engine build method"), + UNKNOWN_CLASSREF("No object has been read in with the specified classRef"), + UNKNOWN_OBJECT("Object is not Translatable by this TranslationSpec"), + UNKNWON_TRANSLATION_ENGINE_TYPE("Translation Engine Type was not set"), + UNKNOWN_TRANSLATION_SPEC("No translation spec was provided for the given class"), + UNSUPPORTED_VERSION("The given version is not supported"); - private final String description; + private final String description; - private CoreTranslationError(final String description) { - this.description = description; - } + private CoreTranslationError(final String description) { + this.description = description; + } - @Override - public String getDescription() { - return description; - } + @Override + public String getDescription() { + return description; + } } diff --git a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java index f08f223..4849a89 100644 --- a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java +++ b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java @@ -78,7 +78,8 @@ public boolean equals(Object obj) { /** * This class contains protected final methods for all of its abstract methods. - * All descendant classes of this class MUST call these if you want it to function properly. + * All descendant classes of this class MUST call these if you want it to + * function properly. */ public abstract static class Builder { protected Data data; @@ -121,6 +122,7 @@ private void validateClassRefNotNull(Class classRef) { void clearBuilder() { this.data = new Data(); } + /** * Builder for the TranslationEngine */ @@ -193,7 +195,7 @@ protected final void _addTranslator(Translator translator) { this.translators.add(translator); } - /** + /** * Adds the given classRef markerInterace mapping. *

* explicitly used when calling {@link TranslationController#writeOutput} with a @@ -212,9 +214,11 @@ protected final void _addTranslator(Translator translator) { * added * */ - public abstract Builder addParentChildClassRelationship(Class classRef, Class parentClassRef); + public abstract Builder addParentChildClassRelationship(Class classRef, + Class parentClassRef); - protected final void _addParentChildClassRelationship(Class classRef, Class parentClassRef) { + protected final void _addParentChildClassRelationship(Class classRef, + Class parentClassRef) { validateClassRefNotNull(classRef); validateClassRefNotNull(parentClassRef); @@ -224,6 +228,7 @@ protected final void _addParentChildClassRelationship(Class this.data.childToParentClassMap.put(classRef, parentClassRef); } + /* * Goes through the list of translators and orders them based on their * dependencies @@ -385,7 +390,7 @@ private void validateTranslatorsInitialized() { } } - // This is package access so the TranslationController can access it but nothing + // This is package access so the TranslationController can access it but nothing // else. Map, Class> getChildParentClassMap() { Map, Class> copyMap = new LinkedHashMap<>(this.data.childToParentClassMap); @@ -394,7 +399,7 @@ Map, Class> getChildParentClassMap() { return copyMap; } - + /** * returns the {@link TranslationEngineType} of this TranslationEngine * @@ -431,6 +436,7 @@ protected void validateInit() { validateTranslationEngineType(); validateTranslatorsInitialized(); } + /** * returns whether this translationEngine is initialized or not */ @@ -468,7 +474,8 @@ public Set getTranslationSpecs() { * abstract method that must be implemented by child TranslatorCores that * defines how to write to output files */ - protected abstract void writeOutput(Path path, M appObject, Optional> superClass) throws IOException; + protected abstract void writeOutput(Path path, M appObject, Optional> superClass) + throws IOException; /** * abstract method that must be implemented by child TranslatorCores that diff --git a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationSpec.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationSpec.java index e20951c..40c0f46 100644 --- a/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationSpec.java +++ b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationSpec.java @@ -133,7 +133,7 @@ public boolean equals(Object obj) { void checkInit() { if (!this.initialized) { - throw new ContractException(CoreTranslationError.UNITIALIZED_TRANSLATION_SPEC); + throw new ContractException(CoreTranslationError.UNINITIALIZED_TRANSLATION_SPEC); } } } diff --git a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationSpec.java b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationSpec.java index 7657111..3c55fad 100644 --- a/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationSpec.java +++ b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationSpec.java @@ -117,7 +117,7 @@ public void testConvert() { testObjectTranslationSpec2.convert(new TestAppObject()); }); - assertEquals(CoreTranslationError.UNITIALIZED_TRANSLATION_SPEC, contractException.getErrorType()); + assertEquals(CoreTranslationError.UNINITIALIZED_TRANSLATION_SPEC, contractException.getErrorType()); // unknown object contractException = assertThrows(ContractException.class, () -> { From 1ed65c3b2835e5a2b24e5be12005389fdc58b12f Mon Sep 17 00:00:00 2001 From: Zachary Bischoff <116595361+bischoffz@users.noreply.github.com> Date: Fri, 5 Apr 2024 23:25:48 -0400 Subject: [PATCH 07/15] Update to util 4.1.1 (#43) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d751996..c7163e6 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ 2.10.1 - 4.1.0 + 4.1.1 5.10.2 0.8.11 From 306719d11371549006f1217980ecde7ab0ee4a89 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 6 Apr 2024 00:24:01 -0400 Subject: [PATCH 08/15] Bump org.apache.maven.plugins:maven-source-plugin (#44) Bumps the standard-plugins group with 1 update: [org.apache.maven.plugins:maven-source-plugin](https://github.com/apache/maven-source-plugin). Updates `org.apache.maven.plugins:maven-source-plugin` from 3.3.0 to 3.3.1 - [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.3.0...maven-source-plugin-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-source-plugin dependency-type: direct:production update-type: version-update:semver-patch dependency-group: standard-plugins ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c7163e6..0174802 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ 1.6.0 3.2.5 - 3.3.0 + 3.3.1 3.1.1 3.1.1 3.6.3 From 05b362c05075e5f36632489ff9e25df7cad6bcf1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 6 Apr 2024 00:24:45 -0400 Subject: [PATCH 09/15] Bump org.jacoco:jacoco-maven-plugin in the test-dependencies group (#45) Bumps the test-dependencies group with 1 update: [org.jacoco:jacoco-maven-plugin](https://github.com/jacoco/jacoco). Updates `org.jacoco:jacoco-maven-plugin` from 0.8.11 to 0.8.12 - [Release notes](https://github.com/jacoco/jacoco/releases) - [Commits](https://github.com/jacoco/jacoco/compare/v0.8.11...v0.8.12) --- updated-dependencies: - dependency-name: org.jacoco:jacoco-maven-plugin dependency-type: direct:development update-type: version-update:semver-patch dependency-group: test-dependencies ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0174802..519939c 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ 2.10.1 4.1.1 5.10.2 - 0.8.11 + 0.8.12 From 238cb80019c8f373ee6901de38859f4b89f91380 Mon Sep 17 00:00:00 2001 From: bischoffz Date: Mon, 8 Apr 2024 16:47:26 -0400 Subject: [PATCH 10/15] update pom project url --- core/pom.xml | 3 ++- protobuf/pom.xml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 4984da0..d94c3b2 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -17,7 +17,8 @@ Translation and Serialization Toolkit (Taskit): Core The core components of a toolkit that aids in the conversion between two Java objects, primiarly for use with coverting between an input Java object and a application Java object. - + https://github.com/HHS/aspr-ms-taskit + scm:git:git://github.com/HHS/aspr-ms-taskit.git diff --git a/protobuf/pom.xml b/protobuf/pom.xml index b271fdb..97794bf 100644 --- a/protobuf/pom.xml +++ b/protobuf/pom.xml @@ -17,7 +17,8 @@ Translation and Serialization Toolkit (Taskit): Protobuf A toolkit that aids in the conversion between Protobuf Java objects and application Java objects. - + https://github.com/HHS/aspr-ms-taskit + scm:git:git://github.com/HHS/aspr-ms-taskit.git From 75704859de3ed9b4c7b20595a182bded8608a9a6 Mon Sep 17 00:00:00 2001 From: bischoffz Date: Fri, 12 Apr 2024 00:09:08 -0400 Subject: [PATCH 11/15] add shawn to developer section in pom --- pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 18316c6..c845e23 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ https://www.gnu.org/licenses/gpl-3.0.en.html - Vulnerability Disclosure Policy + HHS Vulnerability Disclosure Policy https://www.hhs.gov/vulnerability-disclosure-policy/index.html @@ -33,6 +33,12 @@ zachary.bischoff@leidos.com https://www.leidos.com + + Shawn Hatch + Leidos + shawn.hatch@leidos.com + https://www.leidos.com + From c8935af326fd2089fe828228cfcea648e9c3a364 Mon Sep 17 00:00:00 2001 From: bischoffz Date: Sun, 14 Apr 2024 23:26:34 -0400 Subject: [PATCH 12/15] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e14f8ee..4969cbb 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ See [TestObject](protobuf/src/main/proto/gov/hhs/aspr/ms/taskit/protobuf/testobj - Favorite IDE for Java development - Modeling Util located [here](https://github.com/HHS/ASPR-ms-util) -*Note that Modeling Util is in Maven Central, so there is no need to download and build it. +*Note that Modeling Util is in Maven Central, so there is no need to clone and build it. ### Building To build this project: From ac694b7c4db1fa5c195c2c82e9d93cb461f145a4 Mon Sep 17 00:00:00 2001 From: bischoffz Date: Sun, 14 Apr 2024 23:26:55 -0400 Subject: [PATCH 13/15] update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4969cbb..7120523 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,9 @@ See [TestObject](protobuf/src/main/proto/gov/hhs/aspr/ms/taskit/protobuf/testobj - Maven 3.8.x - Java 17 - Favorite IDE for Java development -- Modeling Util located [here](https://github.com/HHS/ASPR-ms-util) +- Modeling Utilities located [here](https://github.com/HHS/ASPR-ms-util) -*Note that Modeling Util is in Maven Central, so there is no need to clone and build it. +*Note that Modeling Utilities is in Maven Central, so there is no need to clone and build it. ### Building To build this project: From ef4e86e2a9eaff2fed2f3fa18976673aeac013d3 Mon Sep 17 00:00:00 2001 From: bischoffz Date: Sun, 14 Apr 2024 23:55:59 -0400 Subject: [PATCH 14/15] update workflows --- .github/workflows/dev_build.yml | 2 +- .github/workflows/release_build.yml | 2 +- .github/workflows/release_pr_build.yml | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dev_build.yml b/.github/workflows/dev_build.yml index 547308a..1ff8580 100644 --- a/.github/workflows/dev_build.yml +++ b/.github/workflows/dev_build.yml @@ -15,7 +15,7 @@ on: branches-ignore: ["main"] jobs: - build: + dev-build: runs-on: ubuntu-latest steps: - name: Checkout Taskit diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml index 6203c86..44b8aa6 100644 --- a/.github/workflows/release_build.yml +++ b/.github/workflows/release_build.yml @@ -16,7 +16,7 @@ on: branches: ["main"] jobs: - create-release: + release: runs-on: ubuntu-latest permissions: contents: write diff --git a/.github/workflows/release_pr_build.yml b/.github/workflows/release_pr_build.yml index 4fb97f0..7637c30 100644 --- a/.github/workflows/release_pr_build.yml +++ b/.github/workflows/release_pr_build.yml @@ -13,7 +13,7 @@ on: branches: ["main"] jobs: - main-build: + release-pr-build: runs-on: ubuntu-latest permissions: contents: write @@ -26,6 +26,16 @@ jobs: with: java-version: '17' distribution: 'temurin' + + - name: Get Version + run: | + echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout --file pom.xml)" >> "$GITHUB_ENV" + - name: Version Is Snapshot + if: ${{ endsWith(env.version, 'SNAPSHOT') }} + run: | + echo "::error Version is a SNAPSHOT. Update version to proper version." + exit 1 + - name: Build Taskit run: mvn clean install -Pjavadoc,jacoco --file pom.xml \ No newline at end of file From 9cfa3c49be7c77263070e918c158539b7f6332a9 Mon Sep 17 00:00:00 2001 From: bischoffz Date: Mon, 15 Apr 2024 01:15:19 -0400 Subject: [PATCH 15/15] update to 4.0.0 proper --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c845e23..01390b8 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ - 4.0.0-SNAPSHOT + 4.0.0 UTF-8