Search in sources :

Example 6 with SearchRecordTypeDesc

use of org.talend.components.netsuite.client.model.SearchRecordTypeDesc in project components by Talend.

the class MetaDataSourceTest method testGetSearchRecordType.

@Test
public void testGetSearchRecordType() {
    SearchRecordTypeDesc searchRecordTypeDesc = metaDataSource.getSearchRecordType(TestRecordTypeEnum.ACCOUNT.getTypeName());
    assertNotNull(searchRecordTypeDesc);
    searchRecordTypeDesc = metaDataSource.getSearchRecordType(TestRecordTypeEnum.ACCOUNT.getTypeName());
    assertNotNull(searchRecordTypeDesc);
    searchRecordTypeDesc = metaDataSource.getSearchRecordType(TestRecordTypeEnum.CUSTOM_RECORD.getType());
    assertNotNull(searchRecordTypeDesc);
    searchRecordTypeDesc = metaDataSource.getSearchRecordType(TestRecordTypeEnum.CUSTOM_RECORD);
    assertNotNull(searchRecordTypeDesc);
    searchRecordTypeDesc = metaDataSource.getSearchRecordType(TestRecordTypeEnum.CUSTOM_TRANSACTION.getType());
    assertNotNull(searchRecordTypeDesc);
    searchRecordTypeDesc = metaDataSource.getSearchRecordType(TestRecordTypeEnum.CUSTOM_TRANSACTION);
    assertNotNull(searchRecordTypeDesc);
    assertNull(metaDataSource.getSearchRecordType(TestRecordTypeEnum.ENTITY_CUSTOM_FIELD.getTypeName()));
}
Also used : SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) Test(org.junit.Test)

Example 7 with SearchRecordTypeDesc

use of org.talend.components.netsuite.client.model.SearchRecordTypeDesc in project components by Talend.

the class SearchResultSetTest method testRecordFiltering.

@Test
public void testRecordFiltering() throws Exception {
    NetSuiteClientService<?> conn = mock(NetSuiteClientService.class);
    List<Record> page1 = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        page1.add(new InventoryItem());
    }
    List<Record> page2 = new ArrayList<>();
    for (int i = 0; i < 750; i++) {
        page2.add(new ServiceSaleItem());
    }
    SearchResult result1 = new SearchResult();
    Status status = new Status();
    status.setIsSuccess(true);
    result1.setStatus(status);
    result1.setSearchId("abc123");
    result1.setPageIndex(1);
    result1.setTotalRecords(page1.size() + page2.size());
    result1.setTotalPages(2);
    result1.setRecordList(new RecordList());
    result1.getRecordList().getRecord().addAll(page1);
    SearchResult result2 = new SearchResult();
    result2.setStatus(status);
    result2.setSearchId(result1.getSearchId());
    result2.setPageIndex(2);
    result2.setTotalRecords(result1.getTotalRecords());
    result2.setTotalPages(result1.getTotalPages());
    result2.setRecordList(new RecordList());
    result2.getRecordList().getRecord().addAll(page2);
    SearchResponse response1 = new SearchResponse();
    response1.setSearchResult(result1);
    SearchMoreWithIdResponse response2 = new SearchMoreWithIdResponse();
    response2.setSearchResult(result2);
    ItemSearch nsSearchRecord1 = new ItemSearch();
    NsSearchResult nsSearchResult1 = TestNetSuiteClientService.toNsSearchResult(result1);
    NsSearchResult nsSearchResult2 = TestNetSuiteClientService.toNsSearchResult(result2);
    when(conn.search(eq(nsSearchRecord1))).thenReturn(nsSearchResult1);
    when(conn.searchMoreWithId(eq("abc123"), eq(2))).thenReturn(nsSearchResult2);
    NetSuiteClientService<?> clientService = new TestNetSuiteClientService();
    RecordTypeInfo recordTypeInfo = clientService.getMetaDataSource().getRecordType("InventoryItem");
    SearchRecordTypeDesc searchRecordTypeDesc = clientService.getMetaDataSource().getSearchRecordType(recordTypeInfo.getRecordType().getSearchRecordType());
    SearchResultSet<Record> resultSet = new SearchResultSet<>(conn, recordTypeInfo.getRecordType(), searchRecordTypeDesc, nsSearchResult1);
    List<Object> recordList = new ArrayList<>();
    while (resultSet.next()) {
        Object record = resultSet.get();
        assertNotNull(record);
        recordList.add(record);
    }
    assertEquals(page1.size(), recordList.size());
}
Also used : Status(com.netsuite.webservices.test.platform.core.Status) InventoryItem(com.netsuite.webservices.test.lists.accounting.InventoryItem) ServiceSaleItem(com.netsuite.webservices.test.lists.accounting.ServiceSaleItem) TestNetSuiteClientService(org.talend.components.netsuite.test.client.TestNetSuiteClientService) SearchMoreWithIdResponse(com.netsuite.webservices.test.platform.messages.SearchMoreWithIdResponse) ArrayList(java.util.ArrayList) SearchResult(com.netsuite.webservices.test.platform.core.SearchResult) ItemSearch(com.netsuite.webservices.test.lists.accounting.ItemSearch) SearchResponse(com.netsuite.webservices.test.platform.messages.SearchResponse) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordList(com.netsuite.webservices.test.platform.core.RecordList) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchResultSet(org.talend.components.netsuite.client.search.SearchResultSet) Record(com.netsuite.webservices.test.platform.core.Record) Test(org.junit.Test)

