From 8295ba9843873c0c01bbbf8e6e7aa3d5b0bad4b0 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 20 Jun 2024 17:14:26 -0600 Subject: [PATCH 1/7] Updating institute-api url from route to service-url --- tools/config/update-configmap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/config/update-configmap.sh b/tools/config/update-configmap.sh index 9b6ace1b..d86cabc9 100644 --- a/tools/config/update-configmap.sh +++ b/tools/config/update-configmap.sh @@ -68,7 +68,7 @@ oc create -n "$GRAD_NAMESPACE"-"$envValue" configmap "$APP_NAME"-config-map \ --from-literal=ENABLE_FLYWAY="true" \ --from-literal=ENABLE_TRAX_UPDATE="true" \ --from-literal=KEYCLOAK_TOKEN_URL="https://soam-$envValue.apps.silver.devops.gov.bc.ca/" \ - --from-literal=INSTITUTE_API_URL_ROOT="https://institute-api-$COMMON_NAMESPACE-$envValue.apps.silver.devops.gov.bc.ca/" \ + --from-literal=INSTITUTE_API_URL_ROOT="http://institute-api-master.$COMMON_NAMESPACE-$envValue.svc.cluster.local:8080/" \ --from-literal=MAX_RETRY_ATTEMPTS="3" \ --from-literal=SCHOOL_CACHE_EXPIRY_IN_MINS="240" \ --dry-run=client -o yaml | oc apply -f - From 38bb39c17d0df40f6492d34f93f9e89a6c033d81 Mon Sep 17 00:00:00 2001 From: githubmamatha Date: Mon, 24 Jun 2024 11:52:13 -0700 Subject: [PATCH 2/7] Grad2-2766 Created Event history table. --- .../V1.0.28__DDL-CREATE_TABLE-EVENT_HISTORY.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 api/src/main/resources/db/migration/1.0/V1.0.28__DDL-CREATE_TABLE-EVENT_HISTORY.sql diff --git a/api/src/main/resources/db/migration/1.0/V1.0.28__DDL-CREATE_TABLE-EVENT_HISTORY.sql b/api/src/main/resources/db/migration/1.0/V1.0.28__DDL-CREATE_TABLE-EVENT_HISTORY.sql new file mode 100644 index 00000000..de8e7a73 --- /dev/null +++ b/api/src/main/resources/db/migration/1.0/V1.0.28__DDL-CREATE_TABLE-EVENT_HISTORY.sql @@ -0,0 +1,14 @@ +CREATE TABLE "EVENT_HISTORY" +( "EVENT_HISTORY_ID" RAW(16) DEFAULT SYS_GUID() NOT NULL ENABLE, + "EVENT_ID" RAW(16) NOT NULL ENABLE, + "ACKNOWLEDGE_FLAG" VARCHAR2(1) NOT NULL ENABLE, + "CREATE_USER" VARCHAR2(32) DEFAULT USER NOT NULL ENABLE, + "CREATE_DATE" DATE DEFAULT SYSTIMESTAMP NOT NULL ENABLE, + "UPDATE_USER" VARCHAR2(32) DEFAULT USER NOT NULL ENABLE, + "UPDATE_DATE" DATE DEFAULT SYSTIMESTAMP NOT NULL ENABLE, + + CONSTRAINT "EVENT_HISTORY_ID_PK" PRIMARY KEY ("EVENT_HISTORY_ID") + USING INDEX TABLESPACE "API_GRAD_IDX" ENABLE +) SEGMENT CREATION IMMEDIATE + NOCOMPRESS LOGGING + TABLESPACE "API_GRAD_DATA" NO INMEMORY ; \ No newline at end of file From 527e148d31c1cfab539b51efc363644e0610277f Mon Sep 17 00:00:00 2001 From: "chris.ditcher" Date: Wed, 26 Jun 2024 14:51:58 -0700 Subject: [PATCH 3/7] Updated to Ubuntu 22.04 --- .github/workflows/build.from.dev.branch.deploy.to.dev.yml | 2 +- .github/workflows/build.from.main.branch.deploy.to.dev.yml | 2 +- .github/workflows/build.from.release.branch.deploy.to.dev.yml | 2 +- .github/workflows/create_tag.yml | 2 +- .github/workflows/deploy_prod.yml | 2 +- .github/workflows/deploy_test.yml | 2 +- .github/workflows/on.pr.yml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.from.dev.branch.deploy.to.dev.yml b/.github/workflows/build.from.dev.branch.deploy.to.dev.yml index cba89407..5749d983 100644 --- a/.github/workflows/build.from.dev.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.dev.branch.deploy.to.dev.yml @@ -48,7 +48,7 @@ on: jobs: openshift-ci-cd: name: Build and deploy to OpenShift DEV from developer branch - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 environment: dev steps: diff --git a/.github/workflows/build.from.main.branch.deploy.to.dev.yml b/.github/workflows/build.from.main.branch.deploy.to.dev.yml index edd10119..9711e715 100644 --- a/.github/workflows/build.from.main.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.main.branch.deploy.to.dev.yml @@ -38,7 +38,7 @@ on: jobs: openshift-ci-cd: name: Build and deploy to OpenShift DEV - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 environment: dev steps: diff --git a/.github/workflows/build.from.release.branch.deploy.to.dev.yml b/.github/workflows/build.from.release.branch.deploy.to.dev.yml index c3b3e3b5..b7837991 100644 --- a/.github/workflows/build.from.release.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.release.branch.deploy.to.dev.yml @@ -43,7 +43,7 @@ on: jobs: openshift-ci-cd: name: Build and deploy to OpenShift DEV from release branch - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 environment: dev steps: diff --git a/.github/workflows/create_tag.yml b/.github/workflows/create_tag.yml index 8de096fc..b63cbb1b 100644 --- a/.github/workflows/create_tag.yml +++ b/.github/workflows/create_tag.yml @@ -26,7 +26,7 @@ on: jobs: tag_image: name: Tag Image - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 environment: dev outputs: diff --git a/.github/workflows/deploy_prod.yml b/.github/workflows/deploy_prod.yml index 6ab6c6f8..1cbcf539 100644 --- a/.github/workflows/deploy_prod.yml +++ b/.github/workflows/deploy_prod.yml @@ -32,7 +32,7 @@ on: jobs: deploy-to-openshift-prod: name: Deploy to OpenShift PROD - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 environment: prod outputs: diff --git a/.github/workflows/deploy_test.yml b/.github/workflows/deploy_test.yml index 39bc2f72..34781f56 100644 --- a/.github/workflows/deploy_test.yml +++ b/.github/workflows/deploy_test.yml @@ -32,7 +32,7 @@ on: jobs: deploy-to-openshift-test: name: Deploy to OpenShift TEST - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 environment: test outputs: diff --git a/.github/workflows/on.pr.yml b/.github/workflows/on.pr.yml index 2eae9936..4c1f2c15 100644 --- a/.github/workflows/on.pr.yml +++ b/.github/workflows/on.pr.yml @@ -10,7 +10,7 @@ on: jobs: quality_profile: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 defaults: run: From 02b8b32a817628189f0cb8af5eaf87dd474feaba Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Wed, 26 Jun 2024 17:31:51 -0600 Subject: [PATCH 4/7] Sync from main (#335) * Updating institute-api url from route to service-url * Updated to Ubuntu 22.04 (cherry picked from commit 527e148d31c1cfab539b51efc363644e0610277f) --------- Co-authored-by: chris.ditcher From 26986e2eb6983f3238a3176def794c41ee00e329 Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Wed, 3 Jul 2024 18:02:08 -0700 Subject: [PATCH 5/7] GRAD2-2805: task is complete. GRAD2-2805: task is complete. --- .../ca/bc/gov/educ/api/trax/service/EventCommonService.java | 2 +- .../test/java/ca/bc/gov/educ/api/trax/support/TestUtils.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventCommonService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventCommonService.java index d07b18ee..bfb40695 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventCommonService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventCommonService.java @@ -281,7 +281,7 @@ private void checkAndPopulateTraxStudentStatus(TraxStudentEntity traxStudentEnti newArchiveFlag = "I"; } else if (StringUtils.equals(gradStudentStatus, "TER")) { newStudStatus = "T"; - newArchiveFlag = "I"; + newArchiveFlag = "A"; } if (!StringUtils.equalsIgnoreCase(studStatus, newStudStatus)) { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/support/TestUtils.java b/api/src/test/java/ca/bc/gov/educ/api/trax/support/TestUtils.java index 327d62c4..e2a7b93e 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/support/TestUtils.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/support/TestUtils.java @@ -178,7 +178,7 @@ public static TraxStudentEntity createTraxStudent(String program, String student traxStudent.setArchiveFlag("I"); } else if (StringUtils.equals(studentStatus, "TER")) { traxStudent.setStudStatus("T"); - traxStudent.setArchiveFlag("I"); + traxStudent.setArchiveFlag("A"); } return traxStudent; } From 066e125f2fc4bfe3778bd55a0a7882e231b99b5b Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 4 Jul 2024 10:40:54 -0600 Subject: [PATCH 6/7] Institute - Cache institute api data into Redis Cluster instead of standalone (#336) * GRAD2-2840 - Institute - Cache institute api data into Redis Cluster instead of standalone * GRAD2-2840 - Institute - Cache institute api data into Redis Cluster instead of standalone * GRAD2-2840 - Institute - Cache institute api data into Redis Cluster instead of standalone --- api/pom.xml | 6 +- .../educ/api/trax/config/GradTraxConfig.java | 14 --- .../gov/educ/api/trax/config/RedisConfig.java | 62 ++++++------- .../trax/service/institute/ServiceHelper.java | 10 +-- .../trax/util/EducGradTraxApiConstants.java | 3 + api/src/main/resources/application.yaml | 1 + .../service/BaseReplicationServiceTest.java | 6 ++ ...reographedEventPersistenceServiceTest.java | 7 ++ .../api/trax/service/CodeServiceTest.java | 6 ++ .../api/trax/service/DistrictServiceTest.java | 6 ++ .../educ/api/trax/service/EdwServiceTest.java | 6 ++ .../GradStudentGraduatedServiceTest.java | 6 ++ .../GradStudentUndoCompletionServiceTest.java | 6 ++ .../GradStudentUpdatedServiceTest.java | 6 ++ .../educ/api/trax/service/PsiServiceTest.java | 6 ++ .../api/trax/service/SchoolServiceTest.java | 6 ++ .../trax/service/TraxCommonServiceTest.java | 6 ++ .../trax/service/TraxUpdateServiceTest.java | 6 ++ .../institute/InstituteCodeServiceTest.java | 86 ++++++++++--------- .../InstituteDistrictServiceTest.java | 58 +++++++------ .../institute/InstituteSchoolServiceTest.java | 6 ++ api/src/test/resources/application.yaml | 1 + 22 files changed, 201 insertions(+), 119 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index cc08bb9c..7b25c92e 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -79,8 +79,10 @@ redis.clients jedis - - + + org.apache.commons + commons-pool2 + org.apache.logging.log4j log4j-api diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/config/GradTraxConfig.java b/api/src/main/java/ca/bc/gov/educ/api/trax/config/GradTraxConfig.java index 9202f87c..17733c10 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/config/GradTraxConfig.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/config/GradTraxConfig.java @@ -18,8 +18,6 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.security.oauth2.client.*; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; -import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizedClientManager; -import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository; import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.web.client.RestTemplate; @@ -80,18 +78,6 @@ public WebClient getInstituteWebClient(OAuth2AuthorizedClientManager authorizedC .apply(filter.oauth2Configuration()) .build(); } - /*@Bean - public OAuth2AuthorizedClientManager authorizedClientManager( - ClientRegistrationRepository clientRegistrationRepository, - OAuth2AuthorizedClientRepository authorizedClientRepository) { - OAuth2AuthorizedClientProvider authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder() - .clientCredentials() - .build(); - DefaultOAuth2AuthorizedClientManager authorizedClientManager = new DefaultOAuth2AuthorizedClientManager( - clientRegistrationRepository, authorizedClientRepository); - authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider); - return authorizedClientManager; - }*/ @Bean public OAuth2AuthorizedClientManager authorizedClientManager( diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java b/api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java index e031932c..d41c9438 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java @@ -1,55 +1,55 @@ package ca.bc.gov.educ.api.trax.config; import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisClusterConfiguration; import org.springframework.data.redis.connection.RedisClusterNode; -import org.springframework.data.redis.connection.RedisNode; -import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; -import org.springframework.data.redis.serializer.GenericToStringSerializer; -import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; -import org.springframework.data.redis.serializer.StringRedisSerializer; -import redis.clients.jedis.Jedis; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisCluster; + +import java.time.Duration; +import java.util.HashSet; +import java.util.Set; @Configuration @EnableRedisRepositories("ca.bc.gov.educ.api.trax.repository.redis") public class RedisConfig { @Autowired private EducGradTraxApiConstants constants; + @Bean public JedisConnectionFactory jedisConnectionFactory() { - RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); - redisStandaloneConfiguration.setHostName(constants.getRedisUrl()); - redisStandaloneConfiguration.setPort(Integer.parseInt(constants.getRedisPort())); - redisStandaloneConfiguration.setPassword(constants.getRedisSecret()); - - //Cluster Configuration RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(); - RedisNode node0 = new RedisNode(constants.getRedisUrl(), Integer.parseInt(constants.getRedisPort())); - redisClusterConfiguration.addClusterNode(node0); - - RedisClusterNode rcn = new RedisClusterNode(constants.getRedisUrl(), Integer.parseInt(constants.getRedisPort())); - - return new JedisConnectionFactory(redisStandaloneConfiguration); + redisClusterConfiguration.addClusterNode(new RedisClusterNode( + constants.getRedisUrl(), + Integer.parseInt(constants.getRedisPort()))); + redisClusterConfiguration.setPassword(constants.getRedisSecret()); + return new JedisConnectionFactory(redisClusterConfiguration); } @Bean - public RedisTemplate redisTemplate() { - final RedisTemplate template = new RedisTemplate<>(); - template.setConnectionFactory(jedisConnectionFactory()); - template.setKeySerializer(new StringRedisSerializer()); - template.setValueSerializer(new GenericToStringSerializer<>(Object.class)); - template.setHashKeySerializer(new JdkSerializationRedisSerializer()); - template.setHashValueSerializer(new JdkSerializationRedisSerializer()); - template.setEnableTransactionSupport(true); - template.afterPropertiesSet(); - - return template; + public JedisCluster jedisCluster() { + Set jedisClusterNodes = new HashSet<>(); + jedisClusterNodes.add( + new HostAndPort(constants.getRedisUrl(), + Integer.parseInt(constants.getRedisPort()))); + + GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); + poolConfig.setMaxTotal(8); + poolConfig.setMaxIdle(8); + poolConfig.setMinIdle(0); + poolConfig.setBlockWhenExhausted(true); + poolConfig.setMaxWait(Duration.ofSeconds(1)); + poolConfig.setTestWhileIdle(true); + poolConfig.setTimeBetweenEvictionRuns(Duration.ofSeconds(1)); + + return new JedisCluster(jedisClusterNodes, 5000, 5000, 3, + constants.getRedisUser(), constants.getRedisSecret(), + "educ-grad-trax-api", poolConfig); } - } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/ServiceHelper.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/ServiceHelper.java index 72aa7196..7b5a1726 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/ServiceHelper.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/ServiceHelper.java @@ -4,18 +4,18 @@ import ca.bc.gov.educ.api.trax.constant.CacheStatus; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; +import redis.clients.jedis.JedisCluster; @Slf4j @Component public class ServiceHelper { @Autowired - RedisTemplate redisTemplate; + JedisCluster jedisCluster; public void initializeCache(boolean force, CacheKey cacheKey, T service) { - String cacheStatus = redisTemplate.opsForValue().get(cacheKey.name()); + String cacheStatus = jedisCluster.get(cacheKey.name()); cacheStatus = cacheStatus == null ? "" : cacheStatus; if (CacheStatus.LOADING.name().compareToIgnoreCase(cacheStatus) == 0 || CacheStatus.READY.name().compareToIgnoreCase(cacheStatus) == 0) { @@ -33,9 +33,9 @@ public void initializeCache(boolean force, CacheKey cacheKey, T service) { } private void loadCache(CacheKey cacheKey, T service) { - redisTemplate.opsForValue().set(cacheKey.name(), CacheStatus.LOADING.name()); + jedisCluster.set(cacheKey.name(), CacheStatus.LOADING.name()); loadDataIntoRedisCache(cacheKey, service); - redisTemplate.opsForValue().set(cacheKey.name(), CacheStatus.READY.name()); + jedisCluster.set(cacheKey.name(), CacheStatus.READY.name()); log.info(String.format("Success! - %s is now READY", cacheKey)); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java index a4ad024f..7b78fcee 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java @@ -138,6 +138,9 @@ public class EducGradTraxApiConstants { @Value("${redis.port}") private String redisPort; + @Value("${redis.user}") + private String redisUser; + @Value("${redis.secret}") private String redisSecret; diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 4ba48ea2..0565b42f 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -134,6 +134,7 @@ nats: redis: url: ${REDIS_URL} port: ${REDIS_PORT} + user: ${REDIS_USER} secret: ${REDIS_SECRET} #Scheduler diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/BaseReplicationServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/BaseReplicationServiceTest.java index 24dbd242..8ae57049 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/BaseReplicationServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/BaseReplicationServiceTest.java @@ -11,11 +11,13 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository; import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.JedisCluster; @RunWith(SpringRunner.class) @SpringBootTest(classes = {EducGradTraxApiApplication.class}) @@ -42,6 +44,10 @@ public abstract class BaseReplicationServiceTest { public OAuth2AuthorizedClientRepository oAuth2AuthorizedClientRepository; @MockBean public OAuth2AuthorizedClientService oAuth2AuthorizedClientService; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @Before public void resetState() { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/ChoreographedEventPersistenceServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/ChoreographedEventPersistenceServiceTest.java index daa9ff92..a64b83cc 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/ChoreographedEventPersistenceServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/ChoreographedEventPersistenceServiceTest.java @@ -19,10 +19,12 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.JedisCluster; import java.util.Optional; import java.util.UUID; @@ -53,6 +55,11 @@ public class ChoreographedEventPersistenceServiceTest { @MockBean private Subscriber subscriber; + @MockBean + private JedisConnectionFactory jedisConnectionFactory; + @MockBean + private JedisCluster jedisClusterMock; + @TestConfiguration static class TestConfig { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/CodeServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/CodeServiceTest.java index 0ce5e3a6..6252e90a 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/CodeServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/CodeServiceTest.java @@ -19,10 +19,12 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.JedisCluster; import java.util.ArrayList; import java.util.List; @@ -58,6 +60,10 @@ public class CodeServiceTest { @MockBean private Subscriber subscriber; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @TestConfiguration static class TestConfig { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictServiceTest.java index e78077b4..b75a811a 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictServiceTest.java @@ -21,11 +21,13 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.WebClient; +import redis.clients.jedis.JedisCluster; import java.util.List; import java.util.Optional; @@ -51,6 +53,10 @@ public class DistrictServiceTest { @Mock WebClient.RequestBodySpec requestBodyMock; @Mock WebClient.RequestBodyUriSpec requestBodyUriMock; @Mock WebClient.ResponseSpec responseMock; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @MockBean @Qualifier("default") diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/EdwServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/EdwServiceTest.java index c9dc8733..6555b550 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/EdwServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/EdwServiceTest.java @@ -15,10 +15,12 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.JedisCluster; import java.math.BigDecimal; import java.util.Arrays; @@ -51,6 +53,10 @@ public class EdwServiceTest { @MockBean private Subscriber subscriber; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @TestConfiguration diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentGraduatedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentGraduatedServiceTest.java index 6bf5f8c7..cec4b060 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentGraduatedServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentGraduatedServiceTest.java @@ -18,10 +18,12 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.JedisCluster; import static org.mockito.MockitoAnnotations.openMocks; @@ -47,6 +49,10 @@ public class GradStudentGraduatedServiceTest { @MockBean private Subscriber subscriber; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @TestConfiguration static class TestConfig { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentUndoCompletionServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentUndoCompletionServiceTest.java index 102578ce..f4c56d8f 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentUndoCompletionServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentUndoCompletionServiceTest.java @@ -18,10 +18,12 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.JedisCluster; import static org.mockito.MockitoAnnotations.openMocks; @@ -47,6 +49,10 @@ public class GradStudentUndoCompletionServiceTest { @MockBean private Subscriber subscriber; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @TestConfiguration static class TestConfig { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentUpdatedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentUpdatedServiceTest.java index 04fd2f95..c3d45833 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentUpdatedServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/GradStudentUpdatedServiceTest.java @@ -18,10 +18,12 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.JedisCluster; import static org.mockito.MockitoAnnotations.openMocks; @@ -47,6 +49,10 @@ public class GradStudentUpdatedServiceTest { @MockBean private Subscriber subscriber; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @TestConfiguration static class TestConfig { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/PsiServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/PsiServiceTest.java index 62b60b0a..d4bb6035 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/PsiServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/PsiServiceTest.java @@ -23,10 +23,12 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.JedisCluster; import java.util.ArrayList; import java.util.List; @@ -64,6 +66,10 @@ public class PsiServiceTest { @MockBean private Subscriber subscriber; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @TestConfiguration static class TestConfig { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolServiceTest.java index 4892a7c1..49408079 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolServiceTest.java @@ -26,11 +26,13 @@ import org.springframework.context.annotation.Bean; import org.springframework.core.ParameterizedTypeReference; import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; +import redis.clients.jedis.JedisCluster; import java.util.ArrayList; import java.util.List; @@ -76,6 +78,10 @@ class SchoolServiceTest { @MockBean private CommonSchoolCache commonSchoolCache; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @TestConfiguration static class TestConfig { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxCommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxCommonServiceTest.java index e8c32fe1..dc82677d 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxCommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxCommonServiceTest.java @@ -20,10 +20,12 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.data.domain.*; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.JedisCluster; import java.math.BigDecimal; import java.util.*; @@ -67,6 +69,10 @@ public class TraxCommonServiceTest { @MockBean private Subscriber subscriber; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @TestConfiguration static class TestConfig { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxUpdateServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxUpdateServiceTest.java index a124dd1d..513ea66a 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxUpdateServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxUpdateServiceTest.java @@ -25,10 +25,12 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.JedisCluster; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -79,6 +81,10 @@ public class TraxUpdateServiceTest { @MockBean private Subscriber subscriber; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @TestConfiguration static class TestConfig { diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteCodeServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteCodeServiceTest.java index bb08b8eb..63f0ac50 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteCodeServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteCodeServiceTest.java @@ -6,6 +6,7 @@ import ca.bc.gov.educ.api.trax.messaging.jetstream.Publisher; import ca.bc.gov.educ.api.trax.messaging.jetstream.Subscriber; import ca.bc.gov.educ.api.trax.model.dto.ResponseObj; +import ca.bc.gov.educ.api.trax.model.dto.institute.District; import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolCategoryCode; import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolFundingGroupCode; import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolCategoryCodeEntity; @@ -29,8 +30,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ValueOperations; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.http.HttpHeaders; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; @@ -38,6 +38,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; +import redis.clients.jedis.JedisCluster; import java.util.ArrayList; import java.util.Arrays; @@ -45,7 +46,6 @@ import java.util.function.Consumer; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; @@ -69,14 +69,14 @@ public class InstituteCodeServiceTest { private GradCountryRepository gradCountryRepository; @MockBean private GradProvinceRepository gradProvinceRepository; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @MockBean @Qualifier("default") WebClient webClientMock; - @MockBean - RedisTemplate redisTemplateMock; - @Mock - ValueOperations valueOperationsMock; @Mock private WebClient.RequestHeadersSpec requestHeadersSpecMock; @Mock @@ -226,21 +226,19 @@ public void whenGetSchoolCategoryCodesFromRedisCache_GetSchoolCategoryCodes() { @Test public void whenInitializeSchoolCategoryCodeCache_WithLoadingAndFalse_DoNotForceLoad() { - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name())) + when(jedisClusterMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.LOADING)); - doNothing().when(valueOperationsMock).set(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name(), CacheStatus.LOADING.name()); + when(jedisClusterMock.set(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name(), CacheStatus.LOADING.name())) + .thenReturn(anyString()); codeService.initializeSchoolCategoryCodeCache(false); } @Test public void whenInitializeSchoolCategoryCodeCache_WithReadyAndFalse_DoNotForceLoad() { - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name())) + when(jedisClusterMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.READY)); - doNothing().when(valueOperationsMock).set(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name(), CacheStatus.READY.name()); + when(jedisClusterMock.set(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name(), CacheStatus.READY.name())) + .thenReturn(anyString()); codeService.initializeSchoolCategoryCodeCache(false); } @@ -300,11 +298,8 @@ public void whenInitializeSchoolCategoryCodeCache_WithLoadingAndTrue_ThenForceLo when(this.responseObjectMock.getAccess_token()) .thenReturn("accessToken"); - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name())) + when(jedisClusterMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.LOADING)); - doNothing().when(valueOperationsMock).set(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name(), CacheStatus.LOADING.name()); CodeService codeServicemock = mock(CodeService.class); when(codeServicemock.getSchoolCategoryCodesFromInstituteApi()).thenReturn(sccs); @@ -316,11 +311,10 @@ public void whenInitializeSchoolCategoryCodeCache_WithLoadingAndTrue_ThenForceLo @Test public void whenInitializeSchoolCategoryCodeCache_WithReadyAndTrue_ThenForceLoad() { - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name())) + when(jedisClusterMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.READY)); - doNothing().when(valueOperationsMock).set(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name(), CacheStatus.READY.name()); + when(jedisClusterMock.set(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name(), CacheStatus.READY.name())) + .thenReturn(anyString()); codeService.initializeSchoolCategoryCodeCache(true); } @@ -341,21 +335,19 @@ public void whenGetSchoolFundingGroupCodesFromRedisCache_GetSchoolFundingGroupCo @Test public void whenInitializeSchoolFundingGroupCodeCache_WithLoadingAndFalse_DoNotForceLoad() { - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name())) + when(jedisClusterMock.get(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.LOADING)); - doNothing().when(valueOperationsMock).set(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name(), CacheStatus.LOADING.name()); + when(jedisClusterMock.set(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name(), CacheStatus.LOADING.name())) + .thenReturn(anyString()); codeService.initializeSchoolFundingGroupCodeCache(false); } @Test public void whenInitializeSchoolFundingGroupCodeCache_WithReadyAndFalse_DoNotForceLoad() { - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name())) + when(jedisClusterMock.get(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.READY)); - doNothing().when(valueOperationsMock).set(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name(), CacheStatus.READY.name()); + when(jedisClusterMock.set(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name(), CacheStatus.READY.name())) + .thenReturn(anyString()); codeService.initializeSchoolFundingGroupCodeCache(false); } @@ -413,11 +405,8 @@ public void whenInitializeSchoolFundingGroupCodeCache_WithLoadingAndTrue_ThenFor when(this.responseObjectMock.getAccess_token()) .thenReturn("accessToken"); - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name())) + when(jedisClusterMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.LOADING)); - doNothing().when(valueOperationsMock).set(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name(), CacheStatus.LOADING.name()); CodeService codeServicemock = mock(CodeService.class); when(codeServicemock.getSchoolFundingGroupCodesFromInstituteApi()).thenReturn(sfgcs); @@ -425,15 +414,34 @@ public void whenInitializeSchoolFundingGroupCodeCache_WithLoadingAndTrue_ThenFor codeService.initializeSchoolFundingGroupCodeCache(true); //verify(codeServicemock).loadSchoolCategoryCodesIntoRedisCache(sccs); + } @Test public void whenInitializeSchoolFundingGroupCodeCache_WithReadyAndTrue_ThenForceLoad() { - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name())) + + SchoolFundingGroupCode sfgc = new SchoolFundingGroupCode(); + List sfgcs = new ArrayList(); + sfgc.setSchoolFundingGroupCode("SCC1"); + sfgc.setLabel("SCC1-label"); + sfgc.setDescription("Desc"); + sfgc.setDisplayOrder("10"); + sfgc.setEffectiveDate("01-01-2024"); + sfgc.setExpiryDate("01-01-2024"); + sfgcs.add(sfgc); + sfgc = new SchoolFundingGroupCode(); + sfgc.setSchoolFundingGroupCode("SCC2"); + sfgc.setLabel("SCC2-label"); + sfgc.setDescription("Desc"); + sfgc.setDisplayOrder("20"); + sfgc.setEffectiveDate("01-01-2024"); + sfgc.setExpiryDate("01-01-2024"); + sfgcs.add(sfgc); + + when(jedisClusterMock.get(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.READY)); - doNothing().when(valueOperationsMock).set(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name(), CacheStatus.READY.name()); + when(jedisClusterMock.set(CacheKey.SCHOOL_FUNDING_GROUP_CODE_CACHE.name(), CacheStatus.READY.name())) + .thenReturn(anyString()); codeService.initializeSchoolFundingGroupCodeCache(true); } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java index 66b9220e..6ad328f1 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java @@ -7,22 +7,18 @@ import ca.bc.gov.educ.api.trax.messaging.jetstream.Subscriber; import ca.bc.gov.educ.api.trax.model.dto.ResponseObj; import ca.bc.gov.educ.api.trax.model.dto.institute.District; -import ca.bc.gov.educ.api.trax.model.dto.institute.DistrictContact; -import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolCategoryCode; import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictContactEntity; import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictEntity; -import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolCategoryCodeEntity; -import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolFundingGroupCodeEntity; import ca.bc.gov.educ.api.trax.model.transformer.institute.DistrictTransformer; -import ca.bc.gov.educ.api.trax.repository.GradCountryRepository; -import ca.bc.gov.educ.api.trax.repository.GradProvinceRepository; import ca.bc.gov.educ.api.trax.repository.redis.DistrictRedisRepository; import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; import ca.bc.gov.educ.api.trax.util.RestUtils; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.exceptions.base.MockitoException; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -31,7 +27,8 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.connection.RedisClusterConfiguration; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.core.ValueOperations; import org.springframework.http.HttpHeaders; import org.springframework.security.oauth2.client.registration.ClientRegistration; @@ -40,13 +37,14 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; +import redis.clients.jedis.JedisCluster; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.function.Consumer; -import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -67,14 +65,14 @@ public class InstituteDistrictServiceTest { private DistrictService districtService; @MockBean private DistrictRedisRepository districtRedisRepository; + @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; @MockBean @Qualifier("default") WebClient webClientMock; - @MockBean - RedisTemplate redisTemplateMock; - @Mock - ValueOperations valueOperationsMock; @Mock private WebClient.RequestHeadersSpec requestHeadersSpecMock; @Mock @@ -160,21 +158,17 @@ public void whenLoadDistrictsIntoRedisCache_DoesNotThrow() { @Test public void whenInitializeDistrictCache_WithLoadingAndFalse_DoNotForceLoad() { - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.DISTRICT_CACHE.name())) + when(jedisClusterMock.get(CacheKey.DISTRICT_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.LOADING)); - doNothing().when(valueOperationsMock).set(CacheKey.DISTRICT_CACHE.name(), CacheStatus.LOADING.name()); + doThrow(new MockitoException("")).when(jedisClusterMock).set(CacheKey.DISTRICT_CACHE.name(), CacheStatus.LOADING.name()); districtService.initializeDistrictCache(false); } @Test public void whenInitializeDistrictCache_WithReadyAndFalse_DoNotForceLoad() { - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.DISTRICT_CACHE.name())) + when(jedisClusterMock.get(CacheKey.DISTRICT_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.READY)); - doNothing().when(valueOperationsMock).set(CacheKey.DISTRICT_CACHE.name(), CacheStatus.READY.name()); + doThrow(new MockitoException("")).when(jedisClusterMock).set(CacheKey.DISTRICT_CACHE.name(), CacheStatus.READY.name()); districtService.initializeDistrictCache(false); } @@ -224,11 +218,9 @@ public void whenInitializeDistrictCache_WithLoadingAndTrue_ThenForceLoad() { when(this.responseObjectMock.getAccess_token()) .thenReturn("accessToken"); - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.DISTRICT_CACHE.name())) + when(jedisClusterMock.get(CacheKey.DISTRICT_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.LOADING)); - doNothing().when(valueOperationsMock).set(CacheKey.DISTRICT_CACHE.name(), CacheStatus.LOADING.name()); + DistrictService districtServiceMock = mock(DistrictService.class); when(districtServiceMock.getDistrictsFromInstituteApi()).thenReturn(ds); @@ -240,11 +232,21 @@ public void whenInitializeDistrictCache_WithLoadingAndTrue_ThenForceLoad() { @Test public void whenInitializeDistrictCache_WithReadyAndTrue_ThenForceLoad() { - when(redisTemplateMock.opsForValue()) - .thenReturn(valueOperationsMock); - when(valueOperationsMock.get(CacheKey.DISTRICT_CACHE.name())) + + District d = new District(); + List ds = new ArrayList(); + d.setDistrictId("123"); + d.setDistrictNumber("456"); + ds.add(d); + d = new District(); + d.setDistrictId("789"); + d.setDistrictNumber("012"); + ds.add(d); + + when(jedisClusterMock.get(CacheKey.DISTRICT_CACHE.name())) .thenReturn(String.valueOf(CacheStatus.READY)); - doNothing().when(valueOperationsMock).set(CacheKey.DISTRICT_CACHE.name(), CacheStatus.READY.name()); + when(jedisClusterMock.set(CacheKey.DISTRICT_CACHE.name(), CacheStatus.READY.name())) + .thenReturn(anyString()); districtService.initializeDistrictCache(true); } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java index d1a253b8..ed7f10d1 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java @@ -28,6 +28,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.core.ParameterizedTypeReference; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.http.HttpHeaders; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; @@ -35,6 +36,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; +import redis.clients.jedis.JedisCluster; import java.util.ArrayList; import java.util.Arrays; @@ -61,6 +63,10 @@ public class InstituteSchoolServiceTest { @MockBean private SchoolRedisRepository schoolRedisRepository; @MockBean + private JedisConnectionFactory jedisConnectionFactoryMock; + @MockBean + private JedisCluster jedisClusterMock; + @MockBean @Qualifier("default") WebClient webClientMock; @Mock diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index ffad5705..1e0bdd5e 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -76,6 +76,7 @@ nats: redis: url: '127.0.0.1' port: '54321' + user: 'default' secret: 'its-a-secret' #Scheduler From 0471f3eafc0d778e49eff745dcf66f466368400f Mon Sep 17 00:00:00 2001 From: githubmamatha <106563495+githubmamatha@users.noreply.github.com> Date: Tue, 9 Jul 2024 10:32:52 -0700 Subject: [PATCH 7/7] Update pom.xml --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index 7b25c92e..5d1eb6e2 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.educ educ-grad-trax-api - 1.8.56 + 1.8.57 educ-grad-trax-api Ministry of Education GRAD TRAX API