DATAES-579 - Reformat test sources.

Original pull request: #283.
This commit is contained in:
Mark Paluch 2019-05-31 11:45:40 +02:00
parent 198ad0e02b
commit 92433b79aa
22 changed files with 94 additions and 91 deletions

View File

@ -25,38 +25,36 @@ import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* A classloader that is a union over the parent core classloader and classloaders of extended plugins. * A classloader that is a union over the parent core classloader and classloaders of extended plugins. Cloned from ES
* Cloned from ES repository * repository - that file is only available in ES server libs - and we need it o create a node client for unittests
* - that file is only available in ES server libs
* - and we need it o create a node client for unittests
*/ */
public class ExtendedPluginsClassLoader extends ClassLoader { public class ExtendedPluginsClassLoader extends ClassLoader {
/** Loaders of plugins extended by a plugin. */ /** Loaders of plugins extended by a plugin. */
private final List<ClassLoader> extendedLoaders; private final List<ClassLoader> extendedLoaders;
private ExtendedPluginsClassLoader(ClassLoader parent, List<ClassLoader> extendedLoaders) { private ExtendedPluginsClassLoader(ClassLoader parent, List<ClassLoader> extendedLoaders) {
super(parent); super(parent);
this.extendedLoaders = Collections.unmodifiableList(extendedLoaders); this.extendedLoaders = Collections.unmodifiableList(extendedLoaders);
} }
@Override @Override
protected Class<?> findClass(String name) throws ClassNotFoundException { protected Class<?> findClass(String name) throws ClassNotFoundException {
for (ClassLoader loader : extendedLoaders) { for (ClassLoader loader : extendedLoaders) {
try { try {
return loader.loadClass(name); return loader.loadClass(name);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// continue // continue
} }
} }
throw new ClassNotFoundException(name); throw new ClassNotFoundException(name);
} }
/** /**
* Return a new classloader across the parent and extended loaders. * Return a new classloader across the parent and extended loaders.
*/ */
public static ExtendedPluginsClassLoader create(ClassLoader parent, List<ClassLoader> extendedLoaders) { public static ExtendedPluginsClassLoader create(ClassLoader parent, List<ClassLoader> extendedLoaders) {
return AccessController.doPrivileged((PrivilegedAction<ExtendedPluginsClassLoader>) return AccessController.doPrivileged(
() -> new ExtendedPluginsClassLoader(parent, extendedLoaders)); (PrivilegedAction<ExtendedPluginsClassLoader>) () -> new ExtendedPluginsClassLoader(parent, extendedLoaders));
} }
} }

View File

