Search in sources :

Example 21 with AvroRegistry

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));
}
Also used : AvroRegistry(org.talend.daikon.avro.AvroRegistry) Schema(org.apache.avro.Schema) Test(org.junit.Test)

Example 22 with AvroRegistry

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);
    }
}
Also used : TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) DoFn(org.apache.beam.sdk.transforms.DoFn) AvroRegistry(org.talend.daikon.avro.AvroRegistry) IndexedRecord(org.apache.avro.generic.IndexedRecord) IndexedRecordConverter(org.talend.daikon.avro.converter.IndexedRecordConverter)

Example 23 with AvroRegistry

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\":[]}";
}
Also used : AvroRegistry(org.talend.daikon.avro.AvroRegistry) Schema(org.apache.avro.Schema) BeforeClass(org.junit.BeforeClass)

Example 24 with AvroRegistry

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);
}
Also used : AvroRegistry(org.talend.daikon.avro.AvroRegistry) Schema(org.apache.avro.Schema) TJiraOutputProperties(org.talend.components.jira.tjiraoutput.TJiraOutputProperties) Matchers.containsString(org.hamcrest.Matchers.containsString) Before(org.junit.Before)

Example 25 with AvroRegistry

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));
}
Also used : Action(org.talend.components.jira.Action) AvroRegistry(org.talend.daikon.avro.AvroRegistry) Schema(org.apache.avro.Schema) Mode(org.talend.components.jira.Mode) Resource(org.talend.components.jira.Resource) Test(org.junit.Test)

Aggregations

AvroRegistry (org.talend.daikon.avro.AvroRegistry)31 Schema (org.apache.avro.Schema)29 Test (org.junit.Test)19 Ignore (org.junit.Ignore)11 Before (org.junit.Before)4 TJiraOutputProperties (org.talend.components.jira.tjiraoutput.TJiraOutputProperties)3 IndexedRecord (org.apache.avro.generic.IndexedRecord)2 BeforeClass (org.junit.BeforeClass)2 SplunkJSONEventField (org.talend.components.splunk.objects.SplunkJSONEventField)2 Field (org.apache.avro.Schema.Field)1 DoFn (org.apache.beam.sdk.transforms.DoFn)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 GenericAvroRegistry (org.talend.components.common.runtime.GenericAvroRegistry)1 Action (org.talend.components.jira.Action)1 Mode (org.talend.components.jira.Mode)1 Resource (org.talend.components.jira.Resource)1 TJiraInputProperties (org.talend.components.jira.tjirainput.TJiraInputProperties)1 IndexedRecordConverter (org.talend.daikon.avro.converter.IndexedRecordConverter)1 TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)1