Example 8 with SearchRecordTypeDesc

use of org.talend.components.netsuite.client.model.SearchRecordTypeDesc in project components by Talend.

the class SearchResultSetTest method testPagination.

@Test
public void testPagination() throws Exception {
    NetSuiteClientService<?> conn = mock(NetSuiteClientService.class);
    List<Record> page1 = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        page1.add(new Account());
    }
    List<Record> page2 = new ArrayList<>();
    for (int i = 0; i < 750; i++) {
        page2.add(new Account());
    }
    SearchResult result1 = new SearchResult();
    Status status = new Status();
    status.setIsSuccess(true);
    result1.setStatus(status);
    result1.setSearchId("abc123");
    result1.setPageIndex(1);
    result1.setTotalRecords(page1.size() + page2.size());
    result1.setTotalPages(2);
    result1.setRecordList(new RecordList());
    result1.getRecordList().getRecord().addAll(page1);
    SearchResult result2 = new SearchResult();
    result2.setStatus(status);
    result2.setSearchId(result1.getSearchId());
    result2.setPageIndex(2);
    result2.setTotalRecords(result1.getTotalRecords());
    result2.setTotalPages(result1.getTotalPages());
    result2.setRecordList(new RecordList());
    result2.getRecordList().getRecord().addAll(page2);
    SearchResponse response1 = new SearchResponse();
    response1.setSearchResult(result1);
    SearchMoreWithIdResponse response2 = new SearchMoreWithIdResponse();
    response2.setSearchResult(result2);
    AccountSearch nsSearchRecord1 = new AccountSearch();
    NsSearchResult nsSearchResult1 = TestNetSuiteClientService.toNsSearchResult(result1);
    NsSearchResult nsSearchResult2 = TestNetSuiteClientService.toNsSearchResult(result2);
    when(conn.search(eq(nsSearchRecord1))).thenReturn(nsSearchResult1);
    when(conn.searchMoreWithId(eq("abc123"), eq(2))).thenReturn(nsSearchResult2);
    NetSuiteClientService<?> clientService = new TestNetSuiteClientService();
    RecordTypeInfo recordTypeInfo = clientService.getMetaDataSource().getRecordType("Account");
    SearchRecordTypeDesc searchRecordTypeDesc = clientService.getMetaDataSource().getSearchRecordType(recordTypeInfo.getRecordType().getSearchRecordType());
    SearchResultSet<Record> resultSet = new SearchResultSet<>(conn, recordTypeInfo.getRecordType(), searchRecordTypeDesc, nsSearchResult1);
    List<Object> recordList = new ArrayList<>();
    while (resultSet.next()) {
        Object record = resultSet.get();
        assertNotNull(record);
        recordList.add(record);
    }
    assertEquals(page1.size() + page2.size(), recordList.size());
}
Also used : Status(com.netsuite.webservices.test.platform.core.Status) Account(com.netsuite.webservices.test.lists.accounting.Account) TestNetSuiteClientService(org.talend.components.netsuite.test.client.TestNetSuiteClientService) SearchMoreWithIdResponse(com.netsuite.webservices.test.platform.messages.SearchMoreWithIdResponse) ArrayList(java.util.ArrayList) SearchResult(com.netsuite.webservices.test.platform.core.SearchResult) SearchResponse(com.netsuite.webservices.test.platform.messages.SearchResponse) AccountSearch(com.netsuite.webservices.test.lists.accounting.AccountSearch) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordList(com.netsuite.webservices.test.platform.core.RecordList) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchResultSet(org.talend.components.netsuite.client.search.SearchResultSet) Record(com.netsuite.webservices.test.platform.core.Record) Test(org.junit.Test)

Example 9 with SearchRecordTypeDesc

use of org.talend.components.netsuite.client.model.SearchRecordTypeDesc in project components by Talend.

the class DefaultMetaDataSource method getSearchRecordType.

/**
 * {@inheritDoc}
 */
