use of org.talend.daikon.avro.AvroRegistry in project components by Talend.
the class TJiraOutputPropertiesTest method testAfterActionUpdate.
/**
* 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));
}
use of org.talend.daikon.avro.AvroRegistry in project components by Talend.
the class JmsOutputPTransformRuntime method expand.
@Override
public PDone expand(PCollection<Object> objectPCollection) {
// TODO remove this method from PCollection<Object> to PCollection<IndexedRecord>, as the incoming type always PCollection<IndexedRecord>
PCollection<IndexedRecord> indexedCollection = objectPCollection.apply("ExtractIndexedRecord", ParDo.of(new DoFn<Object, IndexedRecord>() {
IndexedRecordConverter converter;
@DoFn.ProcessElement
public void processElement(ProcessContext c) throws Exception {
if (c.element() == null) {
return;
}
if (converter == null) {
converter = new AvroRegistry().createIndexedRecordConverter(c.element().getClass());
}
c.output((IndexedRecord) converter.convertToAvro(c.element()));
}
}));
indexedCollection.setCoder(LazyAvroCoder.of());
PCollection<String> jmsCollection = indexedCollection.apply("IndexedRecordToJmsRecord", ParDo.of(new DoFn<IndexedRecord, String>() {
@DoFn.ProcessElement
public void processElement(ProcessContext c) throws Exception {
c.output(c.element().get(0).toString());
}
}));
datastoreRuntime = new JmsDatastoreRuntime();
datastoreRuntime.initialize(null, properties.datasetRef.getReference().getDatastoreProperties());
if (messageType.equals(JmsMessageType.QUEUE)) {
return jmsCollection.apply(JmsIO.write().withConnectionFactory(datastoreRuntime.getConnectionFactory()).withQueue(properties.datasetRef.getReference().queueTopicName.getValue()));
} else if (messageType.equals(JmsMessageType.TOPIC)) {
return jmsCollection.apply(JmsIO.write().withConnectionFactory(datastoreRuntime.getConnectionFactory()).withTopic(properties.datasetRef.getReference().queueTopicName.getValue()));
} else {
throw new TalendRuntimeException(CommonErrorCodes.UNEXPECTED_ARGUMENT);
}
}
use of org.talend.daikon.avro.AvroRegistry in project components by Talend.
the class IssueIndexedRecordTest method setUp.
/**
* 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\":[]}";
}
use of org.talend.daikon.avro.AvroRegistry in project components by Talend.
the class JiraSourceOrSinkTestIT method setUp.
/**
* 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);
}
use of org.talend.daikon.avro.AvroRegistry in project components by Talend.
the class TJiraOutputPropertiesTest method testSetupProperties.
/**
* 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));
}
Aggregations