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

View File

@ -15,13 +15,16 @@
*/
package org.springframework.data.elasticsearch;
import static java.util.Arrays.*;
import java.util.UUID;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.NodeValidationException;
import org.elasticsearch.transport.Netty4Plugin;
import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
import static java.util.Arrays.*;
/**
* @author Mohsin Husen
@ -36,14 +39,9 @@ public class Utils {
String pathData = "target/elasticsearchTestData";
String clusterName = UUID.randomUUID().toString();
return new NodeClientFactoryBean.TestNode(
Settings.builder()
.put("transport.type", "netty4")
.put("http.type", "netty4")
.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();
return new NodeClientFactoryBean.TestNode(Settings.builder().put("transport.type", "netty4")
.put("http.type", "netty4").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 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 java.io.IOException;
@ -41,12 +37,15 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
import org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockWebClientProvider.Send;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
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.RequestBodyUriSpec;
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriBuilder;
/**
* @author Christoph Strobl

View File

@ -75,7 +75,8 @@ public class EnableNestedElasticsearchRepositoriesTests {
@Data
@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 {
@Id private String id;

View File

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

View File

@ -30,7 +30,6 @@ import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
*/
public class CustomResultMapper implements ResultsMapper {
private EntityMapper entityMapper;
public CustomResultMapper(EntityMapper entityMapper) {
@ -44,12 +43,12 @@ public class CustomResultMapper implements ResultsMapper {
@Override
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
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

View File

@ -499,7 +499,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor
@AllArgsConstructor
@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 {
@Id private String id;
@ -515,8 +516,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
* @author Stuart Stevenson
* @author Mohsin Husen
*/
@Document(indexName = "test-index-simple-recursive-mapping-builder", type = "circular-object", shards = 1, replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-simple-recursive-mapping-builder", type = "circular-object", shards = 1,
replicas = 0, refreshInterval = "-1")
static class SimpleRecursiveEntity {
@Id private String id;
@ -551,7 +552,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor
@AllArgsConstructor
@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")
static class NormalizerEntity {
@ -650,7 +652,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor
@AllArgsConstructor
@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 {
@Id private String id;
@ -746,7 +749,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor
@AllArgsConstructor
@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 {
@Id private String id;

View File

@ -15,15 +15,16 @@
*/
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.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
import java.util.Arrays;
/**
* @author Remco Zigterman
*/

View File

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

View File

@ -51,9 +51,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Mohsin Husen
* @author Franck Marchand
* @author Artur Konczak
* @author Peter-Josef Meisch
*
* Basic info: latitude - horizontal lines (equator = 0.0, values -90.0 to 90.0) longitude -
* @author Peter-Josef Meisch 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 =
* 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
@ -93,8 +91,7 @@ public class ElasticsearchTemplateGeoTests {
.id("1").name("Artur Konczak") //
.locationAsString(latLonString) //
.locationAsArray(lonLatArray) //
.locationAsGeoHash(geohash)
.build();
.locationAsGeoHash(geohash).build();
LocationMarkerEntity location2 = LocationMarkerEntity.builder() //
.id("2").name("Mohsin Husen") //
.locationAsString(geohash.substring(0, 8)) //
@ -421,8 +418,8 @@ public class ElasticsearchTemplateGeoTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-location-marker-core-geo", type = "geo-annotation-point-type", shards = 1, replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-location-marker-core-geo", type = "geo-annotation-point-type", shards = 1,
replicas = 0, refreshInterval = "-1")
static class LocationMarkerEntity {
@Id private String id;

View File

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

View File

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

View File

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

View File

@ -21,6 +21,7 @@ import org.springframework.data.repository.Repository;
* @author Mark Paluch
* @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
*/
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 {
@Autowired
private ElasticsearchTemplate template;
@Autowired private ElasticsearchTemplate template;
@Override
public String doSomethingSpecial() {

View File

@ -21,6 +21,8 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
/**
* @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
@AllArgsConstructor
@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 {
@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")
static class FieldDynamicMappingEntity {
@Id
private String id;
@Id private String id;
@Mapping(mappingPath = "/mappings/test-field-mappings.json")
private byte[] file;
@Mapping(mappingPath = "/mappings/test-field-mappings.json") private byte[] file;
public String getId() {
return id;
@ -114,6 +112,7 @@ public class FieldDynamicMappingEntityRepositoryTests {
/**
* @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
List<UUID> docIds = Arrays.asList(documentId, documentId2);
List<SampleEntityUUIDKeyed> sampleEntities = (List<SampleEntityUUIDKeyed>) repository
.findAllById(docIds);
List<SampleEntityUUIDKeyed> sampleEntities = (List<SampleEntityUUIDKeyed>) repository.findAllById(docIds);
// then
assertThat(sampleEntities).isNotNull().hasSize(2);

View File

@ -113,7 +113,8 @@ public class ElasticsearchStringQueryUnitTests {
* @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 {
@Id private String id;
@ -177,7 +178,8 @@ public class ElasticsearchStringQueryUnitTests {
@NoArgsConstructor
@AllArgsConstructor
@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 {
@Id private String id;

View File

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