DATAES-675 - Migrate tests to JUnit 5.

OriginalPR: #345
This commit is contained in:
Peter-Josef Meisch 2019-11-09 21:40:48 +01:00 committed by GitHub
parent 8bc133d955
commit 3f82108734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 103 additions and 157 deletions

View File

@ -22,15 +22,18 @@ import lombok.NoArgsConstructor;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.repository.CrudRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Young Gu
@ -39,14 +42,20 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Christoph Strobl
* @author Peter-Josef Meisch
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:immutable-repository-test.xml")
@SpringIntegrationTest
@ContextConfiguration(classes = { ImmutableElasticsearchRepositoryTests.Config.class })
public class ImmutableElasticsearchRepositoryTests {
@Configuration
@Import({ ElasticsearchTemplateConfiguration.class })
@EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.immutable" },
considerNestedRepositories = true)
static class Config {}
@Autowired ImmutableElasticsearchRepository repository;
@Autowired ElasticsearchOperations operations;
@Before
@BeforeEach
public void before() {
operations.deleteIndex(ImmutableEntity.class);

View File

@ -20,33 +20,42 @@ import static org.springframework.data.elasticsearch.annotations.FieldType.*;
import lombok.Data;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Artur Konczak
* @author Mohsin Husen
* @author Peter-Josef Meisch
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:complex-custom-method-repository-test.xml")
@SpringIntegrationTest
@ContextConfiguration(classes = { ComplexCustomMethodRepositoryTests.Config.class })
public class ComplexCustomMethodRepositoryTests {
@Configuration
@Import({ ElasticsearchTemplateConfiguration.class })
@EnableElasticsearchRepositories(
basePackages = { "org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring" },
considerNestedRepositories = true)
static class Config {}
@Autowired private ComplexElasticsearchRepository complexRepository;
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
@Before
@BeforeEach
public void before() {
IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
}

View File

@ -32,7 +32,7 @@ import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
@ -46,6 +46,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.core.geo.GeoBox;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.data.geo.Box;
import org.springframework.data.geo.Distance;
@ -62,6 +63,7 @@ import org.springframework.data.geo.Point;
* @author Peter-Josef Meisch
* @author Rasmus Faber-Espensen
*/
@SpringIntegrationTest
public abstract class CustomMethodRepositoryBaseTests {
@Autowired private SampleCustomMethodRepository repository;

View File

@ -15,26 +15,34 @@
*/
package org.springframework.data.elasticsearch.repositories.custommethod;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Don Wellington
* @author Mark Paluch
* @author Peter-Josef Meisch
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:custom-method-repository-rest-test.xml")
@ContextConfiguration(classes = { CustomMethodRepositoryRestTests.Config.class })
public class CustomMethodRepositoryRestTests extends CustomMethodRepositoryBaseTests {
@Configuration
@Import({ ElasticsearchRestTemplateConfiguration.class })
@EnableElasticsearchRepositories(
basePackages = { "org.springframework.data.elasticsearch.repositories.custommethod" },
considerNestedRepositories = true)
static class Config {}
@Autowired private ElasticsearchRestTemplate elasticsearchTemplate;
@Before
@BeforeEach
public void before() {
IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
}

View File

@ -15,26 +15,34 @@
*/
package org.springframework.data.elasticsearch.repositories.custommethod;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Don Wellington
* @author Mark Paluch
* @author Peter-Josef Meisch
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:custom-method-repository-test.xml")
@ContextConfiguration(classes = { CustomMethodRepositoryTests.Config.class })
public class CustomMethodRepositoryTests extends CustomMethodRepositoryBaseTests {
@Configuration
@Import({ ElasticsearchTemplateConfiguration.class })
@EnableElasticsearchRepositories(
basePackages = { "org.springframework.data.elasticsearch.repositories.custommethod" },
considerNestedRepositories = true)
static class Config {}
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
@Before
@BeforeEach
public void before() {
IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
}

View File

@ -26,38 +26,47 @@ import lombok.Setter;
import java.util.Locale;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.GeoPointField;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.data.geo.Box;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Point;
import org.springframework.data.geo.Polygon;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Mark Paluch
* @author Christoph Strobl
* @author Peter-Josef Meisch
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/repository-spring-data-geo-support.xml")
@SpringIntegrationTest
@ContextConfiguration(classes = { SpringDataGeoRepositoryTests.Config.class })
public class SpringDataGeoRepositoryTests {
@Configuration
@Import({ ElasticsearchTemplateConfiguration.class })
@EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.repositories.geo" },
considerNestedRepositories = true)
static class Config {}
@Autowired ElasticsearchTemplate template;
@Autowired SpringDataGeoRepository repository;
@Before
@BeforeEach
public void init() {
IndexInitializer.init(template, GeoEntity.class);
}

View File

@ -15,11 +15,9 @@
*/
package org.springframework.data.elasticsearch.repository.query.keywords;
import org.junit.ClassRule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.ElasticsearchTestConfiguration;
import org.springframework.data.elasticsearch.junit.junit4.TestNodeResource;
import org.springframework.context.annotation.Import;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.test.context.ContextConfiguration;
@ -28,16 +26,13 @@ import org.springframework.test.context.ContextConfiguration;
*
* @author Peter-Josef Meisch
*/
@ContextConfiguration(classes = { QueryKeywordsRepositoryTests.class, ElasticsearchTestConfiguration.class })
@Configuration
@EnableElasticsearchRepositories(considerNestedRepositories = true)
@ContextConfiguration(classes = { QueryKeywordsRepositoryTests.Config.class})
public class QueryKeywordsRepositoryTests extends QueryKeywordsTests {
@ClassRule public static TestNodeResource testNodeResource = new TestNodeResource();
// needed by the ElasticsearchTestConfiguration.
@Bean
public TestNodeResource nodeResource() {
return testNodeResource;
}
@Configuration
@Import({ ElasticsearchTemplateConfiguration.class })
@EnableElasticsearchRepositories(
basePackages = { "org.springframework.data.elasticsearch.repository.query.keywords" },
considerNestedRepositories = true)
static class Config {}
}

View File

@ -15,10 +15,9 @@
*/
package org.springframework.data.elasticsearch.repository.query.keywords;
import org.junit.ClassRule;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.RestElasticsearchTestConfiguration;
import org.springframework.data.elasticsearch.junit.junit4.TestNodeResource;
import org.springframework.context.annotation.Import;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.test.context.ContextConfiguration;
@ -27,10 +26,13 @@ import org.springframework.test.context.ContextConfiguration;
*
* @author Peter-Josef Meisch
*/
@ContextConfiguration(classes = { QueryKeywordsRestRepositoryTests.class, RestElasticsearchTestConfiguration.class })
@Configuration
@EnableElasticsearchRepositories(considerNestedRepositories = true)
@ContextConfiguration(classes = { QueryKeywordsRestRepositoryTests.Config.class })
public class QueryKeywordsRestRepositoryTests extends QueryKeywordsTests {
@ClassRule public static TestNodeResource testNodeResource = new TestNodeResource();
@Configuration
@Import({ ElasticsearchRestTemplateConfiguration.class })
@EnableElasticsearchRepositories(
basePackages = { "org.springframework.data.elasticsearch.repository.query.keywords" },
considerNestedRepositories = true)
static class Config {}
}

View File

@ -28,18 +28,17 @@ import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.junit4.SpringRunner;
/**
* base class for query keyword tests. Implemented by subclasses using ElasticsearchClient and ElasticsearchRestClient
@ -49,14 +48,14 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Christoph Strobl
* @author Peter-Josef Meisch
*/
@RunWith(SpringRunner.class)
@SpringIntegrationTest
abstract class QueryKeywordsTests {
@Autowired private ProductRepository repository;
@Autowired private ElasticsearchOperations elasticsearchTemplate;
@Before
@BeforeEach
public void before() {
IndexInitializer.init(elasticsearchTemplate, Product.class);

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring"/>
</beans>

View File

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate">
<constructor-arg name="client" ref="restClient"/>
</bean>
<elasticsearch:rest-client id="restClient"/>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.custommethod"
consider-nested-repositories="true"/>
</beans>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.custommethod"
consider-nested-repositories="true"/>
</beans>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.immutable"
consider-nested-repositories="true"/>
</beans>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories base-package="org.springframework.data.elasticsearch.repositories.geo"
consider-nested-repositories="true"/>
</beans>