Search in sources :

Example 1 with NetSuiteDatasetRuntime

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);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) Opportunity(com.netsuite.webservices.test.transactions.sales.Opportunity) 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) Test(org.junit.Test)

Example 2 with NetSuiteDatasetRuntime

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());
    }
}
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) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) CustomRecordRef(com.netsuite.webservices.test.platform.core.CustomRecordRef) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteWebServiceMockTestFixture.assertNsObject(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertNsObject) TestNetSuiteRuntimeImpl(org.talend.components.netsuite.TestNetSuiteRuntimeImpl) Test(org.junit.Test)

Example 3 with NetSuiteDatasetRuntime

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());
    }
}
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) CustomRecord(com.netsuite.webservices.test.setup.customization.CustomRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) CustomRecord(com.netsuite.webservices.test.setup.customization.CustomRecord) GenericRecord(org.apache.avro.generic.GenericRecord) NetSuiteDatasetRuntimeImpl(org.talend.components.netsuite.NetSuiteDatasetRuntimeImpl) Test(org.junit.Test)

Example 4 with NetSuiteDatasetRuntime

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);
    }
}
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) Opportunity(com.netsuite.webservices.test.transactions.sales.Opportunity) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) TestNetSuiteRuntimeImpl(org.talend.components.netsuite.TestNetSuiteRuntimeImpl) Test(org.junit.Test)

Example 5 with NetSuiteDatasetRuntime

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);
    }
}
Also used : NetSuiteInputProperties(org.talend.components.netsuite.input.NetSuiteInputProperties) NetSuiteSourceImpl(org.talend.components.netsuite.v2014_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) Schema(org.apache.avro.Schema) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2014_2.NetSuiteRuntimeImpl) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Aggregations

Schema (org.apache.avro.Schema)18 IndexedRecord (org.apache.avro.generic.IndexedRecord)18 Test (org.junit.Test)18 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)18 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)13 ArrayList (java.util.ArrayList)10 NetSuiteRuntime (org.talend.components.netsuite.NetSuiteRuntime)10 Result (org.talend.components.api.component.runtime.Result)8 NetSuiteSink (org.talend.components.netsuite.NetSuiteSink)8 NetSuiteOutputWriter (org.talend.components.netsuite.output.NetSuiteOutputWriter)8 NetSuiteWriteOperation (org.talend.components.netsuite.output.NetSuiteWriteOperation)8 NetSuiteRuntimeImpl (org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl)8 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)6 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)6 NetSuiteSinkImpl (org.talend.components.netsuite.v2016_2.NetSuiteSinkImpl)6 RecordRef (com.netsuite.webservices.v2016_2.platform.core.RecordRef)5 GenericRecord (org.apache.avro.generic.GenericRecord)5 CustomFieldList (com.netsuite.webservices.v2016_2.platform.core.CustomFieldList)4 CustomRecordRef (com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef)4 RecordRefList (com.netsuite.webservices.v2016_2.platform.core.RecordRefList)4