Search in sources :

Example 1 with XMLGregorianCalendarToDateTimeConverter

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());
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SearchDateCustomField(com.netsuite.webservices.test.platform.core.SearchDateCustomField) XMLGregorianCalendarToDateTimeConverter(org.talend.components.netsuite.avro.converter.XMLGregorianCalendarToDateTimeConverter) SearchDateField(com.netsuite.webservices.test.platform.core.SearchDateField) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Aggregations

SearchDateCustomField (com.netsuite.webservices.test.platform.core.SearchDateCustomField)1 SearchDateField (com.netsuite.webservices.test.platform.core.SearchDateField)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 Test (org.junit.Test)1 XMLGregorianCalendarToDateTimeConverter (org.talend.components.netsuite.avro.converter.XMLGregorianCalendarToDateTimeConverter)1