Search in sources :

Example 36 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class NsObjectInputTransducerTest method testDynamicSchemaWithCustomFields.

@Test
public void testDynamicSchemaWithCustomFields() throws Exception {
    TestCustomMetaDataSource customMetaDataSource = new TestCustomMetaDataSource(clientService, "Opportunity");
    clientService.getMetaDataSource().setCustomMetaDataSource(customMetaDataSource);
    TypeDesc basicTypeDesc = clientService.getMetaDataSource().getTypeInfo("Opportunity");
    final List<Opportunity> recordList = makeNsObjects(new NsObjectComposer<Opportunity>(clientService.getMetaDataSource(), basicTypeDesc), 10);
    mockSearchRequestResults(recordList, 100);
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(basicTypeDesc.getTypeName());
    Schema schema = getDynamicSchema();
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    SearchResultSet<Record> rs = clientService.newSearch().target(basicTypeDesc.getTypeName()).search();
    while (rs.next()) {
        Record record = rs.get();
        IndexedRecord indexedRecord = transducer.read(record);
        assertIndexedRecord(typeDesc, indexedRecord);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Opportunity(com.netsuite.webservices.test.transactions.sales.Opportunity) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) CustomRecord(com.netsuite.webservices.test.setup.customization.CustomRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Record(com.netsuite.webservices.test.platform.core.Record) Test(org.junit.Test)

Example 37 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class DefaultMetaDataSource method getTypeInfo.

/**
 * {@inheritDoc}
 */
@Override
public TypeDesc getTypeInfo(final String typeName) {
    TypeDesc baseTypeDesc;
    String targetTypeName = null;
    Class<?> targetTypeClass;
    List<FieldDesc> baseFieldDescList;
    RecordTypeInfo recordTypeInfo = getRecordType(typeName);
    if (recordTypeInfo != null) {
        if (recordTypeInfo instanceof CustomRecordTypeInfo) {
            CustomRecordTypeInfo customRecordTypeInfo = (CustomRecordTypeInfo) recordTypeInfo;
            baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(customRecordTypeInfo.getRecordType().getTypeName());
            targetTypeName = customRecordTypeInfo.getName();
        } else {
            baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(typeName);
        }
    } else {
        baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(typeName);
    }
    if (targetTypeName == null) {
        targetTypeName = baseTypeDesc.getTypeName();
    }
    targetTypeClass = baseTypeDesc.getTypeClass();
    baseFieldDescList = baseTypeDesc.getFields();
    List<FieldDesc> resultFieldDescList = new ArrayList<>(baseFieldDescList.size() + 10);
    // Add basic fields except field list containers (custom field list, null field list)
    for (FieldDesc fieldDesc : baseFieldDescList) {
        String fieldName = fieldDesc.getName();
        if (fieldName.equals("customFieldList") || fieldName.equals("nullFieldList")) {
            continue;
        }
        resultFieldDescList.add(fieldDesc);
    }
    if (recordTypeInfo != null) {
        if (customizationEnabled) {
            // Add custom fields
            Map<String, CustomFieldDesc> customFieldMap = customMetaDataSource.getCustomFields(recordTypeInfo);
            for (CustomFieldDesc fieldInfo : customFieldMap.values()) {
                resultFieldDescList.add(fieldInfo);
            }
        }
    }
    return new TypeDesc(targetTypeName, targetTypeClass, resultFieldDescList);
}
Also used : CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 38 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc 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);
        }
    }
}
Also used : AbstractNetSuiteTestBase(org.talend.components.netsuite.AbstractNetSuiteTestBase) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) TestNetSuiteRuntimeImpl(org.talend.components.netsuite.TestNetSuiteRuntimeImpl) NetSuiteWebServiceMockTestFixture.assertNsObject(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertNsObject) Test(org.junit.Test)

Example 39 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class NetSuiteOutputTransducerTest method testCustomRecordRef.

@Test
public void testCustomRecordRef() throws Exception {
    CustomMetaDataSource customMetaDataSource = new TestCustomMetaDataSource(clientService);
    clientService.getMetaDataSource().setCustomMetaDataSource(customMetaDataSource);
    NetSuiteDatasetRuntime dataSetRuntime = new NetSuiteDatasetRuntimeImpl(clientService.getMetaDataSource());
    mockGetRequestResults(null);
    TypeDesc customTypeDesc = clientService.getMetaDataSource().getTypeInfo("custom_record_type_1");
    Schema schema = dataSetRuntime.getSchemaForDelete(customTypeDesc.getTypeName());
    NsObjectOutputTransducer transducer = new NsObjectOutputTransducer(webServiceMockTestFixture.getClientService(), customTypeDesc.getTypeName());
    transducer.setReference(true);
    GenericRecord indexedRecordToAdd = new GenericData.Record(schema);
    indexedRecordToAdd.put("InternalId", "123456789");
    List<IndexedRecord> indexedRecordList = new ArrayList<>();
    indexedRecordList.add(indexedRecordToAdd);
    for (IndexedRecord indexedRecord : indexedRecordList) {
        CustomRecordRef recordRef = (CustomRecordRef) transducer.write(indexedRecord);
        assertNotNull(recordRef.getInternalId());
        assertNotNull(recordRef.getTypeId());
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) CustomRecordRef(com.netsuite.webservices.test.platform.core.CustomRecordRef) CustomRecord(com.netsuite.webservices.test.setup.customization.CustomRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) GenericRecord(org.apache.avro.generic.GenericRecord) NetSuiteDatasetRuntimeImpl(org.talend.components.netsuite.NetSuiteDatasetRuntimeImpl) Test(org.junit.Test)

Example 40 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc 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));
}
Also used : Account(com.netsuite.webservices.v2014_2.lists.accounting.Account) NetSuiteSourceImpl(org.talend.components.netsuite.v2014_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2014_2.NetSuiteRuntimeImpl) Test(org.junit.Test)

Aggregations

TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)48 Test (org.junit.Test)41 Schema (org.apache.avro.Schema)31 IndexedRecord (org.apache.avro.generic.IndexedRecord)23 ArrayList (java.util.ArrayList)14 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)13 LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)12 NetSuiteRuntime (org.talend.components.netsuite.NetSuiteRuntime)10 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)10 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)10 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)10 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)9 PurchaseOrder (com.netsuite.webservices.test.transactions.purchases.PurchaseOrder)8 NetSuiteWebServiceMockTestFixture.assertIndexedRecord (org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord)8 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)8 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)7 CustomRecord (com.netsuite.webservices.test.setup.customization.CustomRecord)7 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)6 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4