use of org.talend.components.netsuite.client.EmptyCustomMetaDataSource 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()));
}
Aggregations