use of org.talend.components.netsuite.NetSuiteRuntime in project components by Talend.
the class NetSuiteConnectionProperties method validateTestConnection.
public ValidationResult validateTestConnection() throws Exception {
ValidationResult vr = withRuntime(this, new Function<NetSuiteRuntime, ValidationResult>() {
@Override
public ValidationResult apply(NetSuiteRuntime runtimeService) {
return runtimeService.validateConnection(NetSuiteConnectionProperties.this);
}
});
ValidationResultMutable vrm = new ValidationResultMutable(vr);
if (vrm.getStatus() == ValidationResult.Result.OK) {
vrm.setMessage(getI18nMessage("message.connectionSuccessful"));
getForm(FORM_WIZARD).setAllowForward(true);
} else {
getForm(FORM_WIZARD).setAllowForward(false);
}
return vrm;
}
use of org.talend.components.netsuite.NetSuiteRuntime in project components by Talend.
the class NetSuiteOutputTransducerTest method testNonRecordObjects.
@Test
public void testNonRecordObjects() throws Exception {
NetSuiteRuntime netSuiteRuntime = new TestNetSuiteRuntimeImpl(webServiceMockTestFixture.getClientFactory());
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(mockTestFixture.getConnectionProperties());
Collection<String> typeNames = Arrays.asList(RefType.RECORD_REF.getTypeName(), RefType.CUSTOM_RECORD_REF.getTypeName());
for (String typeName : typeNames) {
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(typeName);
Schema schema = dataSetRuntime.getSchema(typeDesc.getTypeName());
NsObjectOutputTransducer transducer = new NsObjectOutputTransducer(webServiceMockTestFixture.getClientService(), typeDesc.getTypeName());
List<IndexedRecord> indexedRecordList = makeIndexedRecords(clientService, schema, new AbstractNetSuiteTestBase.SimpleObjectComposer<>(typeDesc.getTypeClass()), 10);
for (IndexedRecord indexedRecord : indexedRecordList) {
Object nsObject = transducer.write(indexedRecord);
assertNsObject(typeDesc, nsObject);
}
}
}
use of org.talend.components.netsuite.NetSuiteRuntime 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 org.talend.components.netsuite.NetSuiteRuntime 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.NetSuiteRuntime in project components by Talend.
the class NetSuiteOutputWriterTest method testDelete.
@Test
public void testDelete() throws Exception {
final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
final TypeDesc typeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RecordTypeEnum.OPPORTUNITY.getTypeName());
final TypeDesc refTypeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RefType.RECORD_REF.getTypeName());
properties.module.moduleName.setValue(typeDesc.getTypeName());
properties.module.action.setValue(OutputAction.DELETE);
final List<RecordRef> deletedRecordRefList = new ArrayList<>();
when(port.deleteList(any(DeleteListRequest.class))).then(new Answer<DeleteListResponse>() {
@Override
public DeleteListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
DeleteListRequest request = (DeleteListRequest) invocationOnMock.getArguments()[0];
DeleteListResponse response = new DeleteListResponse();
WriteResponseList writeResponseList = new WriteResponseList();
for (int i = 0; i < request.getBaseRef().size(); i++) {
RecordRef recordRef = (RecordRef) request.getBaseRef().get(i);
assertNotNull(recordRef);
assertNotNull(recordRef.getInternalId());
assertNotNull(recordRef.getType());
deletedRecordRefList.add(recordRef);
WriteResponse writeResponse = new WriteResponse();
writeResponse.setStatus(createSuccessStatus());
writeResponse.setBaseRef(recordRef);
writeResponseList.getWriteResponse().add(writeResponse);
}
response.setWriteResponseList(writeResponseList);
return response;
}
});
NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(RefType.RECORD_REF.getTypeName());
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 RecordRefComposer<>(refTypeDesc.getTypeClass()), 150);
for (IndexedRecord record : indexedRecordList) {
writer.write(record);
}
Result writerResult = writer.close();
assertNotNull(writerResult);
assertEquals(indexedRecordList.size(), writerResult.totalCount);
verify(port, times(2)).deleteList(any(DeleteListRequest.class));
assertEquals(indexedRecordList.size(), deletedRecordRefList.size());
}
Aggregations