From a962117fb8d98a5172914d5e4ff9639f5893a6cb Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Thu, 5 Dec 2024 14:40:23 -0600 Subject: [PATCH 01/10] Using VS Code TOC generation to generate a table of contents for the scriptes/README.md --- scripts/README.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 554dd3434..df63dab70 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,4 +1,29 @@ -# Scripts +- [Setup](#setup) +- [Available\_Scripts](#available_scripts) + - [submit.sh](#submitsh) + - [Requirements](#requirements) + - [Usage](#usage) + - [rs.sh](#rssh) + - [Requirements](#requirements-1) + - [Usage](#usage-1) + - [Examples](#examples) + - [ti.sh](#tish) + - [Requirements](#requirements-2) + - [Usage](#usage-2) + - [Examples](#examples-1) + - [ucsd.sh](#ucsdsh) + - [Requirements](#requirements-3) + - [Before running the script](#before-running-the-script) + - [Usage](#usage-3) + - [setup/update-examples-snapshots.sh](#setupupdate-examples-snapshotssh) + - [Requirements](#requirements-4) + - [Usage](#usage-4) + - [setup/setup-reportstream.sh](#setupsetup-reportstreamsh) + - [Requirements](#requirements-5) + - [Usage](#usage-5) + - [lib/common.sh](#libcommonsh) + - [lib/submission-utils.sh](#libsubmission-utilssh) +- [Resources](#resources) ## Setup @@ -19,7 +44,7 @@ Follow the instructions below to load the environments variables required for th **Note**: you may also want to add it to your shell's startup file so you don't need to run it for every terminal session. 4. Run your script -## Available Scripts +## Available_Scripts ### submit.sh From d7fcaf0f3f150dbff6909e21d885ef248e7bc1fc Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Fri, 6 Dec 2024 11:52:55 -0600 Subject: [PATCH 02/10] Update env template and readme for TI scripts --- scripts/.env.template | 3 ++- scripts/README.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/.env.template b/scripts/.env.template index 4e274092e..e615c560d 100644 --- a/scripts/.env.template +++ b/scripts/.env.template @@ -7,7 +7,8 @@ RS_HOME="/path/to/prime-reportstream" RS_LCL_API_URL="http://localhost:7071" RS_STG_API_URL="https://staging.prime.cdc.gov:443" RS_PRD_API_URL="https://prime.cdc.gov:443" -TI_LCL_API_URL="http://host.docker.internal:8080" +TI_LCL_API_URL="http://localhost:8080" +TI_DOCKER_LCL_API_URL_RS_CONFIG="http://host.docker.internal:8080" TI_STG_API_URL="https://cdcti-stg-api.azurewebsites.net:443" TI_PRD_API_URL="https://cdcti-prd-api.azurewebsites.net:443" diff --git a/scripts/README.md b/scripts/README.md index df63dab70..8b06410f7 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -26,7 +26,7 @@ - [Resources](#resources) ## Setup - +
Follow the instructions below to load the environments variables required for these scripts 1. Copy `.env.template` to `.env` @@ -43,6 +43,7 @@ Follow the instructions below to load the environments variables required for th ``` **Note**: you may also want to add it to your shell's startup file so you don't need to run it for every terminal session. 4. Run your script +
## Available_Scripts From 80c52559b2de1cd800af5a654aa974e147e807a6 Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Fri, 6 Dec 2024 16:07:29 -0600 Subject: [PATCH 03/10] Update setup rs script to use correct Flexion Org RS SFTP transport - This is based on if you're running TI in docker vs gradle --- scripts/setup/setup-reportstream.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/setup/setup-reportstream.sh b/scripts/setup/setup-reportstream.sh index 2fdc3710c..32d404969 100755 --- a/scripts/setup/setup-reportstream.sh +++ b/scripts/setup/setup-reportstream.sh @@ -40,9 +40,15 @@ yq eval '.[0].receivers[] |= ( } )' -i "settings/STLTs/Flexion/flexion.yml" +LOCAL_DOCKER_IMAGE_NAME=$(docker ps --filter "name=trusted-intermediary-router-1" | grep trusted-intermediary-router-1) echo "Updating local URL and host in transport settings..." -sed -i '' "s|__TI_API_URL__|${TI_LCL_API_URL}|g" "settings/STLTs/Flexion/flexion.yml" -sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url "${TI_LCL_API_URL}")|g" "settings/STLTs/Flexion/flexion.yml" +if [[ ! -z $LOCAL_DOCKER_IMAGE_NAME ]]; then + sed -i '' "s|__TI_API_URL__|${TI_DOCKER_LCL_API_URL_RS_CONFIG}|g" "settings/STLTs/Flexion/flexion.yml" + sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url "${TI_DOCKER_LCL_API_URL_RS_CONFIG}")|g" "settings/STLTs/Flexion/flexion.yml" +else + sed -i '' "s|__TI_API_URL__|${TI_LCL_API_URL}|g" "settings/STLTs/Flexion/flexion.yml" + sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url "${TI_LCL_API_URL}")|g" "settings/STLTs/Flexion/flexion.yml" +fi echo "Updating transport settings in partner org files..." for file in "settings/STLTs/CA/ucsd.yml" "settings/STLTs/LA/la-ochsner.yml" "settings/STLTs/LA/la-phl.yml"; do From aaf5248c39ca3bd865536ef35fb00b20b9645de5 Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Mon, 9 Dec 2024 10:45:49 -0600 Subject: [PATCH 04/10] Update the README for scripts --- scripts/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 8b06410f7..a2574dd73 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -27,7 +27,8 @@ ## Setup
-Follow the instructions below to load the environments variables required for these scripts +Follow the instructions below to load the environments variables required for these scripts. +ReportStream and Trusted Intermediary must be running locally before running any scripts. 1. Copy `.env.template` to `.env` ``` @@ -235,7 +236,7 @@ Sends all the HL7 files with `_0_initial_message.hl7` suffix in the `/examples` ### setup/setup-reportstream.sh -Setup script for ReportStream +Setup script for ReportStream. #### Requirements From f1359d52b95f3b54912e45b503a2a39f6a6ed2ed Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Wed, 11 Dec 2024 09:37:32 -0600 Subject: [PATCH 05/10] Updates for the scripts/README.md --- scripts/README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index a2574dd73..ebeacbdc7 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,5 +1,5 @@ - [Setup](#setup) -- [Available\_Scripts](#available_scripts) +- [Available Scripts](#available-scripts) - [submit.sh](#submitsh) - [Requirements](#requirements) - [Usage](#usage) @@ -22,11 +22,10 @@ - [Requirements](#requirements-5) - [Usage](#usage-5) - [lib/common.sh](#libcommonsh) - - [lib/submission-utils.sh](#libsubmission-utilssh) + - [lib/submission-utils.sh](#libsubmission-utilssh) - [Resources](#resources) ## Setup -
Follow the instructions below to load the environments variables required for these scripts. ReportStream and Trusted Intermediary must be running locally before running any scripts. @@ -44,9 +43,8 @@ ReportStream and Trusted Intermediary must be running locally before running any ``` **Note**: you may also want to add it to your shell's startup file so you don't need to run it for every terminal session. 4. Run your script -
-## Available_Scripts +## Available Scripts ### submit.sh From 98511de165f1e90822a64172457c7cdf8a931203 Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Wed, 11 Dec 2024 11:37:57 -0600 Subject: [PATCH 06/10] Update setup script to remove code duplication and update variables only --- scripts/setup/setup-reportstream.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/setup/setup-reportstream.sh b/scripts/setup/setup-reportstream.sh index 32d404969..e98e5193f 100755 --- a/scripts/setup/setup-reportstream.sh +++ b/scripts/setup/setup-reportstream.sh @@ -16,6 +16,14 @@ echo "Resetting the database and loading the baseline settings..." ./gradlew reloadTable ./gradlew reloadSettings +# Update RS Configuration for the TI API based on docker or gradle +LOCAL_DOCKER_IMAGE_NAME=$(docker ps --filter "name=trusted-intermediary-router-1" | grep trusted-intermediary-router-1) +if [[ ! -z $LOCAL_DOCKER_IMAGE_NAME ]]; then + ti_api_url=${TI_LCL_API_URL} +else + ti_api_url=${TI_DOCKER_LCL_API_URL_RS_CONFIG} +fi + # Need to CD to prime-router to run the prime CLI cd "prime-router" || exit @@ -40,15 +48,9 @@ yq eval '.[0].receivers[] |= ( } )' -i "settings/STLTs/Flexion/flexion.yml" -LOCAL_DOCKER_IMAGE_NAME=$(docker ps --filter "name=trusted-intermediary-router-1" | grep trusted-intermediary-router-1) echo "Updating local URL and host in transport settings..." -if [[ ! -z $LOCAL_DOCKER_IMAGE_NAME ]]; then - sed -i '' "s|__TI_API_URL__|${TI_DOCKER_LCL_API_URL_RS_CONFIG}|g" "settings/STLTs/Flexion/flexion.yml" - sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url "${TI_DOCKER_LCL_API_URL_RS_CONFIG}")|g" "settings/STLTs/Flexion/flexion.yml" -else - sed -i '' "s|__TI_API_URL__|${TI_LCL_API_URL}|g" "settings/STLTs/Flexion/flexion.yml" - sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url "${TI_LCL_API_URL}")|g" "settings/STLTs/Flexion/flexion.yml" -fi +sed -i '' "s|__TI_API_URL__|${ti_api_url}|g" "settings/STLTs/Flexion/flexion.yml" +sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url "${TI_DOCKER_LCL_API_URL_RS_CONFIG}")|g" "settings/STLTs/Flexion/flexion.yml" echo "Updating transport settings in partner org files..." for file in "settings/STLTs/CA/ucsd.yml" "settings/STLTs/LA/la-ochsner.yml" "settings/STLTs/LA/la-phl.yml"; do From d14e7bd4f1da78e32430b1534d340f81d0a999cb Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Wed, 11 Dec 2024 17:03:33 -0600 Subject: [PATCH 07/10] Update rs scripts with some notes to attempt to fix this otherwise we can default to leaving it as a config change per user environment Co-authored-by: Sylvie Co-authored-by: GilmoreA6 Co-authored-by: pluckyswan <96704946+pluckyswan@users.noreply.github.com> --- scripts/setup/setup-reportstream.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/setup/setup-reportstream.sh b/scripts/setup/setup-reportstream.sh index 1b971a7b3..744ca9691 100755 --- a/scripts/setup/setup-reportstream.sh +++ b/scripts/setup/setup-reportstream.sh @@ -17,6 +17,8 @@ echo "Resetting the database and loading the baseline settings..." ./gradlew reloadSettings # Update RS Configuration for the TI API based on docker or gradle +# PS: Logic to determine to use gradle vs docker needs updating +# The logic needs to check if BOTH TI and RS are running in docker, otherwise it should use localhost:8080 LOCAL_DOCKER_IMAGE_NAME=$(docker ps --filter "name=trusted-intermediary-router-1" | grep trusted-intermediary-router-1) if [[ ! -z $LOCAL_DOCKER_IMAGE_NAME ]]; then ti_api_url=${TI_LCL_API_URL} @@ -50,7 +52,7 @@ yq eval '.[0].receivers[] |= ( echo "Updating local URL and host in transport settings..." sed -i '' "s|__TI_API_URL__|${ti_api_url}|g" "settings/STLTs/Flexion/flexion.yml" -sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url "${TI_DOCKER_LCL_API_URL_RS_CONFIG}")|g" "settings/STLTs/Flexion/flexion.yml" +sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url "${ti_api_url}")|g" "settings/STLTs/Flexion/flexion.yml" echo "Updating transport settings in partner org files..." for file in "settings/STLTs/CA/ucsd.yml" "settings/STLTs/LA/la-ochsner.yml" "settings/STLTs/LA/la-phl.yml"; do From f4f7348771d343cd13710b40325b53388a2f6168 Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Thu, 12 Dec 2024 15:36:59 -0600 Subject: [PATCH 08/10] Last attempt to automate rs configuration depending on environment setup --- scripts/setup/setup-reportstream.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/setup/setup-reportstream.sh b/scripts/setup/setup-reportstream.sh index 744ca9691..0f68ecc40 100755 --- a/scripts/setup/setup-reportstream.sh +++ b/scripts/setup/setup-reportstream.sh @@ -17,13 +17,15 @@ echo "Resetting the database and loading the baseline settings..." ./gradlew reloadSettings # Update RS Configuration for the TI API based on docker or gradle -# PS: Logic to determine to use gradle vs docker needs updating -# The logic needs to check if BOTH TI and RS are running in docker, otherwise it should use localhost:8080 +# If either TI or RS are not running in docker, then use a gradle hosted URL LOCAL_DOCKER_IMAGE_NAME=$(docker ps --filter "name=trusted-intermediary-router-1" | grep trusted-intermediary-router-1) -if [[ ! -z $LOCAL_DOCKER_IMAGE_NAME ]]; then +LOCAL_RS_DOCKER_IMAGE_NAME=$(docker ps --filter "name=prime-router-prime_dev-1" | grep prime-router-prime_dev-1) +if [[ -z $LOCAL_DOCKER_IMAGE_NAME || -z $LOCAL_RS_DOCKER_IMAGE_NAME ]]; then ti_api_url=${TI_LCL_API_URL} + echo "Gradle instance detected, ReportStream transport will use ${TI_LCL_API_URL}..." else ti_api_url=${TI_DOCKER_LCL_API_URL_RS_CONFIG} + echo "Docker instances detected, ReportStream transport will use ${TI_DOCKER_LCL_API_URL_RS_CONFIG}..." fi # Need to CD to prime-router to run the prime CLI From e718efdf63dfc86dd327d2f8cf4a7d32ae9e6a5f Mon Sep 17 00:00:00 2001 From: Jorge Lopez <49923512+jorg3lopez@users.noreply.github.com> Date: Fri, 13 Dec 2024 07:26:32 -0800 Subject: [PATCH 09/10] Use inject for non singleton class (#1617) * comment to start branch * getFieldsAnnotatedWithInstance helper method * todo comment deleted * injectIntoField overloaded method * injectIntoNonSingleton * access modifier protected to public * revert access modifier change * changes: added logger to HapiFhirResource in order to test a non-singleton class created HapiFhirResourceTest in order to test the changes to HapiFhirResource * Added implementors unit test to ApplicationContextTest * Minor refactoring on some AppContext injection methods * Make the skip flag on TestApplicationContext switchable from the test classes * Update ApplicationContext.java Remove unreachable if statement * Update TestApplicationContext.groovy Add additional line in coverage * Update TestApplicationContext.groovy Remove parameter from injectRegisteredImplementations * added unit tests to cover new code * Update ApplicationContextTest.groovy Added test case for unsupported injection classes * Update ApplicationContext.java Print an error message if the class implementation is not found * use return instead of System.err * refactoring - dry * thown(NullPointerException) -> noExceptionThrown() * added comments to indicate changes that will be deleted * deleted commented out code * reinstated comments for test case * deleted test changes: in HapiFhirResource and deleted file HapifhirResourceTest.groovy --------- Co-authored-by: Luis Pabon Co-authored-by: Luis Pabon --- .../context/ApplicationContext.java | 54 ++++++----- .../context/Reflection.java | 9 ++ .../context/ApplicationContextTest.groovy | 90 +++++++++++++++++++ .../context/TestApplicationContext.groovy | 3 +- 4 files changed, 133 insertions(+), 23 deletions(-) diff --git a/shared/src/main/java/gov/hhs/cdc/trustedintermediary/context/ApplicationContext.java b/shared/src/main/java/gov/hhs/cdc/trustedintermediary/context/ApplicationContext.java index 04de60817..61b261c72 100644 --- a/shared/src/main/java/gov/hhs/cdc/trustedintermediary/context/ApplicationContext.java +++ b/shared/src/main/java/gov/hhs/cdc/trustedintermediary/context/ApplicationContext.java @@ -31,6 +31,8 @@ public class ApplicationContext { protected static final Map TEST_ENV_VARS = new ConcurrentHashMap<>(); protected static final Set IMPLEMENTATIONS = new HashSet<>(); + protected static boolean skipMissingImplementations = false; + protected ApplicationContext() {} public static void register(Class clazz, Object implementation) { @@ -53,17 +55,39 @@ public static Set> getImplementors(Class interfaze) { } public static void injectRegisteredImplementations() { - injectRegisteredImplementations(false); + doInjectRegisteredImplementations(); } - protected static void injectRegisteredImplementations(boolean skipMissingImplementations) { + protected static void doInjectRegisteredImplementations() { var fields = Reflection.getFieldsAnnotatedWith(Inject.class); - fields.forEach(field -> injectIntoField(field, skipMissingImplementations)); + fields.forEach(ApplicationContext::injectIntoField); + } + + public static void injectIntoNonSingleton(Object instance) { + var fields = Reflection.getFieldsAnnotatedWithInstance(instance.getClass(), Inject.class); + + fields.forEach(field -> injectIntoField(field, instance)); } - private static void injectIntoField(Field field, boolean skipMissingImplementations) { + private static void injectIntoField(Field field, Object instance) { var fieldType = field.getType(); + + Object fieldImplementation = getFieldImplementation(fieldType); + if (fieldImplementation == null) { + return; + } + + field.trySetAccessible(); + try { + field.set(instance, fieldImplementation); + } catch (IllegalAccessException | IllegalArgumentException exception) { + throw new IllegalArgumentException( + "unable to inject " + fieldType + " into " + instance.getClass(), exception); + } + } + + private static void injectIntoField(Field field) { var declaringClass = field.getDeclaringClass(); if (!IMPLEMENTATIONS.contains(declaringClass)) { @@ -76,29 +100,16 @@ private static void injectIntoField(Field field, boolean skipMissingImplementati declaringClassesToTry.add(declaringClass); declaringClassesToTry.addAll(Arrays.asList(declaringClass.getInterfaces())); - Object fieldImplementation = getFieldImplementation(fieldType, skipMissingImplementations); - if (fieldImplementation == null) { - return; - } - Object declaringClassImplementation = - getDeclaringClassImplementation(declaringClassesToTry, skipMissingImplementations); + getDeclaringClassImplementation(declaringClassesToTry); if (declaringClassImplementation == null) { return; } - field.trySetAccessible(); - - try { - field.set(declaringClassImplementation, fieldImplementation); - } catch (IllegalAccessException | IllegalArgumentException exception) { - throw new IllegalArgumentException( - "Unable to inject " + fieldType + " into " + declaringClass, exception); - } + injectIntoField(field, declaringClassImplementation); } - private static Object getFieldImplementation( - Class fieldType, boolean skipMissingImplementations) { + private static Object getFieldImplementation(Class fieldType) { Object fieldImplementation; try { @@ -116,8 +127,7 @@ private static Object getFieldImplementation( return fieldImplementation; } - private static Object getDeclaringClassImplementation( - List> declaringClassesToTry, boolean skipMissingImplementations) { + private static Object getDeclaringClassImplementation(List> declaringClassesToTry) { Object declaringClassImplementation = declaringClassesToTry.stream() .map( diff --git a/shared/src/main/java/gov/hhs/cdc/trustedintermediary/context/Reflection.java b/shared/src/main/java/gov/hhs/cdc/trustedintermediary/context/Reflection.java index 482dade7a..de6d58176 100644 --- a/shared/src/main/java/gov/hhs/cdc/trustedintermediary/context/Reflection.java +++ b/shared/src/main/java/gov/hhs/cdc/trustedintermediary/context/Reflection.java @@ -3,8 +3,11 @@ import static org.reflections.scanners.Scanners.FieldsAnnotated; import static org.reflections.scanners.Scanners.SubTypes; +import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.util.Arrays; import java.util.Set; +import java.util.stream.Collectors; import org.reflections.Reflections; /** @@ -27,4 +30,10 @@ public static Set> getImplementors(Class interfaze) { public static Set getFieldsAnnotatedWith(Class annotation) { return REFLECTIONS.get(FieldsAnnotated.with(annotation).as(Field.class)); } + + public static Set getFieldsAnnotatedWithInstance(Class clazz, Class annotation) { + return Arrays.stream(clazz.getDeclaredFields()) + .filter(field -> field.isAnnotationPresent(annotation.asSubclass(Annotation.class))) + .collect(Collectors.toSet()); + } } diff --git a/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/context/ApplicationContextTest.groovy b/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/context/ApplicationContextTest.groovy index 59902b4f8..72c45dca7 100644 --- a/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/context/ApplicationContextTest.groovy +++ b/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/context/ApplicationContextTest.groovy @@ -1,5 +1,6 @@ package gov.hhs.cdc.trustedintermediary.context +import gov.hhs.cdc.trustedintermediary.wrappers.Logger import spock.lang.Specification import javax.inject.Inject @@ -8,6 +9,34 @@ import java.nio.file.Paths class ApplicationContextTest extends Specification { + interface TestingInterface { + void test() + } + + class NonSingletonClazz { + @Inject + Logger logger + void test() {} + } + + static class DogCow implements TestingInterface { + + @Override + void test() { + print("test()") + } + } + + static class DogCowTwo implements TestingInterface { + + @Override + void test() { + print("testTwo()") + } + } + def DOGCOW = new DogCow() + def DOGCOWTWO = new DogCowTwo() + def setup() { TestApplicationContext.reset() } @@ -21,6 +50,48 @@ class ApplicationContextTest extends Specification { result == ApplicationContext.getImplementation(String.class) } + def "implementors retrieval test"() { + setup: + def dogCow = DOGCOW + def dogCowTwo = DOGCOWTWO + def implementors = new HashSet() + implementors.add(DogCow) + implementors.add(DogCowTwo) + + expect: + implementors == ApplicationContext.getImplementors(TestingInterface) + } + + def "injectIntoNonSingleton unhappy path"() { + given: + def nonSingletonClass = new NonSingletonClazz() + def object = new Object() + ApplicationContext.register(Logger, object) + when: + ApplicationContext.injectIntoNonSingleton(nonSingletonClass) + then: + thrown(IllegalArgumentException) + } + + def "injectIntoNonSingleton unhappy path when fieldImplementation runs into an error"() { + given: + def nonSingletonClass = new NonSingletonClazz() + when: + ApplicationContext.injectIntoNonSingleton(nonSingletonClass) + then: + thrown(IllegalArgumentException) + } + + def "injectIntoNonSingleton unhappy path when fieldImplementation is null"() { + given: + def nonSingletonClass = new NonSingletonClazz() + when: + ApplicationContext.skipMissingImplementations = true + ApplicationContext.injectIntoNonSingleton(nonSingletonClass) + then: + noExceptionThrown() + } + def "implementation injection test"() { given: def injectedValue = "DogCow" @@ -133,6 +204,25 @@ class ApplicationContextTest extends Specification { Files.deleteIfExists(directoryPath) } + def "registering an unsupported injection class"() { + given: + def injectedValue = "DogCow" + def injectionInstantiation = new InjectionDeclaringClass() + + TestApplicationContext.register(List.class, injectionInstantiation) + // notice above that I'm registering the injectionInstantiation object as a List class. + // injectionInstantiation is of class InjectionDeclaringClass, + // and InjectionDeclaringClass doesn't implement List (it only implements AFieldInterface). + TestApplicationContext.register(String.class, injectedValue) + + when: + TestApplicationContext.injectRegisteredImplementations() + injectionInstantiation.getAField() + + then: + noExceptionThrown() + } + class InjectionDeclaringClass { @Inject private String aField diff --git a/shared/src/testFixtures/groovy/gov/hhs/cdc/trustedintermediary/context/TestApplicationContext.groovy b/shared/src/testFixtures/groovy/gov/hhs/cdc/trustedintermediary/context/TestApplicationContext.groovy index 24c37e2a8..735e78fc7 100644 --- a/shared/src/testFixtures/groovy/gov/hhs/cdc/trustedintermediary/context/TestApplicationContext.groovy +++ b/shared/src/testFixtures/groovy/gov/hhs/cdc/trustedintermediary/context/TestApplicationContext.groovy @@ -20,7 +20,8 @@ class TestApplicationContext extends ApplicationContext { } def static injectRegisteredImplementations() { - injectRegisteredImplementations(true) + skipMissingImplementations = true + ApplicationContext.injectRegisteredImplementations() } def static addEnvironmentVariable(String key, String value) { From 196cfd1eaa34a4f6392990ac5ad58ee267fa7f77 Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Fri, 13 Dec 2024 10:28:03 -0600 Subject: [PATCH 10/10] Update to the script setup - template update to rename variables - README update to reference where local set up of RS and TI are - update local variables to be lower case --- scripts/.env.template | 2 +- scripts/README.md | 1 + scripts/setup/setup-reportstream.sh | 13 ++++++------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/.env.template b/scripts/.env.template index e615c560d..dc225ff0e 100644 --- a/scripts/.env.template +++ b/scripts/.env.template @@ -8,7 +8,7 @@ RS_LCL_API_URL="http://localhost:7071" RS_STG_API_URL="https://staging.prime.cdc.gov:443" RS_PRD_API_URL="https://prime.cdc.gov:443" TI_LCL_API_URL="http://localhost:8080" -TI_DOCKER_LCL_API_URL_RS_CONFIG="http://host.docker.internal:8080" +TI_LCL_API_URL_RS_CONFIG="http://host.docker.internal:8080" TI_STG_API_URL="https://cdcti-stg-api.azurewebsites.net:443" TI_PRD_API_URL="https://cdcti-prd-api.azurewebsites.net:443" diff --git a/scripts/README.md b/scripts/README.md index ebeacbdc7..0f9fee201 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -26,6 +26,7 @@ - [Resources](#resources) ## Setup +The steps to set up TT and RS locally are in [setup locally section in the main README.md ](../README.md#setup-with-reportstream). Follow the instructions below to load the environments variables required for these scripts. ReportStream and Trusted Intermediary must be running locally before running any scripts. diff --git a/scripts/setup/setup-reportstream.sh b/scripts/setup/setup-reportstream.sh index 0f68ecc40..6e6f1a71b 100755 --- a/scripts/setup/setup-reportstream.sh +++ b/scripts/setup/setup-reportstream.sh @@ -16,16 +16,15 @@ echo "Resetting the database and loading the baseline settings..." ./gradlew reloadTables ./gradlew reloadSettings -# Update RS Configuration for the TI API based on docker or gradle # If either TI or RS are not running in docker, then use a gradle hosted URL -LOCAL_DOCKER_IMAGE_NAME=$(docker ps --filter "name=trusted-intermediary-router-1" | grep trusted-intermediary-router-1) -LOCAL_RS_DOCKER_IMAGE_NAME=$(docker ps --filter "name=prime-router-prime_dev-1" | grep prime-router-prime_dev-1) -if [[ -z $LOCAL_DOCKER_IMAGE_NAME || -z $LOCAL_RS_DOCKER_IMAGE_NAME ]]; then +local_ti_docker_image_name=$(docker ps --filter "name=trusted-intermediary-router-1" | grep trusted-intermediary-router-1) +local_rs_docker_image_name=$(docker ps --filter "name=prime-router-prime_dev-1" | grep prime-router-prime_dev-1) +if [[ -z $local_ti_docker_image_name || -z $local_rs_docker_image_name ]]; then ti_api_url=${TI_LCL_API_URL} - echo "Gradle instance detected, ReportStream transport will use ${TI_LCL_API_URL}..." + echo "No docker instances detected, ReportStream transport will use ${TI_LCL_API_URL}..." else - ti_api_url=${TI_DOCKER_LCL_API_URL_RS_CONFIG} - echo "Docker instances detected, ReportStream transport will use ${TI_DOCKER_LCL_API_URL_RS_CONFIG}..." + ti_api_url=${TI_LCL_API_URL_RS_CONFIG} + echo "Docker instances detected, ReportStream transport will use ${TI_LCL_API_URL_RS_CONFIG}..." fi # Need to CD to prime-router to run the prime CLI