Java Code Examples for org.apache.nifi.util.TestRunner#setAnnotationData()
The following examples show how to use
org.apache.nifi.util.TestRunner#setAnnotationData() .
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: TestUpdateAttribute.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testRuleMissBecauseValueNoMatch() throws Exception { final Criteria criteria = getCriteria(); addRule(criteria, "rule", Arrays.asList( // conditions "${attribute1:equals('not.value.1')}"), getMap( // actions "attribute.2", "value.2")); final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setAnnotationData(serialize(criteria)); final Map<String, String> attributes = new HashMap<>(); attributes.put("attribute.1", "value.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"); }
Example 2
Source File: TestUpdateAttribute.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testRuleHitWithAConflictingDefault() throws Exception { final Criteria criteria = getCriteria(); addRule(criteria, "rule", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.2")); final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setAnnotationData(serialize(criteria)); runner.setProperty("attribute.2", "default.value.2"); final Map<String, String> attributes = new HashMap<>(); attributes.put("attribute.1", "value.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.2", "value.2"); }
Example 3
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testRuleHitWithAConflictingDefault() throws Exception { final Criteria criteria = getCriteria(); addRule(criteria, "rule", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.2")); final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setAnnotationData(serialize(criteria)); runner.setProperty("attribute.2", "default.value.2"); final Map<String, String> attributes = new HashMap<>(); attributes.put("attribute.1", "value.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.2", "value.2"); }
Example 4
Source File: TestUpdateAttribute.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testRuleHitWithStateWithInitValue() throws Exception { final Criteria criteria = getCriteria(); addRule(criteria, "rule", Arrays.asList( // conditions "${getStateValue('minValue'):ge(${value})}"), getMap( // actions "minValue", "${value}")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "5"); runner.setAnnotationData(serialize(criteria)); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "2"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "4"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 4); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); result.get(3).assertAttributeEquals("minValue", "1"); }
Example 5
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testRuleHitWithStateWithDefault() throws Exception { final Criteria criteria = getCriteria(); addRule(criteria, "rule", Arrays.asList( // conditions "${getStateValue('maxValue'):lt(${value})}"), getMap( // actions "maxValue", "${value}")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0"); runner.setAnnotationData(serialize(criteria)); runner.setProperty("maxValue", "${getStateValue('maxValue')}"); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "2"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "4"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 4); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); result.get(2).assertAttributeEquals("maxValue", "4"); result.get(3).assertAttributeEquals("maxValue", "4"); }
Example 6
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testRuleHitWithStateWithInitValue() throws Exception { final Criteria criteria = getCriteria(); addRule(criteria, "rule", Arrays.asList( // conditions "${getStateValue('minValue'):ge(${value})}"), getMap( // actions "minValue", "${value}")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "5"); runner.setAnnotationData(serialize(criteria)); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "2"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "4"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 4); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); result.get(3).assertAttributeEquals("minValue", "1"); }
Example 7
Source File: TestUpdateAttribute.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testRuleHitWithStateWithDefault() throws Exception { final Criteria criteria = getCriteria(); addRule(criteria, "rule", Arrays.asList( // conditions "${getStateValue('maxValue'):lt(${value})}"), getMap( // actions "maxValue", "${value}")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0"); runner.setAnnotationData(serialize(criteria)); runner.setProperty("maxValue", "${getStateValue('maxValue')}"); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "2"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "4"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 4); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); result.get(2).assertAttributeEquals("maxValue", "4"); result.get(3).assertAttributeEquals("maxValue", "4"); }
Example 8
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testRuleHitWithState() throws Exception { final Criteria criteria = getCriteria(); addRule(criteria, "rule", Arrays.asList( // conditions "${getStateValue('maxValue'):lt(${value})}"), getMap( // actions "maxValue", "${value}")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0"); runner.setAnnotationData(serialize(criteria)); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "2"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "4"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 4); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); result.get(2).assertAttributeEquals("maxValue", "4"); result.get(3).assertAttributeEquals("maxValue", null); }
Example 9
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testMultipleRuleHitsWithUseOriginalDoesntApplyDefaultsRepeatedly() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_ORIGINAL); addRule(criteria, "rule 1", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.2")); addRule(criteria, "rule 2", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.3", "value.3")); addRule(criteria, "rule 3", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.3")); final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setAnnotationData(serialize(criteria)); runner.setProperty("default.attr", "${default.attr}-more-stuff"); final Map<String, String> attributes = new HashMap<>(); attributes.put("attribute.1", "value.1"); runner.enqueue(TEST_CONTENT.getBytes(StandardCharsets.UTF_8), attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); final MockFlowFile flowfile = result.get(0); // ensure the attributes are as expected flowfile.assertAttributeEquals("default.attr", "-more-stuff"); }
Example 10
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testMultipleRuleHitsWithNoFlowFilePolicySpecified() throws Exception { final Criteria criteria = getCriteria(); addRule(criteria, "rule 1", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.2")); addRule(criteria, "rule 2", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.3", "value.3")); final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setAnnotationData(serialize(criteria)); runner.setProperty("attribute.2", "default.value.2"); final Map<String, String> attributes = new HashMap<>(); attributes.put("attribute.1", "value.1"); runner.enqueue(TEST_CONTENT.getBytes(StandardCharsets.UTF_8), attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 2); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); final MockFlowFile flowfile1 = result.get(0); final MockFlowFile flowfile2 = result.get(1); // ensure the attributes are as expected if ("rule 1".equals(flowfile1.getAttribute(runner.getProcessor().getClass().getSimpleName() + ".matchedRule"))) { flowfile1.assertAttributeEquals("attribute.2", "value.2"); flowfile2.assertAttributeEquals("attribute.3", "value.3"); flowfile2.assertAttributeEquals("attribute.2", "default.value.2"); } else { flowfile2.assertAttributeEquals("attribute.2", "value.2"); flowfile1.assertAttributeEquals("attribute.3", "value.3"); flowfile1.assertAttributeEquals("attribute.2", "default.value.2"); } // ensure the content was copied as well flowfile1.assertContentEquals(TEST_CONTENT.getBytes(StandardCharsets.UTF_8)); flowfile2.assertContentEquals(TEST_CONTENT.getBytes(StandardCharsets.UTF_8)); }
Example 11
Source File: TestUpdateAttribute.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testMultipleRulesWithStateAndDelete() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_ORIGINAL); addRule(criteria, "rule", Collections.singletonList( // conditions "${getStateValue('maxValue'):lt(${value})}"), getMap( // actions "maxValue", "${value}")); addRule(criteria, "rule2", Collections.singletonList( // conditions "${value:mod(2):equals(0)}"), getMap( // actions "whatIsIt", "even")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.DELETE_ATTRIBUTES, "badValue"); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0"); runner.setAnnotationData(serialize(criteria)); runner.setProperty("maxValue", "${getStateValue('maxValue')}"); runner.setProperty("whatIsIt", "odd"); runner.setProperty("whatWasIt", "${getStateValue('whatIsIt')}"); runner.setProperty("theCount", "${getStateValue('theCount'):plus(1)}"); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); attributes.put("badValue", "10"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "2"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "5"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 4); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); result.get(3).assertAttributeEquals("maxValue", "5"); result.get(3).assertAttributeEquals("theCount", "4"); result.get(0).assertAttributeEquals("badValue", null); result.get(0).assertAttributeEquals("whatIsIt", "odd"); result.get(1).assertAttributeEquals("whatIsIt", "even"); result.get(2).assertAttributeEquals("whatWasIt", "even"); result.get(3).assertAttributeEquals("whatWasIt", "odd"); }
Example 12
Source File: TestUpdateAttribute.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testStateFailuresWithRulesUsingClone() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_CLONE); addRule(criteria, "rule", Collections.singletonList( // conditions "${getStateValue('maxValue'):lt(${value})}"), getMap( // actions "maxValue", "${value}")); addRule(criteria, "rule2", Collections.singletonList( // conditions "${getStateValue('maxValue2'):lt(${value})}"), getMap( // actions "maxValue2", "${value}")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); final UpdateAttribute processor = (UpdateAttribute) runner.getProcessor(); final ProcessSessionFactory processSessionFactory = runner.getProcessSessionFactory(); MockStateManager mockStateManager = runner.getStateManager(); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0"); runner.setAnnotationData(serialize(criteria)); processor.onScheduled(runner.getProcessContext()); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); mockStateManager.setFailOnStateGet(Scope.LOCAL, true); processor.onTrigger(runner.getProcessContext(), processSessionFactory.createSession()); runner.assertQueueNotEmpty(); mockStateManager.setFailOnStateGet(Scope.LOCAL, false); mockStateManager.setFailOnStateSet(Scope.LOCAL, true); processor.onTrigger(runner.getProcessContext(), processSessionFactory.createSession()); runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_FAILED_SET_STATE, 1); runner.getFlowFilesForRelationship(UpdateAttribute.REL_FAILED_SET_STATE).get(0).assertAttributeEquals("maxValue", "1"); runner.getFlowFilesForRelationship(UpdateAttribute.REL_FAILED_SET_STATE).get(0).assertAttributeNotExists("maxValue2"); }
Example 13
Source File: TestUpdateAttribute.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testStateFailuresWithRulesUsingOriginal() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_ORIGINAL); addRule(criteria, "rule", Collections.singletonList( // conditions "${getStateValue('maxValue'):lt(${value})}"), getMap( // actions "maxValue", "${value}")); addRule(criteria, "rule2", Collections.singletonList( // conditions "${getStateValue('maxValue2'):lt(${value})}"), getMap( // actions "maxValue2", "${value}")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); final UpdateAttribute processor = (UpdateAttribute) runner.getProcessor(); final ProcessSessionFactory processSessionFactory = runner.getProcessSessionFactory(); MockStateManager mockStateManager = runner.getStateManager(); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0"); runner.setAnnotationData(serialize(criteria)); processor.onScheduled(runner.getProcessContext()); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); mockStateManager.setFailOnStateGet(Scope.LOCAL, true); processor.onTrigger(runner.getProcessContext(), processSessionFactory.createSession()); runner.assertQueueNotEmpty(); mockStateManager.setFailOnStateGet(Scope.LOCAL, false); mockStateManager.setFailOnStateSet(Scope.LOCAL, true); processor.onTrigger(runner.getProcessContext(), processSessionFactory.createSession()); runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_FAILED_SET_STATE, 1); runner.getFlowFilesForRelationship(UpdateAttribute.REL_FAILED_SET_STATE).get(0).assertAttributeEquals("maxValue", "1"); runner.getFlowFilesForRelationship(UpdateAttribute.REL_FAILED_SET_STATE).get(0).assertAttributeEquals("maxValue2", "1"); }
Example 14
Source File: TestUpdateAttribute.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testMultipleRuleHitsWithUseOriginal() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_ORIGINAL); addRule(criteria, "rule 1", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.2")); addRule(criteria, "rule 2", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.3", "value.3")); addRule(criteria, "rule 3", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.3")); final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setAnnotationData(serialize(criteria)); runner.setProperty("attribute.2", "default.value.2"); final Map<String, String> attributes = new HashMap<>(); attributes.put("attribute.1", "value.1"); runner.enqueue(TEST_CONTENT.getBytes(StandardCharsets.UTF_8), attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); final MockFlowFile flowfile = result.get(0); // ensure the attributes are as expected flowfile.assertAttributeEquals("attribute.2", "value.3"); flowfile.assertAttributeEquals("attribute.3", "value.3"); // ensure the content was copied as well flowfile.assertContentEquals(TEST_CONTENT.getBytes(StandardCharsets.UTF_8)); }
Example 15
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testMultipleRuleHitsWithUseOriginal() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_ORIGINAL); addRule(criteria, "rule 1", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.2")); addRule(criteria, "rule 2", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.3", "value.3")); addRule(criteria, "rule 3", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.3")); final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setAnnotationData(serialize(criteria)); runner.setProperty("attribute.2", "default.value.2"); final Map<String, String> attributes = new HashMap<>(); attributes.put("attribute.1", "value.1"); runner.enqueue(TEST_CONTENT.getBytes(StandardCharsets.UTF_8), attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); final MockFlowFile flowfile = result.get(0); // ensure the attributes are as expected flowfile.assertAttributeEquals("attribute.2", "value.3"); flowfile.assertAttributeEquals("attribute.3", "value.3"); // ensure the content was copied as well flowfile.assertContentEquals(TEST_CONTENT.getBytes(StandardCharsets.UTF_8)); }
Example 16
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testMultipleRuleHitsWithUseClone() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_CLONE); addRule(criteria, "rule 1", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.2")); addRule(criteria, "rule 2", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.3", "value.3")); final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setAnnotationData(serialize(criteria)); runner.setProperty("attribute.2", "default.value.2"); final Map<String, String> attributes = new HashMap<>(); attributes.put("attribute.1", "value.1"); runner.enqueue(TEST_CONTENT.getBytes(StandardCharsets.UTF_8), attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 2); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); final MockFlowFile flowfile1 = result.get(0); final MockFlowFile flowfile2 = result.get(1); // ensure the attributes are as expected if ("rule 1".equals(flowfile1.getAttribute(runner.getProcessor().getClass().getSimpleName() + ".matchedRule"))) { flowfile1.assertAttributeEquals("attribute.2", "value.2"); flowfile2.assertAttributeEquals("attribute.3", "value.3"); flowfile2.assertAttributeEquals("attribute.2", "default.value.2"); } else { flowfile2.assertAttributeEquals("attribute.2", "value.2"); flowfile1.assertAttributeEquals("attribute.3", "value.3"); flowfile1.assertAttributeEquals("attribute.2", "default.value.2"); } // ensure the content was copied as well flowfile1.assertContentEquals(TEST_CONTENT.getBytes(StandardCharsets.UTF_8)); flowfile2.assertContentEquals(TEST_CONTENT.getBytes(StandardCharsets.UTF_8)); }
Example 17
Source File: TestUpdateAttribute.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testMultipleRuleHitsWithNoFlowFilePolicySpecified() throws Exception { final Criteria criteria = getCriteria(); addRule(criteria, "rule 1", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.2")); addRule(criteria, "rule 2", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.3", "value.3")); final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setAnnotationData(serialize(criteria)); runner.setProperty("attribute.2", "default.value.2"); final Map<String, String> attributes = new HashMap<>(); attributes.put("attribute.1", "value.1"); runner.enqueue(TEST_CONTENT.getBytes(StandardCharsets.UTF_8), attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 2); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); final MockFlowFile flowfile1 = result.get(0); final MockFlowFile flowfile2 = result.get(1); // ensure the attributes are as expected if ("rule 1".equals(flowfile1.getAttribute(runner.getProcessor().getClass().getSimpleName() + ".matchedRule"))) { flowfile1.assertAttributeEquals("attribute.2", "value.2"); flowfile2.assertAttributeEquals("attribute.3", "value.3"); flowfile2.assertAttributeEquals("attribute.2", "default.value.2"); } else { flowfile2.assertAttributeEquals("attribute.2", "value.2"); flowfile1.assertAttributeEquals("attribute.3", "value.3"); flowfile1.assertAttributeEquals("attribute.2", "default.value.2"); } // ensure the content was copied as well flowfile1.assertContentEquals(TEST_CONTENT.getBytes(StandardCharsets.UTF_8)); flowfile2.assertContentEquals(TEST_CONTENT.getBytes(StandardCharsets.UTF_8)); }
Example 18
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testMultipleRulesWithStateAndDelete() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_ORIGINAL); addRule(criteria, "rule", Collections.singletonList( // conditions "${getStateValue('maxValue'):lt(${value})}"), getMap( // actions "maxValue", "${value}")); addRule(criteria, "rule2", Collections.singletonList( // conditions "${value:mod(2):equals(0)}"), getMap( // actions "whatIsIt", "even")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.DELETE_ATTRIBUTES, "badValue"); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0"); runner.setAnnotationData(serialize(criteria)); runner.setProperty("maxValue", "${getStateValue('maxValue')}"); runner.setProperty("whatIsIt", "odd"); runner.setProperty("whatWasIt", "${getStateValue('whatIsIt')}"); runner.setProperty("theCount", "${getStateValue('theCount'):plus(1)}"); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); attributes.put("badValue", "10"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "2"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "5"); runner.enqueue(new byte[0], attributes); runner.run(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 4); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); result.get(3).assertAttributeEquals("maxValue", "5"); result.get(3).assertAttributeEquals("theCount", "4"); result.get(0).assertAttributeEquals("badValue", null); result.get(0).assertAttributeEquals("whatIsIt", "odd"); result.get(1).assertAttributeEquals("whatIsIt", "even"); result.get(2).assertAttributeEquals("whatWasIt", "even"); result.get(3).assertAttributeEquals("whatWasIt", "odd"); }
Example 19
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testStateFailuresWithRulesUsingClone() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_CLONE); addRule(criteria, "rule", Collections.singletonList( // conditions "${getStateValue('maxValue'):lt(${value})}"), getMap( // actions "maxValue", "${value}")); addRule(criteria, "rule2", Collections.singletonList( // conditions "${getStateValue('maxValue2'):lt(${value})}"), getMap( // actions "maxValue2", "${value}")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); final UpdateAttribute processor = (UpdateAttribute) runner.getProcessor(); final ProcessSessionFactory processSessionFactory = runner.getProcessSessionFactory(); MockStateManager mockStateManager = runner.getStateManager(); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0"); runner.setAnnotationData(serialize(criteria)); processor.onScheduled(runner.getProcessContext()); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); mockStateManager.setFailOnStateGet(Scope.LOCAL, true); processor.onTrigger(runner.getProcessContext(), processSessionFactory.createSession()); runner.assertQueueNotEmpty(); mockStateManager.setFailOnStateGet(Scope.LOCAL, false); mockStateManager.setFailOnStateSet(Scope.LOCAL, true); processor.onTrigger(runner.getProcessContext(), processSessionFactory.createSession()); runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_FAILED_SET_STATE, 1); runner.getFlowFilesForRelationship(UpdateAttribute.REL_FAILED_SET_STATE).get(0).assertAttributeEquals("maxValue", "1"); runner.getFlowFilesForRelationship(UpdateAttribute.REL_FAILED_SET_STATE).get(0).assertAttributeNotExists("maxValue2"); }
Example 20
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testStateFailuresWithRulesUsingOriginal() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_ORIGINAL); addRule(criteria, "rule", Collections.singletonList( // conditions "${getStateValue('maxValue'):lt(${value})}"), getMap( // actions "maxValue", "${value}")); addRule(criteria, "rule2", Collections.singletonList( // conditions "${getStateValue('maxValue2'):lt(${value})}"), getMap( // actions "maxValue2", "${value}")); TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); final UpdateAttribute processor = (UpdateAttribute) runner.getProcessor(); final ProcessSessionFactory processSessionFactory = runner.getProcessSessionFactory(); MockStateManager mockStateManager = runner.getStateManager(); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0"); runner.setAnnotationData(serialize(criteria)); processor.onScheduled(runner.getProcessContext()); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "1"); runner.enqueue(new byte[0], attributes); mockStateManager.setFailOnStateGet(Scope.LOCAL, true); processor.onTrigger(runner.getProcessContext(), processSessionFactory.createSession()); runner.assertQueueNotEmpty(); mockStateManager.setFailOnStateGet(Scope.LOCAL, false); mockStateManager.setFailOnStateSet(Scope.LOCAL, true); processor.onTrigger(runner.getProcessContext(), processSessionFactory.createSession()); runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_FAILED_SET_STATE, 1); runner.getFlowFilesForRelationship(UpdateAttribute.REL_FAILED_SET_STATE).get(0).assertAttributeEquals("maxValue", "1"); runner.getFlowFilesForRelationship(UpdateAttribute.REL_FAILED_SET_STATE).get(0).assertAttributeEquals("maxValue2", "1"); }