Search in sources :

Example 1 with RecordList

use of com.netsuite.webservices.v2014_2.platform.core.RecordList in project components by Talend.

the class NetSuiteMockTestBase method mockSearchRequestResults.

protected <T extends Record> void mockSearchRequestResults(List<T> recordList, int pageSize) throws Exception {
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    final List<SearchResult> pageResults = makeRecordPages(recordList, pageSize);
    when(port.search(any(SearchRequest.class))).then(new Answer<SearchResponse>() {

        @Override
        public SearchResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            SearchResponse response = new SearchResponse();
            response.setSearchResult(pageResults.get(0));
            return response;
        }
    });
    when(port.searchMoreWithId(any(SearchMoreWithIdRequest.class))).then(new Answer<SearchMoreWithIdResponse>() {

        @Override
        public SearchMoreWithIdResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            SearchMoreWithIdRequest request = (SearchMoreWithIdRequest) invocationOnMock.getArguments()[0];
            SearchMoreWithIdResponse response = new SearchMoreWithIdResponse();
            response.setSearchResult(pageResults.get(request.getPageIndex() - 1));
            return response;
        }
    });
}
Also used : NetSuitePortType(com.netsuite.webservices.v2014_2.platform.NetSuitePortType) SearchRequest(com.netsuite.webservices.v2014_2.platform.messages.SearchRequest) SearchMoreWithIdResponse(com.netsuite.webservices.v2014_2.platform.messages.SearchMoreWithIdResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SearchResult(com.netsuite.webservices.v2014_2.platform.core.SearchResult) SearchResponse(com.netsuite.webservices.v2014_2.platform.messages.SearchResponse) SearchMoreWithIdRequest(com.netsuite.webservices.v2014_2.platform.messages.SearchMoreWithIdRequest)

Example 2 with RecordList

use of com.netsuite.webservices.v2014_2.platform.core.RecordList in project components by Talend.

the class NetSuiteMockTestBase method makeRecordPages.

public static <T extends Record> List<SearchResult> makeRecordPages(List<T> recordList, int pageSize) throws Exception {
    int count = recordList.size();
    int totalPages = count / pageSize;
    if (count % pageSize != 0) {
        totalPages += 1;
    }
    String searchId = UUID.randomUUID().toString();
    List<SearchResult> pageResults = new ArrayList<>();
    SearchResult result = null;
    Iterator<T> recordIterator = recordList.iterator();
    while (recordIterator.hasNext() && count > 0) {
        T record = recordIterator.next();
        if (result == null) {
            result = new SearchResult();
            result.setSearchId(searchId);
            result.setTotalPages(totalPages);
            result.setTotalRecords(count);
            result.setPageIndex(pageResults.size() + 1);
            result.setPageSize(pageSize);
            result.setStatus(createSuccessStatus());
        }
        if (result.getRecordList() == null) {
            result.setRecordList(new RecordList());
        }
        result.getRecordList().getRecord().add(record);
        if (result.getRecordList().getRecord().size() == pageSize) {
            pageResults.add(result);
            result = null;
        }
        count--;
    }
    if (result != null) {
        pageResults.add(result);
    }
    return pageResults;
}
Also used : RecordList(com.netsuite.webservices.v2016_2.platform.core.RecordList) ArrayList(java.util.ArrayList) SearchResult(com.netsuite.webservices.v2016_2.platform.core.SearchResult)

Example 3 with RecordList

use of com.netsuite.webservices.v2014_2.platform.core.RecordList in project components by Talend.

the class NetSuiteClientServiceImpl 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.v2014_2.platform.core.Record) SearchRecord(com.netsuite.webservices.v2014_2.platform.core.SearchRecord)

Example 4 with RecordList

use of com.netsuite.webservices.v2014_2.platform.core.RecordList in project components by Talend.

the class NetSuiteSearchInputReaderTest method testBasic.

