Skip to content

Commit 9c91723

Browse files
pkraeutlimohsinh
authored andcommitted
DATAES-224 retain newlines when reading mapping/setting files
Fixed test-settings yaml
1 parent 7dbab75 commit 9c91723

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,9 @@ public static String readFileFromClasspath(String url) {
11641164
bufferedReader = new BufferedReader(inputStreamReader);
11651165
String line;
11661166

1167+
String lineSeparator = System.getProperty("line.separator");
11671168
while ((line = bufferedReader.readLine()) != null) {
1168-
stringBuilder.append(line);
1169+
stringBuilder.append(line).append(lineSeparator);
11691170
}
11701171
} catch (Exception e) {
11711172
logger.debug(String.format("Failed to load file from url: %s: %s", url, e.getMessage()));

src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,25 @@ public void shouldCreateIndexUsingServerDefaultConfiguration() {
20062006
assertThat(setting.get("index.number_of_replicas"), Matchers.<Object>is("1"));
20072007
}
20082008

2009+
@Test
2010+
public void shouldReadFileFromClasspathRetainingNewlines() {
2011+
// given
2012+
String settingsFile = "/settings/test-settings.yml";
2013+
2014+
// when
2015+
String content = ElasticsearchTemplate.readFileFromClasspath(settingsFile);
2016+
2017+
// then
2018+
assertThat(content, is("index:\n" +
2019+
" number_of_shards: 1\n" +
2020+
" number_of_replicas: 0\n" +
2021+
" analysis:\n" +
2022+
" analyzer:\n" +
2023+
" emailAnalyzer:\n" +
2024+
" type: custom\n" +
2025+
" tokenizer: uax_url_email\n"));
2026+
}
2027+
20092028
private IndexQuery getIndexQuery(SampleEntity sampleEntity) {
20102029
return new IndexQueryBuilder().withId(sampleEntity.getId()).withObject(sampleEntity).build();
20112030
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
index:
2+
number_of_shards: 1
3+
number_of_replicas: 0
4+
analysis:
5+
analyzer:
6+
emailAnalyzer:
7+
type: custom
8+
tokenizer: uax_url_email

0 commit comments

Comments
 (0)