use of org.talend.components.netsuite.NetSuiteDatasetRuntime in project components by Talend.
the class NetSuiteOutputTransducerTest method testCustomFields.
@Test
public void testCustomFields() throws Exception {
TestCustomMetaDataSource customMetaDataSource = new TestCustomMetaDataSource(clientService, "Opportunity");
clientService.getMetaDataSource().setCustomMetaDataSource(customMetaDataSource);
NetSuiteRuntime netSuiteRuntime = new TestNetSuiteRuntimeImpl(webServiceMockTestFixture.getClientFactory());
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(mockTestFixture.getConnectionProperties());
mockGetRequestResults(null);
TypeDesc basicTypeDesc = clientService.getBasicMetaData().getTypeInfo("Opportunity");
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("Opportunity");
final List<Opportunity> recordList = makeNsObjects(new NsObjectComposer<Opportunity>(clientService.getMetaDataSource(), typeDesc), 10);
mockSearchRequestResults(recordList, 100);
Schema schema = dataSetRuntime.getSchema(typeDesc.getTypeName());
NsObjectOutputTransducer transducer = new NsObjectOutputTransducer(webServiceMockTestFixture.getClientService(), typeDesc.getTypeName());
List<IndexedRecord> indexedRecordList = makeIndexedRecords(clientService, schema, new NsObjectComposer<Opportunity>(clientService.getMetaDataSource(), typeDesc), 10);
for (IndexedRecord indexedRecord : indexedRecordList) {
Opportunity record = (Opportunity) transducer.write(indexedRecord);
assertNsObject(basicTypeDesc, record);
}
}
use of org.talend.components.netsuite.NetSuiteDatasetRuntime in project components by Talend.
the class NetSuiteOutputTransducerTest method testRecordRef.
@Test
public void testRecordRef() throws Exception {
NetSuiteRuntime netSuiteRuntime = new TestNetSuiteRuntimeImpl(webServiceMockTestFixture.getClientFactory());
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(mockTestFixture.getConnectionProperties());
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(RefType.RECORD_REF.getTypeName());
TypeDesc referencedTypeDesc = clientService.getMetaDataSource().getTypeInfo("Opportunity");
Schema schema = dataSetRuntime.getSchema(typeDesc.getTypeName());
NsObjectOutputTransducer transducer = new NsObjectOutputTransducer(webServiceMockTestFixture.getClientService(), referencedTypeDesc.getTypeName());
transducer.setReference(true);
List<IndexedRecord> indexedRecordList = makeIndexedRecords(clientService, schema, new AbstractNetSuiteTestBase.SimpleObjectComposer<>(typeDesc.getTypeClass()), 10);
for (IndexedRecord indexedRecord : indexedRecordList) {
Object nsObject = transducer.write(indexedRecord);
assertNsObject(typeDesc, nsObject);
RecordRef ref = (RecordRef) nsObject;
assertEquals(RecordType.OPPORTUNITY, ref.getType());
}
}
use of org.talend.components.netsuite.NetSuiteDatasetRuntime in project components by Talend.
the class NetSuiteOutputTransducerTest method testCustomRecord.
@Test
public void testCustomRecord() throws Exception {
CustomMetaDataSource customMetaDataSource = new TestCustomMetaDataSource(clientService);
clientService.getMetaDataSource().setCustomMetaDataSource(customMetaDataSource);
NetSuiteDatasetRuntime dataSetRuntime = new NetSuiteDatasetRuntimeImpl(clientService.getMetaDataSource());
mockGetRequestResults(null);
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("custom_record_type_1");
Schema schema = dataSetRuntime.getSchema(typeDesc.getTypeName());
NsObjectOutputTransducer transducer = new NsObjectOutputTransducer(webServiceMockTestFixture.getClientService(), typeDesc.getTypeName());
GenericRecord indexedRecordToAdd = new GenericData.Record(schema);
String testId = Long.toString(System.currentTimeMillis());
indexedRecordToAdd.put("Custom_record_field_1", "Test Project " + testId);
indexedRecordToAdd.put("Custom_record_field_2", Long.valueOf(System.currentTimeMillis()));
List<IndexedRecord> indexedRecordList = new ArrayList<>();
indexedRecordList.add(indexedRecordToAdd);
for (IndexedRecord indexedRecord : indexedRecordList) {
CustomRecord record = (CustomRecord) transducer.write(indexedRecord);
assertNotNull(record.getRecType());
assertNotNull(record.getRecType().getInternalId());
}
}
use of org.talend.components.netsuite.NetSuiteDatasetRuntime in project components by Talend.
the class NetSuiteOutputTransducerTest method testBasic.
@Test
public void testBasic() throws Exception {
NetSuiteRuntime netSuiteRuntime = new TestNetSuiteRuntimeImpl(webServiceMockTestFixture.getClientFactory());
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(mockTestFixture.getConnectionProperties());
mockGetRequestResults(null);
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("Opportunity");
Schema schema = dataSetRuntime.getSchema(typeDesc.getTypeName());
NsObjectOutputTransducer transducer = new NsObjectOutputTransducer(webServiceMockTestFixture.getClientService(), typeDesc.getTypeName());
List<IndexedRecord> indexedRecordList = makeIndexedRecords(clientService, schema, new AbstractNetSuiteTestBase.SimpleObjectComposer<>(Opportunity.class), 10);
for (IndexedRecord indexedRecord : indexedRecordList) {
Opportunity record = (Opportunity) transducer.write(indexedRecord);
assertNsObject(typeDesc, record);
}
}
use of org.talend.components.netsuite.NetSuiteDatasetRuntime 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);
}
}
Aggregations