Search in sources :

Example 51 with PropertyDescriptor

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

the class TestSiteToSiteProvenanceReportingTask method testRemotePorts.

@Test
public void testRemotePorts() 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, "riB2,roB3");
    // riB2 is a Remote Input Port in Process Group B2.
    ProvenanceEventRecord event = createProvenanceEventRecord("riB2", "Remote Input Port");
    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("riB2", reportedEvent.get("componentId").asText());
    assertEquals("Remote Input Port name", reportedEvent.get("componentName").asText());
    assertEquals("pgB2", reportedEvent.get("processGroupId").asText());
    // roB3 is a Remote Output Port in Process Group B3.
    event = createProvenanceEventRecord("roB3", "Remote Output Port");
    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("roB3", reportedEvent.get("componentId").asText());
    assertEquals("Remote Output Port name", reportedEvent.get("componentName").asText());
    assertEquals("pgB3", reportedEvent.get("processGroupId").asText());
}
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 52 with PropertyDescriptor

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

the class TestSiteToSiteStatusReportingTask method testSerializedForm.

@Test
public void testSerializedForm() throws IOException, InitializationException {
    final ProcessGroupStatus pgStatus = generateProcessGroupStatus("root", "Awesome", 1, 0);
    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    properties.put(SiteToSiteStatusReportingTask.BATCH_SIZE, "4");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_NAME_FILTER_REGEX, "Awesome.*");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_TYPE_FILTER_REGEX, ".*");
    MockSiteToSiteStatusReportingTask task = initTask(properties, pgStatus);
    task.onTrigger(context);
    assertEquals(16, task.dataSent.size());
    final String msg = new String(task.dataSent.get(0), StandardCharsets.UTF_8);
    JsonReader jsonReader = Json.createReader(new ByteArrayInputStream(msg.getBytes()));
    JsonString componentId = jsonReader.readArray().getJsonObject(0).getJsonString("componentId");
    assertEquals(pgStatus.getId(), componentId.getString());
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonReader(javax.json.JsonReader) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString) Test(org.junit.Test)

Example 53 with PropertyDescriptor

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

the class TestSiteToSiteStatusReportingTask method testConnectionStatus.

@Test
public void testConnectionStatus() throws IOException, InitializationException {
    final ProcessGroupStatus pgStatus = generateProcessGroupStatus("root", "Awesome", 1, 0);
    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    properties.put(SiteToSiteStatusReportingTask.BATCH_SIZE, "4");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_NAME_FILTER_REGEX, "Awesome.*");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_TYPE_FILTER_REGEX, "(Connection)");
    MockSiteToSiteStatusReportingTask task = initTask(properties, pgStatus);
    task.onTrigger(context);
    final String msg = new String(task.dataSent.get(0), StandardCharsets.UTF_8);
    JsonReader jsonReader = Json.createReader(new ByteArrayInputStream(msg.getBytes()));
    JsonString backpressure = jsonReader.readArray().getJsonObject(0).getJsonString("isBackPressureEnabled");
    assertEquals("true", backpressure.getString());
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonReader(javax.json.JsonReader) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString) Test(org.junit.Test)

Example 54 with PropertyDescriptor

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

the class PutSlackTest method testInvalidDynamicProperties.

@Test
public void testInvalidDynamicProperties() {
    testRunner.setProperty(PutSlack.WEBHOOK_URL, server.getUrl());
    testRunner.setProperty(PutSlack.WEBHOOK_TEXT, WEBHOOK_TEST_TEXT);
    PropertyDescriptor dynamicProp = new PropertyDescriptor.Builder().dynamic(true).name("foo").build();
    testRunner.setProperty(dynamicProp, "{\"a\": a}");
    testRunner.enqueue("{}".getBytes());
    testRunner.run(1);
    testRunner.assertTransferCount(PutSlack.REL_FAILURE, 1);
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) Test(org.junit.Test)

Example 55 with PropertyDescriptor

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

the class PutSlackTest method testValidDynamicProperties.

@Test
public void testValidDynamicProperties() {
    testRunner.setProperty(PutSlack.WEBHOOK_URL, server.getUrl());
    testRunner.setProperty(PutSlack.WEBHOOK_TEXT, WEBHOOK_TEST_TEXT);
    PropertyDescriptor dynamicProp = new PropertyDescriptor.Builder().dynamic(true).name("foo").build();
    testRunner.setProperty(dynamicProp, "{\"a\": \"a\"}");
    testRunner.enqueue("{}".getBytes());
    testRunner.run(1);
    testRunner.assertTransferCount(PutSlack.REL_FAILURE, 0);
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) 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