Skip to content

Commit

Permalink
Add some tests (lengthy ones)
Browse files Browse the repository at this point in the history
  • Loading branch information
JornC committed Feb 3, 2022
1 parent 3f28019 commit 21527e5
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,24 +45,18 @@ public class AssessmentAreaSearchService implements SearchTaskService {
private static final Logger LOG = LoggerFactory.getLogger(AssessmentAreaSearchService.class);

private final Map<String, Nature2000Area> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SearchTaskResult> result = delegator.retrieveSearchResults("veluwe");

final SearchTaskResult suggestions = result.blockingGet();

assertEquals(2, suggestions.getSuggestions().size(), "Expected 2 results for 'veluwe'");
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<SearchTaskResult> result = delegator.retrieveSearchResults("utrecht");

final SearchTaskResult suggestions = result.blockingGet();

assertEquals(suggestions.getSuggestions().size(), 10, "Expected 10 results for 'utrecht'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +34,6 @@
import nl.aerius.search.tasks.SearchTaskService;
import nl.aerius.search.tasks.TaskFactory;

@SpringBootTest
class BlockingSearchTaskDelegatorTest {
BlockingSearchTaskDelegator delegator;

Expand Down

0 comments on commit 21527e5

Please sign in to comment.