From 21527e5607474f88cad810210a5be6631abacc6e Mon Sep 17 00:00:00 2001 From: JornC Date: Thu, 3 Feb 2022 17:25:01 +0100 Subject: [PATCH] Add some tests (lengthy ones) --- .../tasks/AssessmentAreaSearchService.java | 21 ++++------ .../AssessmentAreaSearchServiceTest.java | 13 +++++- .../search/tasks/PdokServiceApplication.java | 27 ++++++++++++ .../search/tasks/PdokSearchServiceTest.java | 41 +++++++++++++++++++ .../sync/BlockingSearchTaskDelegatorTest.java | 2 - 5 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 search-service-pdok-locatieservice/src/main/java/nl/aerius/search/tasks/PdokServiceApplication.java create mode 100644 search-service-pdok-locatieservice/src/test/java/nl/aerius/search/tasks/PdokSearchServiceTest.java diff --git a/search-service-n2000-assessment-areas-nl/src/main/java/nl/aerius/search/tasks/AssessmentAreaSearchService.java b/search-service-n2000-assessment-areas-nl/src/main/java/nl/aerius/search/tasks/AssessmentAreaSearchService.java index 0dfaa93..0a492dc 100644 --- a/search-service-n2000-assessment-areas-nl/src/main/java/nl/aerius/search/tasks/AssessmentAreaSearchService.java +++ b/search-service-n2000-assessment-areas-nl/src/main/java/nl/aerius/search/tasks/AssessmentAreaSearchService.java @@ -17,7 +17,6 @@ package nl.aerius.search.tasks; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -46,24 +45,18 @@ public class AssessmentAreaSearchService implements SearchTaskService { private static final Logger LOG = LoggerFactory.getLogger(AssessmentAreaSearchService.class); private final Map areas; + private final Natura2000WfsInterpreter interpreter; - @Autowired Natura2000WfsInterpreter interpreter; - - public AssessmentAreaSearchService() { - areas = new HashMap<>(); + @Autowired + public AssessmentAreaSearchService(final Natura2000WfsInterpreter interpreter) { + this.interpreter = interpreter; + this.areas = interpreter.retrieveAreas(); } @PostConstruct public void init() { - // Just do this in another thread so it doesn't delay startup - // We don't really care if this takes an age - final Thread n2000Init = new Thread(() -> areas.putAll(interpreter.retrieveAreas())); - n2000Init.setUncaughtExceptionHandler((t, ex) -> { - LOG.error("Could not initialize areas.", ex); - // Crash hard - System.exit(0); - }); - n2000Init.start(); + areas.clear(); + areas.putAll(interpreter.retrieveAreas()); } @Override diff --git a/search-service-n2000-assessment-areas-nl/src/test/java/nl/aerius/search/tasks/AssessmentAreaSearchServiceTest.java b/search-service-n2000-assessment-areas-nl/src/test/java/nl/aerius/search/tasks/AssessmentAreaSearchServiceTest.java index a2cbee1..3fbdd5b 100644 --- a/search-service-n2000-assessment-areas-nl/src/test/java/nl/aerius/search/tasks/AssessmentAreaSearchServiceTest.java +++ b/search-service-n2000-assessment-areas-nl/src/test/java/nl/aerius/search/tasks/AssessmentAreaSearchServiceTest.java @@ -16,17 +16,26 @@ */ package nl.aerius.search.tasks; -import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import io.reactivex.rxjava3.core.Single; + +import nl.aerius.search.domain.SearchTaskResult; + @SpringBootTest class AssessmentAreaSearchServiceTest { @Autowired AssessmentAreaSearchService delegator; @Test void testWorksAtAll() { - Assertions.assertTrue(true, "The test works!"); + final Single result = delegator.retrieveSearchResults("veluwe"); + + final SearchTaskResult suggestions = result.blockingGet(); + + assertEquals(2, suggestions.getSuggestions().size(), "Expected 2 results for 'veluwe'"); } } diff --git a/search-service-pdok-locatieservice/src/main/java/nl/aerius/search/tasks/PdokServiceApplication.java b/search-service-pdok-locatieservice/src/main/java/nl/aerius/search/tasks/PdokServiceApplication.java new file mode 100644 index 0000000..6cf0609 --- /dev/null +++ b/search-service-pdok-locatieservice/src/main/java/nl/aerius/search/tasks/PdokServiceApplication.java @@ -0,0 +1,27 @@ +/* + * Copyright the State of the Netherlands + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package nl.aerius.search.tasks; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PdokServiceApplication { + public static void main(final String[] args) { + SpringApplication.run(PdokServiceApplication.class, args); + } +} diff --git a/search-service-pdok-locatieservice/src/test/java/nl/aerius/search/tasks/PdokSearchServiceTest.java b/search-service-pdok-locatieservice/src/test/java/nl/aerius/search/tasks/PdokSearchServiceTest.java new file mode 100644 index 0000000..396da67 --- /dev/null +++ b/search-service-pdok-locatieservice/src/test/java/nl/aerius/search/tasks/PdokSearchServiceTest.java @@ -0,0 +1,41 @@ +/* + * Copyright the State of the Netherlands + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package nl.aerius.search.tasks; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import io.reactivex.rxjava3.core.Single; + +import nl.aerius.search.domain.SearchTaskResult; + +@SpringBootTest +class PdokSearchServiceTest { + @Autowired PdokSearchService delegator; + + @Test + void testWorksAtAll() { + final Single result = delegator.retrieveSearchResults("utrecht"); + + final SearchTaskResult suggestions = result.blockingGet(); + + assertEquals(suggestions.getSuggestions().size(), 10, "Expected 10 results for 'utrecht'"); + } +} diff --git a/search-service/src/test/java/nl/aerius/search/tasks/sync/BlockingSearchTaskDelegatorTest.java b/search-service/src/test/java/nl/aerius/search/tasks/sync/BlockingSearchTaskDelegatorTest.java index ea0417b..2500465 100644 --- a/search-service/src/test/java/nl/aerius/search/tasks/sync/BlockingSearchTaskDelegatorTest.java +++ b/search-service/src/test/java/nl/aerius/search/tasks/sync/BlockingSearchTaskDelegatorTest.java @@ -23,7 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; import nl.aerius.search.domain.SearchCapability; import nl.aerius.search.domain.SearchRegion; @@ -35,7 +34,6 @@ import nl.aerius.search.tasks.SearchTaskService; import nl.aerius.search.tasks.TaskFactory; -@SpringBootTest class BlockingSearchTaskDelegatorTest { BlockingSearchTaskDelegator delegator;