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")) {
|
} else if (propName.equals("numeric_resolution")) {
|
||||||
builder.timeUnit(TimeUnit.valueOf(propNode.toString().toUpperCase(Locale.ROOT)));
|
builder.timeUnit(TimeUnit.valueOf(propNode.toString().toUpperCase(Locale.ROOT)));
|
||||||
} else if (propName.equals("locale")) {
|
} else if (propName.equals("locale")) {
|
||||||
builder.locale(parseLocal(propNode.toString()));
|
builder.locale(parseLocale(propNode.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -158,7 +158,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// public for test
|
// public for test
|
||||||
public static Locale parseLocal(String locale) {
|
public static Locale parseLocale(String locale) {
|
||||||
final String[] parts = locale.split("_", -1);
|
final String[] parts = locale.split("_", -1);
|
||||||
switch (parts.length) {
|
switch (parts.length) {
|
||||||
case 3:
|
case 3:
|
||||||
|
|
|
@ -87,18 +87,18 @@ public class SimpleDateMappingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseLocal() {
|
public void testParseLocal() {
|
||||||
assertThat(Locale.GERMAN, equalTo(DateFieldMapper.parseLocal("de")));
|
assertThat(Locale.GERMAN, equalTo(DateFieldMapper.parseLocale("de")));
|
||||||
assertThat(Locale.GERMANY, equalTo(DateFieldMapper.parseLocal("de_DE")));
|
assertThat(Locale.GERMANY, equalTo(DateFieldMapper.parseLocale("de_DE")));
|
||||||
assertThat(new Locale("de","DE","DE"), equalTo(DateFieldMapper.parseLocal("de_DE_DE")));
|
assertThat(new Locale("de","DE","DE"), equalTo(DateFieldMapper.parseLocale("de_DE_DE")));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DateFieldMapper.parseLocal("de_DE_DE_DE");
|
DateFieldMapper.parseLocale("de_DE_DE_DE");
|
||||||
assert false;
|
assert false;
|
||||||
} catch(ElasticSearchIllegalArgumentException ex) {
|
} catch(ElasticSearchIllegalArgumentException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
assertThat(Locale.ROOT, equalTo(DateFieldMapper.parseLocal("")));
|
assertThat(Locale.ROOT, equalTo(DateFieldMapper.parseLocale("")));
|
||||||
assertThat(Locale.ROOT, equalTo(DateFieldMapper.parseLocal("ROOT")));
|
assertThat(Locale.ROOT, equalTo(DateFieldMapper.parseLocale("ROOT")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -130,13 +130,18 @@ public class SimpleDateMappingTests {
|
||||||
.startObject()
|
.startObject()
|
||||||
.field("date_field_en", "Wed, 06 Dec 2000 02:55:00 -0800")
|
.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_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()
|
.endObject()
|
||||||
.bytes());
|
.bytes());
|
||||||
assertThat(doc.rootDoc().getField("date_field_en").tokenStream(defaultMapper.indexAnalyzer()), notNullValue());
|
assertNumericTokensEqual(doc, defaultMapper, "date_field_en", "date_field_de");
|
||||||
assertThat(doc.rootDoc().getField("date_field_de").tokenStream(defaultMapper.indexAnalyzer()), notNullValue());
|
assertNumericTokensEqual(doc, defaultMapper, "date_field_en", "date_field_default");
|
||||||
|
}
|
||||||
|
|
||||||
TokenStream tokenStream = doc.rootDoc().getField("date_field_en").tokenStream(defaultMapper.indexAnalyzer());
|
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(fieldA).tokenStream(defaultMapper.indexAnalyzer());
|
||||||
tokenStream.reset();
|
tokenStream.reset();
|
||||||
NumericTermAttribute nta = tokenStream.addAttribute(NumericTermAttribute.class);
|
NumericTermAttribute nta = tokenStream.addAttribute(NumericTermAttribute.class);
|
||||||
List<Long> values = new ArrayList<Long>();
|
List<Long> values = new ArrayList<Long>();
|
||||||
|
@ -144,7 +149,7 @@ public class SimpleDateMappingTests {
|
||||||
values.add(nta.getRawValue());
|
values.add(nta.getRawValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenStream = doc.rootDoc().getField("date_field_de").tokenStream(defaultMapper.indexAnalyzer());
|
tokenStream = doc.rootDoc().getField(fieldB).tokenStream(defaultMapper.indexAnalyzer());
|
||||||
tokenStream.reset();
|
tokenStream.reset();
|
||||||
nta = tokenStream.addAttribute(NumericTermAttribute.class);
|
nta = tokenStream.addAttribute(NumericTermAttribute.class);
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
@ -152,8 +157,6 @@ public class SimpleDateMappingTests {
|
||||||
assertThat(values.get(pos++), equalTo(nta.getRawValue()));
|
assertThat(values.get(pos++), equalTo(nta.getRawValue()));
|
||||||
}
|
}
|
||||||
assertThat(pos, equalTo(values.size()));
|
assertThat(pos, equalTo(values.size()));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue