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 diff --git a/README.md b/README.md index e14f8ee..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 download 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: 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/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/TranslationController.java b/core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java index b3a899b..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 @@ -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,8 +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 +59,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 +125,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,98 +136,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. *

@@ -296,10 +196,9 @@ public Builder addTranslationEngine(TranslationEngine translationEngine) { this.data.parentChildClassRelationshipMap.put(childClassRef, parentClassRef); } - + return this; } - } /** @@ -309,38 +208,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 +279,127 @@ 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) { + + 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); } /** - * 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..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 */ @@ -212,17 +214,19 @@ protected final void _addTranslator(Translator translator) { * added * */ - public abstract Builder addParentChildClassRelationship(Class classRef, Class markerInterface); + public abstract Builder addParentChildClassRelationship(Class classRef, + Class parentClassRef); - protected final void _addParentChildClassRelationship(Class classRef, Class markerInterface) { + protected final void _addParentChildClassRelationship(Class classRef, + Class parentClassRef) { validateClassRefNotNull(classRef); - validateClassRefNotNull(markerInterface); + validateClassRefNotNull(parentClassRef); if (this.data.childToParentClassMap.containsKey(classRef)) { throw new ContractException(CoreTranslationError.DUPLICATE_CLASSREF); } - this.data.childToParentClassMap.put(classRef, markerInterface); + this.data.childToParentClassMap.put(classRef, parentClassRef); } /* @@ -432,6 +436,7 @@ protected void validateInit() { validateTranslationEngineType(); validateTranslatorsInitialized(); } + /** * returns whether this translationEngine is initialized or not */ @@ -469,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_TranslationController.java b/core/src/test/java/gov/hhs/aspr/ms/taskit/core/AT_TranslationController.java index 8bae610..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 @@ -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,189 +219,84 @@ 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"; + @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(); + .addTranslator(TestComplexObjectTranslator.getTranslator()) + .addParentChildClassRelationship(TestAppChildObject.class, TestAppObject.class) + .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"; - - 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(); + TestAppObject expectedAppObject = TestObjectUtil.generateTestAppObject(); - Map outputObjects = new LinkedHashMap<>(); + translationController.writeOutput(expectedAppObject, filePath.resolve(fileName), + TranslationEngineType.CUSTOM); - outputObjects.put("key1", TestObjectUtil.generateTestAppObject()); - outputObjects.put("key2", TestObjectUtil.generateTestComplexAppObject()); - translationController.writeOutput(outputObjects); + 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 - @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(); + // the given parent classref is null + ContractException contractException = assertThrows(ContractException.class, () -> { + Class badClassRef = null; + translationController.writeOutput(expectedAppObject, badClassRef, filePath.resolve(fileName), + TranslationEngineType.CUSTOM); + }); - translationController.writeOutput(expectedAppObject); + assertEquals(CoreTranslationError.NULL_CLASS_REF, contractException.getErrorType()); // 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 - @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 +305,45 @@ 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 +360,12 @@ 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 +398,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 +406,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 +440,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 +448,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,82 +534,6 @@ 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 }) 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, () -> { 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..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 @@ -128,7 +128,7 @@ public void testAddTranslator() { public void testAddParentChildClassRelationship() { TranslationEngineTestHelper.testAddParentChildClassRelationship(TestTranslationEngine.builder()); } - + @Test @UnitTestMethod(target = TestTranslationEngine.class, name = "hashCode", args = {}) public void testHashCode() { diff --git a/pom.xml b/pom.xml index f796f5e..01390b8 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 + @@ -45,7 +51,7 @@ - 3.2.1 + 4.0.0 UTF-8 @@ -55,7 +61,7 @@ 1.6.0 3.2.5 - 3.3.0 + 3.3.1 3.1.1 3.1.1 3.6.3 @@ -66,7 +72,7 @@ 2.10.1 4.1.1 5.10.2 - 0.8.11 + 0.8.12 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 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..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 @@ -200,7 +200,7 @@ public Builder addParentChildClassRelationship(Class classRe 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/protobuf/AT_ProtobufTranslationEngine.java b/protobuf/src/test/java/gov/hhs/aspr/ms/taskit/protobuf/AT_ProtobufTranslationEngine.java index c469380..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 @@ -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 @@ -447,7 +454,7 @@ public void testAddTranslator() { public void testAddParentChildClassRelationship() { ProtobufTranslationEngineTestHelper.testAddParentChildClassRelationship(ProtobufTranslationEngine.builder()); } - + @Test @UnitTestMethod(target = ProtobufTranslationEngine.Builder.class, name = "setIgnoringUnknownFields", args = { boolean.class })