|
@@ -26,6 +26,7 @@ import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
+import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
|
public class UnsignedLongFieldMapperTests extends MapperTestCase {
|
|
|
|
|
@@ -96,7 +97,7 @@ public class UnsignedLongFieldMapperTests extends MapperTestCase {
|
|
|
{
|
|
|
ThrowingRunnable runnable = () -> mapper.parse(source(b -> b.field("field", 10.5)));
|
|
|
MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
|
|
|
- assertThat(e.getCause().getMessage(), containsString("For input string: [10.5]"));
|
|
|
+ assertThat(e.getCause().getMessage(), containsString("Value \"10.5\" has a decimal part"));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -205,6 +206,28 @@ public class UnsignedLongFieldMapperTests extends MapperTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testDecimalParts() throws IOException {
|
|
|
+ XContentBuilder mapping = fieldMapping(b -> b.field("type", "unsigned_long"));
|
|
|
+ DocumentMapper mapper = createDocumentMapper(mapping);
|
|
|
+ {
|
|
|
+ ThrowingRunnable runnable = () -> mapper.parse(source(b -> b.field("field", randomFrom("100.5", 100.5, 100.5f))));
|
|
|
+ MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
|
|
|
+ assertThat(e.getCause().getMessage(), containsString("Value \"100.5\" has a decimal part"));
|
|
|
+ }
|
|
|
+ {
|
|
|
+ ThrowingRunnable runnable = () -> mapper.parse(source(b -> b.field("field", randomFrom("0.9", 0.9, 0.9f))));
|
|
|
+ MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
|
|
|
+ assertThat(e.getCause().getMessage(), containsString("Value \"0.9\" has a decimal part"));
|
|
|
+ }
|
|
|
+ ParsedDocument doc = mapper.parse(source(b -> b.field("field", randomFrom("100.", "100.0", "100.00", 100.0, 100.0f))));
|
|
|
+ assertThat(doc.rootDoc().getFields("field")[0].numericValue().longValue(), equalTo(Long.MIN_VALUE + 100L));
|
|
|
+ assertThat(doc.rootDoc().getFields("field")[1].numericValue().longValue(), equalTo(Long.MIN_VALUE + 100L));
|
|
|
+
|
|
|
+ doc = mapper.parse(source(b -> b.field("field", randomFrom("0.", "0.0", ".00", 0.0, 0.0f))));
|
|
|
+ assertThat(doc.rootDoc().getFields("field")[0].numericValue().longValue(), equalTo(Long.MIN_VALUE));
|
|
|
+ assertThat(doc.rootDoc().getFields("field")[1].numericValue().longValue(), equalTo(Long.MIN_VALUE));
|
|
|
+ }
|
|
|
+
|
|
|
public void testIndexingOutOfRangeValues() throws Exception {
|
|
|
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
|
|
|
for (Object outOfRangeValue : new Object[] { "-1", -1L, "18446744073709551616", new BigInteger("18446744073709551616") }) {
|