Search in sources :

Example 41 with PropertyDescriptor

use of org.apache.nifi.components.PropertyDescriptor in project nifi by apache.

the class TestSiteToSiteProvenanceReportingTask method testFilterProcessGroupId.

@Test
public void testFilterProcessGroupId() throws IOException, InitializationException {
    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    for (final PropertyDescriptor descriptor : new MockSiteToSiteProvenanceReportingTask().getSupportedPropertyDescriptors()) {
        properties.put(descriptor, descriptor.getDefaultValue());
    }
    properties.put(SiteToSiteProvenanceReportingTask.BATCH_SIZE, "1000");
    properties.put(SiteToSiteProvenanceReportingTask.FILTER_COMPONENT_ID, "pgB2");
    // B201 belongs to ProcessGroup B2, so it should be picked.
    ProvenanceEventRecord event = createProvenanceEventRecord("B201", "dummy");
    MockSiteToSiteProvenanceReportingTask task = setup(event, properties, 1);
    task.initialize(initContext);
    task.onScheduled(confContext);
    task.onTrigger(context);
    assertEquals(1, task.dataSent.size());
    JsonNode reportedEvent = new ObjectMapper().readTree(task.dataSent.get(0)).get(0);
    assertEquals("B201", reportedEvent.get("componentId").asText());
    assertEquals("Processor in PGB2", reportedEvent.get("componentName").asText());
    // B301 belongs to PG B3, whose parent is PGB2, so it should be picked, too.
    event = createProvenanceEventRecord("B301", "dummy");
    task = setup(event, properties, 1);
    task.initialize(initContext);
    task.onScheduled(confContext);
    task.onTrigger(context);
    assertEquals(1, task.dataSent.size());
    reportedEvent = new ObjectMapper().readTree(task.dataSent.get(0)).get(0);
    assertEquals("B301", reportedEvent.get("componentId").asText());
    assertEquals("Processor in PGB3", reportedEvent.get("componentName").asText());
    // A001 belongs to PG A, whose parent is the root PG, so it should be filtered out.
    event = createProvenanceEventRecord("A001", "dummy");
    task = setup(event, properties, 1);
    task.initialize(initContext);
    task.onScheduled(confContext);
    task.onTrigger(context);
    assertEquals(0, task.dataSent.size());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 42 with PropertyDescriptor

use of org.apache.nifi.components.PropertyDescriptor in project nifi by apache.

the class TestSiteToSiteProvenanceReportingTask method testFilterComponentIdNoResult.

@Test
public void testFilterComponentIdNoResult() throws IOException, InitializationException {
    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    for (final PropertyDescriptor descriptor : new MockSiteToSiteProvenanceReportingTask().getSupportedPropertyDescriptors()) {
        properties.put(descriptor, descriptor.getDefaultValue());
    }
    properties.put(SiteToSiteProvenanceReportingTask.BATCH_SIZE, "1000");
    properties.put(SiteToSiteProvenanceReportingTask.FILTER_COMPONENT_ID, "9999");
    ProvenanceEventRecord event = createProvenanceEventRecord();
    MockSiteToSiteProvenanceReportingTask task = setup(event, properties);
    task.initialize(initContext);
    task.onScheduled(confContext);
    task.onTrigger(context);
    assertEquals(0, task.dataSent.size());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) Test(org.junit.Test)

Example 43 with PropertyDescriptor

use of org.apache.nifi.components.PropertyDescriptor in project nifi by apache.

the class TestSiteToSiteProvenanceReportingTask method testSerializedForm.

@Test
public void testSerializedForm() throws IOException, InitializationException {
    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    for (final PropertyDescriptor descriptor : new MockSiteToSiteProvenanceReportingTask().getSupportedPropertyDescriptors()) {
        properties.put(descriptor, descriptor.getDefaultValue());
    }
    properties.put(SiteToSiteProvenanceReportingTask.BATCH_SIZE, "1000");
    ProvenanceEventRecord event = createProvenanceEventRecord();
    MockSiteToSiteProvenanceReportingTask task = setup(event, properties);
    task.initialize(initContext);
    task.onScheduled(confContext);
    task.onTrigger(context);
    assertEquals(3, task.dataSent.size());
    final String msg = new String(task.dataSent.get(0), StandardCharsets.UTF_8);
    JsonReader jsonReader = Json.createReader(new ByteArrayInputStream(msg.getBytes()));
    JsonObject msgArray = jsonReader.readArray().getJsonObject(0).getJsonObject("updatedAttributes");
    assertEquals(msgArray.getString("abc"), event.getAttributes().get("abc"));
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 44 with PropertyDescriptor

use of org.apache.nifi.components.PropertyDescriptor in project nifi by apache.

the class TestSiteToSiteProvenanceReportingTask method testFilterComponentTypeSuccess.

@Test
public void testFilterComponentTypeSuccess() throws IOException, InitializationException {
    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    for (final PropertyDescriptor descriptor : new MockSiteToSiteProvenanceReportingTask().getSupportedPropertyDescriptors()) {
        properties.put(descriptor, descriptor.getDefaultValue());
    }
    properties.put(SiteToSiteProvenanceReportingTask.BATCH_SIZE, "1000");
    properties.put(SiteToSiteProvenanceReportingTask.FILTER_COMPONENT_TYPE, "dummy.*");
    ProvenanceEventRecord event = createProvenanceEventRecord();
    MockSiteToSiteProvenanceReportingTask task = setup(event, properties);
    task.initialize(initContext);
    task.onScheduled(confContext);
    task.onTrigger(context);
    assertEquals(3, task.dataSent.size());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) Test(org.junit.Test)

Example 45 with PropertyDescriptor

use of org.apache.nifi.components.PropertyDescriptor in project nifi by apache.

the class TestSiteToSiteProvenanceReportingTask method testFilterEventTypeSuccess.

@Test
public void testFilterEventTypeSuccess() throws IOException, InitializationException {
    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    for (final PropertyDescriptor descriptor : new MockSiteToSiteProvenanceReportingTask().getSupportedPropertyDescriptors()) {
        properties.put(descriptor, descriptor.getDefaultValue());
    }
    properties.put(SiteToSiteProvenanceReportingTask.BATCH_SIZE, "1000");
    properties.put(SiteToSiteProvenanceReportingTask.FILTER_EVENT_TYPE, "RECEIVE, notExistingType, DROP");
    ProvenanceEventRecord event = createProvenanceEventRecord();
    MockSiteToSiteProvenanceReportingTask task = setup(event, properties);
    task.initialize(initContext);
    task.onScheduled(confContext);
    task.onTrigger(context);
    assertEquals(3, task.dataSent.size());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) Test(org.junit.Test)

Aggregations

PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)206 HashMap (java.util.HashMap)97 Test (org.junit.Test)67 Map (java.util.Map)57 ArrayList (java.util.ArrayList)49 HashSet (java.util.HashSet)24 IOException (java.io.IOException)23 Relationship (org.apache.nifi.processor.Relationship)22 ComponentLog (org.apache.nifi.logging.ComponentLog)21 LinkedHashMap (java.util.LinkedHashMap)20 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)19 TestRunner (org.apache.nifi.util.TestRunner)19 ValidationResult (org.apache.nifi.components.ValidationResult)17 ProcessException (org.apache.nifi.processor.exception.ProcessException)17 FlowFile (org.apache.nifi.flowfile.FlowFile)16 LinkedHashSet (java.util.LinkedHashSet)15 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)14 PropertyValue (org.apache.nifi.components.PropertyValue)14 URL (java.net.URL)13 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)13