Fix method name typo & beef up tests
s/DateFieldMapper#parseLocal/DateFieldMapper#parseLocal/ SimpleDateMappingTests Tests now also check local dependent patters with root locale.
This commit is contained in:
parent
e0825686f3
commit
af4205fd30
|
@ -150,7 +150,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
} else if (propName.equals("numeric_resolution")) {
|
||||
builder.timeUnit(TimeUnit.valueOf(propNode.toString().toUpperCase(Locale.ROOT)));
|
||||
} else if (propName.equals("locale")) {
|
||||
builder.locale(parseLocal(propNode.toString()));
|
||||
builder.locale(parseLocale(propNode.toString()));
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
|
@ -158,7 +158,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
// public for test
|
||||
public static Locale parseLocal(String locale) {
|
||||
public static Locale parseLocale(String locale) {
|
||||
final String[] parts = locale.split("_", -1);
|
||||
switch (parts.length) {
|
||||
case 3:
|
||||
|
|
|
@ -87,18 +87,18 @@ public class SimpleDateMappingTests {
|
|||
|
||||
@Test
|
||||
public void testParseLocal() {
|
||||
assertThat(Locale.GERMAN, equalTo(DateFieldMapper.parseLocal("de")));
|
||||
assertThat(Locale.GERMANY, equalTo(DateFieldMapper.parseLocal("de_DE")));
|
||||
assertThat(new Locale("de","DE","DE"), equalTo(DateFieldMapper.parseLocal("de_DE_DE")));
|
||||
assertThat(Locale.GERMAN, equalTo(DateFieldMapper.parseLocale("de")));
|
||||
assertThat(Locale.GERMANY, equalTo(DateFieldMapper.parseLocale("de_DE")));
|
||||
assertThat(new Locale("de","DE","DE"), equalTo(DateFieldMapper.parseLocale("de_DE_DE")));
|
||||
|
||||
try {
|
||||
DateFieldMapper.parseLocal("de_DE_DE_DE");
|
||||
DateFieldMapper.parseLocale("de_DE_DE_DE");
|
||||
assert false;
|
||||
} catch(ElasticSearchIllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
assertThat(Locale.ROOT, equalTo(DateFieldMapper.parseLocal("")));
|
||||
assertThat(Locale.ROOT, equalTo(DateFieldMapper.parseLocal("ROOT")));
|
||||
assertThat(Locale.ROOT, equalTo(DateFieldMapper.parseLocale("")));
|
||||
assertThat(Locale.ROOT, equalTo(DateFieldMapper.parseLocale("ROOT")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -130,13 +130,18 @@ public class SimpleDateMappingTests {
|
|||
.startObject()
|
||||
.field("date_field_en", "Wed, 06 Dec 2000 02:55:00 -0800")
|
||||
.field("date_field_de", "Mi, 06 Dez 2000 02:55:00 -0800")
|
||||
.field("date_field_default", "Wed, 06 Dec 2000 02:55:00 -0800") // check default - root?
|
||||
.field("date_field_default", "Wed, 06 Dec 2000 02:55:00 -0800") // check default - no exception is a successs!
|
||||
.endObject()
|
||||
.bytes());
|
||||
assertThat(doc.rootDoc().getField("date_field_en").tokenStream(defaultMapper.indexAnalyzer()), notNullValue());
|
||||
assertThat(doc.rootDoc().getField("date_field_de").tokenStream(defaultMapper.indexAnalyzer()), notNullValue());
|
||||
assertNumericTokensEqual(doc, defaultMapper, "date_field_en", "date_field_de");
|
||||
assertNumericTokensEqual(doc, defaultMapper, "date_field_en", "date_field_default");
|
||||
}
|
||||
|
||||
private void assertNumericTokensEqual(ParsedDocument doc, DocumentMapper defaultMapper, String fieldA, String fieldB) throws IOException {
|
||||
assertThat(doc.rootDoc().getField(fieldA).tokenStream(defaultMapper.indexAnalyzer()), notNullValue());
|
||||
assertThat(doc.rootDoc().getField(fieldB).tokenStream(defaultMapper.indexAnalyzer()), notNullValue());
|
||||
|
||||
TokenStream tokenStream = doc.rootDoc().getField("date_field_en").tokenStream(defaultMapper.indexAnalyzer());
|
||||
TokenStream tokenStream = doc.rootDoc().getField(fieldA).tokenStream(defaultMapper.indexAnalyzer());
|
||||
tokenStream.reset();
|
||||
NumericTermAttribute nta = tokenStream.addAttribute(NumericTermAttribute.class);
|
||||
List<Long> values = new ArrayList<Long>();
|
||||
|
@ -144,7 +149,7 @@ public class SimpleDateMappingTests {
|
|||
values.add(nta.getRawValue());
|
||||
}
|
||||
|
||||
tokenStream = doc.rootDoc().getField("date_field_de").tokenStream(defaultMapper.indexAnalyzer());
|
||||
tokenStream = doc.rootDoc().getField(fieldB).tokenStream(defaultMapper.indexAnalyzer());
|
||||
tokenStream.reset();
|
||||
nta = tokenStream.addAttribute(NumericTermAttribute.class);
|
||||
int pos = 0;
|
||||
|
@ -152,8 +157,6 @@ public class SimpleDateMappingTests {
|
|||
assertThat(values.get(pos++), equalTo(nta.getRawValue()));
|
||||
}
|
||||
assertThat(pos, equalTo(values.size()));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue