Search in sources :

Example 1 with CustomRecord

use of com.netsuite.webservices.test.setup.customization.CustomRecord 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 2 with CustomRecord

use of com.netsuite.webservices.test.setup.customization.CustomRecord in project components by Talend.

the class NsObjectInputTransducerTest method testDynamicSchemaWithCustomRecordType.

@Test
public void testDynamicSchemaWithCustomRecordType() throws Exception {
    CustomMetaDataSource customMetaDataSource = new TestCustomMetaDataSource(clientService);
    clientService.getMetaDataSource().setCustomMetaDataSource(customMetaDataSource);
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("custom_record_type_1");
    final List<CustomRecord> recordList = makeNsObjects(new NsObjectComposer<CustomRecord>(clientService.getMetaDataSource(), typeDesc), 10);
    mockSearchRequestResults(recordList, 100);
    Schema schema = getDynamicSchema();
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    SearchResultSet<CustomRecord> rs = clientService.newSearch().target(typeDesc.getTypeName()).search();
    while (rs.next()) {
        CustomRecord 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) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) CustomRecord(com.netsuite.webservices.test.setup.customization.CustomRecord) Test(org.junit.Test)

Aggregations

CustomRecord (com.netsuite.webservices.test.setup.customization.CustomRecord)2 Schema (org.apache.avro.Schema)2 IndexedRecord (org.apache.avro.generic.IndexedRecord)2 Test (org.junit.Test)2 CustomMetaDataSource (org.talend.components.netsuite.client.CustomMetaDataSource)2 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)2 ArrayList (java.util.ArrayList)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)1 NetSuiteDatasetRuntimeImpl (org.talend.components.netsuite.NetSuiteDatasetRuntimeImpl)1 NetSuiteWebServiceMockTestFixture.assertIndexedRecord (org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord)1