@Override
public SearchRecordTypeDesc getSearchRecordType(String recordTypeName) {
    SearchRecordTypeDesc searchRecordType = clientService.getBasicMetaData().getSearchRecordType(recordTypeName);
    if (searchRecordType != null) {
        return searchRecordType;
    }
    RecordTypeInfo recordTypeInfo = getRecordType(recordTypeName);
    if (recordTypeInfo != null) {
        return getSearchRecordType(recordTypeInfo.getRecordType());
    }
    return null;
}
Also used : SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo)

Example 10 with SearchRecordTypeDesc

use of org.talend.components.netsuite.client.model.SearchRecordTypeDesc in project components by Talend.

the class NetSuiteClientServiceTest method testBasicMetaData.

@Test
public void testBasicMetaData() throws Exception {
    NetSuiteClientService<?> clientService = webServiceMockTestFixture.getClientService();
    Set<SearchRecordType> searchRecordTypeSet = new HashSet<>(Arrays.asList(SearchRecordType.values()));
    Set<String> searchRecordTypeNameSet = new HashSet<>();
    for (SearchRecordType searchRecordType : searchRecordTypeSet) {
        searchRecordTypeNameSet.add(toInitialUpper(searchRecordType.value()));
    }
    searchRecordTypeNameSet.add("Address");
    searchRecordTypeNameSet.add("InventoryDetail");
    searchRecordTypeNameSet.add("TimeEntry");
    for (String searchRecordType : searchRecordTypeNameSet) {
        try {
            SearchRecordTypeDesc searchRecordInfo = clientService.getMetaDataSource().getSearchRecordType(searchRecordType);
            assertNotNull("Search record def found: " + searchRecordType, searchRecordInfo);
        } catch (Exception e) {
            throw new AssertionError("Search record type: " + searchRecordType, e);
        }
    }
    Set<RecordType> recordTypeSet = new HashSet<>(Arrays.asList(RecordType.values()));
    recordTypeSet.remove(RecordType.CUSTOM_TRANSACTION_TYPE);
    Set<String> recordTypeNameSet = new HashSet<>();
    for (RecordType recordType : recordTypeSet) {
        recordTypeNameSet.add(toInitialUpper(recordType.value()));
    }
    recordTypeNameSet.add("Address");
    recordTypeNameSet.add("InventoryDetail");
    recordTypeNameSet.add("TimeEntry");
    for (String recordType : recordTypeNameSet) {
        RecordTypeInfo recordTypeInfo = clientService.getMetaDataSource().getRecordType(recordType);
        assertNotNull("Record type def found: " + recordType, recordTypeInfo);
    }
    Collection<SearchFieldOperatorName> searchOperatorNames = clientService.getBasicMetaData().getSearchOperatorNames();
    List<SearchFieldOperatorName> searchFieldOperatorNameList = new ArrayList<>(searchOperatorNames);
    Collections.sort(searchFieldOperatorNameList, new Comparator<SearchFieldOperatorName>() {

        @Override
        public int compare(SearchFieldOperatorName o1, SearchFieldOperatorName o2) {
            return o1.getQualifiedName().compareTo(o2.getQualifiedName());
        }
    });
    for (SearchFieldOperatorName operatorName : searchFieldOperatorNameList) {
        assertNotNull(operatorName.getDataType());
        if (!SearchFieldOperatorType.BOOLEAN.dataTypeEquals(operatorName.getDataType())) {
            assertNotNull(operatorName.getName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SearchRecordType(com.netsuite.webservices.v2016_2.platform.core.types.SearchRecordType) SearchFieldOperatorName(org.talend.components.netsuite.client.model.search.SearchFieldOperatorName) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) SearchRecordType(com.netsuite.webservices.v2016_2.platform.core.types.SearchRecordType) RecordType(com.netsuite.webservices.v2016_2.platform.core.types.RecordType) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)11 Test (org.junit.Test)8 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)7 ArrayList (java.util.ArrayList)5 Record (com.netsuite.webservices.test.platform.core.Record)3 SearchResult (com.netsuite.webservices.test.platform.core.SearchResult)3 Status (com.netsuite.webservices.test.platform.core.Status)3 SearchResponse (com.netsuite.webservices.test.platform.messages.SearchResponse)3 SearchResultSet (org.talend.components.netsuite.client.search.SearchResultSet)3 TestNetSuiteClientService (org.talend.components.netsuite.test.client.TestNetSuiteClientService)3 NamedThing (org.talend.daikon.NamedThing)3 AccountSearch (com.netsuite.webservices.test.lists.accounting.AccountSearch)2 RecordList (com.netsuite.webservices.test.platform.core.RecordList)2 SearchMoreWithIdResponse (com.netsuite.webservices.test.platform.messages.SearchMoreWithIdResponse)2 HashSet (java.util.HashSet)2 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)2 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)2 Account (com.netsuite.webservices.test.lists.accounting.Account)1 InventoryItem (com.netsuite.webservices.test.lists.accounting.InventoryItem)1 ItemSearch (com.netsuite.webservices.test.lists.accounting.ItemSearch)1