/** * Internal utility method to add the primitive class to the shared converters and {@link IndexedRecordConverter} to * be reused by all components. */ private static <DatumT> void registerSharedPrimitiveClass(Class<DatumT> primitiveClass, AvroConverter<DatumT, ?> converter) { mapSharedConverter.put(primitiveClass, converter); mapSharedIndexedRecordConverter.put(primitiveClass, new LambdaSingleColumnIndexedRecordConverterSupplier<>(primitiveClass, converter.getSchema())); }
AvroConverter<?, ?> converter = getConverter(datum.getClass()); if (converter != null) { inferrer = new LambdaReturnConstantSchemaFunction<>(converter.getSchema());
/** * Checks {@link TJiraOutputProperties#setupProperties()} sets correct initial property values */ @Test public void testSetupProperties() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); Schema expectedSchema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); expectedSchema.addProp(TALEND_IS_LOCKED, "true"); TJiraOutputProperties properties = new TJiraOutputProperties("root"); properties.setupProperties(); Action actionValue = properties.action.getValue(); Resource resourceValue = properties.resource.getValue(); boolean deleteSubtasksValue = properties.deleteSubtasks.getValue(); Mode modeValue = properties.mode.getValue(); Schema schema = properties.schema.schema.getValue(); assertThat(actionValue, equalTo(Action.INSERT)); assertThat(resourceValue, equalTo(Resource.ISSUE)); assertThat(deleteSubtasksValue, equalTo(true)); assertThat(modeValue, equalTo(Mode.ADVANCED)); assertThat(schema, equalTo(expectedSchema)); }
/** * Initializes test arguments before tests */ @BeforeClass public static void setUp() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); testSchema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); testSchema.addProp(TALEND_IS_LOCKED, "true"); testJson = "{\"startAt\":0,\"maxResults\":2,\"total\":1,\"issues\":[]}"; }
/** * Checks {@link TJiraInputProperties#setupSchema()} sets correct initial schema property */ @Test public void testSetupSchema() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); Schema expectedSchema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); expectedSchema.addProp(TALEND_IS_LOCKED, "true"); TJiraInputProperties properties = new TJiraInputProperties("root"); properties.setupSchema(); Schema schema = properties.schema.schema.getValue(); assertThat(schema, equalTo(expectedSchema)); }
/** * Initializes test arguments before tests */ @BeforeClass public static void setUp() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); testSchema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); testSchema.addProp(TALEND_IS_LOCKED, "true"); issueIndexedRecord = new IssueIndexedRecord(testJson, testSchema); }
/** * add field to Schema. */ private FieldAssembler<Schema> addField(FieldAssembler<Schema> record, String name, Class<?> type, AvroRegistry avroReg) { Schema base = avroReg.getConverter(type).getSchema(); FieldBuilder<Schema> fieldBuilder = record.name(name); fieldBuilder.type(AvroUtils.wrapAsNullable(base)).noDefault(); return record; }
private void setupDefaultSchema() { AvroRegistry avroReg = new AvroRegistry(); FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields(); for (SplunkJSONEventField metadataField : SplunkJSONEventField.getMetadataFields()) { Schema base = avroReg.getConverter(metadataField.getDataType()).getSchema(); FieldBuilder<Schema> fieldBuilder = record.name(metadataField.getName()); if (metadataField.getName().equals(SplunkJSONEventField.TIME.getName())) { fieldBuilder.prop(SchemaConstants.TALEND_COLUMN_PATTERN, "dd-MM-yyyy"); } fieldBuilder.type(AvroUtils.wrapAsNullable(base)).noDefault(); } Schema defaultSchema = record.endRecord(); schema.schema.setValue(defaultSchema); }
private void setupDefaultSchema() { AvroRegistry avroReg = new AvroRegistry(); FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields(); for (SplunkJSONEventField metadataField : SplunkJSONEventField.getMetadataFields()) { Schema base = avroReg.getConverter(metadataField.getDataType()).getSchema(); FieldBuilder<Schema> fieldBuilder = record.name(metadataField.getName()); if (metadataField.getName().equals(SplunkJSONEventField.TIME.getName())) { fieldBuilder.prop(SchemaConstants.TALEND_COLUMN_PATTERN, "dd-MM-yyyy"); } fieldBuilder.type(AvroUtils.wrapAsNullable(base)).noDefault(); } Schema defaultSchema = record.endRecord(); schema.schema.setValue(defaultSchema); }
private Schema initDefaultSchema(Schema designSchema) { AvroRegistry avroReg = new AvroRegistry(); FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields(); for (SplunkJSONEventField metadataField : SplunkJSONEventField.getMetadataFields()) { Schema base = avroReg.getConverter(metadataField.getDataType()).getSchema(); FieldBuilder<Schema> fieldBuilder = record.name(metadataField.getName()); if (metadataField.getName().equals(SplunkJSONEventField.TIME.getName())) { String datePattern; Field designField = designSchema.getField(metadataField.getName()); if (designField != null) { datePattern = designField.getProp(SchemaConstants.TALEND_COLUMN_PATTERN); } else { datePattern = designSchema.getProp(SchemaConstants.TALEND_COLUMN_PATTERN); } if (datePattern == null || datePattern.isEmpty()) { datePattern = "dd-MM-yyyy"; } fieldBuilder.prop(SchemaConstants.TALEND_COLUMN_PATTERN, datePattern); } fieldBuilder.type(AvroUtils.wrapAsNullable(base)).noDefault(); } Schema defaultSchema = record.endRecord(); return defaultSchema; }
/** * Checks {@link TJiraOutputProperties#afterAction()} sets correct schema for Delete * action, if Delete action is chosen */ @Test public void testAfterActionDelete() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field idField = new Schema.Field("id", stringSchema, null, null, Order.ASCENDING); Schema expectedSchema = Schema.createRecord("jira", null, null, false, Collections.singletonList(idField)); expectedSchema.addProp(TALEND_IS_LOCKED, "true"); TJiraOutputProperties properties = new TJiraOutputProperties("root"); properties.init(); properties.action.setValue(Action.DELETE); properties.afterAction(); Schema schema = properties.schema.schema.getValue(); assertThat(schema, equalTo(expectedSchema)); }
private Schema initDefaultSchema(Schema designSchema) { AvroRegistry avroReg = new AvroRegistry(); FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields(); for (SplunkJSONEventField metadataField : SplunkJSONEventField.getMetadataFields()) { Schema base = avroReg.getConverter(metadataField.getDataType()).getSchema(); FieldBuilder<Schema> fieldBuilder = record.name(metadataField.getName()); if (metadataField.getName().equals(SplunkJSONEventField.TIME.getName())) { String datePattern; Field designField = designSchema.getField(metadataField.getName()); if (designField != null) { datePattern = designField.getProp(SchemaConstants.TALEND_COLUMN_PATTERN); } else { datePattern = designSchema.getProp(SchemaConstants.TALEND_COLUMN_PATTERN); } if (datePattern == null || datePattern.isEmpty()) { datePattern = "dd-MM-yyyy"; } fieldBuilder.prop(SchemaConstants.TALEND_COLUMN_PATTERN, datePattern); } fieldBuilder.type(AvroUtils.wrapAsNullable(base)).noDefault(); } Schema defaultSchema = record.endRecord(); return defaultSchema; }
/** * Checks {@link TJiraOutputProperties#afterAction()} hides deleteSubtasks widget and sets correct schema for Insert * action, if Insert action chosen */ @Test public void testAfterActionInsert() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); Schema expectedSchema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); expectedSchema.addProp(TALEND_IS_LOCKED, "true"); TJiraOutputProperties properties = new TJiraOutputProperties("root"); properties.init(); properties.action.setValue(Action.INSERT); properties.afterAction(); boolean deleteSubtasksHidden = properties.getForm(Form.ADVANCED).getWidget("deleteSubtasks").isHidden(); assertTrue(deleteSubtasksHidden); Schema schema = properties.schema.schema.getValue(); assertThat(schema, equalTo(expectedSchema)); }
/** * Checks {@link TJiraOutputProperties#afterAction()} hides deleteSubtasks widget and sets correct schema for Update * action, if Update action chosen */ @Test public void testAfterActionUpdate() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field idField = new Schema.Field("id", stringSchema, null, null, Order.ASCENDING); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); List<Schema.Field> fields = Arrays.asList(idField, jsonField); Schema expectedSchema = Schema.createRecord("jira", null, null, false, fields); expectedSchema.addProp(TALEND_IS_LOCKED, "true"); TJiraOutputProperties properties = new TJiraOutputProperties("root"); properties.init(); properties.action.setValue(Action.UPDATE); properties.afterAction(); boolean deleteSubtasksHidden = properties.getForm(Form.ADVANCED).getWidget("deleteSubtasks").isHidden(); assertTrue(deleteSubtasksHidden); Schema schema = properties.schema.schema.getValue(); assertThat(schema, equalTo(expectedSchema)); }
/** * Prepares required instances for tests */ @Before public void setUp() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); schema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); schema.addProp(TALEND_IS_LOCKED, "true"); outputProperties = new TJiraOutputProperties("root"); outputProperties.connection.hostUrl.setValue(HOST_PORT); outputProperties.connection.basicAuthentication.userId.setValue("userIdValue"); outputProperties.connection.basicAuthentication.password.setValue("passwordValue"); outputProperties.resource.setValue(Resource.ISSUE); outputProperties.schema.schema.setValue(schema); outputProperties.action.setValue(Action.INSERT); }
/** * Prepares required instances for tests */ @Before public void setUp() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); schema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); schema.addProp(TALEND_IS_LOCKED, "true"); outputProperties = new TJiraOutputProperties("root"); outputProperties.connection.hostUrl.setValue("hostValue"); outputProperties.connection.basicAuthentication.userId.setValue("userIdValue"); outputProperties.connection.basicAuthentication.password.setValue("passwordValue"); outputProperties.resource.setValue(Resource.ISSUE); outputProperties.schema.schema.setValue(schema); outputProperties.action.setValue(Action.INSERT); outputProperties.deleteSubtasks.setValue(true); }
/** * Prepares required instances for tests */ @Before public void setUp() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); schema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); schema.addProp(TALEND_IS_LOCKED, "true"); outputProperties = new TJiraOutputProperties("root"); outputProperties.connection.hostUrl.setValue("hostValue"); outputProperties.connection.basicAuthentication.userId.setValue("userIdValue"); outputProperties.connection.basicAuthentication.password.setValue("passwordValue"); outputProperties.resource.setValue(Resource.ISSUE); outputProperties.schema.schema.setValue(schema); outputProperties.action.setValue(Action.INSERT); sourceOrSink = new JiraSourceOrSink(); }
/** * Prepares required instances for tests */ @Before public void setUp() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); schema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); schema.addProp(TALEND_IS_LOCKED, "true"); inputProperties = new TJiraInputProperties("root"); inputProperties.connection.hostUrl.setValue("hostValue"); inputProperties.connection.basicAuthentication.userId.setValue("userIdValue"); inputProperties.connection.basicAuthentication.password.setValue("passwordValue"); inputProperties.resource.setValue(Resource.ISSUE); inputProperties.schema.schema.setValue(schema); inputProperties.jql.setValue("jqlValue"); inputProperties.batchSize.setValue(50); inputProperties.projectId.setValue("projectIdValue"); }
assertEquals(AvroUtils._logicalTimestamp(), converter1.getSchema()); assertEquals(XMLGregorianCalendar.class, converter1.getDatumClass()); assertEquals(controlValue1,
@Test public void testEnumConverter() throws Exception { NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName()); FieldDesc fieldDesc = typeDesc.getField("acctType"); AvroConverter<Enum<AccountType>, String> converter1 = (AvroConverter<Enum<AccountType>, String>) transducer.getValueConverter(fieldDesc); assertEquals(AvroUtils._string(), converter1.getSchema()); assertEquals(AccountType.class, converter1.getDatumClass()); assertEquals(AccountType.ACCOUNTS_PAYABLE.value(), converter1.convertToAvro(AccountType.ACCOUNTS_PAYABLE)); assertEquals(AccountType.ACCOUNTS_PAYABLE, converter1.convertToDatum(AccountType.ACCOUNTS_PAYABLE.value())); assertEquals(AccountType.ACCOUNTS_PAYABLE, converter1.convertToDatum(AccountType.ACCOUNTS_PAYABLE.name())); fieldDesc = typeDesc.getField("generalRate"); assertNotNull(fieldDesc); AvroConverter<Enum<ConsolidatedRate>, String> converter2 = (AvroConverter<Enum<ConsolidatedRate>, String>) transducer.getValueConverter(fieldDesc); assertEquals(ConsolidatedRate.HISTORICAL.value(), converter2.convertToAvro(ConsolidatedRate.HISTORICAL)); assertEquals(ConsolidatedRate.HISTORICAL, converter2.convertToDatum(ConsolidatedRate.HISTORICAL.value())); }