Search in sources :

Example 26 with MockFlowFile

use of org.apache.nifi.util.MockFlowFile in project nifi by apache.

the class TestCompareFuzzyHash method testSsdeepCompareFuzzyHashWithInvalidHashList.

@Test
public void testSsdeepCompareFuzzyHashWithInvalidHashList() {
    // This is different from "BlankHashList series of tests in that the file lacks headers and as such is totally
    // invalid
    double matchingSimilarity = 80;
    runner.setProperty(CompareFuzzyHash.HASH_ALGORITHM, CompareFuzzyHash.allowableValueSSDEEP.getValue());
    runner.setProperty(CompareFuzzyHash.ATTRIBUTE_NAME, "fuzzyhash.value");
    runner.setProperty(CompareFuzzyHash.HASH_LIST_FILE, "src/test/resources/empty.list");
    runner.setProperty(CompareFuzzyHash.MATCH_THRESHOLD, String.valueOf(matchingSimilarity));
    Map<String, String> attributes = new HashMap<>();
    attributes.put("fuzzyhash.value", "6:hERjIfhRrlB63J0FDw1NBQmEH68xwMSELN:hZrlB62IwMS");
    runner.enqueue("bogus".getBytes(), attributes);
    runner.run();
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(CompareFuzzyHash.REL_NOT_FOUND, 1);
    final MockFlowFile outFile = runner.getFlowFilesForRelationship(CompareFuzzyHash.REL_NOT_FOUND).get(0);
    outFile.assertAttributeNotExists("fuzzyhash.value.0.match");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 27 with MockFlowFile

use of org.apache.nifi.util.MockFlowFile in project nifi by apache.

the class TestCompareFuzzyHash method testTLSHCompareFuzzyHashWithInvalidHash.

@Test
public void testTLSHCompareFuzzyHashWithInvalidHash() {
    double matchingSimilarity = 200;
    runner.setProperty(CompareFuzzyHash.HASH_ALGORITHM, CompareFuzzyHash.allowableValueTLSH.getValue());
    runner.setProperty(CompareFuzzyHash.ATTRIBUTE_NAME, "fuzzyhash.value");
    runner.setProperty(CompareFuzzyHash.HASH_LIST_FILE, "src/test/resources/empty.list");
    runner.setProperty(CompareFuzzyHash.MATCH_THRESHOLD, String.valueOf(matchingSimilarity));
    Map<String, String> attributes = new HashMap<>();
    attributes.put("fuzzyhash.value", "Test test test chocolate");
    runner.enqueue("bogus".getBytes(), attributes);
    runner.run();
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(CompareFuzzyHash.REL_FAILURE, 1);
    final MockFlowFile outFile = runner.getFlowFilesForRelationship(CompareFuzzyHash.REL_FAILURE).get(0);
    outFile.assertAttributeNotExists("fuzzyhash.value.0.match");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 28 with MockFlowFile

use of org.apache.nifi.util.MockFlowFile in project nifi by apache.

the class TestCompareFuzzyHash method testSsdeepCompareFuzzyHashMultipleMatches.

@Test
public void testSsdeepCompareFuzzyHashMultipleMatches() {
    double matchingSimilarity = 80;
    runner.setProperty(CompareFuzzyHash.HASH_ALGORITHM, CompareFuzzyHash.allowableValueSSDEEP.getValue());
    runner.setProperty(CompareFuzzyHash.ATTRIBUTE_NAME, "fuzzyhash.value");
    runner.setProperty(CompareFuzzyHash.HASH_LIST_FILE, "src/test/resources/ssdeep.list");
    runner.setProperty(CompareFuzzyHash.MATCH_THRESHOLD, String.valueOf(matchingSimilarity));
    runner.setProperty(CompareFuzzyHash.MATCHING_MODE, CompareFuzzyHash.multiMatch.getValue());
    Map<String, String> attributes = new HashMap<>();
    attributes.put("fuzzyhash.value", ssdeepInput);
    runner.enqueue("bogus".getBytes(), attributes);
    runner.run();
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(CompareFuzzyHash.REL_FOUND, 1);
    final MockFlowFile outFile = runner.getFlowFilesForRelationship(CompareFuzzyHash.REL_FOUND).get(0);
    outFile.assertAttributeEquals("fuzzyhash.value.0.match", "\"nifi/nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/pom.xml\"");
    double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity"));
    Assert.assertTrue(similarity >= matchingSimilarity);
    outFile.assertAttributeEquals("fuzzyhash.value.1.match", "\"nifi/nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml\"");
    similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.1.similarity"));
    Assert.assertTrue(similarity >= matchingSimilarity);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 29 with MockFlowFile

use of org.apache.nifi.util.MockFlowFile in project nifi by apache.

the class TestFuzzyHashContent method testSsdeepFuzzyHashContent.

@Test
public void testSsdeepFuzzyHashContent() {
    runner.setProperty(FuzzyHashContent.HASH_ALGORITHM, FuzzyHashContent.allowableValueSSDEEP.getValue());
    runner.enqueue("This is the a short and meaningless sample taste of 'test test test chocolate' " + "an odd test string that is used within some of the NiFi test units. Once day the author of " + "such strings may decide to tell the history behind this sentence and its true meaning...\n");
    runner.run();
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(FuzzyHashContent.REL_SUCCESS, 1);
    final MockFlowFile outFile = runner.getFlowFilesForRelationship(FuzzyHashContent.REL_SUCCESS).get(0);
    Assert.assertEquals("6:hERjIfhRrlB63J0FDw1NBQmEH68xwMSELN:hZrlB62IwMS", outFile.getAttribute("fuzzyhash.value"));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Example 30 with MockFlowFile

use of org.apache.nifi.util.MockFlowFile in project nifi by apache.

the class ITPutKinesisStream method testIntegrationWithDynamicPartitionSuccess.

@Test
public void testIntegrationWithDynamicPartitionSuccess() throws Exception {
    runner.setProperty(PutKinesisStream.KINESIS_PARTITION_KEY, "${parition}");
    runner.assertValid();
    Map<String, String> properties = new HashMap<>();
    properties.put("partition", "px");
    runner.enqueue("test".getBytes(), properties);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PutKinesisStream.REL_SUCCESS, 1);
    final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(PutKinesisStream.REL_SUCCESS);
    final MockFlowFile out = ffs.iterator().next();
    out.assertContentEquals("test".getBytes());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

MockFlowFile (org.apache.nifi.util.MockFlowFile)1228 Test (org.junit.Test)1198 TestRunner (org.apache.nifi.util.TestRunner)725 HashMap (java.util.HashMap)279 File (java.io.File)155 Matchers.anyString (org.mockito.Matchers.anyString)59 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)48 FlowFile (org.apache.nifi.flowfile.FlowFile)42 ByteArrayInputStream (java.io.ByteArrayInputStream)41 ProcessContext (org.apache.nifi.processor.ProcessContext)37 InputStream (java.io.InputStream)34 Connection (java.sql.Connection)31 GenericRecord (org.apache.avro.generic.GenericRecord)31 Statement (java.sql.Statement)30 Schema (org.apache.avro.Schema)30 ArrayList (java.util.ArrayList)29 Map (java.util.Map)27 SQLException (java.sql.SQLException)25 DBCPService (org.apache.nifi.dbcp.DBCPService)25 GenericDatumWriter (org.apache.avro.generic.GenericDatumWriter)24