Skip to content

Commit 3f82108

Browse files
authored
DATAES-675 - Migrate tests to JUnit 5.
OriginalPR: #345
1 parent 8bc133d commit 3f82108

14 files changed

+103
-157
lines changed

src/test/java/org/springframework/data/elasticsearch/immutable/ImmutableElasticsearchRepositoryTests.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222

2323
import java.util.Optional;
2424

25-
import org.junit.Before;
26-
import org.junit.Test;
27-
import org.junit.runner.RunWith;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2827
import org.springframework.beans.factory.annotation.Autowired;
28+
import org.springframework.context.annotation.Configuration;
29+
import org.springframework.context.annotation.Import;
2930
import org.springframework.data.elasticsearch.annotations.Document;
3031
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
32+
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
33+
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
34+
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
3135
import org.springframework.data.repository.CrudRepository;
3236
import org.springframework.test.context.ContextConfiguration;
33-
import org.springframework.test.context.junit4.SpringRunner;
3437

3538
/**
3639
* @author Young Gu
@@ -39,14 +42,20 @@
3942
* @author Christoph Strobl
4043
* @author Peter-Josef Meisch
4144
*/
42-
@RunWith(SpringRunner.class)
43-
@ContextConfiguration("classpath:immutable-repository-test.xml")
45+
@SpringIntegrationTest
46+
@ContextConfiguration(classes = { ImmutableElasticsearchRepositoryTests.Config.class })
4447
public class ImmutableElasticsearchRepositoryTests {
4548

49+
@Configuration
50+
@Import({ ElasticsearchTemplateConfiguration.class })
51+
@EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.immutable" },
52+
considerNestedRepositories = true)
53+
static class Config {}
54+
4655
@Autowired ImmutableElasticsearchRepository repository;
4756
@Autowired ElasticsearchOperations operations;
4857

