Search in sources :

Example 6 with Record

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

the class TestNetSuiteClientService method toNsSearchResult.

public static <RecT> NsSearchResult<RecT> toNsSearchResult(SearchResult result) {
    NsSearchResult nsResult = new NsSearchResult(toNsStatus(result.getStatus()));
    nsResult.setSearchId(result.getSearchId());
    nsResult.setTotalPages(result.getTotalPages());
    nsResult.setTotalRecords(result.getTotalRecords());
    nsResult.setPageIndex(result.getPageIndex());
    nsResult.setPageSize(result.getPageSize());
    if (result.getRecordList() != null) {
        List<Record> nsRecordList = new ArrayList<>(result.getRecordList().getRecord().size());
        for (Record record : result.getRecordList().getRecord()) {
            nsRecordList.add(record);
        }
        nsResult.setRecordList(nsRecordList);
    } else {
        nsResult.setRecordList(Collections.emptyList());
    }
    return nsResult;
}
Also used : NsSearchResult(org.talend.components.netsuite.client.NsSearchResult) ArrayList(java.util.ArrayList) Record(com.netsuite.webservices.test.platform.core.Record) SearchRecord(com.netsuite.webservices.test.platform.core.SearchRecord)

Example 7 with Record

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

the class TestNetSuiteClientService method toRecordList.

public static <RecT> List<Record> toRecordList(List<RecT> nsRecordList) {
    List<Record> recordList = new ArrayList<>(nsRecordList.size());
    for (RecT nsRecord : nsRecordList) {
        Record r = (Record) nsRecord;
        recordList.add(r);
    }
    return recordList;
}
Also used : ArrayList(java.util.ArrayList) Record(com.netsuite.webservices.test.platform.core.Record) SearchRecord(com.netsuite.webservices.test.platform.core.SearchRecord)

Example 8 with Record

use of com.netsuite.webservices.test.platform.core.Record 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 9 with Record

use of com.netsuite.webservices.test.platform.core.Record 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 10 with Record

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

the class NsObjectInputTransducerTest method testDynamicSchemaWithCustomFields.

@Test
public void testDynamicSchemaWithCustomFields() throws Exception {
    TestCustomMetaDataSource customMetaDataSource = new TestCustomMetaDataSource(clientService, "Opportunity");
    clientService.getMetaDataSource().setCustomMetaDataSource(customMetaDataSource);
    TypeDesc basicTypeDesc = clientService.getMetaDataSource().getTypeInfo("Opportunity");
    final List<Opportunity> recordList = makeNsObjects(new NsObjectComposer<Opportunity>(clientService.getMetaDataSource(), basicTypeDesc), 10);
    mockSearchRequestResults(recordList, 100);
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(basicTypeDesc.getTypeName());
    Schema schema = getDynamicSchema();
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    SearchResultSet<Record> rs = clientService.newSearch().target(basicTypeDesc.getTypeName()).search();
    while (rs.next()) {
        Record record = rs.get();
        IndexedRecord indexedRecord = transducer.read(record);
        assertIndexedRecord(typeDesc, indexedRecord);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Opportunity(com.netsuite.webservices.test.transactions.sales.Opportunity) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) CustomRecord(com.netsuite.webservices.test.setup.customization.CustomRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Record(com.netsuite.webservices.test.platform.core.Record) Test(org.junit.Test)

Aggregations

Record (com.netsuite.webservices.test.platform.core.Record)11 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 Schema (org.apache.avro.Schema)5 IndexedRecord (org.apache.avro.generic.IndexedRecord)5 CustomRecord (com.netsuite.webservices.test.setup.customization.CustomRecord)4 NetSuiteWebServiceMockTestFixture.assertIndexedRecord (org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord)4 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)4 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 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)3 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)3 SearchResultSet (org.talend.components.netsuite.client.search.SearchResultSet)3 TestNetSuiteClientService (org.talend.components.netsuite.test.client.TestNetSuiteClientService)3 AccountSearch (com.netsuite.webservices.test.lists.accounting.AccountSearch)2 RecordList (com.netsuite.webservices.test.platform.core.RecordList)2 SearchRecord (com.netsuite.webservices.test.platform.core.SearchRecord)2 SearchMoreWithIdResponse (com.netsuite.webservices.test.platform.messages.SearchMoreWithIdResponse)2 Check (com.netsuite.webservices.test.transactions.bank.Check)2