Search in sources :

Example 1 with SearchDateField

use of com.netsuite.webservices.test.platform.core.SearchDateField in project components by Talend.

the class SearchQueryTest method testSearchDateField.

@Test
public void testSearchDateField() throws Exception {
    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm:ss");
    Instant now = Instant.now();
    String currentDateFormatted = dateFormatter.print(now.getMillis());
    SearchQuery s1 = clientService.newSearch();
    s1.target("Check");
    s1.condition(new SearchCondition("TranDate", "Date.onOrAfter", Arrays.asList("2017-01-01 12:00:00")));
    s1.condition(new SearchCondition("CustomDateField1", "Date.onOrAfter", Arrays.asList("14:00:00")));
    SearchRecord sr1 = (SearchRecord) s1.toNativeQuery();
    assertNotNull(sr1);
    Assert.assertEquals(TransactionSearch.class, sr1.getClass());
    TransactionSearch search = (TransactionSearch) sr1;
    assertNotNull(search.getBasic());
    TransactionSearchBasic searchBasic = search.getBasic();
    assertNotNull(searchBasic.getTranDate());
    SearchDateField field1 = searchBasic.getTranDate();
    Assert.assertEquals(SearchDateFieldOperator.ON_OR_AFTER, field1.getOperator());
    assertNotNull(field1.getSearchValue());
    assertNull(field1.getSearchValue2());
    assertEquals("2017-01-01 12:00:00", dateTimeFormatter.print((Long) calendarValueConverter.convertToAvro(field1.getSearchValue())));
    SearchCustomFieldList customFieldList = searchBasic.getCustomFieldList();
    assertNotNull(customFieldList);
    assertNotNull(customFieldList.getCustomField());
    Assert.assertEquals(1, customFieldList.getCustomField().size());
    MutableDateTime controlDateTime = new MutableDateTime();
    controlDateTime.setHourOfDay(14);
    controlDateTime.setMinuteOfHour(0);
    controlDateTime.setSecondOfMinute(0);
    controlDateTime.setMillisOfSecond(0);
    String controlTimeFormatted = timeFormatter.print(controlDateTime);
    SearchDateCustomField customField1 = (SearchDateCustomField) customFieldList.getCustomField().get(0);
    Assert.assertEquals(SearchDateFieldOperator.ON_OR_AFTER, customField1.getOperator());
    assertNotNull(customField1.getSearchValue());
    assertNull(customField1.getSearchValue2());
    assertEquals(currentDateFormatted + " " + controlTimeFormatted, dateTimeFormatter.print((Long) calendarValueConverter.convertToAvro(customField1.getSearchValue())));
}
Also used : SearchQuery(org.talend.components.netsuite.client.search.SearchQuery) TransactionSearch(com.netsuite.webservices.test.transactions.sales.TransactionSearch) Instant(org.joda.time.Instant) SearchDateField(com.netsuite.webservices.test.platform.core.SearchDateField) MutableDateTime(org.joda.time.MutableDateTime) TransactionSearchBasic(com.netsuite.webservices.test.platform.common.TransactionSearchBasic) SearchCustomFieldList(com.netsuite.webservices.test.platform.core.SearchCustomFieldList) SearchRecord(com.netsuite.webservices.test.platform.core.SearchRecord) SearchDateCustomField(com.netsuite.webservices.test.platform.core.SearchDateCustomField) SearchCondition(org.talend.components.netsuite.client.search.SearchCondition) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 2 with SearchDateField

use of com.netsuite.webservices.test.platform.core.SearchDateField 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)

Example 3 with SearchDateField

use of com.netsuite.webservices.test.platform.core.SearchDateField in project components by Talend.

the class SearchQueryTest method testSearchDateFieldWithPredefinedDate.