@ -15,13 +15,16 @@
*/ */
package org.springframework.data.elasticsearch; package org.springframework.data.elasticsearch;
import static java.util.Arrays.*;
import java.util.UUID; import java.util.UUID;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.NodeValidationException; import org.elasticsearch.node.NodeValidationException;
import org.elasticsearch.transport.Netty4Plugin; import org.elasticsearch.transport.Netty4Plugin;
import org.springframework.data.elasticsearch.client.NodeClientFactoryBean; import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
import static java.util.Arrays.*;
/** /**
* @author Mohsin Husen * @author Mohsin Husen
@ -36,14 +39,9 @@ public class Utils {
String pathData = "target/elasticsearchTestData"; String pathData = "target/elasticsearchTestData";
String clusterName = UUID.randomUUID().toString(); String clusterName = UUID.randomUUID().toString();
return new NodeClientFactoryBean.TestNode( return new NodeClientFactoryBean.TestNode(Settings.builder().put("transport.type", "netty4")
Settings.builder() .put("http.type", "netty4").put("path.home", pathHome).put("path.data", pathData)
.put("transport.type", "netty4") .put("cluster.name", clusterName).put("node.max_local_storage_nodes", 100).build(), asList(Netty4Plugin.class))
.put("http.type", "netty4") .start().client();
.put("path.home", pathHome)
.put("path.data", pathData)
.put("cluster.name", clusterName)
.put("node.max_local_storage_nodes", 100)
.build(), asList(Netty4Plugin.class)).start().client();
} }
} }

View File

@ -17,10 +17,6 @@ package org.springframework.data.elasticsearch.client.reactive;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.mockito.ArgumentCaptor;
import org.springframework.http.HttpMethod;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriBuilder;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.io.IOException; import java.io.IOException;
@ -41,12 +37,15 @@ import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.data.elasticsearch.client.ElasticsearchHost; import org.springframework.data.elasticsearch.client.ElasticsearchHost;
import org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockWebClientProvider.Send; import org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockWebClientProvider.Send;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -56,6 +55,8 @@ import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClient.RequestBodyUriSpec; import org.springframework.web.reactive.function.client.WebClient.RequestBodyUriSpec;
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriBuilder;
/** /**
* @author Christoph Strobl * @author Christoph Strobl

View File

@ -75,7 +75,8 @@ public class EnableNestedElasticsearchRepositoriesTests {
@Data @Data
@Builder @Builder
@Document(indexName = "test-index-sample-config-nested", type = "test-type", shards = 1, replicas = 0, refreshInterval = "-1") @Document(indexName = "test-index-sample-config-nested", type = "test-type", shards = 1, replicas = 0,
refreshInterval = "-1")
static class SampleEntity { static class SampleEntity {
@Id private String id; @Id private String id;

View File

@ -25,18 +25,18 @@ import java.util.Map;
public class CustomEntityMapper implements EntityMapper { public class CustomEntityMapper implements EntityMapper {
public CustomEntityMapper() { public CustomEntityMapper() {
//custom configuration/implementation (e.g. FasterXML/jackson) // custom configuration/implementation (e.g. FasterXML/jackson)
} }
@Override @Override
public String mapToString(Object object) throws IOException { public String mapToString(Object object) throws IOException {
//mapping Object to text // mapping Object to text
return null; return null;
} }
@Override @Override
public <T> T mapToObject(String source, Class<T> clazz) throws IOException { public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
//mapping text to Object // mapping text to Object
return null; return null;
} }

View File

@ -30,7 +30,6 @@ import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
*/ */
public class CustomResultMapper implements ResultsMapper { public class CustomResultMapper implements ResultsMapper {
private EntityMapper entityMapper; private EntityMapper entityMapper;
public CustomResultMapper(EntityMapper entityMapper) { public CustomResultMapper(EntityMapper entityMapper) {
@ -44,12 +43,12 @@ public class CustomResultMapper implements ResultsMapper {
@Override @Override
public <T> T mapResult(GetResponse response, Class<T> clazz) { public <T> T mapResult(GetResponse response, Class<T> clazz) {
return null; //To change body of implemented methods use File | Settings | File Templates. return null; // To change body of implemented methods use File | Settings | File Templates.
} }
@Override @Override
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
return null; //To change body of implemented methods use File | Settings | File Templates. return null; // To change body of implemented methods use File | Settings | File Templates.
} }
@Override @Override

View File

@ -499,7 +499,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "test-index-book-mapping-builder", type = "book", shards = 1, replicas = 0, refreshInterval = "-1") @Document(indexName = "test-index-book-mapping-builder", type = "book", shards = 1, replicas = 0,
refreshInterval = "-1")
static class Book { static class Book {
@Id private String id; @Id private String id;
@ -515,8 +516,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
* @author Stuart Stevenson * @author Stuart Stevenson
* @author Mohsin Husen * @author Mohsin Husen
*/ */
@Document(indexName = "test-index-simple-recursive-mapping-builder", type = "circular-object", shards = 1, replicas = 0, @Document(indexName = "test-index-simple-recursive-mapping-builder", type = "circular-object", shards = 1,
refreshInterval = "-1") replicas = 0, refreshInterval = "-1")
static class SimpleRecursiveEntity { static class SimpleRecursiveEntity {
@Id private String id; @Id private String id;
@ -551,7 +552,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "test-index-normalizer-mapping-builder", type = "test", shards = 1, replicas = 0, refreshInterval = "-1") @Document(indexName = "test-index-normalizer-mapping-builder", type = "test", shards = 1, replicas = 0,
refreshInterval = "-1")
@Setting(settingPath = "/settings/test-normalizer.json") @Setting(settingPath = "/settings/test-normalizer.json")
static class NormalizerEntity { static class NormalizerEntity {
@ -650,7 +652,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "test-index-stock-mapping-builder", type = "price", shards = 1, replicas = 0, refreshInterval = "-1") @Document(indexName = "test-index-stock-mapping-builder", type = "price", shards = 1, replicas = 0,
refreshInterval = "-1")
static class StockPrice { static class StockPrice {
@Id private String id; @Id private String id;
@ -746,7 +749,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "test-index-geo-mapping-builder", type = "geo-test-index", shards = 1, replicas = 0, refreshInterval = "-1") @Document(indexName = "test-index-geo-mapping-builder", type = "geo-test-index", shards = 1, replicas = 0,
refreshInterval = "-1")
static class GeoEntity { static class GeoEntity {
@Id private String id; @Id private String id;

View File

@ -15,15 +15,16 @@
*/ */
package org.springframework.data.elasticsearch.core.aggregation; package org.springframework.data.elasticsearch.core.aggregation;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test; import org.junit.Test;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl; import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
import java.util.Arrays;
/** /**
* @author Remco Zigterman * @author Remco Zigterman
*/ */

View File

@ -38,8 +38,8 @@ public class DateTimeConvertersTests {
@Test @Test
public void testJodaDateTimeConverter() { public void testJodaDateTimeConverter() {
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC); DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
Assert Assert.assertEquals("2013-01-24T06:35:00.000Z",
.assertEquals("2013-01-24T06:35:00.000Z", DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(dateTime)); DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(dateTime));
} }
@Test @Test

View File

@ -51,9 +51,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Mohsin Husen * @author Mohsin Husen
* @author Franck Marchand * @author Franck Marchand
* @author Artur Konczak * @author Artur Konczak
* @author Peter-Josef Meisch * @author Peter-Josef Meisch Basic info: latitude - horizontal lines (equator = 0.0, values -90.0 to 90.0) longitude -
*
* Basic info: latitude - horizontal lines (equator = 0.0, values -90.0 to 90.0) longitude -
* vertical lines (Greenwich = 0.0, values -180 to 180) London [lat,lon] = [51.50985,-0.118082] - geohash = * vertical lines (Greenwich = 0.0, values -180 to 180) London [lat,lon] = [51.50985,-0.118082] - geohash =
* gcpvj3448 Bouding Box for London = (bbox=-0.489,51.28,0.236,51.686) bbox = left,bottom,right,top bbox = min * gcpvj3448 Bouding Box for London = (bbox=-0.489,51.28,0.236,51.686) bbox = left,bottom,right,top bbox = min
* Longitude , min Latitude , max Longitude , max Latitude * Longitude , min Latitude , max Longitude , max Latitude
@ -93,8 +91,7 @@ public class ElasticsearchTemplateGeoTests {
.id("1").name("Artur Konczak") // .id("1").name("Artur Konczak") //
.locationAsString(latLonString) // .locationAsString(latLonString) //
.locationAsArray(lonLatArray) // .locationAsArray(lonLatArray) //
.locationAsGeoHash(geohash) .locationAsGeoHash(geohash).build();
.build();
LocationMarkerEntity location2 = LocationMarkerEntity.builder() // LocationMarkerEntity location2 = LocationMarkerEntity.builder() //
.id("2").name("Mohsin Husen") // .id("2").name("Mohsin Husen") //
.locationAsString(geohash.substring(0, 8)) // .locationAsString(geohash.substring(0, 8)) //
@ -421,8 +418,8 @@ public class ElasticsearchTemplateGeoTests {
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "test-index-location-marker-core-geo", type = "geo-annotation-point-type", shards = 1, replicas = 0, @Document(indexName = "test-index-location-marker-core-geo", type = "geo-annotation-point-type", shards = 1,
refreshInterval = "-1") replicas = 0, refreshInterval = "-1")
static class LocationMarkerEntity { static class LocationMarkerEntity {
@Id private String id; @Id private String id;

View File

@ -66,7 +66,7 @@ public class SimpleElasticsearchPersistentEntityTests {
// when // when
entity.addPersistentProperty(persistentProperty2); entity.addPersistentProperty(persistentProperty2);
} }
@Test // DATAES-462 @Test // DATAES-462
public void rejectsMultipleScoreProperties() { public void rejectsMultipleScoreProperties() {
@ -123,9 +123,9 @@ public class SimpleElasticsearchPersistentEntityTests {
} }
// DATAES-462 // DATAES-462
static class TwoScoreProperties { static class TwoScoreProperties {
@Score float first; @Score float first;
@Score float second; @Score float second;
} }

View File

@ -29,9 +29,9 @@ import org.springframework.data.elasticsearch.annotations.Document;
@Getter @Getter
public class ImmutableEntity { public class ImmutableEntity {
private final String id, name; private final String id, name;
public ImmutableEntity(String name) { public ImmutableEntity(String name) {
this.id = null; this.id = null;
this.name = name; this.name = name;
} }

View File

@ -49,7 +49,7 @@ class CdiRepositoryClient {
public QualifiedProductRepository getQualifiedProductRepository() { public QualifiedProductRepository getQualifiedProductRepository() {
return qualifiedProductRepository; return qualifiedProductRepository;
} }
@Inject @Inject
public void setQualifiedProductRepository( public void setQualifiedProductRepository(
@PersonDB @OtherQualifier QualifiedProductRepository qualifiedProductRepository) { @PersonDB @OtherQualifier QualifiedProductRepository qualifiedProductRepository) {

View File

@ -21,6 +21,7 @@ import org.springframework.data.repository.Repository;
* @author Mark Paluch * @author Mark Paluch
* @see DATAES-113 * @see DATAES-113
*/ */
public interface SamplePersonRepository extends Repository<CdiRepositoryTests.Person, Long>, SamplePersonRepositoryCustom { public interface SamplePersonRepository
extends Repository<CdiRepositoryTests.Person, Long>, SamplePersonRepositoryCustom {
} }

View File

@ -20,6 +20,8 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
/** /**
* @author Artur Konczak * @author Artur Konczak
*/ */
public interface ComplexElasticsearchRepository extends ElasticsearchRepository<ComplexCustomMethodRepositoryTests.SampleEntity, String>, ComplexElasticsearchRepositoryCustom { public interface ComplexElasticsearchRepository
extends ElasticsearchRepository<ComplexCustomMethodRepositoryTests.SampleEntity, String>,
ComplexElasticsearchRepositoryCustom {
} }

View File

@ -8,8 +8,7 @@ import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
*/ */
public class ComplexElasticsearchRepositoryImpl implements ComplexElasticsearchRepositoryCustom { public class ComplexElasticsearchRepositoryImpl implements ComplexElasticsearchRepositoryCustom {
@Autowired @Autowired private ElasticsearchTemplate template;
private ElasticsearchTemplate template;
@Override @Override
public String doSomethingSpecial() { public String doSomethingSpecial() {

View File

@ -21,6 +21,8 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
/** /**
* @author Artur Konczak * @author Artur Konczak
*/ */
public interface ComplexElasticsearchRepositoryManualWiring extends ElasticsearchRepository<ComplexCustomMethodRepositoryManualWiringTests.SampleEntity, String>, ComplexElasticsearchRepositoryCustom { public interface ComplexElasticsearchRepositoryManualWiring
extends ElasticsearchRepository<ComplexCustomMethodRepositoryManualWiringTests.SampleEntity, String>,
ComplexElasticsearchRepositoryCustom {
} }

View File

@ -103,7 +103,8 @@ public class SpringDataGeoRepositoryTests {
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "test-index-geo-repository", type = "geo-test-index", shards = 1, replicas = 0, refreshInterval = "-1") @Document(indexName = "test-index-geo-repository", type = "geo-test-index", shards = 1, replicas = 0,
refreshInterval = "-1")
static class GeoEntity { static class GeoEntity {
@Id private String id; @Id private String id;

View File

@ -88,11 +88,9 @@ public class FieldDynamicMappingEntityRepositoryTests {
@Document(indexName = "test-index-field-dynamic-mapping", type = "test-field-mapping-type") @Document(indexName = "test-index-field-dynamic-mapping", type = "test-field-mapping-type")
static class FieldDynamicMappingEntity { static class FieldDynamicMappingEntity {
@Id @Id private String id;
private String id;
@Mapping(mappingPath = "/mappings/test-field-mappings.json") @Mapping(mappingPath = "/mappings/test-field-mappings.json") private byte[] file;
private byte[] file;
public String getId() { public String getId() {
return id; return id;
@ -114,6 +112,7 @@ public class FieldDynamicMappingEntityRepositoryTests {
/** /**
* @author Ted Liang * @author Ted Liang
*/ */
public interface FieldDynamicMappingEntityRepository extends ElasticsearchCrudRepository<FieldDynamicMappingEntity, String> { } public interface FieldDynamicMappingEntityRepository
extends ElasticsearchCrudRepository<FieldDynamicMappingEntity, String> {}
} }

View File

@ -246,8 +246,7 @@ public class UUIDElasticsearchRepositoryTests {
// when // when
List<UUID> docIds = Arrays.asList(documentId, documentId2); List<UUID> docIds = Arrays.asList(documentId, documentId2);
List<SampleEntityUUIDKeyed> sampleEntities = (List<SampleEntityUUIDKeyed>) repository List<SampleEntityUUIDKeyed> sampleEntities = (List<SampleEntityUUIDKeyed>) repository.findAllById(docIds);
.findAllById(docIds);
// then // then
assertThat(sampleEntities).isNotNull().hasSize(2); assertThat(sampleEntities).isNotNull().hasSize(2);

View File

@ -113,7 +113,8 @@ public class ElasticsearchStringQueryUnitTests {
* @author Artur Konczak * @author Artur Konczak
*/ */
@Document(indexName = "test-index-person-query-unittest", type = "user", shards = 1, replicas = 0, refreshInterval = "-1") @Document(indexName = "test-index-person-query-unittest", type = "user", shards = 1, replicas = 0,
refreshInterval = "-1")
static class Person { static class Person {
@Id private String id; @Id private String id;
@ -177,7 +178,8 @@ public class ElasticsearchStringQueryUnitTests {
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "test-index-book-query-unittest", type = "book", shards = 1, replicas = 0, refreshInterval = "-1") @Document(indexName = "test-index-book-query-unittest", type = "book", shards = 1, replicas = 0,
refreshInterval = "-1")
static class Book { static class Book {
@Id private String id; @Id private String id;

View File

@ -146,8 +146,7 @@ public class ReactiveElasticsearchQueryMethodUnitTests {
* @author Artur Konczak * @author Artur Konczak
*/ */
@Document(indexName = INDEX_NAME, type = "user", shards = 1, replicas = 0, @Document(indexName = INDEX_NAME, type = "user", shards = 1, replicas = 0, refreshInterval = "-1")
refreshInterval = "-1")
static class Person { static class Person {
@Id private String id; @Id private String id;