diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/ExternalApiConfiguration.java b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/ExternalApiConfiguration.java index ef39be43..124a621b 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/ExternalApiConfiguration.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/ExternalApiConfiguration.java @@ -15,15 +15,15 @@ public class ExternalApiConfiguration { /** * Creates a RestClient bean for the Forest Client API. * - * @param providersConfiguration the configuration properties for providers + * @param silvaConfiguration the configuration properties for providers * @return the configured RestClient instance for the Forest Client API */ @Bean - public RestClient forestClientApi(ProvidersConfiguration providersConfiguration) { + public RestClient forestClientApi(SilvaConfiguration silvaConfiguration) { return RestClient .builder() - .baseUrl(providersConfiguration.getForestClientBaseUri()) - .defaultHeader("X-API-KEY", providersConfiguration.getForestClientApiKey()) + .baseUrl(silvaConfiguration.getForestClientApi().getAddress()) + .defaultHeader("X-API-KEY", silvaConfiguration.getForestClientApi().getKey()) .defaultHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) .build(); } @@ -34,10 +34,10 @@ public RestClient forestClientApi(ProvidersConfiguration providersConfiguration) * @return the configured RestClient instance for the Open Maps API */ @Bean - public RestClient openMapsApi() { + public RestClient openMapsApi(SilvaConfiguration silvaConfiguration) { return RestClient .builder() - .baseUrl("https://openmaps.gov.bc.ca/geo/ows") + .baseUrl(silvaConfiguration.getOpenMaps().getAddress()) .defaultHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) .build(); } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/ProvidersConfiguration.java b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/ProvidersConfiguration.java deleted file mode 100644 index 94764295..00000000 --- a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/ProvidersConfiguration.java +++ /dev/null @@ -1,17 +0,0 @@ -package ca.bc.gov.restapi.results.common.configuration; - -import lombok.Getter; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; - -/** This class contains configurations for all external APIs like address and keys. */ -@Getter -@Configuration -public class ProvidersConfiguration { - - @Value("${forest-client-api.address}") - private String forestClientBaseUri; - - @Value("${forest-client-api.key}") - private String forestClientApiKey; -} diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/SecurityConfiguration.java b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/SecurityConfiguration.java index 41373c72..9410eef8 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/SecurityConfiguration.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/SecurityConfiguration.java @@ -42,7 +42,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.cors(Customizer.withDefaults()) .csrf( customize -> - customize.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())) + customize.csrfTokenRepository(new CookieCsrfTokenRepository())) .authorizeHttpRequests( customize -> customize diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/SilvaConfiguration.java b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/SilvaConfiguration.java new file mode 100644 index 00000000..8af1dc84 --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/SilvaConfiguration.java @@ -0,0 +1,46 @@ +package ca.bc.gov.restapi.results.common.configuration; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.With; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + +/** + * This class contains configurations for all external APIs like address and keys. + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@With +@Builder +@Configuration +@Component +@ConfigurationProperties("ca.bc.gov.nrs") +public class SilvaConfiguration { + + private List dashboardJobUsers; + private List wmsWhitelist; + private List orgUnits; + + @NestedConfigurationProperty + private ExternalApiAddress forestClientApi; + @NestedConfigurationProperty + private ExternalApiAddress openMaps; + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class ExternalApiAddress { + + private String address; + private String key; + } + +} diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/common/endpoint/SecretsServiceEndpoint.java b/backend/src/main/java/ca/bc/gov/restapi/results/common/endpoint/SecretsServiceEndpoint.java index 9cf98a00..31761ef5 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/common/endpoint/SecretsServiceEndpoint.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/common/endpoint/SecretsServiceEndpoint.java @@ -1,9 +1,9 @@ package ca.bc.gov.restapi.results.common.endpoint; +import ca.bc.gov.restapi.results.common.configuration.SilvaConfiguration; import ca.bc.gov.restapi.results.common.dto.WmsLayersWhitelistUserDto; import java.util.List; -import java.util.stream.Stream; -import org.springframework.beans.factory.annotation.Value; +import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -13,10 +13,10 @@ */ @RestController @RequestMapping("/api/secrets") +@RequiredArgsConstructor public class SecretsServiceEndpoint { - @Value("${nr.results.config.wms-layers.whitelist}") - private String[] wmsLayersWhitelistUsers; + private final SilvaConfiguration silvaConfiguration; /** * Get all users allowed to see the WMS layers information. @@ -25,6 +25,10 @@ public class SecretsServiceEndpoint { */ @GetMapping("/wms-layers-whitelist") public List getWmsLayersWhitelistUsers() { - return Stream.of(wmsLayersWhitelistUsers).map(WmsLayersWhitelistUserDto::new).toList(); + return silvaConfiguration + .getWmsWhitelist() + .stream() + .map(WmsLayersWhitelistUserDto::new) + .toList(); } } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpoint.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpoint.java index 536413d5..8a90bdbb 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpoint.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpoint.java @@ -11,6 +11,7 @@ import ca.bc.gov.restapi.results.oracle.service.OpeningService; import ca.bc.gov.restapi.results.oracle.service.OrgUnitService; import jakarta.validation.Valid; +import java.util.Arrays; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; @@ -150,6 +151,6 @@ public List getOpeningOrgUnits() { public List getOpeningOrgUnitsByCode( @RequestParam(value = "orgUnitCodes", required = true) String[] codes) { - return orgUnitService.findAllOrgUnitsByCode(codes); + return orgUnitService.findAllOrgUnitsByCode(Arrays.asList(codes)); } } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepository.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepository.java index b56f5c32..56fb66c0 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepository.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepository.java @@ -9,6 +9,7 @@ import ca.bc.gov.restapi.results.oracle.enums.OpeningStatusEnum; import ca.bc.gov.restapi.results.oracle.util.PaginationUtil; import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Query; import java.math.BigDecimal; import java.sql.Timestamp; @@ -16,18 +17,21 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; /** This class represents the Openings Search repository database access. */ @Slf4j @Component -@AllArgsConstructor public class OpeningSearchRepository { private final EntityManager em; + public OpeningSearchRepository(@Qualifier("oracleEntityManagerFactory") EntityManagerFactory emf) { + this.em = emf.createEntityManager(); + } + /** * Search Opening with filters. * diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepository.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepository.java index 2f48ba89..43861125 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepository.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepository.java @@ -7,5 +7,5 @@ /** This interface provides methods to get, save, and manage org unit data in the database. */ public interface OrgUnitRepository extends JpaRepository { - List findAllByOrgUnitCodeIn(String[] orgUnitCodes); + List findAllByOrgUnitCodeIn(List orgUnitCodes); } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OrgUnitService.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OrgUnitService.java index 507b84f9..4df7972c 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OrgUnitService.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OrgUnitService.java @@ -1,25 +1,25 @@ package ca.bc.gov.restapi.results.oracle.service; +import ca.bc.gov.restapi.results.common.configuration.SilvaConfiguration; import ca.bc.gov.restapi.results.oracle.entity.OrgUnitEntity; import ca.bc.gov.restapi.results.oracle.repository.OrgUnitRepository; import java.util.Arrays; import java.util.List; import java.util.Objects; -import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -/** This class contains methods to handle Org Units. */ +/** + * This class contains methods to handle Org Units. + */ @Slf4j @Service -@AllArgsConstructor +@RequiredArgsConstructor public class OrgUnitService { private final OrgUnitRepository orgUnitRepository; - - @Value("${nr.results.config.opening-search.org-units}") - private String[] orgUnitsFromProps; + private final SilvaConfiguration silvaConfiguration; /** * Find all Org Units for the Openings Search. @@ -29,12 +29,15 @@ public class OrgUnitService { public List findAllOrgUnits() { log.info("Getting all org units for the search openings"); - if (Objects.isNull(orgUnitsFromProps) || orgUnitsFromProps.length == 0) { + if (Objects.isNull(silvaConfiguration.getOrgUnits()) + || silvaConfiguration.getOrgUnits().isEmpty() + ) { log.warn("No Org Units from the properties file."); return List.of(); } - List orgUnits = orgUnitRepository.findAllByOrgUnitCodeIn(orgUnitsFromProps); + List orgUnits = orgUnitRepository.findAllByOrgUnitCodeIn( + silvaConfiguration.getOrgUnits()); log.info("Found {} org units by codes", orgUnits.size()); return orgUnits; @@ -46,8 +49,8 @@ public List findAllOrgUnits() { * @param orgUnitCodes Org Unit codes to search for. * @return List of {@link OrgUnitEntity} with found categories. */ - public List findAllOrgUnitsByCode(String[] orgUnitCodes) { - log.info("Getting all org units by codes: {}", Arrays.toString(orgUnitCodes)); + public List findAllOrgUnitsByCode(List orgUnitCodes) { + log.info("Getting all org units by codes: {}", orgUnitCodes); List orgUnits = orgUnitRepository.findAllByOrgUnitCodeIn(orgUnitCodes); log.info("Found {} org units by codes", orgUnits.size()); diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/configuration/DashboardUserManagerConfiguration.java b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/configuration/DashboardUserManagerConfiguration.java index 2dc9151a..23e4a3ae 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/configuration/DashboardUserManagerConfiguration.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/configuration/DashboardUserManagerConfiguration.java @@ -13,10 +13,10 @@ @Getter @Setter @Configuration -@ConfigurationProperties("nr.results") +@ConfigurationProperties("ca.bc.gov.nrs") public class DashboardUserManagerConfiguration { - private String[] dashboardJobUsers; + private List dashboardJobUsers; /** * Gets the users in a list format. @@ -27,6 +27,6 @@ public List getUserList() { if (Objects.isNull(dashboardJobUsers)) { return List.of(); } - return List.of(dashboardJobUsers); + return dashboardJobUsers; } } diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 185edb77..91e89b55 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -79,10 +79,6 @@ management: health: show-details: always -# Native Cloud -springdoc: - enable-native-support: true - # https://github.com/quarkusio/quarkus/wiki/Migration-Guide-3.2 quarkus: native: @@ -93,28 +89,19 @@ ca: bc: gov: nrs: + dashboard-job-users: ${DASHBOARD_JOB_IDIR_USERS:NONE} + wms-whitelist: ${WMS_LAYERS_WHITELIST_USERS:NONE} + org-units: ${OPENING_SEARCH_ORG_UNITS:DCK,DSQ,DVA,DKM,DSC,DFN,DSI,DCR,DMK,DQC,DKA,DCS,DOS,DSE,DCC,DMH,DQU,DNI,DND,DRM,DPG,DSS,DPC} + forest-client-api: + address: ${FORESTCLIENTAPI_ADDRESS:https://nr-forest-client-api-prod.api.gov.bc.ca/api} + key: ${FORESTCLIENTAPI_KEY:placeholder-api-key} + open-maps: + address: ${OPENMAPS_URL:https://openmaps.gov.bc.ca/geo/ows} oracle: keystore: ${ORACLEDB_KEYSTORE:jssecacerts-path} secret: ${ORACLEDB_SECRET:changeit} host: ${DATABASE_HOST:nrcdb03.bcgov} -# Users allowed to manually trigger the Dashboard extraction job -nr: - results: - dashboard-job-users: ${DASHBOARD_JOB_IDIR_USERS} - -# Users allowed to see and download WMS layers information - config: - wms-layers: - whitelist: ${WMS_LAYERS_WHITELIST_USERS:NONE} - opening-search: - org-units: ${OPENING_SEARCH_ORG_UNITS:-"DCK,DSQ,DVA,DKM,DSC,DFN,DSI,DCR,DMK,DQC,DKA,DCS,DOS,DSE,DCC,DMH,DQU,DNI,DND,DRM,DPG,DSS,DPC"} - -# Forest Client API -forest-client-api: - address: ${FORESTCLIENTAPI_ADDRESS:https://nr-forest-client-api-prod.api.gov.bc.ca/api} - key: ${FORESTCLIENTAPI_KEY:placeholder-api-key} - # Logging logging: level: diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/common/endpoint/SecretsServiceEndpointTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/common/endpoint/SecretsServiceEndpointTest.java index a76da088..6930d54d 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/common/endpoint/SecretsServiceEndpointTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/common/endpoint/SecretsServiceEndpointTest.java @@ -5,19 +5,21 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import ca.bc.gov.restapi.results.extensions.AbstractTestContainerIntegrationTest; +import ca.bc.gov.restapi.results.extensions.WithMockJwt; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; -@WebMvcTest(SecretsServiceEndpoint.class) -@WithMockUser(roles = "user_read") -class SecretsServiceEndpointTest { - - @Autowired private MockMvc mockMvc; +@WithMockJwt +@AutoConfigureMockMvc +class SecretsServiceEndpointTest extends AbstractTestContainerIntegrationTest { + + @Autowired + private MockMvc mockMvc; @Test @DisplayName("Get WMS layers whitelist users happy path should succeed") diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpointTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpointTest.java index d616cc82..517e8969 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpointTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpointTest.java @@ -257,7 +257,7 @@ void getOpeningOrgUnitsByCode_happyPath_shouldSucceed() throws Exception { List orgUnitEntityList = List.of(orgUnit); - when(orgUnitService.findAllOrgUnitsByCode(new String[]{"DAS"})).thenReturn(orgUnitEntityList); + when(orgUnitService.findAllOrgUnitsByCode(List.of("DAS"))).thenReturn(orgUnitEntityList); mockMvc .perform( @@ -287,7 +287,7 @@ void getOpeningOrgUnitsByCode_happyPath_shouldSucceed() throws Exception { @Test @DisplayName("Get Opening Org Units By Code not Found should Succeed") void getOpeningOrgUnitsByCode_notFound_shouldSucceed() throws Exception { - when(orgUnitService.findAllOrgUnitsByCode(new String[]{"DAS"})).thenReturn(List.of()); + when(orgUnitService.findAllOrgUnitsByCode(List.of("DAS"))).thenReturn(List.of()); mockMvc .perform( diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepositoryTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepositoryTest.java index e5cce349..2e1c6a0f 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepositoryTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepositoryTest.java @@ -10,6 +10,7 @@ import ca.bc.gov.restapi.results.oracle.enums.OpeningCategoryEnum; import ca.bc.gov.restapi.results.oracle.enums.OpeningStatusEnum; import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.FlushModeType; import jakarta.persistence.LockModeType; import jakarta.persistence.Parameter; @@ -36,6 +37,7 @@ class OpeningSearchRepositoryTest { @Mock EntityManager entityManager; + @Mock EntityManagerFactory entityManagerFactory; private OpeningSearchRepository openingSearchRepository; @@ -295,7 +297,10 @@ public T unwrap(Class cls) { @BeforeEach void setup() { - openingSearchRepository = new OpeningSearchRepository(entityManager); + + when(entityManagerFactory.createEntityManager()).thenReturn(entityManager); + + openingSearchRepository = new OpeningSearchRepository(entityManagerFactory); } @Test diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepositoryIntegrationTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepositoryIntegrationTest.java index 8c49ba44..324b32bf 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepositoryIntegrationTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepositoryIntegrationTest.java @@ -17,7 +17,7 @@ class OrgUnitRepositoryIntegrationTest extends AbstractTestContainerIntegrationT @Test @DisplayName("Find all by org unit code unit in happy path should succeed") void findAllByOrgUnitCodeIn_happyPath_shouldSucceed() { - List list = orgUnitRepository.findAllByOrgUnitCodeIn(new String[]{"DAS"}); + List list = orgUnitRepository.findAllByOrgUnitCodeIn(List.of("DAS")); Assertions.assertNotNull(list); Assertions.assertEquals(1, list.size()); diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpeningServiceTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpeningServiceTest.java index ff83205a..33dbe06f 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpeningServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpeningServiceTest.java @@ -1,188 +1,52 @@ package ca.bc.gov.restapi.results.oracle.service; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import ca.bc.gov.restapi.results.common.exception.MaxPageSizeException; import ca.bc.gov.restapi.results.common.pagination.PaginatedResult; import ca.bc.gov.restapi.results.common.pagination.PaginationParameters; -import ca.bc.gov.restapi.results.common.provider.ForestClientApiProvider; -import ca.bc.gov.restapi.results.common.security.LoggedUserService; +import ca.bc.gov.restapi.results.extensions.AbstractTestContainerIntegrationTest; +import ca.bc.gov.restapi.results.extensions.WiremockLogNotifier; +import ca.bc.gov.restapi.results.extensions.WithMockJwt; import ca.bc.gov.restapi.results.oracle.dto.OpeningSearchFiltersDto; import ca.bc.gov.restapi.results.oracle.dto.OpeningSearchResponseDto; import ca.bc.gov.restapi.results.oracle.dto.RecentOpeningDto; -import ca.bc.gov.restapi.results.oracle.entity.CutBlockOpenAdminEntity; -import ca.bc.gov.restapi.results.oracle.entity.OpeningEntity; import ca.bc.gov.restapi.results.oracle.enums.OpeningCategoryEnum; import ca.bc.gov.restapi.results.oracle.enums.OpeningStatusEnum; -import ca.bc.gov.restapi.results.oracle.repository.OpeningRepository; -import ca.bc.gov.restapi.results.oracle.repository.OpeningSearchRepository; +import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import java.math.BigDecimal; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.Pageable; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -class OpeningServiceTest { - - @Mock OpeningRepository openingRepository; - - @Mock CutBlockOpenAdminService cutBlockOpenAdminService; - - @Mock LoggedUserService loggedUserService; - - @Mock OpeningSearchRepository openingSearchRepository; - - @Mock ForestClientApiProvider forestClientApiProvider; - +import org.junit.jupiter.api.extension.RegisterExtension; +import org.springframework.beans.factory.annotation.Autowired; + +@DisplayName("Integrated Test | Opening Service") +@WithMockJwt(value = "ttester") +class OpeningServiceTest extends AbstractTestContainerIntegrationTest { + + @RegisterExtension + static WireMockExtension clientApiStub = WireMockExtension + .newInstance() + .options( + wireMockConfig() + .port(10000) + .notifier(new WiremockLogNotifier()) + .asynchronousResponseEnabled(true) + .stubRequestLoggingDisabled(false) + ) + .configureStaticDsl(true) + .build(); + + @Autowired private OpeningService openingService; - private OpeningSearchFiltersDto mockFilter( - String orgUnit, - String category, - List statusList, - Boolean myOpenings, - Boolean submittedToFrpa, - String disturbanceDateStart, - String disturbanceDateEnd, - String regenDelayDateStart, - String regenDelayDateEnd, - String freeGrowingDateStart, - String freeGrowingDateEnd, - String updateDateStart, - String updateDateEnd, - String cuttingPermitId, - String cutBlockId, - String timberMark, - String mainSearchTerm) { - return new OpeningSearchFiltersDto( - orgUnit, - category, - statusList, - myOpenings, - submittedToFrpa, - disturbanceDateStart, - disturbanceDateEnd, - regenDelayDateStart, - regenDelayDateEnd, - freeGrowingDateStart, - freeGrowingDateEnd, - updateDateStart, - updateDateEnd, - cuttingPermitId, - cutBlockId, - timberMark, - mainSearchTerm); - } - - private OpeningSearchFiltersDto mockOrgUnit(String orgUnit) { - return mockFilter( - orgUnit, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null); - } - - private OpeningSearchFiltersDto mockMainFilter(String mainSearchTerm) { - return mockFilter( - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - mainSearchTerm); - } - - @BeforeEach - void setup() { - openingService = - new OpeningService( - openingRepository, - cutBlockOpenAdminService, - loggedUserService, - openingSearchRepository, - forestClientApiProvider); - } - - @Test - @DisplayName("Get a list of recent openings without Cut Block for the home screen") - void getRecentOpenings_openingWithoutCutBlockAdmin_shouldSucceed() { - OpeningEntity openingEntity = new OpeningEntity(); - openingEntity.setId(123L); - - List openingList = new ArrayList<>(1); - openingList.add(openingEntity); - - int pages = 3; - int pageSize = 5; - int totalResults = pageSize * pages - 1; - Pageable openingsPageable = Pageable.ofSize(pageSize); - - Page openingsPage = new PageImpl<>(openingList, openingsPageable, totalResults); - when(openingRepository.findAllByEntryUserId(any(), any())).thenReturn(openingsPage); - - when(cutBlockOpenAdminService.findAllByOpeningIdIn(any())).thenReturn(List.of()); - - int currentPage = 1; - - PaginationParameters pagination = new PaginationParameters(currentPage, pages); - PaginatedResult paginatedResult = - openingService.getRecentOpeningsCurrentUser(pagination); - - Assertions.assertNotNull(paginatedResult); - Assertions.assertEquals(currentPage, paginatedResult.getPageIndex()); - Assertions.assertEquals(pages, paginatedResult.getTotalPages()); - Assertions.assertFalse(paginatedResult.getData().isEmpty()); - Assertions.assertEquals(1, paginatedResult.getData().size()); - } - @Test @DisplayName("Get a list of recent openings for logged user") void getRecentOpenings_fetchPaginated_shouldSucceed() { - OpeningEntity openingEntity = new OpeningEntity(); - openingEntity.setId(123L); - - List openingList = new ArrayList<>(1); - openingList.add(openingEntity); - int pages = 3; - int pageSize = 5; - int totalResults = pageSize * pages - 1; - Pageable openingsPageable = Pageable.ofSize(pageSize); - - Page openingsPage = new PageImpl<>(openingList, openingsPageable, totalResults); - when(openingRepository.findAllByEntryUserId(any(), any())).thenReturn(openingsPage); - - CutBlockOpenAdminEntity cutBlock = new CutBlockOpenAdminEntity(); - cutBlock.setId(222L); - cutBlock.setForestFileId("TFL47"); - cutBlock.setCuttingPermitId("12T"); - cutBlock.setTimberMark("47/12S"); - cutBlock.setCutBlockId("12-69"); - cutBlock.setOpeningGrossArea(new BigDecimal("12.9")); - cutBlock.setOpeningId(openingEntity.getId()); - when(cutBlockOpenAdminService.findAllByOpeningIdIn(any())).thenReturn(List.of(cutBlock)); - - int currentPage = 1; + int currentPage = 0; PaginationParameters pagination = new PaginationParameters(currentPage, pages); PaginatedResult paginatedResult = @@ -190,7 +54,7 @@ void getRecentOpenings_fetchPaginated_shouldSucceed() { Assertions.assertNotNull(paginatedResult); Assertions.assertEquals(currentPage, paginatedResult.getPageIndex()); - Assertions.assertEquals(pages, paginatedResult.getTotalPages()); + Assertions.assertEquals(1, paginatedResult.getTotalPages()); Assertions.assertFalse(paginatedResult.getData().isEmpty()); Assertions.assertEquals(1, paginatedResult.getData().size()); } @@ -198,10 +62,6 @@ void getRecentOpenings_fetchPaginated_shouldSucceed() { @Test @DisplayName("Get an empty list of recent openings for the home screen") void getRecentOpenings_emptyPages_shouldSucceed() { - Page openingsPage = new PageImpl<>(new ArrayList<>()); - when(openingRepository.findAllByEntryUserId(any(), any())).thenReturn(openingsPage); - - when(cutBlockOpenAdminService.findAllByOpeningIdIn(any())).thenReturn(List.of()); int currentPage = 0; int pages = 1; @@ -211,46 +71,20 @@ void getRecentOpenings_emptyPages_shouldSucceed() { Assertions.assertNotNull(paginatedResult); Assertions.assertEquals(currentPage, paginatedResult.getPageIndex()); - Assertions.assertEquals(0, paginatedResult.getTotalPages()); - Assertions.assertTrue(paginatedResult.getData().isEmpty()); + Assertions.assertEquals(1, paginatedResult.getTotalPages()); + Assertions.assertFalse(paginatedResult.getData().isEmpty()); } @Test @DisplayName("Get a list of recent openings without user") void getRecentOpenings_fetchNoUserPaginated_shouldSucceed() { - OpeningEntity openingEntity = new OpeningEntity(); - openingEntity.setId(123L); - - List openingList = new ArrayList<>(1); - openingList.add(openingEntity); - - int pages = 3; - int pageSize = 5; - int totalResults = pageSize * pages - 1; - Pageable openingsPageable = Pageable.ofSize(pageSize); - - Page openingsPage = new PageImpl<>(openingList, openingsPageable, totalResults); - when(openingRepository.findAll(any(Pageable.class))).thenReturn(openingsPage); - CutBlockOpenAdminEntity cutBlock = new CutBlockOpenAdminEntity(); - cutBlock.setId(222L); - cutBlock.setForestFileId("TFL47"); - cutBlock.setCuttingPermitId("12T"); - cutBlock.setTimberMark("47/12S"); - cutBlock.setCutBlockId("12-69"); - cutBlock.setOpeningGrossArea(new BigDecimal("12.9")); - cutBlock.setOpeningId(openingEntity.getId()); - when(cutBlockOpenAdminService.findAllByOpeningIdIn(any())).thenReturn(List.of(cutBlock)); - - int currentPage = 1; - - PaginationParameters pagination = new PaginationParameters(currentPage, pages); PaginatedResult paginatedResult = - openingService.getRecentOpenings(pagination); + openingService.getRecentOpenings(new PaginationParameters(1, 1)); Assertions.assertNotNull(paginatedResult); - Assertions.assertEquals(currentPage, paginatedResult.getPageIndex()); - Assertions.assertEquals(pages, paginatedResult.getTotalPages()); + Assertions.assertEquals(1, paginatedResult.getPageIndex()); + Assertions.assertEquals(3, paginatedResult.getTotalPages()); Assertions.assertFalse(paginatedResult.getData().isEmpty()); Assertions.assertEquals(1, paginatedResult.getData().size()); } @@ -258,163 +92,150 @@ void getRecentOpenings_fetchNoUserPaginated_shouldSucceed() { @Test @DisplayName("Opening search file id happy path should succeed") void openingSearch_fileId_shouldSucceed() { - PaginationParameters pagination = new PaginationParameters(0, 10); - PaginatedResult paginated = new PaginatedResult<>(); - paginated.setPageIndex(pagination.page()); - paginated.setPerPage(pagination.perPage()); - paginated.setTotalPages(1); - paginated.setHasNextPage(false); - - OpeningSearchResponseDto dto = new OpeningSearchResponseDto(); - dto.setOpeningId(123456); - dto.setOpeningNumber("123"); - dto.setCategory(OpeningCategoryEnum.FTML); - dto.setStatus(OpeningStatusEnum.RET); - dto.setCuttingPermitId(""); - dto.setTimberMark(""); - dto.setCutBlockId(""); - dto.setOpeningGrossAreaHa(BigDecimal.ZERO); - dto.setDisturbanceStartDate(LocalDateTime.now()); - dto.setOrgUnitCode(""); - dto.setOrgUnitName(""); - dto.setClientNumber(""); - dto.setClientAcronym(""); - dto.setRegenDelayDate(LocalDateTime.now()); - dto.setEarlyFreeGrowingDate(LocalDateTime.now()); - dto.setLateFreeGrowingDate(LocalDateTime.now()); - dto.setUpdateTimestamp(LocalDateTime.now()); - dto.setEntryUserId(""); - dto.setSubmittedToFrpa(false); - dto.setForestFileId("TFL47"); - paginated.setData(List.of(dto)); - - OpeningSearchFiltersDto filters = mockMainFilter("407"); - when(openingSearchRepository.searchOpeningQuery(filters, pagination)).thenReturn(paginated); PaginatedResult result = - openingService.openingSearch(filters, pagination); + openingService.openingSearch(new OpeningSearchFiltersDto( + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + "103" + ), + new PaginationParameters(0, 10) + ); Assertions.assertNotNull(result); Assertions.assertEquals(0, result.getPageIndex()); - Assertions.assertEquals(10, result.getPerPage()); + Assertions.assertEquals(1, result.getPerPage()); Assertions.assertEquals(1, result.getTotalPages()); Assertions.assertEquals(1, result.getData().size()); - Assertions.assertEquals(dto.getOpeningId(), result.getData().get(0).getOpeningId()); - Assertions.assertEquals(dto.getOpeningNumber(), result.getData().get(0).getOpeningNumber()); - Assertions.assertEquals(dto.getCategory(), result.getData().get(0).getCategory()); - Assertions.assertEquals(dto.getStatus(), result.getData().get(0).getStatus()); - Assertions.assertEquals(dto.getCuttingPermitId(), result.getData().get(0).getCuttingPermitId()); - Assertions.assertEquals(dto.getTimberMark(), result.getData().get(0).getTimberMark()); - Assertions.assertEquals(dto.getCutBlockId(), result.getData().get(0).getCutBlockId()); - Assertions.assertEquals( - dto.getOpeningGrossAreaHa(), result.getData().get(0).getOpeningGrossAreaHa()); - Assertions.assertEquals( - dto.getDisturbanceStartDate(), result.getData().get(0).getDisturbanceStartDate()); - Assertions.assertEquals(dto.getForestFileId(), result.getData().get(0).getForestFileId()); - Assertions.assertEquals(dto.getOrgUnitCode(), result.getData().get(0).getOrgUnitCode()); - Assertions.assertEquals(dto.getOrgUnitName(), result.getData().get(0).getOrgUnitName()); - Assertions.assertEquals(dto.getClientNumber(), result.getData().get(0).getClientNumber()); - Assertions.assertEquals(dto.getRegenDelayDate(), result.getData().get(0).getRegenDelayDate()); - Assertions.assertEquals( - dto.getEarlyFreeGrowingDate(), result.getData().get(0).getEarlyFreeGrowingDate()); - Assertions.assertEquals( - dto.getLateFreeGrowingDate(), result.getData().get(0).getLateFreeGrowingDate()); - Assertions.assertEquals(dto.getEntryUserId(), result.getData().get(0).getEntryUserId()); - Assertions.assertEquals(dto.getSubmittedToFrpa(), result.getData().get(0).getSubmittedToFrpa()); + Assertions.assertEquals(103, result.getData().get(0).getOpeningId()); + Assertions.assertNull(result.getData().get(0).getOpeningNumber()); + Assertions.assertEquals(OpeningCategoryEnum.FTML, result.getData().get(0).getCategory()); + Assertions.assertEquals(OpeningStatusEnum.APP, result.getData().get(0).getStatus()); + Assertions.assertEquals("14T", result.getData().get(0).getCuttingPermitId()); + Assertions.assertEquals("49/14S", result.getData().get(0).getTimberMark()); + Assertions.assertEquals("14-71", result.getData().get(0).getCutBlockId()); + Assertions.assertEquals(new BigDecimal("14.9"), + result.getData().get(0).getOpeningGrossAreaHa()); + Assertions.assertEquals(LocalDateTime.of(2024, 1, 24, 0, 0, 0), + result.getData().get(0).getDisturbanceStartDate()); + Assertions.assertEquals("TFL49", result.getData().get(0).getForestFileId()); + Assertions.assertEquals("TWO", result.getData().get(0).getOrgUnitCode()); + Assertions.assertEquals("Org two", result.getData().get(0).getOrgUnitName()); + Assertions.assertNull(result.getData().get(0).getClientNumber()); + Assertions.assertEquals(LocalDateTime.of(2024, 1, 24, 0, 0, 0), + result.getData().get(0).getRegenDelayDate()); + Assertions.assertEquals(LocalDateTime.of(2024, 1, 24, 0, 0, 0), + result.getData().get(0).getEarlyFreeGrowingDate()); + Assertions.assertEquals(LocalDateTime.of(2024, 1, 24, 0, 0, 0), + result.getData().get(0).getLateFreeGrowingDate()); + Assertions.assertEquals("IDIR@TTESTER", result.getData().get(0).getEntryUserId()); + Assertions.assertFalse(result.getData().get(0).getSubmittedToFrpa()); Assertions.assertFalse(result.isHasNextPage()); } @Test @DisplayName("Opening search org unit happy path should succeed") void openingSearch_orgUnit_shouldSucceed() { - PaginationParameters pagination = new PaginationParameters(0, 10); - PaginatedResult paginated = new PaginatedResult<>(); - paginated.setPageIndex(pagination.page()); - paginated.setPerPage(pagination.perPage()); - paginated.setTotalPages(1); - paginated.setHasNextPage(false); - - OpeningSearchResponseDto dto = new OpeningSearchResponseDto(); - dto.setOpeningId(123456); - dto.setOpeningNumber("123"); - dto.setCategory(OpeningCategoryEnum.FTML); - dto.setStatus(OpeningStatusEnum.RET); - dto.setCuttingPermitId(""); - dto.setTimberMark(""); - dto.setCutBlockId(""); - dto.setOpeningGrossAreaHa(BigDecimal.ZERO); - dto.setDisturbanceStartDate(LocalDateTime.now()); - dto.setOrgUnitCode(""); - dto.setOrgUnitName(""); - dto.setClientNumber(""); - dto.setClientAcronym(""); - dto.setRegenDelayDate(LocalDateTime.now()); - dto.setEarlyFreeGrowingDate(LocalDateTime.now()); - dto.setLateFreeGrowingDate(LocalDateTime.now()); - dto.setUpdateTimestamp(LocalDateTime.now()); - dto.setEntryUserId(""); - dto.setSubmittedToFrpa(false); - dto.setForestFileId("TFL47"); - paginated.setData(List.of(dto)); - - OpeningSearchFiltersDto filters = mockOrgUnit("DCR"); - when(openingSearchRepository.searchOpeningQuery(filters, pagination)).thenReturn(paginated); PaginatedResult result = - openingService.openingSearch(filters, pagination); + openingService.openingSearch(new OpeningSearchFiltersDto( + "TWO", + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ), + new PaginationParameters(0, 10) + ); Assertions.assertNotNull(result); Assertions.assertEquals(0, result.getPageIndex()); - Assertions.assertEquals(10, result.getPerPage()); + Assertions.assertEquals(1, result.getPerPage()); Assertions.assertEquals(1, result.getTotalPages()); Assertions.assertEquals(1, result.getData().size()); - Assertions.assertEquals(dto.getOpeningId(), result.getData().get(0).getOpeningId()); - Assertions.assertEquals(dto.getOpeningNumber(), result.getData().get(0).getOpeningNumber()); - Assertions.assertEquals(dto.getCategory(), result.getData().get(0).getCategory()); - Assertions.assertEquals(dto.getStatus(), result.getData().get(0).getStatus()); - Assertions.assertEquals(dto.getCuttingPermitId(), result.getData().get(0).getCuttingPermitId()); - Assertions.assertEquals(dto.getTimberMark(), result.getData().get(0).getTimberMark()); - Assertions.assertEquals(dto.getCutBlockId(), result.getData().get(0).getCutBlockId()); - Assertions.assertEquals( - dto.getOpeningGrossAreaHa(), result.getData().get(0).getOpeningGrossAreaHa()); - Assertions.assertEquals( - dto.getDisturbanceStartDate(), result.getData().get(0).getDisturbanceStartDate()); - Assertions.assertEquals(dto.getForestFileId(), result.getData().get(0).getForestFileId()); - Assertions.assertEquals(dto.getOrgUnitCode(), result.getData().get(0).getOrgUnitCode()); - Assertions.assertEquals(dto.getOrgUnitName(), result.getData().get(0).getOrgUnitName()); - Assertions.assertEquals(dto.getClientNumber(), result.getData().get(0).getClientNumber()); - Assertions.assertEquals(dto.getRegenDelayDate(), result.getData().get(0).getRegenDelayDate()); - Assertions.assertEquals( - dto.getEarlyFreeGrowingDate(), result.getData().get(0).getEarlyFreeGrowingDate()); - Assertions.assertEquals( - dto.getLateFreeGrowingDate(), result.getData().get(0).getLateFreeGrowingDate()); - Assertions.assertEquals(dto.getEntryUserId(), result.getData().get(0).getEntryUserId()); - Assertions.assertEquals(dto.getSubmittedToFrpa(), result.getData().get(0).getSubmittedToFrpa()); + Assertions.assertEquals(103, result.getData().get(0).getOpeningId()); + Assertions.assertNull(result.getData().get(0).getOpeningNumber()); + Assertions.assertEquals(OpeningCategoryEnum.FTML, result.getData().get(0).getCategory()); + Assertions.assertEquals(OpeningStatusEnum.APP, result.getData().get(0).getStatus()); + Assertions.assertEquals("14T", result.getData().get(0).getCuttingPermitId()); + Assertions.assertEquals("49/14S", result.getData().get(0).getTimberMark()); + Assertions.assertEquals("14-71", result.getData().get(0).getCutBlockId()); + Assertions.assertEquals(new BigDecimal("14.9"), + result.getData().get(0).getOpeningGrossAreaHa()); + Assertions.assertEquals(LocalDateTime.of(2024, 1, 24, 0, 0, 0), + result.getData().get(0).getDisturbanceStartDate()); + Assertions.assertEquals("TFL49", result.getData().get(0).getForestFileId()); + Assertions.assertEquals("TWO", result.getData().get(0).getOrgUnitCode()); + Assertions.assertEquals("Org two", result.getData().get(0).getOrgUnitName()); + Assertions.assertNull(result.getData().get(0).getClientNumber()); + Assertions.assertEquals(LocalDateTime.of(2024, 1, 24, 0, 0, 0), + result.getData().get(0).getRegenDelayDate()); + Assertions.assertEquals(LocalDateTime.of(2024, 1, 24, 0, 0, 0), + result.getData().get(0).getEarlyFreeGrowingDate()); + Assertions.assertEquals(LocalDateTime.of(2024, 1, 24, 0, 0, 0), + result.getData().get(0).getLateFreeGrowingDate()); + Assertions.assertEquals("IDIR@TTESTER", result.getData().get(0).getEntryUserId()); + Assertions.assertFalse(result.getData().get(0).getSubmittedToFrpa()); Assertions.assertFalse(result.isHasNextPage()); } @Test @DisplayName("Opening search no records found should succeed") void openingSearch_noRecordsFound_shouldSucceed() { - PaginationParameters pagination = new PaginationParameters(0, 10); - PaginatedResult paginated = new PaginatedResult<>(); - paginated.setPageIndex(pagination.page()); - paginated.setPerPage(pagination.perPage()); - paginated.setTotalPages(1); - paginated.setHasNextPage(false); - paginated.setData(List.of()); - - OpeningSearchFiltersDto filters = mockOrgUnit("AAA"); - - when(openingSearchRepository.searchOpeningQuery(filters, pagination)).thenReturn(paginated); - PaginatedResult result = - openingService.openingSearch(filters, pagination); + openingService.openingSearch( + new OpeningSearchFiltersDto( + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + "ABCD" + ), + new PaginationParameters(0, 10) + ); Assertions.assertNotNull(result); Assertions.assertEquals(0, result.getPageIndex()); Assertions.assertEquals(10, result.getPerPage()); - Assertions.assertEquals(1, result.getTotalPages()); + Assertions.assertEquals(0, result.getTotalPages()); Assertions.assertTrue(result.getData().isEmpty()); Assertions.assertFalse(result.isHasNextPage()); } @@ -422,13 +243,31 @@ void openingSearch_noRecordsFound_shouldSucceed() { @Test @DisplayName("Opening search max page exception should fail") void openingSearch_maxPageException_shouldFail() { - OpeningSearchFiltersDto filters = mockMainFilter("407"); - PaginationParameters pagination = new PaginationParameters(0, 2999); - Assertions.assertThrows( MaxPageSizeException.class, - () -> { - openingService.openingSearch(filters, pagination); - }); + () -> + openingService.openingSearch( + new OpeningSearchFiltersDto( + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + "FTML" + ), + new PaginationParameters(0, 2999) + ) + ); } } diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OrgUnitServiceTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OrgUnitServiceTest.java index e3e2a618..4919f4df 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OrgUnitServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OrgUnitServiceTest.java @@ -4,6 +4,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import ca.bc.gov.restapi.results.common.configuration.SilvaConfiguration; import ca.bc.gov.restapi.results.oracle.entity.OrgUnitEntity; import ca.bc.gov.restapi.results.oracle.repository.OrgUnitRepository; import java.time.LocalDate; @@ -22,10 +23,11 @@ class OrgUnitServiceTest { @Mock OrgUnitRepository orgUnitRepository; private OrgUnitService orgUnitService; + private final SilvaConfiguration silvaConfiguration = new SilvaConfiguration().withOrgUnits(List.of("DAS")); @BeforeEach void setup() { - orgUnitService = new OrgUnitService(orgUnitRepository, new String[] {"DAS"}); + orgUnitService = new OrgUnitService(orgUnitRepository, silvaConfiguration); } @Test @@ -48,7 +50,7 @@ void findAllOrgUnits_happyPath_shouldSucceed() { orgUnit.setExpiryDate(LocalDate.now().plusYears(3L)); orgUnit.setUpdateTimestamp(LocalDate.now()); - when(orgUnitRepository.findAllByOrgUnitCodeIn(new String[] {"DAS"})) + when(orgUnitRepository.findAllByOrgUnitCodeIn(List.of("DAS"))) .thenReturn(List.of(orgUnit)); List entities = orgUnitService.findAllOrgUnits(); @@ -76,9 +78,9 @@ void findAllOrgUnits_happyPath_shouldSucceed() { @Test @DisplayName("Find all org units empty response should succeed") void findAllOrgUnits_emptyResponse_shouldSucceed() { - orgUnitService = new OrgUnitService(orgUnitRepository, new String[] {}); + orgUnitService = new OrgUnitService(orgUnitRepository, silvaConfiguration); - when(orgUnitRepository.findAllByOrgUnitCodeIn(new String[] {"DAS"})).thenReturn(List.of()); + when(orgUnitRepository.findAllByOrgUnitCodeIn(List.of("DAS"))).thenReturn(List.of()); List entities = orgUnitService.findAllOrgUnits(); Assertions.assertNotNull(entities); @@ -107,7 +109,7 @@ void findAllOrgUnitsByCode_happyPath_shouldSucceed() { orgUnit.setExpiryDate(LocalDate.now().minusYears(1L)); orgUnit.setUpdateTimestamp(LocalDate.now()); - String[] units = new String[] {"DAS"}; + List units = List.of("DAS"); when(orgUnitRepository.findAllByOrgUnitCodeIn(units)).thenReturn(List.of(orgUnit)); List entities = orgUnitService.findAllOrgUnitsByCode(units); @@ -134,7 +136,7 @@ void findAllOrgUnitsByCode_happyPath_shouldSucceed() { @Test @DisplayName("Find all org units by code not found should succeed") void findAllOrgUnitsByCode_notFound_shouldSucceed() { - String[] units = new String[] {"DAS"}; + List units = List.of("DAS"); when(orgUnitRepository.findAllByOrgUnitCodeIn(units)).thenReturn(List.of()); List entities = orgUnitService.findAllOrgUnitsByCode(units); diff --git a/backend/src/test/resources/application-default.yml b/backend/src/test/resources/application-default.yml index 67b39a04..400798cf 100644 --- a/backend/src/test/resources/application-default.yml +++ b/backend/src/test/resources/application-default.yml @@ -14,11 +14,9 @@ ca: bc: gov: nrs: - results: - wms-layers: - whitelist: ${WMS_LAYERS_WHITELIST_USERS:NONE} - opening-search: - org-units: ${OPENING_SEARCH_ORG_UNITS:DAS} + dashboard-job-users: ${DASHBOARD_JOB_IDIR_USERS:NONE} + wms-whitelist: ${WMS_LAYERS_WHITELIST_USERS:NONE} + org-units: ${OPENING_SEARCH_ORG_UNITS:DAS} forest-client-api: address: http://localhost:10000 key: 123456789abcdef