use of org.talend.components.netsuite.client.model.TypeDesc 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.client.model.TypeDesc 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.client.model.TypeDesc 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.client.model.TypeDesc 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.client.model.TypeDesc in project components by Talend.
the class NsObjectInputTransducerIT method testIncludeAllFields.
@Test
public void testIncludeAllFields() throws Exception {
NetSuiteClientService<?> connection = webServiceTestFixture.getClientService();
connection.login();
TypeDesc basicTypeDesc = connection.getBasicMetaData().getTypeInfo("Opportunity");
Schema schema = getDynamicSchema();
NsObjectInputTransducer transducer = new NsObjectInputTransducer(connection, schema, basicTypeDesc.getTypeName());
SearchResultSet<Record> rs = connection.newSearch().target(basicTypeDesc.getTypeName()).search();
TypeDesc typeDesc = connection.getMetaDataSource().getTypeInfo(basicTypeDesc.getTypeName());
int count = 0;
while (count++ < connection.getSearchPageSize() && rs.next()) {
Record record = rs.get();
IndexedRecord indexedRecord = transducer.read(record);
logger.debug("Indexed record: {}", indexedRecord);
Schema recordSchema = indexedRecord.getSchema();
assertEquals(typeDesc.getFields().size(), recordSchema.getFields().size());
for (FieldDesc fieldDesc : typeDesc.getFields()) {
String fieldName = fieldDesc.getName();
Schema.Field field = recordSchema.getField(fieldName);
assertNotNull(field);
Object value = indexedRecord.get(field.pos());
}
}
if (count == 0) {
throw new IllegalStateException("No records");
}
}
Aggregations