Search in sources :

Example 1 with CustomMetaDataSource

use of org.talend.components.netsuite.client.CustomMetaDataSource 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 CustomMetaDataSource

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

the class NetSuiteDatasetRuntimeTest method testGetSchemaForRecordWithCustomFields.

@Test
public void testGetSchemaForRecordWithCustomFields() throws Exception {
    final CustomMetaDataSource customMetaDataSource = new EmptyCustomMetaDataSource() {

        @Override
        public Map<String, CustomFieldDesc> getCustomFields(RecordTypeInfo recordTypeInfo) {
            try {
                if (recordTypeInfo.getName().equals("Account")) {
                    JsonNode fieldListNode = objectMapper.readTree(NetSuiteDatasetRuntimeTest.class.getResource("/test-data/customFields-1.json"));
                    Map<String, CustomFieldDesc> customFieldDescMap = TestUtils.readCustomFields(fieldListNode);
                    return customFieldDescMap;
                }
                return null;
            } catch (IOException e) {
                throw new NetSuiteException(e.getMessage(), e);
            }
        }
    };
    MetaDataSource metaDataSource = clientService.createDefaultMetaDataSource();
    metaDataSource.setCustomMetaDataSource(customMetaDataSource);
    NetSuiteDatasetRuntimeImpl datasetRuntime = new NetSuiteDatasetRuntimeImpl(metaDataSource);
    TypeDesc typeDesc = metaDataSource.getTypeInfo("Account");
    Schema s = datasetRuntime.getSchema(typeDesc.getTypeName());
    assertThat(s.getType(), is(Schema.Type.RECORD));
    assertThat(s.getName(), is("Account"));
    assertThat(s.getFields(), hasSize(typeDesc.getFields().size()));
    assertThat(s.getObjectProps().keySet(), Matchers.<String>empty());
    CustomFieldDesc fieldDesc = (CustomFieldDesc) typeDesc.getField("custom_field_1");
    Schema.Field f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.STRING, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE, NetSuiteSchemaConstants.NS_CUSTOM_FIELD, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_SCRIPT_ID, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_INTERNAL_ID, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_CUSTOMIZATION_TYPE, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
    CustomFieldDesc customFieldDesc = NetSuiteDatasetRuntimeImpl.readCustomField(f);
    assertThat(customFieldDesc.getName(), is(fieldDesc.getName()));
}
Also used : EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) IOException(java.io.IOException) EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) MetaDataSource(org.talend.components.netsuite.client.MetaDataSource) EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) Test(org.junit.Test)

Example 3 with CustomMetaDataSource

use of org.talend.components.netsuite.client.CustomMetaDataSource 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)

Example 4 with CustomMetaDataSource

use of org.talend.components.netsuite.client.CustomMetaDataSource 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)

Aggregations

Schema (org.apache.avro.Schema)4 Test (org.junit.Test)4 CustomMetaDataSource (org.talend.components.netsuite.client.CustomMetaDataSource)4 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)4 CustomRecord (com.netsuite.webservices.test.setup.customization.CustomRecord)3 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 ArrayList (java.util.ArrayList)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)2 NetSuiteDatasetRuntimeImpl (org.talend.components.netsuite.NetSuiteDatasetRuntimeImpl)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CustomRecordRef (com.netsuite.webservices.test.platform.core.CustomRecordRef)1 IOException (java.io.IOException)1 NetSuiteWebServiceMockTestFixture.assertIndexedRecord (org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord)1 EmptyCustomMetaDataSource (org.talend.components.netsuite.client.EmptyCustomMetaDataSource)1 MetaDataSource (org.talend.components.netsuite.client.MetaDataSource)1 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)1 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)1 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)1