use of org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl in project components by Talend.
the class NetSuiteSearchInputReaderIT method testInput.
@Test
public void testInput() throws Exception {
RuntimeContainer container = mock(RuntimeContainer.class);
NetSuiteInputProperties properties = new NetSuiteInputProperties("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("Account");
NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
properties.module.main.schema.setValue(schema);
properties.module.afterModuleName();
properties.module.searchQuery.field.setValue(Arrays.asList("Type"));
properties.module.searchQuery.operator.setValue(Arrays.asList("List.anyOf"));
properties.module.searchQuery.value1.setValue(Arrays.<Object>asList("Bank"));
properties.module.searchQuery.value2.setValue(Arrays.<Object>asList((String) null));
NetSuiteSource source = new NetSuiteSourceImpl();
source.initialize(container, properties);
NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(container);
boolean started = reader.start();
assertTrue(started);
IndexedRecord record = reader.getCurrent();
assertNotNull(record);
List<Schema.Field> fields = record.getSchema().getFields();
for (int i = 0; i < fields.size(); i++) {
Schema.Field typeField = getFieldByName(fields, "AcctType");
Object value = record.get(typeField.pos());
assertNotNull(value);
assertEquals(AccountType.BANK.value(), value);
}
}
use of org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl in project components by Talend.
the class NetSuiteSearchInputReaderTest method testBasic.
@Test
public void testBasic() throws Exception {
properties.module.moduleName.setValue("Account");
properties.module.searchQuery.field.setValue(Lists.newArrayList("type", "generalRateType"));
properties.module.searchQuery.operator.setValue(Lists.newArrayList("List.anyOf", "List.anyOf"));
properties.module.searchQuery.value1.setValue(Lists.newArrayList((Object) Arrays.asList("bank", "otherAsset"), (Object) Arrays.asList("current", "historical")));
properties.module.searchQuery.value2.setValue(Lists.newArrayList(null, null));
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 org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl in project components by Talend.
the class NetSuiteOutputWriterTest method testUpdate.
@Test
public void testUpdate() throws Exception {
final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
final TypeDesc typeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RecordTypeEnum.OPPORTUNITY.getTypeName());
mockGetListRequestResults(null);
final List<Opportunity> updatedRecordList = new ArrayList<>();
when(port.updateList(any(UpdateListRequest.class))).then(new Answer<UpdateListResponse>() {
@Override
public UpdateListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
UpdateListRequest request = (UpdateListRequest) invocationOnMock.getArguments()[0];
assertFalse(request.getRecord().isEmpty());
UpdateListResponse response = new UpdateListResponse();
WriteResponseList writeResponseList = new WriteResponseList();
writeResponseList.setStatus(createSuccessStatus());
for (int i = 0; i < request.getRecord().size(); i++) {
Opportunity record = (Opportunity) request.getRecord().get(i);
assertNotNull(record);
assertNotNull(record.getInternalId());
RecordRef recordRef = new RecordRef();
recordRef.setInternalId(record.getInternalId());
recordRef.setType(RecordType.OPPORTUNITY);
updatedRecordList.add(record);
WriteResponse writeResponse = new WriteResponse();
writeResponse.setStatus(createSuccessStatus());
writeResponse.setBaseRef(recordRef);
writeResponseList.getWriteResponse().add(writeResponse);
}
response.setWriteResponseList(writeResponseList);
return response;
}
});
properties.module.moduleName.setValue(typeDesc.getTypeName());
properties.module.action.setValue(OutputAction.UPDATE);
NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
properties.module.main.schema.setValue(schema);
NetSuiteSink sink = new NetSuiteSinkImpl();
sink.initialize(mockTestFixture.getRuntimeContainer(), properties);
NetSuiteClientService<?> clientService = sink.getClientService();
NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
NetSuiteOutputWriter writer = (NetSuiteOutputWriter) writeOperation.createWriter(mockTestFixture.getRuntimeContainer());
writer.open(UUID.randomUUID().toString());
List<IndexedRecord> indexedRecordList = makeIndexedRecords(clientService, schema, new SimpleObjectComposer<>(typeDesc.getTypeClass()), 150);
for (IndexedRecord record : indexedRecordList) {
writer.write(record);
}
Result writerResult = writer.close();
assertNotNull(writerResult);
assertEquals(indexedRecordList.size(), writerResult.totalCount);
verify(port, times(2)).updateList(any(UpdateListRequest.class));
assertEquals(indexedRecordList.size(), updatedRecordList.size());
}
use of org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl in project components by Talend.
the class NetSuiteOutputWriterIT method testDelete.
@Test
public void testDelete() throws Exception {
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.MESSAGE.getTypeName());
properties.module.action.setValue(OutputAction.DELETE);
NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
runtime.setClientFactory(clientFactory);
NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(RefType.RECORD_REF.getTypeName());
properties.module.main.schema.setValue(schema);
List<Message> recordsToAdd = makeMessageRecords(5);
final List<RecordRef> refList = new ArrayList<>(recordsToAdd.size());
List<NsWriteResponse<RecordRef>> writeResponseList = clientService.addList(recordsToAdd);
for (NsWriteResponse<RecordRef> writeResponse : writeResponseList) {
assertTrue(writeResponse.getStatus().isSuccess());
assertNotNull(writeResponse.getRef());
refList.add(writeResponse.getRef());
}
List<IndexedRecord> indexedRecordList = makeRecordRefIndexedRecords(schema, refList);
NetSuiteSink sink = new NetSuiteSinkImpl();
sink.setClientFactory(new NetSuiteClientFactoryImpl() {
@Override
public NetSuiteClientService<NetSuitePortType> createClient() throws NetSuiteException {
NetSuiteClientService<NetSuitePortType> service = super.createClient();
service.getMetaDataSource().setCustomizationEnabled(webServiceTestFixture.getClientService().getMetaDataSource().isCustomizationEnabled());
return service;
}
});
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);
List<NsReadResponse<Message>> readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Message>>, NetSuitePortType>() {
@Override
public List<NsReadResponse<Message>> execute(NetSuitePortType port) throws Exception {
GetListRequest request = new GetListRequest();
request.getBaseRef().addAll(refList);
return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
}
});
for (NsReadResponse<Message> readResponse : readResponseList) {
// success=false means that NetSuite Record was not found because it was deleted
assertFalse(readResponse.getStatus().isSuccess());
}
}
use of org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl 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