Skip to content

DATAES-675 - Migrate tests to JUnit 5. #345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@

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
Expand All @@ -39,14 +42,20 @@
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,42 @@

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
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;
Expand All @@ -46,6 +46,7 @@
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;
Expand All @@ -62,6 +63,7 @@
* @author Peter-Josef Meisch
* @author Rasmus Faber-Espensen
*/
@SpringIntegrationTest
public abstract class CustomMethodRepositoryBaseTests {

@Autowired private SampleCustomMethodRepository repository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,47 @@
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -28,16 +26,13 @@
*
* @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 {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,10 +26,13 @@
*
* @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 {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@
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
Expand All @@ -49,14 +48,14 @@
* @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);
Expand Down
18 changes: 0 additions & 18 deletions src/test/resources/complex-custom-method-repository-test.xml

This file was deleted.

Loading