use of com.netsuite.webservices.v2016_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;
}
});
}
use of com.netsuite.webservices.v2016_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;
}
use of com.netsuite.webservices.v2016_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;
}
use of com.netsuite.webservices.v2016_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;
}
});
}
use of com.netsuite.webservices.v2016_2.platform.core.SearchResult in project components by Talend.
the class NetSuiteOutputWriterIT method testUpdate.
@Test
public void testUpdate() throws Exception {
final NetSuiteClientService<NetSuitePortType> clientService = webServiceTestFixture.getClientService();
clientService.getMetaDataSource().setCustomizationEnabled(false);
RuntimeContainer container = mock(RuntimeContainer.class);
NetSuiteOutputProperties properties = new NetSuiteOutputProperties("test");
properties.init();
properties.connection.endpoint.setValue(webServiceTestFixture.getEndpointUrl());
properties.connection.email.setValue(webServiceTestFixture.getCredentials().getEmail());
properties.connection.password.setValue(webServiceTestFixture.getCredentials().getPassword());
properties.connection.account.setValue(webServiceTestFixture.getCredentials().getAccount());
properties.connection.role.setValue(Integer.valueOf(webServiceTestFixture.getCredentials().getRoleId()));
properties.connection.applicationId.setValue(webServiceTestFixture.getCredentials().getApplicationId());
properties.module.moduleName.setValue(RecordTypeEnum.ACCOUNT.getTypeName());
properties.module.action.setValue(OutputAction.UPDATE);
NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
runtime.setClientFactory(clientFactory);
NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
properties.module.main.schema.setValue(schema);
SubsidiarySearch subsidiarySearch = new SubsidiarySearch();
SubsidiarySearchBasic subsidiarySearchBasic = new SubsidiarySearchBasic();
subsidiarySearch.setBasic(subsidiarySearchBasic);
NsSearchResult<Subsidiary> searchResult = clientService.search(subsidiarySearch);
assertTrue(searchResult.isSuccess());
assertNotNull(searchResult.getRecordList());
assertTrue(searchResult.getRecordList().size() > 0);
Subsidiary subsidiary = searchResult.getRecordList().get(0);
RecordRef subsidiaryRef = new RecordRef();
subsidiaryRef.setType(RecordType.SUBSIDIARY);
subsidiaryRef.setInternalId(subsidiary.getInternalId());
List<Account> recordsToAdd = makeAccountRecords(5, subsidiaryRef);
final List<RecordRef> refList = new ArrayList<>(recordsToAdd.size());
// Add records
List<NsWriteResponse<RecordRef>> writeResponseList = clientService.addList(recordsToAdd);
for (NsWriteResponse<RecordRef> writeResponse : writeResponseList) {
assertTrue(writeResponse.getStatus().isSuccess());
assertNotNull(writeResponse.getRef());
refList.add(writeResponse.getRef());
}
// Read added records
List<Account> recordList = new ArrayList<>(refList.size());
List<NsReadResponse<Account>> readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Account>>, NetSuitePortType>() {
@Override
public List<NsReadResponse<Account>> execute(NetSuitePortType port) throws Exception {
GetListRequest request = new GetListRequest();
request.getBaseRef().addAll(refList);
return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
}
});
for (NsReadResponse<Account> readResponse : readResponseList) {
assertTrue(readResponse.getStatus().isSuccess());
recordList.add(readResponse.getRecord());
}
List<IndexedRecord> indexedRecordList = new ArrayList<>(refList.size());
for (Account record : recordList) {
GenericRecord indexedRecord = new GenericData.Record(schema);
indexedRecord.put("InternalId", record.getInternalId());
indexedRecord.put("AcctNumber", record.getAcctNumber());
indexedRecord.put("AcctType", record.getAcctType().value());
// Updated fields
indexedRecord.put("AcctName", record.getAcctName() + " (edited)");
indexedRecord.put("Description", "qwerty");
indexedRecordList.add(indexedRecord);
}
// Update records
NetSuiteSink sink = new NetSuiteSinkImpl();
sink.setClientFactory(clientFactory);
sink.initialize(container, properties);
NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
NetSuiteOutputWriter writer = (NetSuiteOutputWriter) writeOperation.createWriter(container);
writer.open(UUID.randomUUID().toString());
for (IndexedRecord indexedRecord : indexedRecordList) {
writer.write(indexedRecord);
}
Result writerResult = writer.close();
assertNotNull(writerResult);
assertEquals(indexedRecordList.size(), writerResult.totalCount);
assertEquals(indexedRecordList.size(), writerResult.successCount);
// Re-read updated records
readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Account>>, NetSuitePortType>() {
@Override
public List<NsReadResponse<Account>> execute(NetSuitePortType port) throws Exception {
GetListRequest request = new GetListRequest();
request.getBaseRef().addAll(refList);
return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
}
});
for (NsReadResponse<Account> readResponse : readResponseList) {
assertTrue(readResponse.getStatus().isSuccess());
Account record = readResponse.getRecord();
assertEquals("qwerty", record.getDescription());
assertTrue(record.getAcctName().endsWith("(edited)"));
}
clientService.deleteList(refList);
}
Aggregations