diff --git a/src/main/java/org/fairdatateam/fairdatapoint/Application.java b/src/main/java/org/fairdatateam/fairdatapoint/Application.java index 8f87b614c..d6c224f80 100644 --- a/src/main/java/org/fairdatateam/fairdatapoint/Application.java +++ b/src/main/java/org/fairdatateam/fairdatapoint/Application.java @@ -25,18 +25,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; @SpringBootApplication -@EnableWebMvc -@EnableAsync -@ComponentScan(basePackages = { - "org.eclipse.rdf4j.http.server.readonly.sparql", - "org.fairdatateam.fairdatapoint.*" -}) -@ConfigurationPropertiesScan("org.fairdatateam.fairdatapoint.config.*") +@ConfigurationPropertiesScan public class Application { public static void main(String[] args) { diff --git a/src/main/java/org/fairdatateam/fairdatapoint/config/Rdf4jSparqlConfig.java b/src/main/java/org/fairdatateam/fairdatapoint/config/Rdf4jSparqlConfig.java new file mode 100644 index 000000000..f447150d8 --- /dev/null +++ b/src/main/java/org/fairdatateam/fairdatapoint/config/Rdf4jSparqlConfig.java @@ -0,0 +1,34 @@ +/** + * The MIT License + * Copyright © 2017 FAIR Data Team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.fairdatateam.fairdatapoint.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * Make sure the SparqlQueryEvaluator implementation bean can be found (SparqlQueryEvaluatorDefault) + */ +@Configuration +@ComponentScan("org.eclipse.rdf4j.http.server.readonly.sparql") +public class Rdf4jSparqlConfig { +} diff --git a/src/main/java/org/fairdatateam/fairdatapoint/config/WebConfig.java b/src/main/java/org/fairdatateam/fairdatapoint/config/WebMvcConfig.java similarity index 98% rename from src/main/java/org/fairdatateam/fairdatapoint/config/WebConfig.java rename to src/main/java/org/fairdatateam/fairdatapoint/config/WebMvcConfig.java index 6213c796b..540c31b7f 100644 --- a/src/main/java/org/fairdatateam/fairdatapoint/config/WebConfig.java +++ b/src/main/java/org/fairdatateam/fairdatapoint/config/WebMvcConfig.java @@ -43,7 +43,7 @@ import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; @Configuration -public class WebConfig implements WebMvcConfigurer { +public class WebMvcConfig implements WebMvcConfigurer { @Autowired private List errorConverters; diff --git a/src/test/java/org/fairdatateam/fairdatapoint/BaseIntegrationTest.java b/src/test/java/org/fairdatateam/fairdatapoint/BaseIntegrationTest.java index 2ff2b8a93..6aa7dc146 100644 --- a/src/test/java/org/fairdatateam/fairdatapoint/BaseIntegrationTest.java +++ b/src/test/java/org/fairdatateam/fairdatapoint/BaseIntegrationTest.java @@ -22,13 +22,10 @@ */ package org.fairdatateam.fairdatapoint; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; -@ExtendWith(SpringExtension.class) @ActiveProfiles(Profiles.TESTING) -@SpringBootTest(properties = {"spring.main.allow-bean-definition-overriding=true"}) +@SpringBootTest public abstract class BaseIntegrationTest { } diff --git a/src/test/java/org/fairdatateam/fairdatapoint/WebIntegrationTest.java b/src/test/java/org/fairdatateam/fairdatapoint/WebIntegrationTest.java index e1b0ecd61..c76cc00cf 100644 --- a/src/test/java/org/fairdatateam/fairdatapoint/WebIntegrationTest.java +++ b/src/test/java/org/fairdatateam/fairdatapoint/WebIntegrationTest.java @@ -25,18 +25,14 @@ import org.fairdatateam.fairdatapoint.database.mongo.migration.development.MigrationRunner; import org.fairdatateam.fairdatapoint.database.rdf.migration.development.RdfDevelopmentMigrationRunner; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; -@ExtendWith(SpringExtension.class) @ActiveProfiles(Profiles.TESTING) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -@AutoConfigureMockMvc +// todo: in most cases we can probably use WebEnvironment.MOCK with MockMvc instead of TestRestTemplate (see #862) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public abstract class WebIntegrationTest { public static final String ADMIN_TOKEN = "Bearer eyJhbGciOiJIUzUxMiJ9" + diff --git a/src/test/java/org/fairdatateam/fairdatapoint/acceptance/index/admin/List_Trigger_POST.java b/src/test/java/org/fairdatateam/fairdatapoint/acceptance/index/admin/List_Trigger_POST.java index 2d592d094..5433d0554 100644 --- a/src/test/java/org/fairdatateam/fairdatapoint/acceptance/index/admin/List_Trigger_POST.java +++ b/src/test/java/org/fairdatateam/fairdatapoint/acceptance/index/admin/List_Trigger_POST.java @@ -34,11 +34,13 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.TestConfiguration; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.EnableAsync; import java.net.URI; import java.util.List; @@ -202,4 +204,16 @@ public void res404_triggerOne() { assertThat("One AdminTrigger event is created", events.size(), is(equalTo(1))); assertThat("Records correct client URL", events.get(0).getAdminTrigger().getClientUrl(), is(equalTo(entry.getClientUrl()))); } + + /** + * Enables asynchronous request processing. + * This reproduces the exception handling behaviour of the production config, + * which causes RDF parsing exceptions to be ignored by the ExceptionControllerAdvice, + * because they occur in worker threads. + * The parsing exceptions should be reflected in the resulting IndexEntryState instead. + */ + @TestConfiguration + @EnableAsync + public static class AsyncConfig { + } } diff --git a/src/test/java/org/fairdatateam/fairdatapoint/acceptance/index/ping/List_POST.java b/src/test/java/org/fairdatateam/fairdatapoint/acceptance/index/ping/List_POST.java index 754d4279d..5dca9395a 100644 --- a/src/test/java/org/fairdatateam/fairdatapoint/acceptance/index/ping/List_POST.java +++ b/src/test/java/org/fairdatateam/fairdatapoint/acceptance/index/ping/List_POST.java @@ -31,11 +31,13 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.TestConfiguration; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.EnableAsync; import java.net.URI; import java.util.HashMap; @@ -177,4 +179,16 @@ public void res400_differentBody() { // THEN assertThat("Correct response code is received", result.getStatusCode(), is(equalTo(HttpStatus.BAD_REQUEST))); } + + /** + * Enables asynchronous request processing. + * This reproduces the exception handling behaviour of the production config, + * which causes RDF parsing exceptions to be ignored by the ExceptionControllerAdvice, + * because they occur in worker threads. + * The parsing exceptions should be reflected in the resulting IndexEntryState instead. + */ + @TestConfiguration + @EnableAsync + public static class AsyncConfig { + } }