Skip to content

Commit c3bf3b1

Browse files
committed
Tests: AnalysisService constructor signature change
Due to this [change](elastic#8018), we need to fix our tests for elasticsearch 1.4.0 and above. Closes elastic#87. (cherry picked from commit b3b0d34)
1 parent 03b47d5 commit c3bf3b1

7 files changed

+33
-31
lines changed

src/test/java/org/elasticsearch/index/mapper/xcontent/DateAttachmentMapperTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
package org.elasticsearch.index.mapper.xcontent;
2121

22-
import org.elasticsearch.common.settings.ImmutableSettings;
23-
import org.elasticsearch.index.Index;
24-
import org.elasticsearch.index.analysis.AnalysisService;
2522
import org.elasticsearch.index.mapper.DocumentMapper;
2623
import org.elasticsearch.index.mapper.DocumentMapperParser;
2724
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
@@ -42,7 +39,7 @@ public class DateAttachmentMapperTests extends ElasticsearchTestCase {
4239

4340
@Before
4441
public void setupMapperParser() {
45-
mapperParser = new DocumentMapperParser(new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null, null);
42+
mapperParser = MapperTestUtils.newMapperParser();
4643
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
4744
}
4845

src/test/java/org/elasticsearch/index/mapper/xcontent/EncryptedDocMapperTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import org.elasticsearch.common.bytes.BytesReference;
2323
import org.elasticsearch.common.settings.ImmutableSettings;
24-
import org.elasticsearch.index.Index;
25-
import org.elasticsearch.index.analysis.AnalysisService;
2624
import org.elasticsearch.index.mapper.DocumentMapper;
2725
import org.elasticsearch.index.mapper.DocumentMapperParser;
2826
import org.elasticsearch.index.mapper.MapperParsingException;
@@ -47,7 +45,7 @@ public class EncryptedDocMapperTest extends ElasticsearchTestCase {
4745

4846
@Test
4947
public void testMultipleDocsEncryptedLast() throws IOException {
50-
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null, null);
48+
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
5149
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
5250

5351
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
@@ -80,7 +78,7 @@ public void testMultipleDocsEncryptedLast() throws IOException {
8078

8179
@Test
8280
public void testMultipleDocsEncryptedFirst() throws IOException {
83-
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null, null);
81+
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
8482
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
8583

8684
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
@@ -113,9 +111,7 @@ public void testMultipleDocsEncryptedFirst() throws IOException {
113111

114112
@Test(expected = MapperParsingException.class)
115113
public void testMultipleDocsEncryptedNotIgnoringErrors() throws IOException {
116-
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"),
117-
ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build(),
118-
new AnalysisService(new Index("test")), null, null, null, null);
114+
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build());
119115
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
120116

121117
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");

src/test/java/org/elasticsearch/index/mapper/xcontent/LanguageDetectionAttachmentMapperTests.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import org.elasticsearch.common.settings.ImmutableSettings;
2323
import org.elasticsearch.common.xcontent.XContentBuilder;
24-
import org.elasticsearch.index.Index;
25-
import org.elasticsearch.index.analysis.AnalysisService;
2624
import org.elasticsearch.index.mapper.DocumentMapper;
2725
import org.elasticsearch.index.mapper.DocumentMapperParser;
2826
import org.elasticsearch.index.mapper.ParseContext;
@@ -53,9 +51,8 @@ public void setupMapperParser() throws IOException {
5351
}
5452

5553
public void setupMapperParser(boolean langDetect) throws IOException {
56-
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"),
57-
ImmutableSettings.settingsBuilder().put("index.mapping.attachment.detect_language", langDetect).build(),
58-
new AnalysisService(new Index("test")), null, null, null, null);
54+
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(
55+
ImmutableSettings.settingsBuilder().put("index.mapping.attachment.detect_language", langDetect).build());
5956
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
6057
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/language/language-mapping.json");
6158
docMapper = mapperParser.parse(mapping);

src/test/java/org/elasticsearch/index/mapper/xcontent/MapperTestUtils.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.elasticsearch.index.mapper.xcontent;
2121

22+
import org.elasticsearch.Version;
23+
import org.elasticsearch.cluster.metadata.IndexMetaData;
2224
import org.elasticsearch.common.inject.Injector;
2325
import org.elasticsearch.common.inject.ModulesBuilder;
2426
import org.elasticsearch.common.settings.ImmutableSettings;
@@ -33,6 +35,7 @@
3335
import org.elasticsearch.index.codec.docvaluesformat.DocValuesFormatService;
3436
import org.elasticsearch.index.codec.postingsformat.PostingsFormatService;
3537
import org.elasticsearch.index.fielddata.IndexFieldDataService;
38+
import org.elasticsearch.index.mapper.DocumentMapperParser;
3639
import org.elasticsearch.index.mapper.MapperService;
3740
import org.elasticsearch.index.settings.IndexSettingsModule;
3841
import org.elasticsearch.index.similarity.SimilarityLookupService;
@@ -46,7 +49,9 @@
4649
public class MapperTestUtils {
4750

4851
public static MapperService newMapperService() {
49-
return newMapperService(new Index("test"), ImmutableSettings.Builder.EMPTY_SETTINGS);
52+
return newMapperService(new Index("test"), ImmutableSettings.builder()
53+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
54+
.build());
5055
}
5156

5257
public static MapperService newMapperService(Index index, Settings indexSettings) {
@@ -58,14 +63,17 @@ public static MapperService newMapperService(Index index, Settings indexSettings
5863
}
5964

6065
public static AnalysisService newAnalysisService() {
61-
return newAnalysisService(ImmutableSettings.Builder.EMPTY_SETTINGS);
66+
return newAnalysisService(ImmutableSettings.builder()
67+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
68+
.build());
6269
}
6370

6471
public static AnalysisService newAnalysisService(Settings indexSettings) {
6572
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(ImmutableSettings.Builder.EMPTY_SETTINGS)), new IndicesAnalysisModule()).createInjector();
73+
Index index = new Index("test");
6674
Injector injector = new ModulesBuilder().add(
67-
new IndexSettingsModule(new Index("test"), indexSettings),
68-
new IndexNameModule(new Index("test")),
75+
new IndexSettingsModule(index, indexSettings),
76+
new IndexNameModule(index),
6977
new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector);
7078

7179
return injector.getInstance(AnalysisService.class);
@@ -74,4 +82,16 @@ public static AnalysisService newAnalysisService(Settings indexSettings) {
7482
public static SimilarityLookupService newSimilarityLookupService() {
7583
return new SimilarityLookupService(new Index("test"), ImmutableSettings.Builder.EMPTY_SETTINGS);
7684
}
85+
86+
public static DocumentMapperParser newMapperParser() {
87+
return newMapperParser(ImmutableSettings.Builder.EMPTY_SETTINGS);
88+
}
89+
90+
public static DocumentMapperParser newMapperParser(Settings settings) {
91+
Settings forcedSettings = ImmutableSettings.builder()
92+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
93+
.put(settings)
94+
.build();
95+
return new DocumentMapperParser(new Index("test"), forcedSettings, MapperTestUtils.newAnalysisService(forcedSettings), null, null, null, null);
96+
}
7797
}

src/test/java/org/elasticsearch/index/mapper/xcontent/MetadataMapperTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import org.elasticsearch.common.bytes.BytesReference;
2323
import org.elasticsearch.common.settings.ImmutableSettings;
2424
import org.elasticsearch.common.settings.Settings;
25-
import org.elasticsearch.index.Index;
26-
import org.elasticsearch.index.analysis.AnalysisService;
2725
import org.elasticsearch.index.mapper.DocumentMapper;
2826
import org.elasticsearch.index.mapper.DocumentMapperParser;
2927
import org.elasticsearch.index.mapper.MapperParsingException;
@@ -45,7 +43,7 @@
4543
public class MetadataMapperTest extends ElasticsearchTestCase {
4644

4745
protected void checkMeta(String filename, Settings settings, Long expectedDate, Long expectedLength) throws IOException {
48-
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"), settings, new AnalysisService(new Index("test")), null, null, null, null);
46+
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(settings);
4947
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
5048

5149
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");

src/test/java/org/elasticsearch/index/mapper/xcontent/MultifieldAttachmentMapperTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
package org.elasticsearch.index.mapper.xcontent;
2121

2222
import org.elasticsearch.common.Base64;
23-
import org.elasticsearch.common.settings.ImmutableSettings;
2423
import org.elasticsearch.common.xcontent.XContentFactory;
25-
import org.elasticsearch.index.Index;
26-
import org.elasticsearch.index.analysis.AnalysisService;
2724
import org.elasticsearch.index.mapper.DocumentMapper;
2825
import org.elasticsearch.index.mapper.DocumentMapperParser;
2926
import org.elasticsearch.index.mapper.MapperService;
@@ -47,7 +44,7 @@ public class MultifieldAttachmentMapperTests extends ElasticsearchTestCase {
4744

4845
@Before
4946
public void setupMapperParser() {
50-
mapperParser = new DocumentMapperParser(new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null, null);
47+
mapperParser = MapperTestUtils.newMapperParser();
5148
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
5249
}
5350

src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
package org.elasticsearch.index.mapper.xcontent;
2121

2222
import org.elasticsearch.common.bytes.BytesReference;
23-
import org.elasticsearch.common.settings.ImmutableSettings;
24-
import org.elasticsearch.index.Index;
25-
import org.elasticsearch.index.analysis.AnalysisService;
2623
import org.elasticsearch.index.mapper.DocumentMapper;
2724
import org.elasticsearch.index.mapper.DocumentMapperParser;
2825
import org.elasticsearch.index.mapper.ParseContext;
@@ -46,7 +43,7 @@ public class SimpleAttachmentMapperTests extends ElasticsearchTestCase {
4643

4744
@Before
4845
public void setupMapperParser() {
49-
mapperParser = new DocumentMapperParser(new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null, null);
46+
mapperParser = MapperTestUtils.newMapperParser();
5047
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
5148
}
5249

0 commit comments

Comments
 (0)