Search in sources :

Example 1 with TypeDesc

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);
    }
}
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 TypeDesc

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());
    }
}
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 TypeDesc

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());
    }
}
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 TypeDesc

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);
    }
}
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 TypeDesc

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");
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) Record(com.netsuite.webservices.v2014_2.platform.core.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) 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