Search in sources :

Example 1 with SearchResult

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

the class SearchResultSetTest method testEmptyResult.

@Test
public void testEmptyResult() throws Exception {
    NetSuiteClientService<?> conn = mock(NetSuiteClientService.class);
    SearchResult result1 = new SearchResult();
    Status status = new Status();
    status.setIsSuccess(true);
    result1.setStatus(status);
    result1.setSearchId("abc123");
    result1.setPageIndex(1);
    result1.setTotalRecords(0);
    result1.setTotalPages(0);
    SearchResponse response1 = new SearchResponse();
    response1.setSearchResult(result1);
    AccountSearch nsSearchRecord1 = new AccountSearch();
    NsSearchResult nsSearchResult1 = TestNetSuiteClientService.toNsSearchResult(result1);
    when(conn.search(eq(nsSearchRecord1))).thenReturn(nsSearchResult1);
    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);
    assertFalse(resultSet.next());
}
Also used : Status(com.netsuite.webservices.test.platform.core.Status) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) TestNetSuiteClientService(org.talend.components.netsuite.test.client.TestNetSuiteClientService) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchResultSet(org.talend.components.netsuite.client.search.SearchResultSet) SearchResult(com.netsuite.webservices.test.platform.core.SearchResult) Record(com.netsuite.webservices.test.platform.core.Record) SearchResponse(com.netsuite.webservices.test.platform.messages.SearchResponse) AccountSearch(com.netsuite.webservices.test.lists.accounting.AccountSearch) Test(org.junit.Test)

Example 2 with SearchResult

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

Example 3 with SearchResult

use of com.netsuite.webservices.test.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.test.platform.core.RecordList) ArrayList(java.util.ArrayList) SearchResult(com.netsuite.webservices.test.platform.core.SearchResult)

Example 4 with SearchResult

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

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

Aggregations

SearchResult (com.netsuite.webservices.test.platform.core.SearchResult)5 SearchResponse (com.netsuite.webservices.test.platform.messages.SearchResponse)4 Record (com.netsuite.webservices.test.platform.core.Record)3 RecordList (com.netsuite.webservices.test.platform.core.RecordList)3 Status (com.netsuite.webservices.test.platform.core.Status)3 SearchMoreWithIdResponse (com.netsuite.webservices.test.platform.messages.SearchMoreWithIdResponse)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)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 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 ServiceSaleItem (com.netsuite.webservices.test.lists.accounting.ServiceSaleItem)1 NetSuitePortType (com.netsuite.webservices.test.platform.NetSuitePortType)1 SearchMoreWithIdRequest (com.netsuite.webservices.test.platform.messages.SearchMoreWithIdRequest)1 SearchRequest (com.netsuite.webservices.test.platform.messages.SearchRequest)1