BitemporalMapper extends MultipleColumnMapper { public BitemporalMapper(String field, Boolean validated, String vtFrom, String vtTo, String ttFrom, String ttTo, String pattern, Object nowValue) { super(field, validated, Arrays.asList(vtFrom, vtTo, ttFrom, ttTo), DATE_TYPES); if (StringUtils.isBlank(vtFrom)) { throw new IndexException("vt_from column name is required"); } if (StringUtils.isBlank(vtTo)) { throw new IndexException("vt_to column name is required"); } if (StringUtils.isBlank(ttFrom)) { throw new IndexException("tt_from column name is required"); } if (StringUtils.isBlank(ttTo)) { throw new IndexException("tt_to column name is required"); } this.vtFrom = vtFrom; this.vtTo = vtTo; this.ttFrom = ttFrom; this.ttTo = ttTo; this.parser = new DateParser(pattern); this.nowValue = (nowValue == null) ? Long.MAX_VALUE : parser.parse(nowValue).getTime(); } BitemporalMapper(String field,
                            Boolean validated,
                            String vtFrom,
                            String vtTo,
                            String ttFrom,
                            String ttTo,
                            String pattern,
                            Object nowValue); @Override List<IndexableField> indexableFields(Columns columns); BitemporalDateTime parseBitemporalDate(Object value); @Override SortField sortField(String name, boolean reverse); @Override String toString(); static final String VT_FROM_FIELD_SUFFIX; static final String VT_TO_FIELD_SUFFIX; static final String TT_FROM_FIELD_SUFFIX; static final String TT_TO_FIELD_SUFFIX; final DateParser parser; }
@Test public void testConstructorWithDefaultArgs() { BitemporalMapper mapper = bitemporalMapper("vtFrom", "vtTo", "ttFrom", "ttTo").build("f"); assertEquals("Field is not set", "f", mapper.field); assertEquals("vtFrom is not set", "vtFrom", mapper.vtFrom); assertEquals("vtTo is not set", "vtTo", mapper.vtTo); assertEquals("ttFrom is not set", "ttFrom", mapper.ttFrom); assertEquals("ttTo is not set", "ttTo", mapper.ttTo); assertEquals("Now value is not set to default", Long.MAX_VALUE, mapper.nowValue, 0); assertEquals("Date pattern is not set to default value", DEFAULT_PATTERN, mapper.parser.pattern); }
@Test public void testMappedColumns() { BitemporalMapper mapper = bitemporalMapper("vtFrom", "vtTo", "ttFrom", "ttTo").build("f"); assertEquals("Mapped columns are not properly set", 4, mapper.mappedColumns.size()); assertTrue("Mapped columns are not set", mapper.mappedColumns.contains("vtFrom")); assertTrue("Mapped columns are not set", mapper.mappedColumns.contains("vtTo")); assertTrue("Mapped columns are not set", mapper.mappedColumns.contains("ttFrom")); assertTrue("Mapped columns are not set", mapper.mappedColumns.contains("ttTo")); }
@Test public void testParseJSONWithDefaultArgs() throws IOException { BitemporalMapperBuilder builder = bitemporalMapper("vtFrom", "vtTo", "ttFrom", "ttTo"); testJson(builder, "{type:\"bitemporal\",vt_from:\"vtFrom\",vt_to:\"vtTo\",tt_from:\"ttFrom\",tt_to:\"ttTo\"}"); }
@Test public void testParseJSONWithAllArgs() throws IOException { BitemporalMapperBuilder builder = bitemporalMapper("vtFrom", "vtTo", "ttFrom", "ttTo").pattern("yyyy/MM/dd") .nowValue("2021/03/11"); testJson(builder, "{type:\"bitemporal\",vt_from:\"vtFrom\",vt_to:\"vtTo\",tt_from:\"ttFrom\",tt_to:\"ttTo\"," + "pattern:\"yyyy/MM/dd\",now_value:\"2021/03/11\"}"); }
@Test(expected = IndexException.class) public void testConstructorWithNullVtFrom() { bitemporalMapper(null, "vtTo", "ttFrom", "ttTo").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithEmptyVtFrom() { bitemporalMapper("", "vtTo", "ttFrom", "ttTo").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithBlankVtFrom() { bitemporalMapper(" ", "vtTo", "ttFrom", "ttTo").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithNullVtTo() { bitemporalMapper("vtFrom", null, "ttFrom", "ttTo").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithEmptyVtTo() { bitemporalMapper("vtFrom", "", "ttFrom", "ttTo").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithBlankVtTo() { bitemporalMapper("vtFrom", " ", "ttFrom", "ttTo").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithNullTtFrom() { bitemporalMapper("vtFrom", "vtTo", null, "ttTo").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithEmptyTtFrom() { bitemporalMapper("vtFrom", "vtTo", "", "ttTo").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithBlankTtFrom() { bitemporalMapper("vtFrom", "vtTo", " ", "ttTo").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithNullTtTo() { bitemporalMapper("vtFrom", "vtTo", "ttFrom", null).pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithEmptyTtTo() { bitemporalMapper("vtFrom", "vtTo", "ttFrom", "").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithBlankTtTo() { bitemporalMapper("vtFrom", "vtTo", "ttFrom", " ").pattern("yyyy/MM/dd").nowValue("2021/03/11").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithEmptyNowValue() { bitemporalMapper("vtFrom", "vtTo", "ttFrom", "ttTo").pattern("yyyy/MM/dd").nowValue("").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithBlankNowValue() { bitemporalMapper("vtFrom", "vtTo", "ttFrom", "ttTo").pattern("yyyy/MM/dd").nowValue(" ").build("f"); }
@Test(expected = IndexException.class) public void testConstructorWithInvalidNowValue() { bitemporalMapper("vtFrom", "vtTo", "ttFrom", "ttTo").pattern("yyyy/MM/dd") .nowValue("2021-03-11 00:00:00.001") .build("f"); }
@Test public void testExtractAnalyzers() throws ParseException { BitemporalMapper mapper = bitemporalMapper("vtFrom", "vtTo", "ttFrom", "ttTo").build("f"); assertNull("Analyzer should be null", mapper.analyzer); }