Java Code Examples for org.apache.nifi.util.MockComponentLog#getInfoMessages()

The following examples show how to use org.apache.nifi.util.MockComponentLog#getInfoMessages() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestContent.java    From nifi-scripting-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Demonstrates splitting an array in a single incoming FlowFile into multiple output FlowFiles
 * @throws Exception
 */
@Test
public void testSplitJavascript() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
    runner.setValidateExpressionUsage(false);
    runner.setProperty(SCRIPT_ENGINE, "ECMAScript");
    runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/content/split.js");
    runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
    runner.assertValid();

    String inputContent = "[";
    inputContent += "{ \"color\": \"blue\" },";
    inputContent += "{ \"color\": \"green\" },";
    inputContent += "{ \"color\": \"red\" }";
    inputContent += "]";
    runner.enqueue(inputContent.getBytes(StandardCharsets.UTF_8));
    runner.run();

    MockComponentLog log = runner.getLogger();
    List<LogMessage> infoMessages = log.getInfoMessages();

    runner.assertAllFlowFilesTransferred("success", 3);
    final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
    MockFlowFile blueFlowFile = successFlowFiles.get(0);
    blueFlowFile.assertAttributeEquals("color", "blue");
    MockFlowFile greenFlowFile = successFlowFiles.get(1);
    greenFlowFile.assertAttributeEquals("color", "green");
    MockFlowFile redFlowFile = successFlowFiles.get(2);
    redFlowFile.assertAttributeEquals("color", "red");
}
 
Example 2
Source File: TestContent.java    From nifi-scripting-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Demonstrates splitting an array in a single incoming FlowFile into multiple output FlowFiles
 * @throws Exception
 */
@Test
public void testSplitPython() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
    runner.setValidateExpressionUsage(false);
    runner.setProperty(SCRIPT_ENGINE, "python");
    runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/content/split.py");
    runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
    runner.assertValid();

    String inputContent = "[";
    inputContent += "{ \"color\": \"blue\" },";
    inputContent += "{ \"color\": \"green\" },";
    inputContent += "{ \"color\": \"red\" }";
    inputContent += "]";
    runner.enqueue(inputContent.getBytes(StandardCharsets.UTF_8));
    runner.run();

    MockComponentLog log = runner.getLogger();
    List<LogMessage> infoMessages = log.getInfoMessages();

    runner.assertAllFlowFilesTransferred("success", 3);
    final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
    MockFlowFile blueFlowFile = successFlowFiles.get(0);
    blueFlowFile.assertAttributeEquals("color", "blue");
    MockFlowFile greenFlowFile = successFlowFiles.get(1);
    greenFlowFile.assertAttributeEquals("color", "green");
    MockFlowFile redFlowFile = successFlowFiles.get(2);
    redFlowFile.assertAttributeEquals("color", "red");
}
 
Example 3
Source File: TestLog.java    From nifi-scripting-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Demonstrates logging from within scripts
 * @throws Exception
 */
@Test
public void testLogJavascript() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
    runner.setValidateExpressionUsage(false);
    runner.setProperty(SCRIPT_ENGINE, "ECMAScript");
    runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/log/log.js");
    runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
    runner.assertValid();

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("greeting", "Hello");
    runner.enqueue("sample text".getBytes(StandardCharsets.UTF_8), attributes);
    runner.run();

    runner.assertAllFlowFilesTransferred("success", 1);
    final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
    MockFlowFile result = successFlowFiles.get(0);

    MockComponentLog log = runner.getLogger();

    List<LogMessage> debugMessages = log.getDebugMessages();
    Assert.assertEquals(1, debugMessages.size());
    Assert.assertTrue(debugMessages.get(0).getMsg().contains("Hello, Debug"));

    List<LogMessage> infoMessages = log.getInfoMessages();
    Assert.assertEquals(1, infoMessages.size());
    Assert.assertTrue(infoMessages.get(0).getMsg().contains("Hello, Info"));

    List<LogMessage> warnMessages = log.getWarnMessages();
    Assert.assertEquals(1, warnMessages.size());
    Assert.assertTrue(warnMessages.get(0).getMsg().contains("Hello, Warn"));

    List<LogMessage> errorMessages = log.getErrorMessages();
    Assert.assertEquals(1, errorMessages.size());
    Assert.assertTrue(errorMessages.get(0).getMsg().contains("Hello, Error"));
}
 
