From c4e3f6d5b125487f0df5460e24650d8f921b7a0b Mon Sep 17 00:00:00 2001 From: mark <1165786+mprins@users.noreply.github.com> Date: Fri, 5 Jul 2024 12:01:52 +0200 Subject: [PATCH] move testcases and remove now useless test, use solr service inject --- .../configuration/dev/PopulateTestData.java | 6 ++-- .../controller/admin/SolrAdminController.java | 16 --------- .../api/repository/ApplicationRepository.java | 5 ++- .../b3p/tailormap/api/solr/SolrService.java | 8 +++-- .../ApplicationRepositoryIntegrationTest.java | 16 +++++++++ .../GeoServiceRepositoryIntegrationTest.java | 35 ------------------- 6 files changed, 26 insertions(+), 60 deletions(-) delete mode 100644 src/test/java/nl/b3p/tailormap/api/repository/GeoServiceRepositoryIntegrationTest.java diff --git a/src/main/java/nl/b3p/tailormap/api/configuration/dev/PopulateTestData.java b/src/main/java/nl/b3p/tailormap/api/configuration/dev/PopulateTestData.java index c4a66945ce..5d34bab3c6 100644 --- a/src/main/java/nl/b3p/tailormap/api/configuration/dev/PopulateTestData.java +++ b/src/main/java/nl/b3p/tailormap/api/configuration/dev/PopulateTestData.java @@ -1363,10 +1363,8 @@ public void createSolrIndex() throws Exception { logger.info("Creating Solr index"); @SuppressWarnings("PMD.AvoidUsingHardCodedIP") final String solrUrl = - "http://" - + (connectToSpatialDbsAtLocalhost ? "127.0.0.1" : "solr") - + ":8983/solr/" - + solrCoreName; + "http://" + (connectToSpatialDbsAtLocalhost ? "127.0.0.1" : "solr") + ":8983/solr/"; + this.solrService.setSolrUrl(solrUrl); SolrHelper solrHelper = new SolrHelper(this.solrService.getSolrClientForIndexing()); GeoService geoService = geoServiceRepository.findById("snapshot-geoserver").orElseThrow(); diff --git a/src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java b/src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java index 0b5e59ad54..14ec2778dc 100644 --- a/src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java +++ b/src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java @@ -17,9 +17,7 @@ import nl.b3p.tailormap.api.geotools.featuresources.FeatureSourceFactoryHelper; import nl.b3p.tailormap.api.persistence.SearchIndex; import nl.b3p.tailormap.api.persistence.TMFeatureType; -import nl.b3p.tailormap.api.repository.FeatureSourceRepository; import nl.b3p.tailormap.api.repository.FeatureTypeRepository; -import nl.b3p.tailormap.api.repository.GeoServiceRepository; import nl.b3p.tailormap.api.repository.SearchIndexRepository; import nl.b3p.tailormap.api.solr.SolrHelper; import nl.b3p.tailormap.api.solr.SolrService; @@ -30,7 +28,6 @@ import org.apache.solr.common.SolrException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -45,33 +42,20 @@ /** Admin controller for Solr. */ @RestController public class SolrAdminController { - @Value("${tailormap-api.solr-url}") - private String solrUrl; - - @Value("${tailormap-api.solr-core-name:tailormap}") - private String solrCoreName; - private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final FeatureSourceFactoryHelper featureSourceFactoryHelper; - - private final FeatureSourceRepository featureSourceRepository; private final FeatureTypeRepository featureTypeRepository; - private final GeoServiceRepository geoServiceRepository; private final SearchIndexRepository searchIndexRepository; private final SolrService solrService; public SolrAdminController( FeatureSourceFactoryHelper featureSourceFactoryHelper, - FeatureSourceRepository featureSourceRepository, FeatureTypeRepository featureTypeRepository, - GeoServiceRepository geoServiceRepository, SearchIndexRepository searchIndexRepository, SolrService solrService) { this.featureSourceFactoryHelper = featureSourceFactoryHelper; - this.featureSourceRepository = featureSourceRepository; this.featureTypeRepository = featureTypeRepository; - this.geoServiceRepository = geoServiceRepository; this.searchIndexRepository = searchIndexRepository; this.solrService = solrService; } diff --git a/src/main/java/nl/b3p/tailormap/api/repository/ApplicationRepository.java b/src/main/java/nl/b3p/tailormap/api/repository/ApplicationRepository.java index 5e06889bda..16d0c6be95 100644 --- a/src/main/java/nl/b3p/tailormap/api/repository/ApplicationRepository.java +++ b/src/main/java/nl/b3p/tailormap/api/repository/ApplicationRepository.java @@ -28,14 +28,13 @@ public interface ApplicationRepository extends JpaRepository /** * Find all applications that have a layer that is linked to a specific (Solr) index. * - * @param indexId The index id to search for //TODO: This query is not working as expected. It - * should return all applications that have a layer that is linked to a specific (Solr) index. + * @param indexId The index id to search for */ @NonNull @PreAuthorize("permitAll()") @Query( value = - "select * from application app, lateral jsonb_path_query(gs.settings, ('$.layerSettings.**{1}.searchIndex.searchIndexId ? (@ == '||:indexId||')')::jsonpath)", + "select * from application app, lateral jsonb_path_query(app.settings, ('$.layerSettings.**{1}.searchIndexId ? (@ == '||:indexId||')')::jsonpath)", nativeQuery = true) List findByIndexId(@Param("indexId") @NonNull Long indexId); } diff --git a/src/main/java/nl/b3p/tailormap/api/solr/SolrService.java b/src/main/java/nl/b3p/tailormap/api/solr/SolrService.java index 7119f2313d..f236c65afd 100644 --- a/src/main/java/nl/b3p/tailormap/api/solr/SolrService.java +++ b/src/main/java/nl/b3p/tailormap/api/solr/SolrService.java @@ -27,7 +27,7 @@ public class SolrService { */ public SolrClient getSolrClientForIndexing() { return new ConcurrentUpdateHttp2SolrClient.Builder( - solrUrl + solrCoreName, + this.solrUrl + this.solrCoreName, new Http2SolrClient.Builder() .withFollowRedirects(true) .withConnectionTimeout(10000, TimeUnit.MILLISECONDS) @@ -44,9 +44,13 @@ public SolrClient getSolrClientForIndexing() { * @return the Solr client */ public SolrClient getSolrClientForSearching() { - return new Http2SolrClient.Builder(solrUrl + solrCoreName) + return new Http2SolrClient.Builder(this.solrUrl + this.solrCoreName) .withConnectionTimeout(10, TimeUnit.SECONDS) .withFollowRedirects(true) .build(); } + + public void setSolrUrl(String solrUrl) { + this.solrUrl = solrUrl; + } } diff --git a/src/test/java/nl/b3p/tailormap/api/repository/ApplicationRepositoryIntegrationTest.java b/src/test/java/nl/b3p/tailormap/api/repository/ApplicationRepositoryIntegrationTest.java index 2cb6a1088d..b9b6cddbcc 100644 --- a/src/test/java/nl/b3p/tailormap/api/repository/ApplicationRepositoryIntegrationTest.java +++ b/src/test/java/nl/b3p/tailormap/api/repository/ApplicationRepositoryIntegrationTest.java @@ -8,9 +8,12 @@ import static org.hibernate.validator.internal.util.Contracts.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.List; import nl.b3p.tailormap.api.annotation.PostgresIntegrationTest; import nl.b3p.tailormap.api.persistence.Application; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -30,4 +33,17 @@ void should_not_find_application_by_nonexistent_name() { Application a = applicationRepository.findByName("does-not-exist"); assertNull(a); } + + @Test + void it_should_find_application_using_findByIndexId_with_valid_ID() { + final Application application = applicationRepository.findByIndexId(2L).get(0); + Assertions.assertNotNull(application); + assertEquals("default", application.getName()); + } + + @Test + void it_should_not_find_applications_findByIndexId_with_invalid_ID() { + final List applications = applicationRepository.findByIndexId(-2L); + assertTrue(applications.isEmpty()); + } } diff --git a/src/test/java/nl/b3p/tailormap/api/repository/GeoServiceRepositoryIntegrationTest.java b/src/test/java/nl/b3p/tailormap/api/repository/GeoServiceRepositoryIntegrationTest.java deleted file mode 100644 index e4f7719d90..0000000000 --- a/src/test/java/nl/b3p/tailormap/api/repository/GeoServiceRepositoryIntegrationTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2024 B3Partners B.V. - * - * SPDX-License-Identifier: MIT - */ -package nl.b3p.tailormap.api.repository; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.List; -import nl.b3p.tailormap.api.annotation.PostgresIntegrationTest; -import nl.b3p.tailormap.api.persistence.GeoService; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -@PostgresIntegrationTest -class GeoServiceRepositoryIntegrationTest { - - @Autowired private GeoServiceRepository geoServiceRepository; - - @Test - void it_should_find_service_using_findByIndexId_with_valid_ID() { - final GeoService geoService = geoServiceRepository.findByIndexId(2L).get(0); - assertNotNull(geoService); - assertEquals("snapshot-geoserver", geoService.getId()); - } - - @Test - void it_should_not_find_services_findByIndexId_with_invalid_ID() { - final List geoServices = geoServiceRepository.findByIndexId(-2L); - assertTrue(geoServices.isEmpty()); - } -}