Search in sources :

Example 1 with UpdateAttribute

use of org.apache.nifi.processors.attributes.UpdateAttribute in project nifi by apache.

the class TestUpdateAttribute method testInvalidRegexInAttribute.

@Test
public void testInvalidRegexInAttribute() {
    final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());
    runner.setProperty(UpdateAttribute.DELETE_ATTRIBUTES, "${butter}");
    runner.assertValid();
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("butter", "(");
    runner.enqueue(new byte[0], attributes);
    try {
        runner.run();
    } catch (Throwable t) {
        assertEquals(ProcessException.class, t.getCause().getClass());
    }
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) UpdateAttribute(org.apache.nifi.processors.attributes.UpdateAttribute) Test(org.junit.Test)

Example 2 with UpdateAttribute

use of org.apache.nifi.processors.attributes.UpdateAttribute in project nifi by apache.

the class TestUpdateAttribute method testDefaultEscapeValue.

@Test
public void testDefaultEscapeValue() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());
    runner.setProperty("NewAttr", "$${a}");
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("a", "b");
    runner.enqueue(new byte[0], attributes);
    runner.run();
    runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1);
    runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS).get(0).assertAttributeEquals("NewAttr", "${a}");
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) UpdateAttribute(org.apache.nifi.processors.attributes.UpdateAttribute) Test(org.junit.Test)

Example 3 with UpdateAttribute

use of org.apache.nifi.processors.attributes.UpdateAttribute in project nifi by apache.

the class TestUpdateAttribute method testAttributeListDelete.

@Test
public void testAttributeListDelete() {
    final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());
    runner.setProperty(UpdateAttribute.DELETE_ATTRIBUTES, "attribute.1|attribute.2|sample.1|simple.1");
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("attribute.1", "value.1");
    attributes.put("attribute.2", "value.2");
    attributes.put("attribute.6", "value.6");
    attributes.put("sampleSize", "value.size");
    attributes.put("sample.1", "value.sample.1");
    attributes.put("simple.1", "value.simple.1");
    runner.enqueue(new byte[0], attributes);
    runner.run();
    runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1);
    final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS);
    result.get(0).assertAttributeNotExists("attribute.1");
    result.get(0).assertAttributeNotExists("attribute.2");
    result.get(0).assertAttributeExists("attribute.6");
    result.get(0).assertAttributeExists("sampleSize");
    result.get(0).assertAttributeNotExists("sample.1");
    result.get(0).assertAttributeNotExists("simple.1");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) UpdateAttribute(org.apache.nifi.processors.attributes.UpdateAttribute) Test(org.junit.Test)

Example 4 with UpdateAttribute

use of org.apache.nifi.processors.attributes.UpdateAttribute in project nifi by apache.

the class TestUpdateAttribute method testExpressionRegexDelete.

@Test
public void testExpressionRegexDelete() {
    final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());
    runner.setProperty(UpdateAttribute.DELETE_ATTRIBUTES, "${literal('(attribute\\.'):append(${literal('[2-5]')}):append(${literal('|sample.*)')})}");
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("attribute.1", "value.1");
    attributes.put("attribute.2", "value.2");
    attributes.put("attribute.6", "value.6");
    attributes.put("sampleSize", "value.size");
    attributes.put("sample.1", "value.sample.1");
    attributes.put("simple.1", "value.simple.1");
    runner.enqueue(new byte[0], attributes);
    runner.run();
    runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1);
    final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS);
    result.get(0).assertAttributeEquals("attribute.1", "value.1");
    result.get(0).assertAttributeNotExists("attribute.2");
    result.get(0).assertAttributeExists("attribute.6");
    result.get(0).assertAttributeNotExists("sampleSize");
    result.get(0).assertAttributeNotExists("sample.1");
    result.get(0).assertAttributeExists("simple.1");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) UpdateAttribute(org.apache.nifi.processors.attributes.UpdateAttribute) Test(org.junit.Test)

Example 5 with UpdateAttribute

use of org.apache.nifi.processors.attributes.UpdateAttribute in project nifi by apache.

the class TestUpdateAttribute method testSimpleDelete.

@Test
public void testSimpleDelete() {
    final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());
    runner.setProperty(UpdateAttribute.DELETE_ATTRIBUTES, "attribute.2");
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("attribute.1", "value.1");
    attributes.put("attribute.2", "value.2");
    runner.enqueue(new byte[0], attributes);
    runner.run();
    runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1);
    final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS);
    result.get(0).assertAttributeEquals("attribute.1", "value.1");
    result.get(0).assertAttributeNotExists("attribute.2");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) UpdateAttribute(org.apache.nifi.processors.attributes.UpdateAttribute) Test(org.junit.Test)

Aggregations

UpdateAttribute (org.apache.nifi.processors.attributes.UpdateAttribute)32 TestRunner (org.apache.nifi.util.TestRunner)32 Test (org.junit.Test)32 HashMap (java.util.HashMap)31 MockFlowFile (org.apache.nifi.util.MockFlowFile)21 ProcessSessionFactory (org.apache.nifi.processor.ProcessSessionFactory)3 MockStateManager (org.apache.nifi.state.MockStateManager)3 ProcessException (org.apache.nifi.processor.exception.ProcessException)1