mirror of https://github.com/apache/nifi.git
NIFI-3497 test cases for metadata updates
Adding test cases to support metadata option update.
This commit is contained in:
parent
f52e1f2a06
commit
8eb54a5019
|
@ -16,9 +16,12 @@
|
|||
*/
|
||||
package org.apache.nifi.processors.standard;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.nifi.flowfile.FlowFile;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
|
||||
|
@ -145,4 +148,189 @@ public class TestScanAttribute {
|
|||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_MATCHED, 1);
|
||||
runner.clearTransferState();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleMatchWithMeta() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new ScanAttribute());
|
||||
FlowFile f;
|
||||
|
||||
runner.setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary1_meta");
|
||||
runner.setProperty(ScanAttribute.DICTIONARY_ENTRY_METADATA_DEMARCATOR, ":");
|
||||
|
||||
final Map<String, String> attributes = new HashMap<>();
|
||||
attributes.put("produce_name", "banana");
|
||||
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_MATCHED, 1);
|
||||
f = runner.getFlowFilesForRelationship(ScanAttribute.REL_MATCHED).get(0);
|
||||
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.term");
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.metadata");
|
||||
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.term") ,"banana");
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.metadata"), "yellow fruit");
|
||||
|
||||
runner.clearTransferState();
|
||||
|
||||
attributes.remove("produce_name");
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_UNMATCHED, 1);
|
||||
runner.clearTransferState();
|
||||
|
||||
attributes.put("produce_name", "cherry");
|
||||
runner.setProperty(ScanAttribute.ATTRIBUTE_PATTERN, "pro.*");
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_MATCHED, 1);
|
||||
f = runner.getFlowFilesForRelationship(ScanAttribute.REL_MATCHED).get(0);
|
||||
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.term");
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.metadata");
|
||||
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.term") ,"cherry");
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.metadata"), "red fruit");
|
||||
runner.clearTransferState();
|
||||
|
||||
runner.setProperty(ScanAttribute.ATTRIBUTE_PATTERN, "c.*");
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_UNMATCHED, 1);
|
||||
runner.clearTransferState();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllMatchWithMeta() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new ScanAttribute());
|
||||
FlowFile f;
|
||||
|
||||
runner.setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary1_meta");
|
||||
runner.setProperty(ScanAttribute.MATCHING_CRITERIA, ScanAttribute.MATCH_CRITERIA_ALL);
|
||||
runner.setProperty(ScanAttribute.ATTRIBUTE_PATTERN, "pro.*");
|
||||
runner.setProperty(ScanAttribute.DICTIONARY_ENTRY_METADATA_DEMARCATOR, ":");
|
||||
|
||||
final Map<String, String> attributes = new HashMap<>();
|
||||
attributes.put("produce_name", "banana");
|
||||
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_MATCHED, 1);
|
||||
f = runner.getFlowFilesForRelationship(ScanAttribute.REL_MATCHED).get(0);
|
||||
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.term");
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.metadata");
|
||||
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.term") ,"banana");
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.metadata"), "yellow fruit");
|
||||
|
||||
runner.clearTransferState();
|
||||
|
||||
attributes.remove("produce_name");
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_MATCHED, 1);
|
||||
runner.clearTransferState();
|
||||
|
||||
attributes.put("produce_name", "banana");
|
||||
attributes.put("produce_name_2", "french fries");
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_UNMATCHED, 1);
|
||||
runner.clearTransferState();
|
||||
|
||||
attributes.put("produce_name", "corn");
|
||||
attributes.put("produce_name_2", "banana");
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
|
||||
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_MATCHED, 1);
|
||||
f = runner.getFlowFilesForRelationship(ScanAttribute.REL_MATCHED).get(0);
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.term");
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.metadata");
|
||||
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.term") ,"banana");
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.metadata"), "yellow fruit");
|
||||
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.2.term");
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.2.metadata");
|
||||
|
||||
assertEquals(f.getAttribute("dictionary.hit.2.term") ,"corn");
|
||||
assertEquals(f.getAttribute("dictionary.hit.2.metadata"), "yellow vegetable");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithEmptyEntriesWithMeta() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new ScanAttribute());
|
||||
runner.setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary-with-empty-new-lines_meta");
|
||||
runner.setProperty(ScanAttribute.DICTIONARY_ENTRY_METADATA_DEMARCATOR, ":");
|
||||
|
||||
final Map<String, String> attributes = new HashMap<>();
|
||||
attributes.put("produce_name", "");
|
||||
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_UNMATCHED, 1);
|
||||
runner.clearTransferState();
|
||||
|
||||
runner.setProperty(ScanAttribute.ATTRIBUTE_PATTERN, "pro.*");
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_UNMATCHED, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithDictionaryFilterWithMeta() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new ScanAttribute());
|
||||
FlowFile f;
|
||||
|
||||
runner.setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary-with-extra-info_meta");
|
||||
runner.setProperty(ScanAttribute.DICTIONARY_FILTER, "(.*)<fruit>");
|
||||
runner.setProperty(ScanAttribute.DICTIONARY_ENTRY_METADATA_DEMARCATOR, ":");
|
||||
|
||||
final Map<String, String> attributes = new HashMap<>();
|
||||
attributes.put("produce_name", "banana");
|
||||
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_MATCHED, 1);
|
||||
f = runner.getFlowFilesForRelationship(ScanAttribute.REL_MATCHED).get(0);
|
||||
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.term");
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.metadata");
|
||||
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.term") ,"banana");
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.metadata"), "yellow fruit");
|
||||
runner.clearTransferState();
|
||||
|
||||
attributes.put("produce_name", "tomatoe");
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_UNMATCHED, 1);
|
||||
runner.clearTransferState();
|
||||
|
||||
runner.setProperty(ScanAttribute.DICTIONARY_FILTER, "(.*)<.*>");
|
||||
runner.enqueue(new byte[0], attributes);
|
||||
runner.run();
|
||||
|
||||
runner.assertAllFlowFilesTransferred(ScanAttribute.REL_MATCHED, 1);
|
||||
f = runner.getFlowFilesForRelationship(ScanAttribute.REL_MATCHED).get(0);
|
||||
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.term");
|
||||
runner.assertAllFlowFilesContainAttribute("dictionary.hit.1.metadata");
|
||||
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.term") ,"tomatoe");
|
||||
assertEquals(f.getAttribute("dictionary.hit.1.metadata"), "red vegetable");
|
||||
|
||||
|
||||
runner.clearTransferState();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue