use of org.talend.components.netsuite.avro.converter.XMLGregorianCalendarToDateTimeConverter in project components by Talend.
the class SearchFieldAdaptersTest method testAdapterForDateSearchField.
@Test
public void testAdapterForDateSearchField() throws Exception {
XMLGregorianCalendarToDateTimeConverter calendarValueConverter = new XMLGregorianCalendarToDateTimeConverter(DatatypeFactory.newInstance());
DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
String dateString1 = "2017-01-01";
String dateString2 = "2017-02-01";
XMLGregorianCalendar xmlGregorianCalendar1 = calendarValueConverter.convertToDatum(dateFormatter.parseDateTime(dateString1).getMillis());
XMLGregorianCalendar xmlGregorianCalendar2 = calendarValueConverter.convertToDatum(dateFormatter.parseDateTime(dateString2).getMillis());
SearchDateFieldAdapter adapter1 = new SearchDateFieldAdapter(basicMetaData, SearchFieldType.DATE, SearchDateField.class);
SearchDateField field1 = (SearchDateField) adapter1.populate(null, "Date.onOrAfter", Arrays.asList(dateString1));
assertNotNull(field1);
assertEquals(SearchDateFieldOperator.ON_OR_AFTER, field1.getOperator());
assertEquals(xmlGregorianCalendar1, field1.getSearchValue());
field1 = (SearchDateField) adapter1.populate(null, "Date.within", Arrays.asList(dateString1, dateString2));
assertEquals(SearchDateFieldOperator.WITHIN, field1.getOperator());
assertEquals(xmlGregorianCalendar1, field1.getSearchValue());
assertEquals(xmlGregorianCalendar2, field1.getSearchValue2());
field1 = (SearchDateField) adapter1.populate(null, "Date.before", null);
assertEquals(SearchDateFieldOperator.BEFORE, field1.getOperator());
assertNull(field1.getSearchValue());
SearchDateFieldAdapter adapter2 = new SearchDateFieldAdapter(basicMetaData, SearchFieldType.CUSTOM_DATE, SearchDateCustomField.class);
SearchDateCustomField field2 = (SearchDateCustomField) adapter2.populate(null, "Date.notBefore", Arrays.asList(dateString1));
assertNotNull(field2);
assertEquals(SearchDateFieldOperator.NOT_BEFORE, field2.getOperator());
assertEquals(xmlGregorianCalendar1, field2.getSearchValue());
assertNull(field2.getSearchValue2());
field2 = (SearchDateCustomField) adapter2.populate(null, "PredefinedDate.lastFiscalQuarter", null);
assertNotNull(field2);
assertEquals(SearchDate.LAST_FISCAL_QUARTER, field2.getPredefinedSearchValue());
assertNull(field2.getSearchValue());
assertNull(field2.getSearchValue2());
}
Aggregations