Skip to content

Commit

Permalink
Polish and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VanRoy committed Feb 14, 2019
1 parent a6c4e23 commit 3c363d9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<!-- Dependencies version -->
<springboot>2.1.2.RELEASE</springboot>
<spring>5.1.4.RELEASE</spring>
<springdataes>3.1.2.RELEASE</springdataes>
<springdataes>3.1.3.RELEASE</springdataes>
<springdatacommons>2.1.4.RELEASE</springdatacommons>
<jest>6.3.1</jest>
<gson>2.8.0</gson>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,6 @@ public <T> boolean createIndex(Class<T> clazz, Object settings) {
return createIndex(getPersistentEntityFor(clazz).getIndexName(), settings);
}

private String xContentBuilderToString(XContentBuilder builder) {
builder.close();
ByteArrayOutputStream bos = (ByteArrayOutputStream) builder.getOutputStream();
return bos.toString();
}

@Override
public <T> boolean putMapping(Class<T> clazz) {
if (clazz.isAnnotationPresent(Mapping.class)) {
Expand All @@ -230,7 +224,7 @@ public <T> boolean putMapping(Class<T> clazz) {
throw new IllegalArgumentException(String.format("No Id property for %s found", clazz.getSimpleName()));
}

mapping =xContentBuilderToString( buildMapping(
mapping = xContentBuilderToString(buildMapping(
clazz,
persistentEntity.getIndexType(),
idProperty.getFieldName(),
Expand All @@ -256,7 +250,7 @@ public boolean putMapping(String indexName, String type, Object mapping) {
} else if (mapping instanceof Map) {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map((Map) mapping);
source = xContentBuilderToString( builder );
source = xContentBuilderToString(builder);
} else if (mapping instanceof XContentBuilder) {
source = xContentBuilderToString(((XContentBuilder) mapping));
} else if (mapping instanceof DocumentMapper) {
Expand All @@ -272,6 +266,12 @@ public boolean putMapping(String indexName, String type, Object mapping) {
}
}

private String xContentBuilderToString(XContentBuilder builder) {
builder.close();
ByteArrayOutputStream bos = (ByteArrayOutputStream) builder.getOutputStream();
return bos.toString();
}

@Override
public <T> boolean putMapping(Class<T> clazz, Object mapping) {
return putMapping(getPersistentEntityFor(clazz).getIndexName(), getPersistentEntityFor(clazz).getIndexType(), mapping);
Expand Down Expand Up @@ -1231,8 +1231,7 @@ private SearchResult executeSearch(Query query, SearchSourceBuilder request) {

private Index prepareIndex(IndexQuery query) {
try {
String indexName = !hasText(query.getIndexName()) ? retrieveIndexNameFromPersistentEntity(query.getObject()
.getClass())[0] : query.getIndexName();
String indexName = !hasText(query.getIndexName()) ? retrieveIndexNameFromPersistentEntity(query.getObject().getClass())[0] : query.getIndexName();
String type = !hasText(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0]
: query.getType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2019,8 +2019,12 @@ public void shouldCreateIndexWithGivenSettings() {
" \"analysis\": {\n" +
" \"analyzer\": {\n" +
" \"emailAnalyzer\": {\n" +
" \"type\": \"custom\",\n" +
" \"tokenizer\": \"uax_url_email\"\n" +
" \"tokenizer\": \"emailTokenizer\"\n" +
" }\n" +
" },\n" +
" \"tokenizer\": {\n" +
" \"emailTokenizer\": {\n" +
" \"type\": \"standard\"\n" +
" }\n" +
" }\n" +
" }\n" +
Expand All @@ -2036,7 +2040,7 @@ public void shouldCreateIndexWithGivenSettings() {
String emailAnalyzer = (String) map.get("index.analysis.analyzer.emailAnalyzer.tokenizer");
assertThat(elasticsearchTemplate.indexExists("test-index"), is(true));
assertThat(hasAnalyzer, is(true));
assertThat(emailAnalyzer, is("uax_url_email"));
assertThat(emailAnalyzer, is("emailTokenizer"));
}

/*
Expand Down Expand Up @@ -2073,8 +2077,12 @@ public void shouldCreateIndexWithGivenClassAndSettings() {
" \"analysis\": {\n" +
" \"analyzer\": {\n" +
" \"emailAnalyzer\": {\n" +
" \"type\": \"custom\",\n" +
" \"tokenizer\": \"uax_url_email\"\n" +
" \"tokenizer\": \"emailTokenizer\"\n" +
" }\n" +
" },\n" +
" \"tokenizer\": {\n" +
" \"emailTokenizer\": {\n" +
" \"type\": \"standard\"\n" +
" }\n" +
" }\n" +
" }\n" +
Expand Down Expand Up @@ -2201,8 +2209,11 @@ public void shouldReadFileFromClasspathRetainingNewlines() {
" analysis:\n" +
" analyzer:\n" +
" emailAnalyzer:\n" +
" type: custom\n" +
" tokenizer: uax_url_email\n"));
" tokenizer: emailTokenizer\n" +
" tokenizer:\n" +
" emailTokenizer:\n" +
" type: uax_url_email\n"
));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ index:
analysis:
analyzer:
emailAnalyzer:
type: custom
tokenizer: uax_url_email
tokenizer: emailTokenizer
tokenizer:
emailTokenizer:
type: uax_url_email

0 comments on commit 3c363d9

Please sign in to comment.