Search in sources :

Example 1 with SearchResult

use of com.netsuite.webservices.v2014_2.platform.core.SearchResult 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 SearchResult

use of com.netsuite.webservices.v2014_2.platform.core.SearchResult 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 SearchResult

use of com.netsuite.webservices.v2014_2.platform.core.SearchResult 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.v2016_2.platform.NetSuitePortType) SearchRequest(com.netsuite.webservices.v2016_2.platform.messages.SearchRequest) SearchMoreWithIdResponse(com.netsuite.webservices.v2016_2.platform.messages.SearchMoreWithIdResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SearchResult(com.netsuite.webservices.v2016_2.platform.core.SearchResult) SearchResponse(com.netsuite.webservices.v2016_2.platform.messages.SearchResponse) SearchMoreWithIdRequest(com.netsuite.webservices.v2016_2.platform.messages.SearchMoreWithIdRequest)

Example 4 with SearchResult

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

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

Example 5 with SearchResult

use of com.netsuite.webservices.v2014_2.platform.core.SearchResult 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)3 SearchResult (com.netsuite.webservices.v2014_2.platform.core.SearchResult)2 SearchResult (com.netsuite.webservices.v2016_2.platform.core.SearchResult)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)1 Record (com.netsuite.webservices.v2014_2.platform.core.Record)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 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)1 RecordList (com.netsuite.webservices.v2016_2.platform.core.RecordList)1 SearchMoreWithIdRequest (com.netsuite.webservices.v2016_2.platform.messages.SearchMoreWithIdRequest)1 SearchMoreWithIdResponse (com.netsuite.webservices.v2016_2.platform.messages.SearchMoreWithIdResponse)1 SearchRequest (com.netsuite.webservices.v2016_2.platform.messages.SearchRequest)1 SearchResponse (com.netsuite.webservices.v2016_2.platform.messages.SearchResponse)1 NsSearchResult (org.talend.components.netsuite.client.NsSearchResult)1