LongMapper extends SingleColumnMapper.SingleFieldMapper<Long> { public LongMapper(String field, String column, Boolean validated, Float boost) { super(field, column, true, validated, null, Long.class, NUMERIC_TYPES_WITH_DATE); this.boost = boost == null ? DEFAULT_BOOST : boost; } LongMapper(String field, String column, Boolean validated, Float boost); @Override Optional<Field> indexedField(String name, Long value); @Override Optional<Field> sortedField(String name, Long value); @Override SortField sortField(String name, boolean reverse); @Override String toString(); static final Float DEFAULT_BOOST; final Float boost; }
@Test public void testConstructorWithoutArgs() { LongMapper mapper = longMapper().build("field"); assertEquals("Field is not set", "field", mapper.field); assertEquals("Validated is not set to default value", Mapper.DEFAULT_VALIDATED, mapper.validated); assertEquals("Column is not set to default value", "field", mapper.column); assertEquals("Mapped columns are not set", 1, mapper.mappedColumns.size()); assertTrue("Mapped columns are not set", mapper.mappedColumns.contains("field")); assertEquals("Boost is not set to default value", DoubleMapper.DEFAULT_BOOST, mapper.boost, 1); }
@Test public void testConstructorWithAllArgs() { LongMapper mapper = longMapper().validated(true).column("column").boost(2.3f).build("field"); assertEquals("Field is not set", "field", mapper.field); assertTrue("Validated is not properly set", mapper.validated); assertEquals("Column is not set", "column", mapper.column); assertEquals("Mapped columns are not set", 1, mapper.mappedColumns.size()); assertTrue("Mapped columns are not set", mapper.mappedColumns.contains("column")); assertEquals("Boost is not set", 2.3f, mapper.boost, 1); }
@Test public void testJsonSerialization() { LongMapperBuilder builder = longMapper().validated(true).column("column").boost(2f); testJson(builder, "{type:\"long\",validated:true,column:\"column\",boost:2.0}"); }
@Test public void testJsonSerializationDefaults() { LongMapperBuilder builder = longMapper(); testJson(builder, "{type:\"long\"}"); }
@Test public void testValueNull() { LongMapper mapper = longMapper().boost(1f).build("field"); assertNull("Base for nulls is wrong", mapper.base("test", null)); }
@Test public void testValueString() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", "3"); assertEquals("Base for string is wrong", Long.valueOf(3), parsed); }
@Test(expected = IndexException.class) public void testValueStringInvalid() { LongMapper mapper = longMapper().boost(1f).build("field"); mapper.base("test", "error"); }
@Test public void testValueInteger() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", 3); assertEquals("Base for integer is wrong", Long.valueOf(3), parsed); }
@Test public void testValueLong() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", 3l); assertEquals("Base for long is wrong", Long.valueOf(3), parsed); }
@Test public void testValueShort() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", new Short("3")); assertEquals("Base for long is wrong", Long.valueOf(3), parsed); }
@Test public void testValueByte() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", new Byte("3")); assertEquals("Base for long is wrong", Long.valueOf(3), parsed); }
@Test public void testValueFloatWithoutDecimal() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", 3f); assertEquals("Base for float is wrong", Long.valueOf(3), parsed); }
@Test public void testValueFloatWithDecimalFloor() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", 3.5f); assertEquals("Base for float is wrong", Long.valueOf(3), parsed); }
@Test public void testValueFloatWithDecimalCeil() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", 3.6f); assertEquals("Base for float is wrong", Long.valueOf(3), parsed); }
@Test public void testValueDoubleWithoutDecimal() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", 3d); assertEquals("Base for double is wrong", Long.valueOf(3), parsed); }
@Test public void testValueDoubleWithDecimalFloor() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", 3.5d); assertEquals("Base for double is wrong", Long.valueOf(3), parsed); }
@Test public void testValueDoubleWithDecimalCeil() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", 3.6d); assertEquals("Base for double is wrong", Long.valueOf(3), parsed); }
@Test public void testValueStringWithoutDecimal() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", "3"); assertEquals("Base for string is wrong", Long.valueOf(3), parsed); }
@Test public void testValueStringWithDecimalFloor() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", "3.2"); assertEquals("Base for string is wrong", Long.valueOf(3), parsed); }
@Test public void testValueStringWithDecimalCeil() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", "3.2"); assertEquals("Base for string is wrong", Long.valueOf(3), parsed); }
@Test public void testValueWithDate() { LongMapper mapper = longMapper().boost(1f).build("field"); Long parsed = mapper.base("test", new Date(10)); assertEquals("Base for dates is wrong", Long.valueOf(10), parsed); }
@Test public void testExtractAnalyzers() { LongMapper mapper = longMapper().boost(1f).build("field"); assertNull("Analyzer must be null", mapper.analyzer); }