Skip to content

DATAES-675 - Migrate tests to JUnit5. #336

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
Oct 25, 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 @@ -20,7 +20,7 @@
import java.util.Arrays;
import java.util.Collections;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.elasticsearch.core.document.Document;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
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.domain.Page;
Expand All @@ -50,9 +49,10 @@
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

/**
* @author Rizwan Idrees
Expand All @@ -61,13 +61,13 @@
* @author Peter-Josef Meisch
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/elasticsearch-template-test.xml")
@SpringIntegrationTest
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
public class NestedObjectTests {

@Autowired private ElasticsearchTemplate elasticsearchTemplate;

@Before
@BeforeEach
public void before() {

IndexInitializer.init(elasticsearchTemplate, Book.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import javax.net.ssl.SSLContext;

import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static org.assertj.core.api.Assertions.*;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link ClusterNodes}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.net.InetSocketAddress;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link InetSocketAddressParser}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.net.InetSocketAddress;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.web.reactive.function.client.WebClient;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
import org.springframework.data.elasticsearch.client.ElasticsearchHost.State;
import org.springframework.data.elasticsearch.client.reactive.HostProvider.Verification;
Expand All @@ -32,7 +32,6 @@

/**
* @author Christoph Strobl
* @currentRead Golden Fool - Robin Hobb
*/
public class MultiNodeHostProviderUnitTests {

Expand All @@ -43,7 +42,7 @@ public class MultiNodeHostProviderUnitTests {
MockDelegatingElasticsearchHostProvider<MultiNodeHostProvider> mock;
MultiNodeHostProvider provider;

@Before
@BeforeEach
public void setUp() {

mock = ReactiveMockClientTestsUtils.multi(HOST_1, HOST_2, HOST_3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.VersionType;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.reactivestreams.Publisher;
import org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockDelegatingElasticsearchHostProvider;
Expand All @@ -51,7 +51,6 @@

/**
* @author Christoph Strobl
* @currentRead Golden Fool - Robin Hobb
*/
public class ReactiveElasticsearchClientUnitTests {

Expand All @@ -60,7 +59,7 @@ public class ReactiveElasticsearchClientUnitTests {
MockDelegatingElasticsearchHostProvider<HostProvider> hostProvider;
ReactiveElasticsearchClient client;

@Before
@BeforeEach
public void setUp() {

hostProvider = ReactiveMockClientTestsUtils.provider(HOST).withActiveDefaultHost(HOST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import reactor.test.StepVerifier;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
import org.springframework.data.elasticsearch.client.ElasticsearchHost.State;
import org.springframework.data.elasticsearch.client.NoReachableHostException;
Expand All @@ -30,7 +30,6 @@

/**
* @author Christoph Strobl
* @currentRead Golden Fool - Robin Hobb
*/
public class SingleNodeHostProviderUnitTests {

Expand All @@ -39,7 +38,7 @@ public class SingleNodeHostProviderUnitTests {
MockDelegatingElasticsearchHostProvider<SingleNodeHostProvider> mock;
SingleNodeHostProvider provider;

@Before
@BeforeEach
public void setUp() {

mock = ReactiveMockClientTestsUtils.single(HOST_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package org.springframework.data.elasticsearch.client.util;

import static org.assertj.core.api.Assertions.*;

import java.util.Collections;

import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.Request;
import org.junit.Test;

import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link RequestConverters}.
Expand All @@ -38,8 +38,7 @@ public void shouldNotAddIfSeqNoAndIfPrimaryTermToResultIfInputDoesNotcontainThem

Request result = RequestConverters.index(request);

assertThat(result.getParameters())
.doesNotContainKeys("if_seq_no", "if_primary_term");
assertThat(result.getParameters()).doesNotContainKeys("if_seq_no", "if_primary_term");
}

private IndexRequest createMinimalIndexRequest() {
Expand All @@ -58,8 +57,7 @@ public void shouldAddIfSeqNoAndIfPrimaryTermToResultIfInputcontainsThemWhenConve

Request result = RequestConverters.index(request);

assertThat(result.getParameters()).containsEntry("if_seq_no", "3")
.containsEntry("if_primary_term", "4");
assertThat(result.getParameters()).containsEntry("if_seq_no", "3").containsEntry("if_primary_term", "4");
}

@Test // DATAES-652
Expand All @@ -69,8 +67,7 @@ public void shouldNotAddIfSeqNoAndIfPrimaryTermToResultIfInputDoesNotcontainThem

Request result = RequestConverters.delete(request);

assertThat(result.getParameters())
.doesNotContainKeys("if_seq_no", "if_primary_term");
assertThat(result.getParameters()).doesNotContainKeys("if_seq_no", "if_primary_term");
}

private DeleteRequest createMinimalDeleteRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.search.SearchHit;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.elasticsearch.core.document.Document;
import org.springframework.data.elasticsearch.core.document.DocumentAdapters;
import org.springframework.data.elasticsearch.core.document.SearchDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
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.query.UpdateQuery;
import org.springframework.data.elasticsearch.core.query.UpdateQueryBuilder;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;

/**
Expand All @@ -56,19 +56,21 @@
* @author Don Wellington
* @author Peter-Josef Meisch
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:elasticsearch-rest-template-test.xml")
@SpringIntegrationTest
@ContextConfiguration(classes = { ElasticsearchRestTemplateConfiguration.class })
public class ElasticsearchRestTemplateTests extends ElasticsearchTemplateTests {

@Test(expected = ElasticsearchStatusException.class)
@Test
public void shouldThrowExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {

// when
IndexRequest indexRequest = new IndexRequest();
indexRequest.source("{}", XContentType.JSON);
UpdateQuery updateQuery = new UpdateQueryBuilder().withId(randomNumeric(5)).withClass(SampleEntity.class)
.withIndexRequest(indexRequest).build();
elasticsearchTemplate.update(updateQuery);
assertThatThrownBy(() -> {
elasticsearchTemplate.update(updateQuery);
}).isInstanceOf(ElasticsearchStatusException.class);
}

@Test // DATAES-227
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
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.annotation.Version;
Expand Down Expand Up @@ -110,7 +110,7 @@ public abstract class ElasticsearchTemplateTests {

@Autowired protected ElasticsearchOperations elasticsearchTemplate;

@Before
@BeforeEach
public void before() {

deleteIndices();
Expand All @@ -122,7 +122,7 @@ public void before() {
elasticsearchTemplate.putMapping(SampleEntityUUIDKeyed.class);
}

@After
@AfterEach
public void after() {

deleteIndices();
Expand Down Expand Up @@ -306,7 +306,7 @@ public void shouldReturnPageUsingLocalPreferenceForGivenSearchQuery() {
assertThat(sampleEntities.getTotalElements()).isGreaterThanOrEqualTo(1);
}

@Test(expected = Exception.class) // DATAES-595
@Test // DATAES-595
public void shouldThrowExceptionWhenInvalidPreferenceForSearchQuery() {

// given
Expand All @@ -323,10 +323,9 @@ public void shouldThrowExceptionWhenInvalidPreferenceForSearchQuery() {
.withPreference("_only_nodes:oops").build();

// when
elasticsearchTemplate.queryForPage(searchQueryWithInvalidPreference, SampleEntity.class);

// then Throw IllegalArgumentException in case of ElasticsearchTemplate and ElasticsearchStatusException in case of
// ElasticsearchRestTemplate
assertThatThrownBy(() -> {
elasticsearchTemplate.queryForPage(searchQueryWithInvalidPreference, SampleEntity.class);
}).isInstanceOf(Exception.class);
}

@Test // DATAES-422 - Add support for IndicesOptions in search queries
Expand Down Expand Up @@ -1639,17 +1638,17 @@ public void shouldIndexDocumentForSpecifiedSource() {
assertThat(page.getContent().get(0).getId()).isEqualTo(indexQuery.getId());
}

@Test(expected = ElasticsearchException.class)
@Test
public void shouldThrowElasticsearchExceptionWhenNoDocumentSpecified() {

// given
IndexQuery indexQuery = new IndexQuery();
final IndexQuery indexQuery = new IndexQuery();
indexQuery.setId("2333343434");
indexQuery.setIndexName(INDEX_NAME_SAMPLE_ENTITY);
indexQuery.setType(TYPE_NAME);

// when
elasticsearchTemplate.index(indexQuery);
assertThatThrownBy(() -> elasticsearchTemplate.index(indexQuery)).isInstanceOf(ElasticsearchException.class);
}

@Test
Expand Down Expand Up @@ -2136,7 +2135,7 @@ public void shouldReturnCountForGivenSearchQueryWithGivenIndexNameForSpecificInd
assertThat(count).isEqualTo(1);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void shouldThrowAnExceptionForGivenCriteriaQueryWhenNoIndexSpecifiedForCountQuery() {

// given
Expand All @@ -2150,13 +2149,12 @@ public void shouldThrowAnExceptionForGivenCriteriaQueryWhenNoIndexSpecifiedForCo
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());

// when
long count = elasticsearchTemplate.count(criteriaQuery);

// then
assertThat(count).isEqualTo(1);
assertThatThrownBy(() -> {
long count = elasticsearchTemplate.count(criteriaQuery);
}).isInstanceOf(IllegalArgumentException.class);
}

@Test(expected = IllegalArgumentException.class) // DATAES-67
@Test // DATAES-67
public void shouldThrowAnExceptionForGivenSearchQueryWhenNoIndexSpecifiedForCountQuery() {

// given
Expand All @@ -2170,7 +2168,9 @@ public void shouldThrowAnExceptionForGivenSearchQueryWhenNoIndexSpecifiedForCoun
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();

// when
elasticsearchTemplate.count(searchQuery);
assertThatThrownBy(() -> {
elasticsearchTemplate.count(searchQuery);
}).isInstanceOf(IllegalArgumentException.class);
}

@Test // DATAES-71
Expand Down
Loading