49-
@Before
58+
@BeforeEach
5059
public void before() {
5160

5261
operations.deleteIndex(ImmutableEntity.class);

src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexCustomMethodRepositoryTests.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,42 @@
2020

2121
import lombok.Data;
2222

23-
import org.junit.Before;
24-
import org.junit.Test;
25-
import org.junit.runner.RunWith;
26-
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2725
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.context.annotation.Configuration;
27+
import org.springframework.context.annotation.Import;
2828
import org.springframework.data.annotation.Id;
2929
import org.springframework.data.elasticsearch.annotations.Document;
3030
import org.springframework.data.elasticsearch.annotations.Field;
3131
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
32+
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
33+
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
34+
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
3235
import org.springframework.data.elasticsearch.utils.IndexInitializer;
3336
import org.springframework.test.context.ContextConfiguration;
34-
import org.springframework.test.context.junit4.SpringRunner;
3537

3638
/**
3739
* @author Artur Konczak
3840
* @author Mohsin Husen
3941
* @author Peter-Josef Meisch
4042
*/
41-
@RunWith(SpringRunner.class)
42-
@ContextConfiguration("classpath:complex-custom-method-repository-test.xml")
43+
@SpringIntegrationTest
44+
@ContextConfiguration(classes = { ComplexCustomMethodRepositoryTests.Config.class })
4345
public class ComplexCustomMethodRepositoryTests {
4446

47+
@Configuration
48+
@Import({ ElasticsearchTemplateConfiguration.class })
49+
@EnableElasticsearchRepositories(
50+
basePackages = { "org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring" },
51+
considerNestedRepositories = true)
52+
static class Config {}
53+
4554
@Autowired private ComplexElasticsearchRepository complexRepository;
4655

4756
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
4857

49-
@Before
58+
@BeforeEach
5059
public void before() {
5160
IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
5261
}

src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryBaseTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import java.util.UUID;
3333
import java.util.stream.Stream;
3434

35-
import org.junit.Test;
35+
import org.junit.jupiter.api.Test;
3636
import org.springframework.beans.factory.annotation.Autowired;
3737
import org.springframework.data.annotation.Id;
3838
import org.springframework.data.annotation.Version;
@@ -46,6 +46,7 @@
4646
import org.springframework.data.elasticsearch.annotations.Query;
4747
import org.springframework.data.elasticsearch.core.geo.GeoBox;
4848
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
49+
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
4950
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
5051
import org.springframework.data.geo.Box;
5152
import org.springframework.data.geo.Distance;
@@ -62,6 +63,7 @@
6263
* @author Peter-Josef Meisch
6364
* @author Rasmus Faber-Espensen
6465
*/
66+
@SpringIntegrationTest
6567
public abstract class CustomMethodRepositoryBaseTests {
6668

6769
@Autowired private SampleCustomMethodRepository repository;

src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryRestTests.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,34 @@
1515
*/
1616
package org.springframework.data.elasticsearch.repositories.custommethod;
1717

18-
import org.junit.Before;
19-
import org.junit.runner.RunWith;
18+
import org.junit.jupiter.api.BeforeEach;
2019
import org.springframework.beans.factory.annotation.Autowired;
20+
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.context.annotation.Import;
2122
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
23+
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
24+
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
2225
import org.springframework.data.elasticsearch.utils.IndexInitializer;
2326
import org.springframework.test.context.ContextConfiguration;
24-
import org.springframework.test.context.junit4.SpringRunner;
2527

2628
/**
2729
* @author Don Wellington
2830
* @author Mark Paluch
2931
* @author Peter-Josef Meisch
3032
*/
31-
@RunWith(SpringRunner.class)
32-
@ContextConfiguration("classpath:custom-method-repository-rest-test.xml")
33+
@ContextConfiguration(classes = { CustomMethodRepositoryRestTests.Config.class })
3334
public class CustomMethodRepositoryRestTests extends CustomMethodRepositoryBaseTests {
3435

36+
@Configuration
37+
@Import({ ElasticsearchRestTemplateConfiguration.class })
38+
@EnableElasticsearchRepositories(
39+
basePackages = { "org.springframework.data.elasticsearch.repositories.custommethod" },
40+
considerNestedRepositories = true)
41+
static class Config {}
42+
3543
@Autowired private ElasticsearchRestTemplate elasticsearchTemplate;
3644

37-
@Before
45+
@BeforeEach
3846
public void before() {
3947
IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
4048
}

src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryTests.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,34 @@
1515
*/
1616
package org.springframework.data.elasticsearch.repositories.custommethod;
1717

18-
import org.junit.Before;
19-
import org.junit.runner.RunWith;
18+
import org.junit.jupiter.api.BeforeEach;
2019
import org.springframework.beans.factory.annotation.Autowired;
20+
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.context.annotation.Import;
2122
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
23+
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
24+
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
2225
import org.springframework.data.elasticsearch.utils.IndexInitializer;
2326
import org.springframework.test.context.ContextConfiguration;
24-
import org.springframework.test.context.junit4.SpringRunner;
2527

2628
/**
2729
* @author Don Wellington
2830
* @author Mark Paluch
2931
* @author Peter-Josef Meisch
3032
*/
31-
@RunWith(SpringRunner.class)
32-
@ContextConfiguration("classpath:custom-method-repository-test.xml")
33+
@ContextConfiguration(classes = { CustomMethodRepositoryTests.Config.class })
3334
public class CustomMethodRepositoryTests extends CustomMethodRepositoryBaseTests {
3435

36+
@Configuration
37+
@Import({ ElasticsearchTemplateConfiguration.class })
38+
@EnableElasticsearchRepositories(
39+
basePackages = { "org.springframework.data.elasticsearch.repositories.custommethod" },
40+
considerNestedRepositories = true)
41+
static class Config {}
42+
3543
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
3644

37-
@Before
45+
@BeforeEach
3846
public void before() {
3947
IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
4048
}

src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTests.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,47 @@
2626
import java.util.Locale;
2727
import java.util.Optional;
2828

29-
import org.junit.Before;
30-
import org.junit.Test;
31-
import org.junit.runner.RunWith;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
3231
import org.springframework.beans.factory.annotation.Autowired;
32+
import org.springframework.context.annotation.Configuration;
33+
import org.springframework.context.annotation.Import;
3334
import org.springframework.data.annotation.Id;
3435
import org.springframework.data.elasticsearch.annotations.Document;
3536
import org.springframework.data.elasticsearch.annotations.GeoPointField;
3637
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
3738
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
39+
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
40+
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
3841
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
42+
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
3943
import org.springframework.data.elasticsearch.utils.IndexInitializer;
4044
import org.springframework.data.geo.Box;
4145
import org.springframework.data.geo.Circle;
4246
import org.springframework.data.geo.Point;
4347
import org.springframework.data.geo.Polygon;
4448
import org.springframework.test.context.ContextConfiguration;
45-
import org.springframework.test.context.junit4.SpringRunner;
4649

4750
/**
4851
* @author Mark Paluch
4952
* @author Christoph Strobl
5053
* @author Peter-Josef Meisch
5154
*/
52-
@RunWith(SpringRunner.class)
53-
@ContextConfiguration("classpath:/repository-spring-data-geo-support.xml")
55+
@SpringIntegrationTest
56+
@ContextConfiguration(classes = { SpringDataGeoRepositoryTests.Config.class })
5457
public class SpringDataGeoRepositoryTests {
5558

59+
@Configuration
60+
@Import({ ElasticsearchTemplateConfiguration.class })
61+
@EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.repositories.geo" },
62+
considerNestedRepositories = true)
63+
static class Config {}
64+
5665
@Autowired ElasticsearchTemplate template;
5766

5867
@Autowired SpringDataGeoRepository repository;
5968

60-
@Before
69+
@BeforeEach
6170
public void init() {
6271
IndexInitializer.init(template, GeoEntity.class);
6372
}

src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRepositoryTests.java

+9-14
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
*/
1616
package org.springframework.data.elasticsearch.repository.query.keywords;
1717

18-
import org.junit.ClassRule;
19-
import org.springframework.context.annotation.Bean;
2018
import org.springframework.context.annotation.Configuration;
21-
import org.springframework.data.elasticsearch.ElasticsearchTestConfiguration;
22-
import org.springframework.data.elasticsearch.junit.junit4.TestNodeResource;
19+
import org.springframework.context.annotation.Import;
20+
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
2321
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
2422
import org.springframework.test.context.ContextConfiguration;
2523

@@ -28,16 +26,13 @@
2826
*
2927
* @author Peter-Josef Meisch
3028
*/
31-
@ContextConfiguration(classes = { QueryKeywordsRepositoryTests.class, ElasticsearchTestConfiguration.class })
32-
@Configuration
33-
@EnableElasticsearchRepositories(considerNestedRepositories = true)
29+
@ContextConfiguration(classes = { QueryKeywordsRepositoryTests.Config.class})
3430
public class QueryKeywordsRepositoryTests extends QueryKeywordsTests {
3531

36-
@ClassRule public static TestNodeResource testNodeResource = new TestNodeResource();
37-
38-
// needed by the ElasticsearchTestConfiguration.
39-
@Bean
40-
public TestNodeResource nodeResource() {
41-
return testNodeResource;
42-
}
32+
@Configuration
33+
@Import({ ElasticsearchTemplateConfiguration.class })
34+
@EnableElasticsearchRepositories(
35+
basePackages = { "org.springframework.data.elasticsearch.repository.query.keywords" },
36+
considerNestedRepositories = true)
37+
static class Config {}
4338
}

src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRestRepositoryTests.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
*/
1616
package org.springframework.data.elasticsearch.repository.query.keywords;
1717

18-
import org.junit.ClassRule;
1918
import org.springframework.context.annotation.Configuration;
20-
import org.springframework.data.elasticsearch.RestElasticsearchTestConfiguration;
21-
import org.springframework.data.elasticsearch.junit.junit4.TestNodeResource;
19+
import org.springframework.context.annotation.Import;
20+
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
2221
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
2322
import org.springframework.test.context.ContextConfiguration;
2423

@@ -27,10 +26,13 @@
2726
*
2827
* @author Peter-Josef Meisch
2928
*/
30-
@ContextConfiguration(classes = { QueryKeywordsRestRepositoryTests.class, RestElasticsearchTestConfiguration.class })
31-
@Configuration
32-
@EnableElasticsearchRepositories(considerNestedRepositories = true)
29+
@ContextConfiguration(classes = { QueryKeywordsRestRepositoryTests.Config.class })
3330
public class QueryKeywordsRestRepositoryTests extends QueryKeywordsTests {
3431

35-
@ClassRule public static TestNodeResource testNodeResource = new TestNodeResource();
32+
@Configuration
33+
@Import({ ElasticsearchRestTemplateConfiguration.class })
34+
@EnableElasticsearchRepositories(
35+
basePackages = { "org.springframework.data.elasticsearch.repository.query.keywords" },
36+
considerNestedRepositories = true)
37+
static class Config {}
3638
}

src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsTests.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@
2828
import java.util.List;
2929
import java.util.stream.Collectors;
3030

31-
import org.junit.Before;
32-
import org.junit.Test;
33-
import org.junit.runner.RunWith;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
3433
import org.springframework.beans.factory.annotation.Autowired;
3534
import org.springframework.data.annotation.Id;
3635
import org.springframework.data.elasticsearch.annotations.Document;
3736
import org.springframework.data.elasticsearch.annotations.Field;
3837
import org.springframework.data.elasticsearch.annotations.FieldType;
3938
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
39+
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
4040
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
4141
import org.springframework.data.elasticsearch.utils.IndexInitializer;
42-
import org.springframework.test.context.junit4.SpringRunner;
4342

4443
/**
4544
* base class for query keyword tests. Implemented by subclasses using ElasticsearchClient and ElasticsearchRestClient
@@ -49,14 +48,14 @@
4948
* @author Christoph Strobl
5049
* @author Peter-Josef Meisch
5150
*/
52-
@RunWith(SpringRunner.class)
51+
@SpringIntegrationTest
5352
abstract class QueryKeywordsTests {
5453

5554
@Autowired private ProductRepository repository;
5655

5756
@Autowired private ElasticsearchOperations elasticsearchTemplate;
5857

59-
@Before
58+
@BeforeEach
6059
public void before() {
6160

6261
IndexInitializer.init(elasticsearchTemplate, Product.class);

src/test/resources/complex-custom-method-repository-test.xml

-18
This file was deleted.

0 commit comments

Comments
 (0)