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;
}
});
}
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;
}
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;
}
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));
}
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;
}
Aggregations