DATAES-352 - Adapt to API changes in repository interfaces.
We now follow a more consistent naming scheme for the methods in repository that are driven by the following guidelines: * Methods referring to an identifier now all end on …ById(…). * Methods taking or returning a collection are named …All(…) Please see DATACMNS-944 for details.
This commit is contained in:
committed by
Oliver Gierke
parent
939c0f96f4
commit
416a3f2baf
@@ -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.
|
||||
@@ -33,17 +33,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-test-nested-object.xml")
|
||||
public class InnerObjectTests {
|
||||
|
||||
@Autowired
|
||||
private SampleElasticSearchBookRepository bookRepository;
|
||||
@Autowired private SampleElasticSearchBookRepository bookRepository;
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@@ -67,6 +66,6 @@ public class InnerObjectTests {
|
||||
// when
|
||||
bookRepository.save(book);
|
||||
// then
|
||||
assertThat(bookRepository.findOne(id), is(notNullValue()));
|
||||
assertThat(bookRepository.findById(id), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Young Gu
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:immutable-repository-test.xml")
|
||||
@@ -59,7 +60,7 @@ public class ImmutableElasticsearchRepositoryTests {
|
||||
assertThat(entity.getId(), is(notNullValue()));
|
||||
|
||||
// then
|
||||
Optional<ImmutableEntity> entityFromElasticSearch = repository.findOne(entity.getId());
|
||||
Optional<ImmutableEntity> entityFromElasticSearch = repository.findById(entity.getId());
|
||||
|
||||
assertThat(entityFromElasticSearch.isPresent(), is(true));
|
||||
|
||||
|
||||
@@ -47,16 +47,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Mohsin Husen
|
||||
* @author Franck Marchand
|
||||
* @author Kevin Leturc
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:custom-method-repository-test.xml")
|
||||
public class CustomMethodRepositoryTests {
|
||||
|
||||
@Autowired
|
||||
private SampleCustomMethodRepository repository;
|
||||
@Autowired private SampleCustomMethodRepository repository;
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@@ -460,8 +459,8 @@ public class CustomMethodRepositoryTests {
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity3);
|
||||
// when
|
||||
Page<SampleEntity> pageResult = repository.findByMessageContaining("a", new PageRequest(0, 23, new Sort(
|
||||
new Sort.Order(Sort.Direction.DESC, "message"))));
|
||||
Page<SampleEntity> pageResult = repository.findByMessageContaining("a",
|
||||
new PageRequest(0, 23, new Sort(new Sort.Order(Sort.Direction.DESC, "message"))));
|
||||
// then
|
||||
assertThat(pageResult.getContent().isEmpty(), is(false));
|
||||
assertThat(pageResult.getContent().get(0).getMessage(), is(sampleEntity3.getMessage()));
|
||||
@@ -541,7 +540,8 @@ public class CustomMethodRepositoryTests {
|
||||
repository.save(sampleEntity);
|
||||
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByLocationAndMessage(new GeoPoint(45.7806d, 3.0875d), "foo", new PageRequest(0, 10));
|
||||
Page<SampleEntity> page = repository.findByLocationAndMessage(new GeoPoint(45.7806d, 3.0875d), "foo",
|
||||
new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
@@ -561,7 +561,8 @@ public class CustomMethodRepositoryTests {
|
||||
repository.save(sampleEntity);
|
||||
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByLocationWithin(new GeoPoint(45.7806d, 3.0875d), "2km", new PageRequest(0, 10));
|
||||
Page<SampleEntity> page = repository.findByLocationWithin(new GeoPoint(45.7806d, 3.0875d), "2km",
|
||||
new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
@@ -581,7 +582,8 @@ public class CustomMethodRepositoryTests {
|
||||
repository.save(sampleEntity);
|
||||
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByLocationWithin(new Point(45.7806d, 3.0875d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
|
||||
Page<SampleEntity> page = repository.findByLocationWithin(new Point(45.7806d, 3.0875d),
|
||||
new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
@@ -617,7 +619,8 @@ public class CustomMethodRepositoryTests {
|
||||
assertThat(pageAll.getTotalElements(), is(equalTo(2L)));
|
||||
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByLocationNear(new Box(new Point(46d, 3d), new Point(45d, 4d)), new PageRequest(0, 10));
|
||||
Page<SampleEntity> page = repository.findByLocationNear(new Box(new Point(46d, 3d), new Point(45d, 4d)),
|
||||
new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
@@ -637,7 +640,8 @@ public class CustomMethodRepositoryTests {
|
||||
repository.save(sampleEntity);
|
||||
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByLocationNear(new Point(45.7806d, 3.0875d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
|
||||
Page<SampleEntity> page = repository.findByLocationNear(new Point(45.7806d, 3.0875d),
|
||||
new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
@@ -650,7 +654,7 @@ public class CustomMethodRepositoryTests {
|
||||
public void shouldAllowReturningJava8StreamInCustomQuery() {
|
||||
// given
|
||||
List<SampleEntity> entities = createSampleEntities("abc", 30);
|
||||
repository.save(entities);
|
||||
repository.saveAll(entities);
|
||||
|
||||
// when
|
||||
Stream<SampleEntity> stream = repository.findByType("abc");
|
||||
@@ -1206,4 +1210,3 @@ public class CustomMethodRepositoryTests {
|
||||
return entities;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,9 @@ import org.springframework.data.repository.CrudRepository;
|
||||
* @author Mohsin Husen
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface CdiProductRepository extends CrudRepository<Product, String> {
|
||||
|
||||
Optional<Product> findOne(String id);
|
||||
Optional<Product> findById(String id);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.data.elasticsearch.entities.Product;
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class CdiRepositoryTests {
|
||||
|
||||
@@ -70,9 +71,9 @@ public class CdiRepositoryTests {
|
||||
|
||||
repository.save(bean);
|
||||
|
||||
assertTrue(repository.exists(bean.getId()));
|
||||
assertTrue(repository.existsById(bean.getId()));
|
||||
|
||||
Optional<Product> retrieved = repository.findOne(bean.getId());
|
||||
Optional<Product> retrieved = repository.findById(bean.getId());
|
||||
|
||||
assertTrue(retrieved.isPresent());
|
||||
retrieved.ifPresent(product -> {
|
||||
@@ -82,12 +83,12 @@ public class CdiRepositoryTests {
|
||||
|
||||
assertEquals(1, repository.count());
|
||||
|
||||
assertTrue(repository.exists(bean.getId()));
|
||||
assertTrue(repository.existsById(bean.getId()));
|
||||
|
||||
repository.delete(bean);
|
||||
|
||||
assertEquals(0, repository.count());
|
||||
retrieved = repository.findOne(bean.getId());
|
||||
retrieved = repository.findById(bean.getId());
|
||||
assertFalse(retrieved.isPresent());
|
||||
}
|
||||
|
||||
@@ -104,9 +105,9 @@ public class CdiRepositoryTests {
|
||||
|
||||
qualifiedProductRepository.save(bean);
|
||||
|
||||
assertTrue(qualifiedProductRepository.exists(bean.getId()));
|
||||
assertTrue(qualifiedProductRepository.existsById(bean.getId()));
|
||||
|
||||
Optional<Product> retrieved = qualifiedProductRepository.findOne(bean.getId());
|
||||
Optional<Product> retrieved = qualifiedProductRepository.findById(bean.getId());
|
||||
|
||||
assertTrue(retrieved.isPresent());
|
||||
retrieved.ifPresent(product -> {
|
||||
@@ -116,12 +117,12 @@ public class CdiRepositoryTests {
|
||||
|
||||
assertEquals(1, qualifiedProductRepository.count());
|
||||
|
||||
assertTrue(qualifiedProductRepository.exists(bean.getId()));
|
||||
assertTrue(qualifiedProductRepository.existsById(bean.getId()));
|
||||
|
||||
qualifiedProductRepository.delete(bean);
|
||||
|
||||
assertEquals(0, qualifiedProductRepository.count());
|
||||
retrieved = qualifiedProductRepository.findOne(bean.getId());
|
||||
retrieved = qualifiedProductRepository.findById(bean.getId());
|
||||
assertFalse(retrieved.isPresent());
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-spring-data-geo-support.xml")
|
||||
@@ -59,7 +60,7 @@ public class SpringDataGeoRepositoryTests {
|
||||
.pointC(toGeoString(point)).pointD(toGeoArray(point)).build();
|
||||
// when
|
||||
GeoEntity saved = repository.save(entity);
|
||||
Optional<GeoEntity> result = repository.findOne(entity.getId());
|
||||
Optional<GeoEntity> result = repository.findById(entity.getId());
|
||||
// then
|
||||
|
||||
assertThat(result.isPresent(), is(true));
|
||||
|
||||
@@ -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.
|
||||
@@ -23,12 +23,16 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface SampleElasticsearchRepository extends ElasticsearchRepository<SampleEntity, String> {
|
||||
|
||||
long deleteById(String id);
|
||||
long deleteSampleEntityById(String id);
|
||||
|
||||
List<SampleEntity> deleteByAvailable(boolean available);
|
||||
|
||||
List<SampleEntity> deleteByMessage(String message);
|
||||
|
||||
void deleteByType(String type);
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -23,12 +23,16 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
|
||||
|
||||
/**
|
||||
* @author Gad Akuka
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface SampleUUIDKeyedElasticsearchRepository extends ElasticsearchRepository<SampleEntityUUIDKeyed, UUID> {
|
||||
|
||||
long deleteById(UUID id);
|
||||
long deleteSampleEntityUUIDKeyedById(UUID id);
|
||||
|
||||
List<SampleEntityUUIDKeyed> deleteByAvailable(boolean available);
|
||||
|
||||
List<SampleEntityUUIDKeyed> deleteByMessage(String message);
|
||||
|
||||
void deleteByType(String type);
|
||||
|
||||
}
|
||||
|
||||
@@ -36,17 +36,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/double-id-repository-test.xml")
|
||||
public class DoubleIDRepositoryTests {
|
||||
|
||||
@Autowired
|
||||
private DoubleIDRepository repository;
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
@Autowired private DoubleIDRepository repository;
|
||||
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@@ -71,12 +69,12 @@ public class DoubleIDRepositoryTests {
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
// when
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
// then
|
||||
Optional<DoubleIDEntity> entity1FromElasticSearch = repository.findOne(documentId1);
|
||||
Optional<DoubleIDEntity> entity1FromElasticSearch = repository.findById(documentId1);
|
||||
assertThat(entity1FromElasticSearch.isPresent(), is(true));
|
||||
|
||||
Optional<DoubleIDEntity> entity2FromElasticSearch = repository.findOne(documentId2);
|
||||
Optional<DoubleIDEntity> entity2FromElasticSearch = repository.findById(documentId2);
|
||||
assertThat(entity2FromElasticSearch.isPresent(), is(true));
|
||||
}
|
||||
|
||||
@@ -91,7 +89,7 @@ public class DoubleIDRepositoryTests {
|
||||
// when
|
||||
repository.save(sampleEntity);
|
||||
// then
|
||||
Optional<DoubleIDEntity> entityFromElasticSearch = repository.findOne(documentId);
|
||||
Optional<DoubleIDEntity> entityFromElasticSearch = repository.findById(documentId);
|
||||
assertThat(entityFromElasticSearch.isPresent(), is(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,17 +36,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/integer-id-repository-test.xml")
|
||||
public class IntegerIDRepositoryTests {
|
||||
|
||||
@Autowired
|
||||
private IntegerIDRepository repository;
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
@Autowired private IntegerIDRepository repository;
|
||||
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@@ -71,12 +69,12 @@ public class IntegerIDRepositoryTests {
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
// when
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
// then
|
||||
Optional<IntegerIDEntity> entity1FromElasticSearch = repository.findOne(documentId1);
|
||||
Optional<IntegerIDEntity> entity1FromElasticSearch = repository.findById(documentId1);
|
||||
assertThat(entity1FromElasticSearch.isPresent(), is(true));
|
||||
|
||||
Optional<IntegerIDEntity> entity2FromElasticSearch = repository.findOne(documentId2);
|
||||
Optional<IntegerIDEntity> entity2FromElasticSearch = repository.findById(documentId2);
|
||||
assertThat(entity2FromElasticSearch.isPresent(), is(true));
|
||||
}
|
||||
|
||||
@@ -91,7 +89,7 @@ public class IntegerIDRepositoryTests {
|
||||
// when
|
||||
repository.save(sampleEntity);
|
||||
// then
|
||||
Optional<IntegerIDEntity> entityFromElasticSearch = repository.findOne(documentId);
|
||||
Optional<IntegerIDEntity> entityFromElasticSearch = repository.findById(documentId);
|
||||
assertThat(entityFromElasticSearch.isPresent(), is(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-query-support.xml")
|
||||
@@ -50,7 +51,7 @@ public class QueryKeywordsTests {
|
||||
elasticsearchTemplate.putMapping(Product.class);
|
||||
elasticsearchTemplate.refresh(Product.class);
|
||||
|
||||
repository.save(Arrays.asList(
|
||||
repository.saveAll(Arrays.asList(
|
||||
Product.builder().id("1").name("Sugar").text("Cane sugar").price(1.0f).available(false).build()
|
||||
, Product.builder().id("2").name("Sugar").text("Cane sugar").price(1.2f).available(true).build()
|
||||
, Product.builder().id("3").name("Sugar").text("Beet sugar").price(1.1f).available(true).build()
|
||||
|
||||
@@ -46,17 +46,15 @@ import com.google.common.collect.Lists;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
||||
public class SimpleElasticsearchRepositoryTests {
|
||||
|
||||
@Autowired
|
||||
private SampleElasticsearchRepository repository;
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
@Autowired private SampleElasticsearchRepository repository;
|
||||
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@@ -81,12 +79,12 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
// when
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
// then
|
||||
Optional<SampleEntity> entity1FromElasticSearch = repository.findOne(documentId1);
|
||||
Optional<SampleEntity> entity1FromElasticSearch = repository.findById(documentId1);
|
||||
assertThat(entity1FromElasticSearch.isPresent(), is(true));
|
||||
|
||||
Optional<SampleEntity> entity2FromElasticSearch = repository.findOne(documentId2);
|
||||
Optional<SampleEntity> entity2FromElasticSearch = repository.findById(documentId2);
|
||||
assertThat(entity2FromElasticSearch.isPresent(), is(true));
|
||||
}
|
||||
|
||||
@@ -101,7 +99,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
// when
|
||||
repository.save(sampleEntity);
|
||||
// then
|
||||
Optional<SampleEntity> entityFromElasticSearch = repository.findOne(documentId);
|
||||
Optional<SampleEntity> entityFromElasticSearch = repository.findById(documentId);
|
||||
assertThat(entityFromElasticSearch.isPresent(), is(true));
|
||||
}
|
||||
|
||||
@@ -127,7 +125,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Optional<SampleEntity> entityFromElasticSearch = repository.findOne(documentId);
|
||||
Optional<SampleEntity> entityFromElasticSearch = repository.findById(documentId);
|
||||
// then
|
||||
assertThat(entityFromElasticSearch.isPresent(), is(true));
|
||||
assertThat(sampleEntity, is((equalTo(sampleEntity))));
|
||||
@@ -166,9 +164,9 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
repository.delete(documentId);
|
||||
repository.deleteById(documentId);
|
||||
// then
|
||||
Optional<SampleEntity> entityFromElasticSearch = repository.findOne(documentId);
|
||||
Optional<SampleEntity> entityFromElasticSearch = repository.findById(documentId);
|
||||
assertThat(entityFromElasticSearch.isPresent(), is(false));
|
||||
}
|
||||
|
||||
@@ -227,7 +225,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
// when
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Arrays.asList(documentId, documentId2));
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAllById(Arrays.asList(documentId, documentId2));
|
||||
|
||||
// then
|
||||
assertNotNull("sample entities cant be null..", sampleEntities);
|
||||
@@ -252,7 +250,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
|
||||
Iterable<SampleEntity> sampleEntities = Arrays.asList(sampleEntity1, sampleEntity2);
|
||||
// when
|
||||
repository.save(sampleEntities);
|
||||
repository.saveAll(sampleEntities);
|
||||
// then
|
||||
Page<SampleEntity> entities = repository.search(termQuery("id", documentId), new PageRequest(0, 50));
|
||||
assertNotNull(entities);
|
||||
@@ -269,7 +267,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
repository.save(sampleEntity);
|
||||
|
||||
// when
|
||||
boolean exist = repository.exists(documentId);
|
||||
boolean exist = repository.existsById(documentId);
|
||||
|
||||
// then
|
||||
assertEquals(exist, true);
|
||||
@@ -311,7 +309,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
long result = repository.deleteById(documentId);
|
||||
long result = repository.deleteSampleEntityById(documentId);
|
||||
repository.refresh();
|
||||
|
||||
// then
|
||||
@@ -344,7 +342,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
sampleEntity3.setMessage("hello world 3");
|
||||
sampleEntity3.setAvailable(false);
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3));
|
||||
repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3));
|
||||
// when
|
||||
List<SampleEntity> result = repository.deleteByAvailable(true);
|
||||
repository.refresh();
|
||||
@@ -375,7 +373,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
sampleEntity3.setId(documentId);
|
||||
sampleEntity3.setMessage("hello world 3");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3));
|
||||
repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3));
|
||||
// when
|
||||
List<SampleEntity> result = repository.deleteByMessage("hello world 3");
|
||||
repository.refresh();
|
||||
@@ -406,7 +404,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
sampleEntity3.setId(documentId);
|
||||
sampleEntity3.setType("image");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3));
|
||||
repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3));
|
||||
// when
|
||||
repository.deleteByType("article");
|
||||
repository.refresh();
|
||||
@@ -474,10 +472,10 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
|
||||
Iterable<SampleEntity> sampleEntities = Arrays.asList(sampleEntity2, sampleEntity2);
|
||||
// when
|
||||
repository.delete(sampleEntities);
|
||||
repository.deleteAll(sampleEntities);
|
||||
// then
|
||||
assertThat(repository.findOne(documentId1).isPresent(), is(false));
|
||||
assertThat(repository.findOne(documentId2).isPresent(), is(false));
|
||||
assertThat(repository.findById(documentId1).isPresent(), is(false));
|
||||
assertThat(repository.findById(documentId2).isPresent(), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -525,10 +523,11 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
+ "we want real-time search, we want simple multi-tenancy, and we want a solution that is built for the cloud.";
|
||||
|
||||
List<SampleEntity> sampleEntities = createSampleEntitiesWithMessage(sampleMessage, 30);
|
||||
repository.save(sampleEntities);
|
||||
repository.saveAll(sampleEntities);
|
||||
|
||||
// when
|
||||
Page<SampleEntity> results = repository.searchSimilar(sampleEntities.get(0), new String[]{"message"}, new PageRequest(0, 5));
|
||||
Page<SampleEntity> results = repository.searchSimilar(sampleEntities.get(0), new String[] { "message" },
|
||||
new PageRequest(0, 5));
|
||||
|
||||
// then
|
||||
assertThat(results.getTotalElements(), is(greaterThanOrEqualTo(1L)));
|
||||
|
||||
@@ -46,17 +46,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
||||
public class UUIDElasticsearchRepositoryTests {
|
||||
|
||||
@Autowired
|
||||
private SampleUUIDKeyedElasticsearchRepository repository;
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
@Autowired private SampleUUIDKeyedElasticsearchRepository repository;
|
||||
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@@ -82,12 +80,12 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
sampleEntityUUIDKeyed2.setVersion(System.currentTimeMillis());
|
||||
|
||||
// when
|
||||
repository.save(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2));
|
||||
repository.saveAll(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2));
|
||||
// then
|
||||
Optional<SampleEntityUUIDKeyed> entity1FromElasticSearch = repository.findOne(documentId1);
|
||||
Optional<SampleEntityUUIDKeyed> entity1FromElasticSearch = repository.findById(documentId1);
|
||||
assertThat(entity1FromElasticSearch.isPresent(), is(true));
|
||||
|
||||
Optional<SampleEntityUUIDKeyed> entity2FromElasticSearch = repository.findOne(documentId2);
|
||||
Optional<SampleEntityUUIDKeyed> entity2FromElasticSearch = repository.findById(documentId2);
|
||||
assertThat(entity2FromElasticSearch.isPresent(), is(true));
|
||||
}
|
||||
|
||||
@@ -102,7 +100,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
// when
|
||||
repository.save(sampleEntityUUIDKeyed);
|
||||
// then
|
||||
Optional<SampleEntityUUIDKeyed> entityFromElasticSearch = repository.findOne(documentId);
|
||||
Optional<SampleEntityUUIDKeyed> entityFromElasticSearch = repository.findById(documentId);
|
||||
assertThat(entityFromElasticSearch.isPresent(), is(true));
|
||||
}
|
||||
|
||||
@@ -116,7 +114,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
sampleEntityUUIDKeyed.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntityUUIDKeyed);
|
||||
// when
|
||||
Optional<SampleEntityUUIDKeyed> entityFromElasticSearch = repository.findOne(documentId);
|
||||
Optional<SampleEntityUUIDKeyed> entityFromElasticSearch = repository.findById(documentId);
|
||||
// then
|
||||
assertThat(entityFromElasticSearch.isPresent(), is(true));
|
||||
assertThat(sampleEntityUUIDKeyed, is((equalTo(sampleEntityUUIDKeyed))));
|
||||
@@ -155,9 +153,9 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
sampleEntityUUIDKeyed.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntityUUIDKeyed);
|
||||
// when
|
||||
repository.delete(documentId);
|
||||
repository.deleteById(documentId);
|
||||
// then
|
||||
Optional<SampleEntityUUIDKeyed> entityFromElasticSearch = repository.findOne(documentId);
|
||||
Optional<SampleEntityUUIDKeyed> entityFromElasticSearch = repository.findById(documentId);
|
||||
assertThat(entityFromElasticSearch.isPresent(), is(false));
|
||||
}
|
||||
|
||||
@@ -216,7 +214,8 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
repository.save(sampleEntityUUIDKeyed2);
|
||||
|
||||
// when
|
||||
LinkedList<SampleEntityUUIDKeyed> sampleEntities = (LinkedList<SampleEntityUUIDKeyed>) repository.findAll(Arrays.asList(documentId, documentId2));
|
||||
LinkedList<SampleEntityUUIDKeyed> sampleEntities = (LinkedList<SampleEntityUUIDKeyed>) repository
|
||||
.findAllById(Arrays.asList(documentId, documentId2));
|
||||
|
||||
// then
|
||||
assertNotNull("sample entities cant be null..", sampleEntities);
|
||||
@@ -242,7 +241,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2);
|
||||
// when
|
||||
repository.save(sampleEntities);
|
||||
repository.saveAll(sampleEntities);
|
||||
// then
|
||||
Page<SampleEntityUUIDKeyed> entities = repository.search(termQuery("id", documentId), new PageRequest(0, 50));
|
||||
assertNotNull(entities);
|
||||
@@ -259,7 +258,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
repository.save(sampleEntityUUIDKeyed);
|
||||
|
||||
// when
|
||||
boolean exist = repository.exists(documentId);
|
||||
boolean exist = repository.existsById(documentId);
|
||||
|
||||
// then
|
||||
assertEquals(exist, true);
|
||||
@@ -285,7 +284,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
sampleEntityUUIDKeyed.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntityUUIDKeyed);
|
||||
// when
|
||||
long result = repository.deleteById(documentId);
|
||||
long result = repository.deleteSampleEntityUUIDKeyedById(documentId);
|
||||
// then
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId)).build();
|
||||
Page<SampleEntityUUIDKeyed> sampleEntities = repository.search(searchQuery);
|
||||
@@ -316,7 +315,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
sampleEntityUUIDKeyed3.setMessage("hello world 3");
|
||||
sampleEntityUUIDKeyed3.setAvailable(false);
|
||||
sampleEntityUUIDKeyed3.setVersion(System.currentTimeMillis());
|
||||
repository.save(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3));
|
||||
repository.saveAll(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3));
|
||||
// when
|
||||
List<SampleEntityUUIDKeyed> result = repository.deleteByAvailable(true);
|
||||
repository.refresh();
|
||||
@@ -347,7 +346,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
sampleEntityUUIDKeyed3.setId(documentId);
|
||||
sampleEntityUUIDKeyed3.setMessage("hello world 3");
|
||||
sampleEntityUUIDKeyed3.setVersion(System.currentTimeMillis());
|
||||
repository.save(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3));
|
||||
repository.saveAll(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3));
|
||||
// when
|
||||
List<SampleEntityUUIDKeyed> result = repository.deleteByMessage("hello world 3");
|
||||
repository.refresh();
|
||||
@@ -378,7 +377,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
sampleEntityUUIDKeyed3.setId(documentId);
|
||||
sampleEntityUUIDKeyed3.setType("image");
|
||||
sampleEntityUUIDKeyed3.setVersion(System.currentTimeMillis());
|
||||
repository.save(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3));
|
||||
repository.saveAll(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3));
|
||||
// when
|
||||
repository.deleteByType("article");
|
||||
repository.refresh();
|
||||
@@ -388,7 +387,6 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(2L));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldDeleteEntity() {
|
||||
// given
|
||||
@@ -448,10 +446,10 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = Arrays.asList(sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed2);
|
||||
// when
|
||||
repository.delete(sampleEntities);
|
||||
repository.deleteAll(sampleEntities);
|
||||
// then
|
||||
assertThat(repository.findOne(documentId1).isPresent(), is(false));
|
||||
assertThat(repository.findOne(documentId2).isPresent(), is(false));
|
||||
assertThat(repository.findById(documentId1).isPresent(), is(false));
|
||||
assertThat(repository.findById(documentId2).isPresent(), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -470,7 +468,8 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
sampleEntityUUIDKeyed2.setMessage("hello");
|
||||
repository.save(sampleEntityUUIDKeyed2);
|
||||
// when
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.findAll(new Sort(new Sort.Order(Sort.Direction.ASC, "message")));
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository
|
||||
.findAll(new Sort(new Sort.Order(Sort.Direction.ASC, "message")));
|
||||
// then
|
||||
assertThat(sampleEntities, is(notNullValue()));
|
||||
}
|
||||
@@ -485,10 +484,11 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
+ "we want real-time search, we want simple multi-tenancy, and we want a solution that is built for the cloud.";
|
||||
|
||||
List<SampleEntityUUIDKeyed> sampleEntities = createSampleEntitiesWithMessage(sampleMessage, 30);
|
||||
repository.save(sampleEntities);
|
||||
repository.saveAll(sampleEntities);
|
||||
|
||||
// when
|
||||
Page<SampleEntityUUIDKeyed> results = repository.searchSimilar(sampleEntities.get(0), new String[]{"message"}, new PageRequest(0, 5));
|
||||
Page<SampleEntityUUIDKeyed> results = repository.searchSimilar(sampleEntities.get(0), new String[] { "message" },
|
||||
new PageRequest(0, 5));
|
||||
|
||||
// then
|
||||
assertThat(results.getTotalElements(), is(greaterThanOrEqualTo(1L)));
|
||||
|
||||
Reference in New Issue
Block a user