@Test
public void testBasic() throws Exception {
    properties.module.moduleName.setValue("Account");
    NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
    NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    properties.module.main.schema.setValue(schema);
    NetSuiteSource source = new NetSuiteSourceImpl();
    source.initialize(mockTestFixture.getRuntimeContainer(), properties);
    List<Account> recordList = makeNsObjects(new SimpleObjectComposer<>(Account.class), 150);
    mockSearchRequestResults(recordList, 100);
    NetSuiteClientService<?> clientService = source.getClientService();
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(Account.class);
    NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(mockTestFixture.getRuntimeContainer());
    boolean started = reader.start();
    assertTrue(started);
    IndexedRecord record = reader.getCurrent();
    assertNotNull(record);
    while (reader.advance()) {
        record = reader.getCurrent();
        assertIndexedRecord(typeDesc, record);
    }
    Map<String, Object> readerResult = reader.getReturnValues();
    assertNotNull(readerResult);
    assertEquals(150, readerResult.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
}
Also used : Account(com.netsuite.webservices.v2014_2.lists.accounting.Account) NetSuiteSourceImpl(org.talend.components.netsuite.v2014_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2014_2.NetSuiteRuntimeImpl) Test(org.junit.Test)

Example 5 with RecordList

use of com.netsuite.webservices.v2014_2.platform.core.RecordList in project components by Talend.

the class NetSuiteMockTestBase method makeRecordPages.

public static <T extends Record> List<SearchResult> makeRecordPages(List<T> recordList, int pageSize) throws Exception {
    int count = recordList.size();
    int totalPages = count / pageSize;
    if (count % pageSize != 0) {
        totalPages += 1;
    }
    String searchId = UUID.randomUUID().toString();
    List<SearchResult> pageResults = new ArrayList<>();
    SearchResult result = null;
    Iterator<T> recordIterator = recordList.iterator();
    while (recordIterator.hasNext() && count > 0) {
        T record = recordIterator.next();
        if (result == null) {
            result = new SearchResult();
            result.setSearchId(searchId);
            result.setTotalPages(totalPages);
            result.setTotalRecords(count);
            result.setPageIndex(pageResults.size() + 1);
            result.setPageSize(pageSize);
            result.setStatus(createSuccessStatus());
        }
        if (result.getRecordList() == null) {
            result.setRecordList(new RecordList());
        }
        result.getRecordList().getRecord().add(record);
        if (result.getRecordList().getRecord().size() == pageSize) {
            pageResults.add(result);
            result = null;
        }
        count--;
    }
    if (result != null) {
        pageResults.add(result);
    }
    return pageResults;
}
Also used : RecordList(com.netsuite.webservices.v2014_2.platform.core.RecordList) ArrayList(java.util.ArrayList) SearchResult(com.netsuite.webservices.v2014_2.platform.core.SearchResult)

Aggregations

ArrayList (java.util.ArrayList)4 Record (com.netsuite.webservices.v2014_2.platform.core.Record)2 SearchResult (com.netsuite.webservices.v2014_2.platform.core.SearchResult)2 Schema (org.apache.avro.Schema)2 IndexedRecord (org.apache.avro.generic.IndexedRecord)2 Account (com.netsuite.webservices.v2014_2.lists.accounting.Account)1 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)1 RecordList (com.netsuite.webservices.v2014_2.platform.core.RecordList)1 SearchRecord (com.netsuite.webservices.v2014_2.platform.core.SearchRecord)1 SearchMoreWithIdRequest (com.netsuite.webservices.v2014_2.platform.messages.SearchMoreWithIdRequest)1 SearchMoreWithIdResponse (com.netsuite.webservices.v2014_2.platform.messages.SearchMoreWithIdResponse)1 SearchRequest (com.netsuite.webservices.v2014_2.platform.messages.SearchRequest)1 SearchResponse (com.netsuite.webservices.v2014_2.platform.messages.SearchResponse)1 RecordList (com.netsuite.webservices.v2016_2.platform.core.RecordList)1 SearchResult (com.netsuite.webservices.v2016_2.platform.core.SearchResult)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)1 NetSuiteRuntime (org.talend.components.netsuite.NetSuiteRuntime)1