Example 4
Source File: TestLog.java    From nifi-scripting-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Demonstrates logging from within scripts
 * @throws Exception
 */
@Test
public void testLogPython() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
    runner.setValidateExpressionUsage(false);
    runner.setProperty(SCRIPT_ENGINE, "python");
    runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/log/log.py");
    runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
    runner.assertValid();

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("greeting", "Hello");
    runner.enqueue("sample text".getBytes(StandardCharsets.UTF_8), attributes);
    runner.run();

    runner.assertAllFlowFilesTransferred("success", 1);
    final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
    MockFlowFile result = successFlowFiles.get(0);

    MockComponentLog log = runner.getLogger();

    List<LogMessage> debugMessages = log.getDebugMessages();
    Assert.assertEquals(1, debugMessages.size());
    Assert.assertTrue(debugMessages.get(0).getMsg().contains("Hello, Debug"));

    List<LogMessage> infoMessages = log.getInfoMessages();
    Assert.assertEquals(1, infoMessages.size());
    Assert.assertTrue(infoMessages.get(0).getMsg().contains("Hello, Info"));

    List<LogMessage> warnMessages = log.getWarnMessages();
    Assert.assertEquals(1, warnMessages.size());
    Assert.assertTrue(warnMessages.get(0).getMsg().contains("Hello, Warn"));

    List<LogMessage> errorMessages = log.getErrorMessages();
    Assert.assertEquals(1, errorMessages.size());
    Assert.assertTrue(errorMessages.get(0).getMsg().contains("Hello, Error"));
}
 
Example 5
Source File: TestLogMessage.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testInfoMessageLogged() throws InitializationException, IOException {

    runner.setProperty(LogMessage.LOG_MESSAGE, "This should help the operator to follow the flow: ${foobar}");
    runner.setProperty(LogMessage.LOG_LEVEL, LogMessage.MessageLogLevel.info.toString());

    HashMap<String, String> flowAttributes = new HashMap<>();
    flowAttributes.put("foobar", "baz");

    runner.enqueue("This is a message!", flowAttributes);
    runner.run();

    List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship(LogMessage.REL_SUCCESS);
    Assert.assertEquals(1, successFlowFiles.size());

    MockComponentLog mockComponentLog = testableLogMessage.getMockComponentLog();
    List<org.apache.nifi.util.LogMessage> infoMessages = mockComponentLog.getInfoMessages();
    Assert.assertEquals(1, infoMessages.size());
    Assert.assertTrue(infoMessages.get(0).getMsg()
            .endsWith("This should help the operator to follow the flow: baz"));


    Assert.assertTrue(mockComponentLog.getTraceMessages().isEmpty());
    Assert.assertTrue(mockComponentLog.getDebugMessages().isEmpty());
    Assert.assertTrue(mockComponentLog.getWarnMessages().isEmpty());
    Assert.assertTrue(mockComponentLog.getErrorMessages().isEmpty());
}
 
Example 6
Source File: TestLogMessage.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testInfoMessageWithPrefixLogged() throws InitializationException, IOException {

    runner.setProperty(LogMessage.LOG_PREFIX, "FOOBAR>>>");
    runner.setProperty(LogMessage.LOG_MESSAGE, "This should help the operator to follow the flow: ${foobar}");
    runner.setProperty(LogMessage.LOG_LEVEL, LogMessage.MessageLogLevel.info.toString());

    HashMap<String, String> flowAttributes = new HashMap<>();
    flowAttributes.put("foobar", "baz");

    runner.enqueue("This is a message!", flowAttributes);
    runner.run();

    List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship(LogMessage.REL_SUCCESS);
    Assert.assertEquals(1, successFlowFiles.size());

    MockComponentLog mockComponentLog = testableLogMessage.getMockComponentLog();
    List<org.apache.nifi.util.LogMessage> infoMessages = mockComponentLog.getInfoMessages();
    Assert.assertEquals(1, infoMessages.size());
    Assert.assertTrue(infoMessages.get(0).getMsg()
            .endsWith("FOOBAR>>>This should help the operator to follow the flow: baz"));



    Assert.assertTrue(mockComponentLog.getTraceMessages().isEmpty());
    Assert.assertTrue(mockComponentLog.getDebugMessages().isEmpty());
    Assert.assertTrue(mockComponentLog.getWarnMessages().isEmpty());
    Assert.assertTrue(mockComponentLog.getErrorMessages().isEmpty());
}