Skip to content

Commit 155fa28

Browse files
authored
Clean up annotations for application class and test classes (#888)
* remove @componentscan in favor of @SpringBootApplication and remove the redundant org.fairdatateam.fairdatapoint * remove @EnableWebMvc in favor of the existing WebConfig (WebMvcConfigurer) class * rename WebConfig to WebMvcConfig * remove @EnableAsync in favor of the existing AsyncConfig class * remove redundant package name from @ConfigurationPropertiesScan * move the rdf4j sparql component scan to a separate Rdf4jSparqlConfig class (note that RepositoryConfig should actually be called Rdf4jRepositoryConfig, for consistency) * remove allow-bean-definition-overriding from BaseIntegrationTest (no longer necessary after removing the test config classes in #902) * remove SpringExtension from test base classes because this is already included in @SpringBootTest * re-enable async processing in index trigger and ping tests * remove unused @AutoConfigureMockMvc from WebIntegrationTest class because MockMvc is not used anywhere * switch from WebEnvironment.DEFINED_PORT to WebEnvironment.RANDOM_PORT in WebIntegrationTest class to prevent issues with occupied port see spring-boot testing docs for more info: https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html
1 parent bfb5d49 commit 155fa28

7 files changed

Lines changed: 67 additions & 21 deletions

File tree

src/main/java/org/fairdatateam/fairdatapoint/Application.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,9 @@
2525
import org.springframework.boot.SpringApplication;
2626
import org.springframework.boot.autoconfigure.SpringBootApplication;
2727
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
28-
import org.springframework.context.annotation.ComponentScan;
29-
import org.springframework.scheduling.annotation.EnableAsync;
30-
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
3128

3229
@SpringBootApplication
33-
@EnableWebMvc
34-
@EnableAsync
35-
@ComponentScan(basePackages = {
36-
"org.eclipse.rdf4j.http.server.readonly.sparql",
37-
"org.fairdatateam.fairdatapoint.*"
38-
})
39-
@ConfigurationPropertiesScan("org.fairdatateam.fairdatapoint.config.*")
30+
@ConfigurationPropertiesScan
4031
public class Application {
4132

4233
public static void main(String[] args) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* The MIT License
3+
* Copyright © 2017 FAIR Data Team
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
package org.fairdatateam.fairdatapoint.config;
24+
25+
import org.springframework.context.annotation.ComponentScan;
26+
import org.springframework.context.annotation.Configuration;
27+
28+
/**
29+
* Make sure the SparqlQueryEvaluator implementation bean can be found (SparqlQueryEvaluatorDefault)
30+
*/
31+
@Configuration
32+
@ComponentScan("org.eclipse.rdf4j.http.server.readonly.sparql")
33+
public class Rdf4jSparqlConfig {
34+
}

src/main/java/org/fairdatateam/fairdatapoint/config/WebConfig.java renamed to src/main/java/org/fairdatateam/fairdatapoint/config/WebMvcConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
4444

4545
@Configuration
46-
public class WebConfig implements WebMvcConfigurer {
46+
public class WebMvcConfig implements WebMvcConfigurer {
4747

4848
@Autowired
4949
private List<ErrorConverter> errorConverters;

src/test/java/org/fairdatateam/fairdatapoint/BaseIntegrationTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222
*/
2323
package org.fairdatateam.fairdatapoint;
2424

25-
import org.junit.jupiter.api.extension.ExtendWith;
2625
import org.springframework.boot.test.context.SpringBootTest;
2726
import org.springframework.test.context.ActiveProfiles;
28-
import org.springframework.test.context.junit.jupiter.SpringExtension;
2927

30-
@ExtendWith(SpringExtension.class)
3128
@ActiveProfiles(Profiles.TESTING)
32-
@SpringBootTest(properties = {"spring.main.allow-bean-definition-overriding=true"})
29+
@SpringBootTest
3330
public abstract class BaseIntegrationTest {
3431
}

src/test/java/org/fairdatateam/fairdatapoint/WebIntegrationTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,14 @@
2525
import org.fairdatateam.fairdatapoint.database.mongo.migration.development.MigrationRunner;
2626
import org.fairdatateam.fairdatapoint.database.rdf.migration.development.RdfDevelopmentMigrationRunner;
2727
import org.junit.jupiter.api.BeforeEach;
28-
import org.junit.jupiter.api.extension.ExtendWith;
2928
import org.springframework.beans.factory.annotation.Autowired;
30-
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
3129
import org.springframework.boot.test.context.SpringBootTest;
3230
import org.springframework.boot.test.web.client.TestRestTemplate;
3331
import org.springframework.test.context.ActiveProfiles;
34-
import org.springframework.test.context.junit.jupiter.SpringExtension;
3532

36-
@ExtendWith(SpringExtension.class)
3733
@ActiveProfiles(Profiles.TESTING)
38-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
39-
@AutoConfigureMockMvc
34+
// todo: in most cases we can probably use WebEnvironment.MOCK with MockMvc instead of TestRestTemplate (see #862)
35+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
4036
public abstract class WebIntegrationTest {
4137

4238
public static final String ADMIN_TOKEN = "Bearer eyJhbGciOiJIUzUxMiJ9" +

src/test/java/org/fairdatateam/fairdatapoint/acceptance/index/admin/List_Trigger_POST.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
import org.junit.jupiter.api.DisplayName;
3535
import org.junit.jupiter.api.Test;
3636
import org.springframework.beans.factory.annotation.Autowired;
37+
import org.springframework.boot.test.context.TestConfiguration;
3738
import org.springframework.core.ParameterizedTypeReference;
3839
import org.springframework.http.HttpHeaders;
3940
import org.springframework.http.HttpStatus;
4041
import org.springframework.http.RequestEntity;
4142
import org.springframework.http.ResponseEntity;
43+
import org.springframework.scheduling.annotation.EnableAsync;
4244

4345
import java.net.URI;
4446
import java.util.List;
@@ -202,4 +204,16 @@ public void res404_triggerOne() {
202204
assertThat("One AdminTrigger event is created", events.size(), is(equalTo(1)));
203205
assertThat("Records correct client URL", events.get(0).getAdminTrigger().getClientUrl(), is(equalTo(entry.getClientUrl())));
204206
}
207+
208+
/**
209+
* Enables asynchronous request processing.
210+
* This reproduces the exception handling behaviour of the production config,
211+
* which causes RDF parsing exceptions to be ignored by the ExceptionControllerAdvice,
212+
* because they occur in worker threads.
213+
* The parsing exceptions should be reflected in the resulting IndexEntryState instead.
214+
*/
215+
@TestConfiguration
216+
@EnableAsync
217+
public static class AsyncConfig {
218+
}
205219
}

src/test/java/org/fairdatateam/fairdatapoint/acceptance/index/ping/List_POST.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
import org.junit.jupiter.api.DisplayName;
3232
import org.junit.jupiter.api.Test;
3333
import org.springframework.beans.factory.annotation.Autowired;
34+
import org.springframework.boot.test.context.TestConfiguration;
3435
import org.springframework.core.ParameterizedTypeReference;
3536
import org.springframework.http.HttpStatus;
3637
import org.springframework.http.MediaType;
3738
import org.springframework.http.RequestEntity;
3839
import org.springframework.http.ResponseEntity;
40+
import org.springframework.scheduling.annotation.EnableAsync;
3941

4042
import java.net.URI;
4143
import java.util.HashMap;
@@ -177,4 +179,16 @@ public void res400_differentBody() {
177179
// THEN
178180
assertThat("Correct response code is received", result.getStatusCode(), is(equalTo(HttpStatus.BAD_REQUEST)));
179181
}
182+
183+
/**
184+
* Enables asynchronous request processing.
185+
* This reproduces the exception handling behaviour of the production config,
186+
* which causes RDF parsing exceptions to be ignored by the ExceptionControllerAdvice,
187+
* because they occur in worker threads.
188+
* The parsing exceptions should be reflected in the resulting IndexEntryState instead.
189+
*/
190+
@TestConfiguration
191+
@EnableAsync
192+
public static class AsyncConfig {
193+
}
180194
}

0 commit comments

Comments
 (0)