@Test
public void testSearchDateFieldWithPredefinedDate() throws Exception {
    SearchQuery s1 = clientService.newSearch();
    s1.target("Check");
    s1.condition(new SearchCondition("TranDate", "PredefinedDate.lastBusinessWeek", null));
    s1.condition(new SearchCondition("CustomDateField1", "PredefinedDate.lastBusinessWeek", null));
    SearchRecord sr1 = (SearchRecord) s1.toNativeQuery();
    assertNotNull(sr1);
    Assert.assertEquals(TransactionSearch.class, sr1.getClass());
    TransactionSearch search = (TransactionSearch) sr1;
    assertNotNull(search.getBasic());
    TransactionSearchBasic searchBasic = search.getBasic();
    assertNotNull(searchBasic.getTranDate());
    SearchEnumMultiSelectField typeField = searchBasic.getType();
    assertNotNull(typeField);
    assertNotNull(typeField.getSearchValue());
    Assert.assertEquals(1, typeField.getSearchValue().size());
    Assert.assertEquals(RecordType.CHECK.value(), typeField.getSearchValue().get(0));
    SearchDateField field1 = searchBasic.getTranDate();
    assertNull(field1.getOperator());
    assertNull(field1.getSearchValue());
    assertNull(field1.getSearchValue2());
    assertNotNull(field1.getPredefinedSearchValue());
    Assert.assertEquals(SearchDate.LAST_BUSINESS_WEEK, field1.getPredefinedSearchValue());
    SearchCustomFieldList customFieldList = searchBasic.getCustomFieldList();
    assertNotNull(customFieldList);
    assertNotNull(customFieldList.getCustomField());
    Assert.assertEquals(1, customFieldList.getCustomField().size());
    SearchDateCustomField customField1 = (SearchDateCustomField) customFieldList.getCustomField().get(0);
    assertNull(customField1.getOperator());
    assertNull(customField1.getSearchValue());
    assertNull(customField1.getSearchValue2());
    assertNotNull(customField1.getPredefinedSearchValue());
    Assert.assertEquals(SearchDate.LAST_BUSINESS_WEEK, customField1.getPredefinedSearchValue());
}
Also used : SearchQuery(org.talend.components.netsuite.client.search.SearchQuery) TransactionSearch(com.netsuite.webservices.test.transactions.sales.TransactionSearch) SearchRecord(com.netsuite.webservices.test.platform.core.SearchRecord) SearchDateCustomField(com.netsuite.webservices.test.platform.core.SearchDateCustomField) SearchCondition(org.talend.components.netsuite.client.search.SearchCondition) SearchDateField(com.netsuite.webservices.test.platform.core.SearchDateField) TransactionSearchBasic(com.netsuite.webservices.test.platform.common.TransactionSearchBasic) SearchCustomFieldList(com.netsuite.webservices.test.platform.core.SearchCustomFieldList) SearchEnumMultiSelectField(com.netsuite.webservices.test.platform.core.SearchEnumMultiSelectField) Test(org.junit.Test)

Aggregations

SearchDateCustomField (com.netsuite.webservices.test.platform.core.SearchDateCustomField)3 SearchDateField (com.netsuite.webservices.test.platform.core.SearchDateField)3 Test (org.junit.Test)3 TransactionSearchBasic (com.netsuite.webservices.test.platform.common.TransactionSearchBasic)2 SearchCustomFieldList (com.netsuite.webservices.test.platform.core.SearchCustomFieldList)2 SearchRecord (com.netsuite.webservices.test.platform.core.SearchRecord)2 TransactionSearch (com.netsuite.webservices.test.transactions.sales.TransactionSearch)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2 SearchCondition (org.talend.components.netsuite.client.search.SearchCondition)2 SearchQuery (org.talend.components.netsuite.client.search.SearchQuery)2 SearchEnumMultiSelectField (com.netsuite.webservices.test.platform.core.SearchEnumMultiSelectField)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 Instant (org.joda.time.Instant)1 MutableDateTime (org.joda.time.MutableDateTime)1 XMLGregorianCalendarToDateTimeConverter (org.talend.components.netsuite.avro.converter.XMLGregorianCalendarToDateTimeConverter)1