DATAES-46 - Apply code formatting

This commit is contained in:
Mohsin Husen
2014-07-20 17:07:57 +01:00
parent 6d61dceab9
commit fa5d1b1e49
24 changed files with 474 additions and 471 deletions

View File

@@ -199,5 +199,4 @@ public class AliasTests {
elasticsearchTemplate.putMapping(SampleEntity.class);
elasticsearchTemplate.refresh(SampleEntity.class, true);
}
}

View File

@@ -621,7 +621,7 @@ public class ElasticsearchTemplateTests {
@Override
public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
List<SampleEntity> result = new ArrayList<SampleEntity>();
for(SearchHit searchHit : response.getHits()){
for (SearchHit searchHit : response.getHits()) {
String message = searchHit.getFields().get("message").getValue();
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(searchHit.getId());
@@ -629,7 +629,7 @@ public class ElasticsearchTemplateTests {
result.add(sampleEntity);
}
if(result.size() > 0) {
if (result.size() > 0) {
return new FacetedPageImpl<T>((List<T>) result);
}
return null;
@@ -1378,19 +1378,19 @@ public class ElasticsearchTemplateTests {
public void shouldCreateIndexWithGivenSettings() {
// given
String settings = "{\n" +
" \"index\": {\n" +
" \"number_of_shards\": \"1\",\n" +
" \"number_of_replicas\": \"0\",\n" +
" \"analysis\": {\n" +
" \"analyzer\": {\n" +
" \"emailAnalyzer\": {\n" +
" \"type\": \"custom\",\n" +
" \"tokenizer\": \"uax_url_email\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
" \"index\": {\n" +
" \"number_of_shards\": \"1\",\n" +
" \"number_of_replicas\": \"0\",\n" +
" \"analysis\": {\n" +
" \"analyzer\": {\n" +
" \"emailAnalyzer\": {\n" +
" \"type\": \"custom\",\n" +
" \"tokenizer\": \"uax_url_email\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
elasticsearchTemplate.deleteIndex("test-index");
// when

View File

@@ -30,7 +30,6 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.elasticsearch.action.search.SearchType.COUNT;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
@@ -48,56 +47,55 @@ import static org.junit.Assert.assertThat;
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
public class ElasticsearchTemplateAggregationTests {
public static final String RIZWAN_IDREES = "Rizwan Idrees";
public static final String MOHSIN_HUSEN = "Mohsin Husen";
public static final String JONATHAN_YAN = "Jonathan Yan";
public static final String ARTUR_KONCZAK = "Artur Konczak";
public static final int YEAR_2002 = 2002;
public static final int YEAR_2001 = 2001;
public static final int YEAR_2000 = 2000;
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
public static final String RIZWAN_IDREES = "Rizwan Idrees";
public static final String MOHSIN_HUSEN = "Mohsin Husen";
public static final String JONATHAN_YAN = "Jonathan Yan";
public static final String ARTUR_KONCZAK = "Artur Konczak";
public static final int YEAR_2002 = 2002;
public static final int YEAR_2001 = 2001;
public static final int YEAR_2000 = 2000;
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
@Before
public void before() {
elasticsearchTemplate.deleteIndex(ArticleEntity.class);
elasticsearchTemplate.createIndex(ArticleEntity.class);
elasticsearchTemplate.putMapping(ArticleEntity.class);
elasticsearchTemplate.refresh(ArticleEntity.class, true);
@Before
public void before() {
elasticsearchTemplate.deleteIndex(ArticleEntity.class);
elasticsearchTemplate.createIndex(ArticleEntity.class);
elasticsearchTemplate.putMapping(ArticleEntity.class);
elasticsearchTemplate.refresh(ArticleEntity.class, true);
IndexQuery article1 = new ArticleEntityBuilder("1").title("article four").subject("computing").addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addAuthor(MOHSIN_HUSEN).addAuthor(JONATHAN_YAN).score(10).buildIndex();
IndexQuery article2 = new ArticleEntityBuilder("2").title("article three").subject("computing").addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addAuthor(MOHSIN_HUSEN).addPublishedYear(YEAR_2000).score(20).buildIndex();
IndexQuery article3 = new ArticleEntityBuilder("3").title("article two").subject("computing").addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addPublishedYear(YEAR_2001).addPublishedYear(YEAR_2000).score(30).buildIndex();
IndexQuery article4 = new ArticleEntityBuilder("4").title("article one").subject("accounting").addAuthor(RIZWAN_IDREES).addPublishedYear(YEAR_2002).addPublishedYear(YEAR_2001).addPublishedYear(YEAR_2000).score(40).buildIndex();
IndexQuery article1 = new ArticleEntityBuilder("1").title("article four").subject("computing").addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addAuthor(MOHSIN_HUSEN).addAuthor(JONATHAN_YAN).score(10).buildIndex();
IndexQuery article2 = new ArticleEntityBuilder("2").title("article three").subject("computing").addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addAuthor(MOHSIN_HUSEN).addPublishedYear(YEAR_2000).score(20).buildIndex();
IndexQuery article3 = new ArticleEntityBuilder("3").title("article two").subject("computing").addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addPublishedYear(YEAR_2001).addPublishedYear(YEAR_2000).score(30).buildIndex();
IndexQuery article4 = new ArticleEntityBuilder("4").title("article one").subject("accounting").addAuthor(RIZWAN_IDREES).addPublishedYear(YEAR_2002).addPublishedYear(YEAR_2001).addPublishedYear(YEAR_2000).score(40).buildIndex();
elasticsearchTemplate.index(article1);
elasticsearchTemplate.index(article2);
elasticsearchTemplate.index(article3);
elasticsearchTemplate.index(article4);
elasticsearchTemplate.refresh(ArticleEntity.class, true);
}
@Test
public void shouldReturnAggregatedResponseForGivenSearchQuery() {
// given
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(matchAllQuery())
.withSearchType(COUNT)
.withIndices("articles").withTypes("article")
.addAggregation(terms("subjects").field("subject"))
.build();
// when
Aggregations aggregations = elasticsearchTemplate.query(searchQuery, new ResultsExtractor<Aggregations>() {
@Override
public Aggregations extract(SearchResponse response) {
return response.getAggregations();
}
});
// then
assertThat(aggregations, is(notNullValue()));
assertThat(aggregations.asMap().get("subjects"), is(notNullValue()));
}
elasticsearchTemplate.index(article1);
elasticsearchTemplate.index(article2);
elasticsearchTemplate.index(article3);
elasticsearchTemplate.index(article4);
elasticsearchTemplate.refresh(ArticleEntity.class, true);
}
@Test
public void shouldReturnAggregatedResponseForGivenSearchQuery() {
// given
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(matchAllQuery())
.withSearchType(COUNT)
.withIndices("articles").withTypes("article")
.addAggregation(terms("subjects").field("subject"))
.build();
// when
Aggregations aggregations = elasticsearchTemplate.query(searchQuery, new ResultsExtractor<Aggregations>() {
@Override
public Aggregations extract(SearchResponse response) {
return response.getAggregations();
}
});
// then
assertThat(aggregations, is(notNullValue()));
assertThat(aggregations.asMap().get("subjects"), is(notNullValue()));
}
}

View File

@@ -40,7 +40,7 @@ public class ArticleEntity {
@Id
private String id;
private String title;
private String subject;
private String subject;
@MultiField(
mainField = @Field(type = String, index = analyzed),
@@ -80,15 +80,15 @@ public class ArticleEntity {
this.title = title;
}
public String getSubject() {
return subject;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public List<String> getAuthors() {
public List<String> getAuthors() {
return authors;
}

View File

@@ -35,10 +35,11 @@ public class ArticleEntityBuilder {
result.setTitle(title);
return this;
}
public ArticleEntityBuilder subject(String subject) {
result.setSubject(subject);
return this;
}
public ArticleEntityBuilder subject(String subject) {
result.setSubject(subject);
return this;
}
public ArticleEntityBuilder addAuthor(String author) {
result.getAuthors().add(author);

View File

@@ -16,7 +16,9 @@
package org.springframework.data.elasticsearch.entities;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Mapping;
import org.springframework.data.elasticsearch.annotations.Setting;
/**
* Sample DynamicSettingAndMappingEntity for test out dynamic setting using @Setting Annotation

View File

@@ -37,7 +37,7 @@ public class SampleEntity {
private boolean available;
private String highlightedMessage;
private GeoPoint location;
private GeoPoint location;
@Version
private Long version;
@@ -90,13 +90,13 @@ public class SampleEntity {
this.highlightedMessage = highlightedMessage;
}
public GeoPoint getLocation() {
return location;
}
public GeoPoint getLocation() {
return location;
}
public void setLocation(GeoPoint location) {
this.location = location;
}
public void setLocation(GeoPoint location) {
this.location = location;
}
public Long getVersion() {
return version;

View File

@@ -494,100 +494,100 @@ public class CustomMethodRepositoryTests {
assertThat(sampleEntities.size(), is(1));
}
@Test
public void shouldExecuteCustomMethodWithWithinGeoPoint() {
// given
String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
@Test
public void shouldExecuteCustomMethodWithWithinGeoPoint() {
// given
String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
repository.save(sampleEntity);
repository.save(sampleEntity);
// when
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)));
}
// when
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)));
}
@Test
public void shouldExecuteCustomMethodWithWithinPoint() {
// given
String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
@Test
public void shouldExecuteCustomMethodWithWithinPoint() {
// given
String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
repository.save(sampleEntity);
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByLocationWithin(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
}
// when
Page<SampleEntity> page = repository.findByLocationWithin(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
}
@Test
public void shouldExecuteCustomMethodWithNearBox() {
// given
String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
@Test
public void shouldExecuteCustomMethodWithNearBox() {
// given
String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
repository.save(sampleEntity);
repository.save(sampleEntity);
documentId = randomNumeric(5);
SampleEntity sampleEntity2 = new SampleEntity();
sampleEntity2.setId(documentId);
sampleEntity2.setType("test2");
sampleEntity2.setRate(10);
sampleEntity2.setMessage("foo");
sampleEntity2.setLocation(new GeoPoint(30.7806d, 0.0875d));
documentId = randomNumeric(5);
SampleEntity sampleEntity2 = new SampleEntity();
sampleEntity2.setId(documentId);
sampleEntity2.setType("test2");
sampleEntity2.setRate(10);
sampleEntity2.setMessage("foo");
sampleEntity2.setLocation(new GeoPoint(30.7806d, 0.0875d));
repository.save(sampleEntity2);
repository.save(sampleEntity2);
// when
Page<SampleEntity> pageAll = repository.findAll(new PageRequest(0, 10));
// then
assertThat(pageAll, is(notNullValue()));
assertThat(pageAll.getTotalElements(), is(equalTo(2L)));
// when
Page<SampleEntity> pageAll = repository.findAll(new PageRequest(0, 10));
// then
assertThat(pageAll, is(notNullValue()));
assertThat(pageAll.getTotalElements(), is(equalTo(2L)));
// when
Page<SampleEntity> page = repository.findByLocationNear(new Box(new Point(3d, 46d), new Point(4d, 45d)), new PageRequest(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
}
// when
Page<SampleEntity> page = repository.findByLocationNear(new Box(new Point(3d, 46d), new Point(4d, 45d)), new PageRequest(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
}
@Test
public void shouldExecuteCustomMethodWithNearPointAndDistance() {
// given
String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
@Test
public void shouldExecuteCustomMethodWithNearPointAndDistance() {
// given
String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
repository.save(sampleEntity);
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByLocationNear(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
}
// when
Page<SampleEntity> page = repository.findByLocationNear(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
}
}

View File

@@ -70,15 +70,15 @@ public interface SampleCustomMethodRepository extends ElasticsearchRepository<Sa
Page<SampleEntity> findByMessageOrderByTypeAsc(String message, Pageable pageable);
Page<SampleEntity> findByLocationWithin(GeoPoint point, String distance, Pageable pageable);
Page<SampleEntity> findByLocationWithin(GeoPoint point, String distance, Pageable pageable);
Page<SampleEntity> findByLocationWithin(Point point, Distance distance, Pageable pageable);
Page<SampleEntity> findByLocationWithin(Point point, Distance distance, Pageable pageable);
Page<SampleEntity> findByLocationNear(GeoBox box, Pageable pageable);
Page<SampleEntity> findByLocationNear(GeoBox box, Pageable pageable);
Page<SampleEntity> findByLocationNear(Box box, Pageable pageable);
Page<SampleEntity> findByLocationNear(Box box, Pageable pageable);
Page<SampleEntity> findByLocationNear(Point point, Distance distance, Pageable pageable);
Page<SampleEntity> findByLocationNear(Point point, Distance distance, Pageable pageable);
Page<SampleEntity> findByLocationNear(GeoPoint point, String distance, Pageable pageable);
Page<SampleEntity> findByLocationNear(GeoPoint point, String distance, Pageable pageable);
}

View File

@@ -121,7 +121,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
assertThat(mapping, is(notNullValue()));
assertThat(properties, is(notNullValue()));
assertThat(((String) ((Map) properties.get("email")).get("type")), is("string"));
assertThat((String) ((Map)properties.get("email")).get("analyzer"), is("emailAnalyzer"));
assertThat((String) ((Map) properties.get("email")).get("analyzer"), is("emailAnalyzer"));
}
@Test
@@ -146,7 +146,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
assertThat(mapping, is(notNullValue()));
assertThat(properties, is(notNullValue()));
assertThat(((String) ((Map) properties.get("email")).get("type")), is("string"));
assertThat((String) ((Map)properties.get("email")).get("analyzer"), is("emailAnalyzer"));
assertThat((String) ((Map) properties.get("email")).get("analyzer"), is("emailAnalyzer"));
}
/*
@@ -162,6 +162,6 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
assertThat(mapping, is(notNullValue()));
assertThat(properties, is(notNullValue()));
assertThat(((String) ((Map) properties.get("email")).get("type")), is("string"));
assertThat((String) ((Map)properties.get("email")).get("analyzer"), is("emailAnalyzer"));
assertThat((String) ((Map) properties.get("email")).get("analyzer"), is("emailAnalyzer"));
}
}