DATAES-328 - Integrate Data Commons Java 8 upgrade branch.

This commit is contained in:
Mark Paluch
2017-01-30 13:58:24 +01:00
parent 64bad236da
commit 0cada7f374
25 changed files with 447 additions and 372 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,11 +41,9 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.data.annotation.AccessType;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.core.DefaultResultMapperTests.ImmutableEntity;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
import org.springframework.data.elasticsearch.entities.Car;
@@ -53,6 +51,7 @@ import org.springframework.data.elasticsearch.entities.Car;
/**
* @author Artur Konczak
* @author Mohsin Husen
* @author Mark Paluch
*/
public class DefaultResultMapperTests {
@@ -85,7 +84,7 @@ public class DefaultResultMapperTests {
when(response.getAggregations()).thenReturn(aggregations);
//When
AggregatedPage<Car> page = (AggregatedPage<Car>) resultMapper.mapResults(response, Car.class, null);
AggregatedPage<Car> page = (AggregatedPage<Car>) resultMapper.mapResults(response, Car.class, Pageable.NONE);
//Then
page.hasFacets();
@@ -103,7 +102,7 @@ public class DefaultResultMapperTests {
when(response.getHits()).thenReturn(searchHits);
//When
Page<Car> page = resultMapper.mapResults(response, Car.class, null);
Page<Car> page = resultMapper.mapResults(response, Car.class, Pageable.NONE);
//Then
assertThat(page.hasContent(), is(true));
@@ -121,7 +120,7 @@ public class DefaultResultMapperTests {
when(response.getHits()).thenReturn(searchHits);
//When
Page<Car> page = resultMapper.mapResults(response, Car.class, null);
Page<Car> page = resultMapper.mapResults(response, Car.class, Pageable.NONE);
//Then
assertThat(page.hasContent(), is(true));
@@ -143,19 +142,19 @@ public class DefaultResultMapperTests {
assertThat(result.getModel(), is("Grat"));
assertThat(result.getName(), is("Ford"));
}
/**
* @see DATAES-281.
*/
@Test
public void setsIdentifierOnImmutableType() {
GetResponse response = mock(GetResponse.class);
when(response.getSourceAsString()).thenReturn("{}");
when(response.getId()).thenReturn("identifier");
ImmutableEntity result = resultMapper.mapResult(response, ImmutableEntity.class);
assertThat(result, is(notNullValue()));
assertThat(result.getId(), is("identifier"));
}
@@ -193,7 +192,7 @@ public class DefaultResultMapperTests {
result.put("model", new InternalSearchHitField("model", Arrays.<Object>asList(model)));
return result;
}
@Document(indexName = "someIndex")
@NoArgsConstructor(force = true)
@Getter

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +16,20 @@
package org.springframework.data.elasticsearch.core.mapping;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import org.junit.Test;
import org.springframework.data.annotation.Version;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ReflectionUtils;
/**
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Mark Paluch
*/
public class SimpleElasticsearchPersistentEntityTests {
@@ -35,46 +37,43 @@ public class SimpleElasticsearchPersistentEntityTests {
public void shouldThrowExceptionGivenVersionPropertyIsNotLong() throws NoSuchFieldException, IntrospectionException {
// given
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithWrongVersionType.class);
SimpleElasticsearchPersistentProperty persistentProperty = new SimpleElasticsearchPersistentProperty(
EntityWithWrongVersionType.class.getDeclaredField("version"), new PropertyDescriptor("version",
EntityWithWrongVersionType.class), new SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType>(
typeInformation), new SimpleTypeHolder()
);
SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType> entity = new SimpleElasticsearchPersistentEntity<>(
typeInformation);
SimpleElasticsearchPersistentProperty persistentProperty = createProperty(entity, "version");
// when
new SimpleElasticsearchPersistentEntity(typeInformation).addPersistentProperty(persistentProperty);
entity.addPersistentProperty(persistentProperty);
}
@Test(expected = MappingException.class)
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent() throws NoSuchFieldException,
IntrospectionException {
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent()
throws NoSuchFieldException, IntrospectionException {
// given
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithMultipleVersionField.class);
SimpleElasticsearchPersistentProperty persistentProperty1 = new SimpleElasticsearchPersistentProperty(
EntityWithMultipleVersionField.class.getDeclaredField("version1"), new PropertyDescriptor("version1",
EntityWithMultipleVersionField.class),
new SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField>(typeInformation),
new SimpleTypeHolder()
);
SimpleElasticsearchPersistentProperty persistentProperty2 = new SimpleElasticsearchPersistentProperty(
EntityWithMultipleVersionField.class.getDeclaredField("version2"), new PropertyDescriptor("version2",
EntityWithMultipleVersionField.class),
new SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField>(typeInformation),
new SimpleTypeHolder()
);
SimpleElasticsearchPersistentEntity simpleElasticsearchPersistentEntity = new SimpleElasticsearchPersistentEntity(
SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField> entity = new SimpleElasticsearchPersistentEntity<>(
typeInformation);
simpleElasticsearchPersistentEntity.addPersistentProperty(persistentProperty1);
SimpleElasticsearchPersistentProperty persistentProperty1 = createProperty(entity, "version1");
SimpleElasticsearchPersistentProperty persistentProperty2 = createProperty(entity, "version2");
entity.addPersistentProperty(persistentProperty1);
// when
simpleElasticsearchPersistentEntity.addPersistentProperty(persistentProperty2);
entity.addPersistentProperty(persistentProperty2);
}
private static SimpleElasticsearchPersistentProperty createProperty(SimpleElasticsearchPersistentEntity<?> entity,
String field) {
Property property = Property.of(ReflectionUtils.findField(entity.getTypeInformation().getType(), field));
return new SimpleElasticsearchPersistentProperty(property, entity, new SimpleTypeHolder());
}
private class EntityWithWrongVersionType {
@Version
private String version;
@Version private String version;
public String getVersion() {
return version;
@@ -87,10 +86,8 @@ public class SimpleElasticsearchPersistentEntityTests {
private class EntityWithMultipleVersionField {
@Version
private Long version1;
@Version
private Long version2;
@Version private Long version1;
@Version private Long version2;
public Long getVersion1() {
return version1;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@ package org.springframework.data.elasticsearch.immutable;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,6 +31,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Young Gu
* @author Oliver Gierke
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:immutable-repository-test.xml")
@@ -37,29 +40,34 @@ public class ImmutableElasticsearchRepositoryTests {
@Autowired ImmutableElasticsearchRepository repository;
@Autowired ElasticsearchOperations operations;
@Before
public void before() {
operations.deleteIndex(ImmutableEntity.class);
operations.createIndex(ImmutableEntity.class);
operations.refresh(ImmutableEntity.class);
}
/**
* @see DATAES-281
*/
@Test
public void shouldSaveAndFindImmutableDocument() {
// when
ImmutableEntity entity = repository.save(new ImmutableEntity("test name"));
assertThat(entity.getId(), is(notNullValue()));
// then
ImmutableEntity entityFromElasticSearch = repository.findOne(entity.getId());
assertThat(entityFromElasticSearch.getName(), is("test name"));
assertThat(entityFromElasticSearch.getId(), is(entity.getId()));
Optional<ImmutableEntity> entityFromElasticSearch = repository.findOne(entity.getId());
assertThat(entityFromElasticSearch.isPresent(), is(true));
entityFromElasticSearch.ifPresent(immutableEntity -> {
assertThat(immutableEntity.getName(), is("test name"));
assertThat(immutableEntity.getId(), is(entity.getId()));
});
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,17 @@
*/
package org.springframework.data.elasticsearch.repositories.cdi;
import java.util.Optional;
import org.springframework.data.elasticsearch.entities.Product;
import org.springframework.data.repository.CrudRepository;
/**
* @author Mohsin Husen
* @author Oliver Gierke
* @author Mark Paluch
*/
public interface CdiProductRepository extends CrudRepository<Product, String> {
Product findOne(String id);
Optional<Product> findOne(String id);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@ package org.springframework.data.elasticsearch.repositories.cdi;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.util.Optional;
import org.apache.webbeans.cditest.CdiTestContainer;
import org.apache.webbeans.cditest.CdiTestContainerLoader;
import org.junit.AfterClass;
@@ -70,10 +72,13 @@ public class CdiRepositoryTests {
assertTrue(repository.exists(bean.getId()));
Product retrieved = repository.findOne(bean.getId());
assertNotNull(retrieved);
assertEquals(bean.getId(), retrieved.getId());
assertEquals(bean.getName(), retrieved.getName());
Optional<Product> retrieved = repository.findOne(bean.getId());
assertTrue(retrieved.isPresent());
retrieved.ifPresent(product -> {
assertEquals(bean.getId(), product.getId());
assertEquals(bean.getName(), product.getName());
});
assertEquals(1, repository.count());
@@ -83,7 +88,7 @@ public class CdiRepositoryTests {
assertEquals(0, repository.count());
retrieved = repository.findOne(bean.getId());
assertNull(retrieved);
assertFalse(retrieved.isPresent());
}
/**
@@ -101,10 +106,13 @@ public class CdiRepositoryTests {
assertTrue(qualifiedProductRepository.exists(bean.getId()));
Product retrieved = qualifiedProductRepository.findOne(bean.getId());
assertNotNull(retrieved);
assertEquals(bean.getId(), retrieved.getId());
assertEquals(bean.getName(), retrieved.getName());
Optional<Product> retrieved = qualifiedProductRepository.findOne(bean.getId());
assertTrue(retrieved.isPresent());
retrieved.ifPresent(product -> {
assertEquals(bean.getId(), product.getId());
assertEquals(bean.getName(), product.getName());
});
assertEquals(1, qualifiedProductRepository.count());
@@ -114,7 +122,7 @@ public class CdiRepositoryTests {
assertEquals(0, qualifiedProductRepository.count());
retrieved = qualifiedProductRepository.findOne(bean.getId());
assertNull(retrieved);
assertFalse(retrieved.isPresent());
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,9 @@ package org.springframework.data.elasticsearch.repositories.geo;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.Locale;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,18 +32,16 @@ import org.springframework.data.geo.Point;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Locale;
/**
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/repository-spring-data-geo-support.xml")
public class SpringDataGeoRepositoryTests {
@Autowired
private ElasticsearchTemplate template;
@Autowired ElasticsearchTemplate template;
@Autowired
private SpringDataGeoRepository repository;
@Autowired SpringDataGeoRepository repository;
@Before
public void init() {
@@ -52,25 +53,25 @@ public class SpringDataGeoRepositoryTests {
@Test
public void shouldSaveAndLoadGeoPoints() {
//given
// given
final Point point = new Point(15, 25);
GeoEntity entity = GeoEntity.builder()
.pointA(point)
.pointB(new GeoPoint(point.getX(), point.getY()))
.pointC(toGeoString(point))
.pointD(toGeoArray(point))
.build();
//when
entity = repository.save(entity);
GeoEntity result = repository.findOne(entity.getId());
//then
GeoEntity entity = GeoEntity.builder().pointA(point).pointB(new GeoPoint(point.getX(), point.getY()))
.pointC(toGeoString(point)).pointD(toGeoArray(point)).build();
// when
GeoEntity saved = repository.save(entity);
Optional<GeoEntity> result = repository.findOne(entity.getId());
// then
assertThat(entity.getPointA().getX(), is(result.getPointA().getX()));
assertThat(entity.getPointA().getY(), is(result.getPointA().getY()));
assertThat(entity.getPointB().getLat(), is(result.getPointB().getLat()));
assertThat(entity.getPointB().getLon(), is(result.getPointB().getLon()));
assertThat(entity.getPointC(), is(result.getPointC()));
assertThat(entity.getPointD(), is(result.getPointD()));
assertThat(result.isPresent(), is(true));
result.ifPresent(geoEntity -> {
assertThat(saved.getPointA().getX(), is(geoEntity.getPointA().getX()));
assertThat(saved.getPointA().getY(), is(geoEntity.getPointA().getY()));
assertThat(saved.getPointB().getLat(), is(geoEntity.getPointB().getLat()));
assertThat(saved.getPointB().getLon(), is(geoEntity.getPointB().getLon()));
assertThat(saved.getPointC(), is(geoEntity.getPointC()));
assertThat(saved.getPointD(), is(geoEntity.getPointD()));
});
}
private String toGeoString(Point point) {
@@ -78,8 +79,6 @@ public class SpringDataGeoRepositoryTests {
}
private double[] toGeoArray(Point point) {
return new double[]{
point.getX(), point.getY()
};
return new double[] { point.getX(), point.getY() };
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Optional;
import org.apache.commons.lang.math.RandomUtils;
import org.junit.Before;
@@ -34,8 +35,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/double-id-repository-test.xml")
public class DoubleIDRepositoryTests {
@@ -72,11 +73,11 @@ public class DoubleIDRepositoryTests {
// when
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
// then
DoubleIDEntity entity1FromElasticSearch = repository.findOne(documentId1);
assertThat(entity1FromElasticSearch, is(notNullValue()));
Optional<DoubleIDEntity> entity1FromElasticSearch = repository.findOne(documentId1);
assertThat(entity1FromElasticSearch.isPresent(), is(true));
DoubleIDEntity entity2FromElasticSearch = repository.findOne(documentId2);
assertThat(entity2FromElasticSearch, is(notNullValue()));
Optional<DoubleIDEntity> entity2FromElasticSearch = repository.findOne(documentId2);
assertThat(entity2FromElasticSearch.isPresent(), is(true));
}
@Test
@@ -90,7 +91,7 @@ public class DoubleIDRepositoryTests {
// when
repository.save(sampleEntity);
// then
DoubleIDEntity entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch, is(notNullValue()));
Optional<DoubleIDEntity> entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch.isPresent(), is(true));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,10 @@
*/
package org.springframework.data.elasticsearch.repository.support;
import static org.mockito.Mockito.*;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -24,19 +28,17 @@ import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersiste
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
import org.springframework.data.mapping.context.MappingContext;
import static org.mockito.Mockito.doReturn;
/**
* @author Florian Hopf
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class ElasticsearchEntityInformationCreatorImplTests {
@Mock
private MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
@Mock
private ElasticsearchPersistentEntity<String> persistentEntity;
private ElasticsearchEntityInformationCreatorImpl entityInfoCreator;
@Mock MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
@Mock ElasticsearchPersistentEntity<String> persistentEntity;
ElasticsearchEntityInformationCreatorImpl entityInfoCreator;
@Before
public void before() {
@@ -50,9 +52,9 @@ public class ElasticsearchEntityInformationCreatorImplTests {
@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionOnMissingIdAnnotation() {
doReturn(persistentEntity).when(mappingContext).getPersistentEntity(String.class);
doReturn(Optional.of(persistentEntity)).when(mappingContext).getPersistentEntity(String.class);
doReturn(String.class).when(persistentEntity).getType();
doReturn(null).when(persistentEntity).getIdProperty();
doReturn(Optional.empty()).when(persistentEntity).getIdProperty();
entityInfoCreator.getEntityInformation(String.class);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,13 +29,14 @@ import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersiste
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
/**
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class ElasticsearchRepositoryFactoryTests {
@@ -56,7 +57,7 @@ public class ElasticsearchRepositoryFactoryTests {
@Test(expected = IllegalArgumentException.class)
public void shouldThrowExceptionGivenQueryDslRepository() {
// given
RepositoryMetadata metadata = new DefaultRepositoryMetadata(QueryDslPredicateExecutor.class);
RepositoryMetadata metadata = new DefaultRepositoryMetadata(QuerydslPredicateExecutor.class);
// when
factory.getRepositoryBaseClass(metadata);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Optional;
import org.apache.commons.lang.math.RandomUtils;
import org.junit.Before;
@@ -34,8 +35,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/integer-id-repository-test.xml")
public class IntegerIDRepositoryTests {
@@ -72,11 +73,11 @@ public class IntegerIDRepositoryTests {
// when
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
// then
IntegerIDEntity entity1FromElasticSearch = repository.findOne(documentId1);
assertThat(entity1FromElasticSearch, is(notNullValue()));
Optional<IntegerIDEntity> entity1FromElasticSearch = repository.findOne(documentId1);
assertThat(entity1FromElasticSearch.isPresent(), is(true));
IntegerIDEntity entity2FromElasticSearch = repository.findOne(documentId2);
assertThat(entity2FromElasticSearch, is(notNullValue()));
Optional<IntegerIDEntity> entity2FromElasticSearch = repository.findOne(documentId2);
assertThat(entity2FromElasticSearch.isPresent(), is(true));
}
@Test
@@ -90,7 +91,7 @@ public class IntegerIDRepositoryTests {
// when
repository.save(sampleEntity);
// then
IntegerIDEntity entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch, is(notNullValue()));
Optional<IntegerIDEntity> entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch.isPresent(), is(true));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
import org.junit.Before;
@@ -43,8 +44,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/simple-repository-test.xml")
public class SimpleElasticsearchRepositoryTests {
@@ -81,11 +82,11 @@ public class SimpleElasticsearchRepositoryTests {
// when
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
// then
SampleEntity entity1FromElasticSearch = repository.findOne(documentId1);
assertThat(entity1FromElasticSearch, is(notNullValue()));
Optional<SampleEntity> entity1FromElasticSearch = repository.findOne(documentId1);
assertThat(entity1FromElasticSearch.isPresent(), is(true));
SampleEntity entity2FromElasticSearch = repository.findOne(documentId2);
assertThat(entity2FromElasticSearch, is(notNullValue()));
Optional<SampleEntity> entity2FromElasticSearch = repository.findOne(documentId2);
assertThat(entity2FromElasticSearch.isPresent(), is(true));
}
@Test
@@ -99,8 +100,8 @@ public class SimpleElasticsearchRepositoryTests {
// when
repository.save(sampleEntity);
// then
SampleEntity entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch, is(notNullValue()));
Optional<SampleEntity> entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch.isPresent(), is(true));
}
@Test
@@ -125,9 +126,9 @@ public class SimpleElasticsearchRepositoryTests {
sampleEntity.setVersion(System.currentTimeMillis());
repository.save(sampleEntity);
// when
SampleEntity entityFromElasticSearch = repository.findOne(documentId);
Optional<SampleEntity> entityFromElasticSearch = repository.findOne(documentId);
// then
assertThat(entityFromElasticSearch, is(notNullValue()));
assertThat(entityFromElasticSearch.isPresent(), is(true));
assertThat(sampleEntity, is((equalTo(sampleEntity))));
}
@@ -166,8 +167,8 @@ public class SimpleElasticsearchRepositoryTests {
// when
repository.delete(documentId);
// then
SampleEntity entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch, is(nullValue()));
Optional<SampleEntity> entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch.isPresent(), is(false));
}
@Test
@@ -474,8 +475,8 @@ public class SimpleElasticsearchRepositoryTests {
// when
repository.delete(sampleEntities);
// then
assertThat(repository.findOne(documentId1), is(nullValue()));
assertThat(repository.findOne(documentId2), is(nullValue()));
assertThat(repository.findOne(documentId1).isPresent(), is(false));
assertThat(repository.findOne(documentId2).isPresent(), is(false));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,8 +40,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Gad Akuka
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/simple-repository-test.xml")
public class UUIDElasticsearchRepositoryTests {
@@ -79,11 +79,11 @@ public class UUIDElasticsearchRepositoryTests {
// when
repository.save(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2));
// then
SampleEntityUUIDKeyed entity1FromElasticSearch = repository.findOne(documentId1);
assertThat(entity1FromElasticSearch, is(notNullValue()));
Optional<SampleEntityUUIDKeyed> entity1FromElasticSearch = repository.findOne(documentId1);
assertThat(entity1FromElasticSearch.isPresent(), is(true));
SampleEntityUUIDKeyed entity2FromElasticSearch = repository.findOne(documentId2);
assertThat(entity2FromElasticSearch, is(notNullValue()));
Optional<SampleEntityUUIDKeyed> entity2FromElasticSearch = repository.findOne(documentId2);
assertThat(entity2FromElasticSearch.isPresent(), is(true));
}
@Test
@@ -97,8 +97,8 @@ public class UUIDElasticsearchRepositoryTests {
// when
repository.save(sampleEntityUUIDKeyed);
// then
SampleEntityUUIDKeyed entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch, is(notNullValue()));
Optional<SampleEntityUUIDKeyed> entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch.isPresent(), is(true));
}
@Test
@@ -111,9 +111,9 @@ public class UUIDElasticsearchRepositoryTests {
sampleEntityUUIDKeyed.setVersion(System.currentTimeMillis());
repository.save(sampleEntityUUIDKeyed);
// when
SampleEntityUUIDKeyed entityFromElasticSearch = repository.findOne(documentId);
Optional<SampleEntityUUIDKeyed> entityFromElasticSearch = repository.findOne(documentId);
// then
assertThat(entityFromElasticSearch, is(notNullValue()));
assertThat(entityFromElasticSearch.isPresent(), is(true));
assertThat(sampleEntityUUIDKeyed, is((equalTo(sampleEntityUUIDKeyed))));
}
@@ -152,8 +152,8 @@ public class UUIDElasticsearchRepositoryTests {
// when
repository.delete(documentId);
// then
SampleEntityUUIDKeyed entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch, is(nullValue()));
Optional<SampleEntityUUIDKeyed> entityFromElasticSearch = repository.findOne(documentId);
assertThat(entityFromElasticSearch.isPresent(), is(false));
}
@Test
@@ -445,8 +445,8 @@ public class UUIDElasticsearchRepositoryTests {
// when
repository.delete(sampleEntities);
// then
assertThat(repository.findOne(documentId1), is(nullValue()));
assertThat(repository.findOne(documentId2), is(nullValue()));
assertThat(repository.findOne(documentId1).isPresent(), is(false));
assertThat(repository.findOne(documentId2).isPresent(), is(false));
}
@Test