Java Code Examples for org.apache.nifi.util.MockFlowFile#putAttributes()

The following examples show how to use org.apache.nifi.util.MockFlowFile#putAttributes() . 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: TestDBCPConnectionPoolLookup.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlowFileFiltering() {
    final FlowFileFilter filter = dbcpLookupService.getFlowFileFilter();
    assertNotNull(filter);

    final MockFlowFile ff0 = new MockFlowFile(0);
    final MockFlowFile ff1 = new MockFlowFile(1);
    final MockFlowFile ff2 = new MockFlowFile(2);
    final MockFlowFile ff3 = new MockFlowFile(3);
    final MockFlowFile ff4 = new MockFlowFile(4);

    ff0.putAttributes(Collections.singletonMap(DBCPConnectionPoolLookup.DATABASE_NAME_ATTRIBUTE, "db-A"));
    ff1.putAttributes(Collections.singletonMap(DBCPConnectionPoolLookup.DATABASE_NAME_ATTRIBUTE, "db-B"));
    ff2.putAttributes(Collections.singletonMap(DBCPConnectionPoolLookup.DATABASE_NAME_ATTRIBUTE, "db-A"));
    ff3.putAttributes(Collections.singletonMap(DBCPConnectionPoolLookup.DATABASE_NAME_ATTRIBUTE, "db-B"));
    ff4.putAttributes(Collections.singletonMap(DBCPConnectionPoolLookup.DATABASE_NAME_ATTRIBUTE, "db-A"));

    assertEquals(FlowFileFilter.FlowFileFilterResult.ACCEPT_AND_CONTINUE, filter.filter(ff0));
    assertEquals(FlowFileFilter.FlowFileFilterResult.REJECT_AND_CONTINUE, filter.filter(ff1));
    assertEquals(FlowFileFilter.FlowFileFilterResult.ACCEPT_AND_CONTINUE, filter.filter(ff2));
    assertEquals(FlowFileFilter.FlowFileFilterResult.REJECT_AND_CONTINUE, filter.filter(ff3));
    assertEquals(FlowFileFilter.FlowFileFilterResult.ACCEPT_AND_CONTINUE, filter.filter(ff4));
}
 
Example 2
Source File: ExtractTextProcessorTest.java    From nifi-extracttext-processor with Apache License 2.0 6 votes vote down vote up
@Test
public void when_running_processor_mime_type_should_be_discovered_for_pdf_input() {
	
	try {
		final String filename = "simple.pdf";
		MockFlowFile flowFile = testRunner.enqueue(new FileInputStream(new File("src/test/resources/" + filename)));
		Map<String, String> attrs = new HashMap<String, String>() {{ put("filename", filename); }};
		flowFile.putAttributes(attrs);
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}

	testRunner.assertValid();
	testRunner.run();
	
	testRunner.assertAllFlowFilesTransferred(ExtractTextProcessor.REL_SUCCESS);
	List<MockFlowFile> successFiles = testRunner.getFlowFilesForRelationship(ExtractTextProcessor.REL_SUCCESS);
	for (MockFlowFile mockFile : successFiles) {
		mockFile.assertAttributeExists("mime.type");
		mockFile.assertAttributeEquals("mime.type", "text/plain");
		mockFile.assertAttributeExists("orig.mime.type");
		mockFile.assertAttributeEquals("orig.mime.type", "application/pdf");
	}
}
 
Example 3
Source File: PutAzureEventHubTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllAttributesAreLiftedToProperties() {
    MockedEventhubClientMockPutAzureEventHub processor = new PutAzureEventHubTest.MockedEventhubClientMockPutAzureEventHub();
    MockitoAnnotations.initMocks(processor);

    EventHubClient eventHubClient = processor.getEventHubClient();
    when(eventHubClient.send(any(EventData.class)))
    .thenReturn(CompletableFuture.completedFuture(null));

    testRunner = TestRunners.newTestRunner(processor);
    setUpStandardTestConfig();

    MockFlowFile flowFile = new MockFlowFile(1234);
    ImmutableMap<String, String> demoAttributes = ImmutableMap.of("A", "a", "B", "b", "D", "d", "C", "c");
    flowFile.putAttributes(demoAttributes);

    testRunner.enqueue(flowFile);
    testRunner.run(1, true);
    ArgumentCaptor<EventData> eventDataCaptor = ArgumentCaptor.forClass(EventData.class);

    Mockito.verify(eventHubClient).send(eventDataCaptor.capture());

    EventData event = eventDataCaptor.getValue();
    assertTrue(event.getProperties().entrySet().containsAll(demoAttributes.entrySet()));
}
 
Example 4
Source File: ExtractTextProcessorTest.java    From nifi-extracttext-processor with Apache License 2.0 6 votes vote down vote up
@Test
public void when_running_processor_mime_type_should_be_discovered_for_doc_input() {
	
	try {
		final String filename = "simple.doc";
		MockFlowFile flowFile = testRunner.enqueue(new FileInputStream(new File("src/test/resources/" + filename)));
		Map<String, String> attrs = new HashMap<String, String>() {{ put("filename", filename); }};
		flowFile.putAttributes(attrs);
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}

	testRunner.assertValid();
	testRunner.run();
	
	testRunner.assertAllFlowFilesTransferred(ExtractTextProcessor.REL_SUCCESS);
	List<MockFlowFile> successFiles = testRunner.getFlowFilesForRelationship(ExtractTextProcessor.REL_SUCCESS);
	for (MockFlowFile mockFile : successFiles) {
		mockFile.assertAttributeExists("mime.type");
		mockFile.assertAttributeEquals("mime.type", "text/plain");
		mockFile.assertAttributeExists("orig.mime.type");
		mockFile.assertAttributeEquals("orig.mime.type", "application/msword");
	}
}
 
Example 5
Source File: PutAzureEventHubTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testMessageIsSentWithPartitioningKeyIfSpecifiedAndPopulated() {
    MockedEventhubClientMockPutAzureEventHub processor = new PutAzureEventHubTest.MockedEventhubClientMockPutAzureEventHub();
    MockitoAnnotations.initMocks(processor);

    EventHubClient eventHubClient = processor.getEventHubClient();
    when(eventHubClient.send(any(EventData.class), anyString()))
    .thenReturn(CompletableFuture.completedFuture(null));

    when(eventHubClient.send(any(EventData.class)))
    .thenThrow(new RuntimeException("Partition-key-less method called despite key is defined and required."));

    testRunner = TestRunners.newTestRunner(processor);
    setUpStandardTestConfig();
    testRunner.setProperty(PutAzureEventHub.PARTITIONING_KEY_ATTRIBUTE_NAME, TEST_PARTITIONING_KEY_ATTRIBUTE_NAME);

    MockFlowFile flowFile = new MockFlowFile(1234);
    flowFile.putAttributes(ImmutableMap.of(TEST_PARTITIONING_KEY_ATTRIBUTE_NAME, TEST_PARTITIONING_KEY));
    testRunner.enqueue(flowFile);
    testRunner.run(1, true);

    Mockito.verify(eventHubClient).send(any(EventData.class), eq(TEST_PARTITIONING_KEY));
}
 
Example 6
Source File: TestPutRiemann.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test(expected = AssertionError.class)
public void testFailedDeref() {
  TestRunner runner = getTestRunner(true);
  MockFlowFile flowFile = new MockFlowFile(1);
  Map<String, String> attributes = new HashMap<>();
  attributes.put("riemann.metric", "5");
  flowFile.putAttributes(attributes);
  runner.enqueue(flowFile);
  try {
    runner.run();
  } catch (ProcessException e) {
    runner.assertQueueNotEmpty();
    throw e;
  }
}
 
Example 7
Source File: TestPutRiemann.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testBatchedEvents() {
  // (2 batches) + (1 remaining event)
  int iterations = Integer.parseInt(PutRiemann.BATCH_SIZE.getDefaultValue()) * 2 + 1;
  TestRunner runner = getTestRunner();

  for (int i = 0; i < iterations; i++) {
    Map<String, String> attributes = new HashMap<>();
    attributes.put("riemann.metric", Float.toString(i));
    attributes.put("riemann.host", "batch-host");
    attributes.put("custom.attribute.1", "attr1");
    attributes.put("custom.attribute.2", "attr2");
    attributes.put("custom.attribute.3", "attr3");
    MockFlowFile flowFile = new MockFlowFile(i);
    flowFile.putAttributes(attributes);
    runner.enqueue(flowFile);
  }
  runner.run(3);
  runner.assertAllFlowFilesTransferred(PutRiemann.REL_SUCCESS);

  for (int i = 0; i < iterations; i++) {
    Proto.Event event = eventStream.remove();
    assertEquals("nifi-test-service", event.getService());
    assertTrue(5.0 == event.getTtl());
    assertTrue(i == event.getMetricF());
    assertEquals("batch-host", event.getHost());
    assertEquals("test", event.getDescription());
    assertEquals(3, event.getTagsCount());
    assertEquals(3, event.getAttributesCount());
    assertTrue(event.getTagsList().contains("tag1"));
    assertTrue(event.getTagsList().contains("tag2"));
    assertTrue(event.getTagsList().contains("tag3"));
  }
}
 
Example 8
Source File: TestVisibilityUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnlyColumnFamilyOnFlowfile() {
    runner.setProperty("visibility.test", "U&PII");

    MockFlowFile ff = new MockFlowFile(System.currentTimeMillis());
    ff.putAttributes(new HashMap<String, String>(){{
        put("visibility.test", "U&PII&PHI");
    }});
    ProcessContext context = runner.getProcessContext();

    String label = VisibilityUtil.pickVisibilityString("test", "test", ff, context);

    Assert.assertNotNull(label);
    Assert.assertEquals("U&PII&PHI", label);
}
 
Example 9
Source File: TestVisibilityUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllPresentOnFlowfile() {
    runner.setProperty("visibility.test.test", "U&PII");

    MockFlowFile ff = new MockFlowFile(System.currentTimeMillis());
    ff.putAttributes(new HashMap<String, String>(){{
        put("visibility.test.test", "U&PII&PHI");
    }});
    ProcessContext context = runner.getProcessContext();

    String label = VisibilityUtil.pickVisibilityString("test", "test", ff, context);

    Assert.assertNotNull(label);
    Assert.assertEquals("U&PII&PHI", label);
}
 
Example 10
Source File: TestVisibilityUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testColumnFamilyAttributeOnly() {
    MockFlowFile ff = new MockFlowFile(System.currentTimeMillis());
    ff.putAttributes(new HashMap<String, String>(){{
        put("visibility.test", "U&PII");
    }});
    ProcessContext context = runner.getProcessContext();

    String label = VisibilityUtil.pickVisibilityString("test", "test", ff, context);

    Assert.assertNotNull(label);
    Assert.assertEquals("U&PII", label);
}
 
Example 11
Source File: PutAzureEventHubTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testMessageIsSentWithoutPartitioningKeyIfNotSpecifiedOrNotPopulated() {
    MockedEventhubClientMockPutAzureEventHub processor = new PutAzureEventHubTest.MockedEventhubClientMockPutAzureEventHub();
    MockitoAnnotations.initMocks(processor);

    EventHubClient eventHubClient = processor.getEventHubClient();
    when(eventHubClient.send(any(EventData.class), anyString()))
    .thenThrow(new RuntimeException("Partition-key-full method called despite key is Not required or not populated."));

    when(eventHubClient.send(any(EventData.class)))
    .thenReturn(CompletableFuture.completedFuture(null));

    testRunner = TestRunners.newTestRunner(processor);
    setUpStandardTestConfig();

    MockFlowFile flowFile = new MockFlowFile(1234);
    flowFile.putAttributes(ImmutableMap.of(TEST_PARTITIONING_KEY_ATTRIBUTE_NAME, TEST_PARTITIONING_KEY));

    // Key not specified
    testRunner.enqueue(flowFile);
    testRunner.run(1, true);

    Mockito.verify(eventHubClient, never()).send(any(EventData.class), eq(TEST_PARTITIONING_KEY));
    Mockito.verify(eventHubClient).send(any(EventData.class));

    // Key wanted but not available
    testRunner.setProperty(PutAzureEventHub.PARTITIONING_KEY_ATTRIBUTE_NAME, "Non-existing-attribute");

    testRunner.enqueue(flowFile);
    testRunner.run(1, true);

    Mockito.verify(eventHubClient, never()).send(any(EventData.class), eq(TEST_PARTITIONING_KEY));
    Mockito.verify(eventHubClient, times(2)).send(any(EventData.class));
}
 
Example 12
Source File: TestVisibilityUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidAttributes() {
    runner.setProperty("visibility.test", "U&PII");

    MockFlowFile ff = new MockFlowFile(System.currentTimeMillis());
    ff.putAttributes(new HashMap<String, String>(){{
        put("visibility..test", "U&PII&PHI");
    }});
    ProcessContext context = runner.getProcessContext();

    String label = VisibilityUtil.pickVisibilityString("test", "test", ff, context);

    Assert.assertNotNull(label);
    Assert.assertEquals("U&PII", label);
}
 
Example 13
Source File: ExtractTextProcessorTest.java    From nifi-extracttext-processor with Apache License 2.0 5 votes vote down vote up
@Test
	public void when_running_processor_mime_type_should_be_discovered_for_pdf_input_html() {
		
		try {
			final String filename = "simple.pdf";
			MockFlowFile flowFile = testRunner.enqueue(new FileInputStream(new File("src/test/resources/" + filename)));
			Map<String, String> attrs = new HashMap<String, String>() {{ put("filename", filename);  }};

			testRunner.setProperty(ExtractTextProcessor.FIELD_HTML_OUTPUT, ExtractTextProcessor.HTML_FORMAT);

			flowFile.putAttributes(attrs);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		testRunner.assertValid();
		testRunner.run();
		
		testRunner.assertAllFlowFilesTransferred(ExtractTextProcessor.REL_SUCCESS);
		List<MockFlowFile> successFiles = testRunner.getFlowFilesForRelationship(ExtractTextProcessor.REL_SUCCESS);
		for (MockFlowFile mockFile : successFiles) {
			
//			 for ( String attribute : mockFile.getAttributes().keySet() ) {
//				 System.out.println("Attribute:" + attribute + "=" + mockFile.getAttribute(attribute));
//			 }
			 			
			mockFile.assertAttributeExists("mime.type");
			mockFile.assertAttributeEquals("mime.type", "text/html");
			mockFile.assertAttributeExists("orig.mime.type");
			mockFile.assertAttributeEquals("orig.mime.type", "application/pdf");
		}
	}
 
Example 14
Source File: TestPutRiemann.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test(expected = AssertionError.class)
public void testFailedDeref() {
  TestRunner runner = getTestRunner(true);
  MockFlowFile flowFile = new MockFlowFile(1);
  Map<String, String> attributes = new HashMap<>();
  attributes.put("riemann.metric", "5");
  flowFile.putAttributes(attributes);
  runner.enqueue(flowFile);
  try {
    runner.run();
  } catch (ProcessException e) {
    runner.assertQueueNotEmpty();
    throw e;
  }
}
 
Example 15
Source File: TestPutRiemann.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidEvents() {
  TestRunner runner = getTestRunner();
  MockFlowFile flowFile = new MockFlowFile(1);
  Map<String, String> attributes = new HashMap<>();
  attributes.put("riemann.metric", "NOT A NUMBER");
  flowFile.putAttributes(attributes);
  runner.enqueue(flowFile);
  runner.run();
  runner.assertAllFlowFilesTransferred(PutRiemann.REL_FAILURE);
}
 
Example 16
Source File: TestPutRiemann.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testBatchedEvents() {
  // (2 batches) + (1 remaining event)
  int iterations = Integer.parseInt(PutRiemann.BATCH_SIZE.getDefaultValue()) * 2 + 1;
  TestRunner runner = getTestRunner();

  for (int i = 0; i < iterations; i++) {
    Map<String, String> attributes = new HashMap<>();
    attributes.put("riemann.metric", Float.toString(i));
    attributes.put("riemann.host", "batch-host");
    attributes.put("custom.attribute.1", "attr1");
    attributes.put("custom.attribute.2", "attr2");
    attributes.put("custom.attribute.3", "attr3");
    MockFlowFile flowFile = new MockFlowFile(i);
    flowFile.putAttributes(attributes);
    runner.enqueue(flowFile);
  }
  runner.run(3);
  runner.assertAllFlowFilesTransferred(PutRiemann.REL_SUCCESS);

  for (int i = 0; i < iterations; i++) {
    Proto.Event event = eventStream.remove();
    assertEquals("nifi-test-service", event.getService());
    assertTrue(5.0 == event.getTtl());
    assertTrue(i == event.getMetricF());
    assertEquals("batch-host", event.getHost());
    assertEquals("test", event.getDescription());
    assertEquals(3, event.getTagsCount());
    assertEquals(3, event.getAttributesCount());
    assertTrue(event.getTagsList().contains("tag1"));
    assertTrue(event.getTagsList().contains("tag2"));
    assertTrue(event.getTagsList().contains("tag3"));
  }
}
 
Example 17
Source File: TestParseUserAgent.java    From yauaa with Apache License 2.0 4 votes vote down vote up
@Test
public void testParserPartial() {
    // Content to be mock a json file
    String content = "CONTENT:>>" + TEST_USER_AGENT + "<<";

    // Add properties
    runner.setProperty(PROPERTY_PREFIX + "DeviceClass",                      "true");
    runner.setProperty(PROPERTY_PREFIX + "OperatingSystemName",              "true");
    runner.setProperty(PROPERTY_PREFIX + "OperatingSystemVersion",           "true");
    runner.setProperty(PROPERTY_PREFIX + "AgentClass",                       "true");
    runner.setProperty(PROPERTY_PREFIX + "AgentName",                        "true");
    runner.setProperty(PROPERTY_PREFIX + "AgentNameVersionMajor",            "true");

    // Add the content to the runner (just because we 'should' have some content).
    MockFlowFile flowfile = runner.enqueue(content);
    Map<String, String> attributes = new HashMap<>();
    attributes.put(ParseUserAgent.USERAGENTSTRING_ATTRIBUTENAME, TEST_USER_AGENT);
    flowfile.putAttributes(attributes);

    // Run the enqueued content, it also takes an int = number of contents queued
    runner.run(1);

    // All results were processed with out failure
    runner.assertQueueEmpty();

    // If you need to read or do additional tests on results you can access the content
    List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseUserAgent.SUCCESS);
    assertEquals(1, results.size(), "Must be 1 match");
    MockFlowFile result = results.get(0);
    result.assertAttributeEquals(ATTRIBUTE_PREFIX + "DeviceClass",            "Desktop"      );
    result.assertAttributeEquals(ATTRIBUTE_PREFIX + "OperatingSystemName",    "Linux"        );
    result.assertAttributeEquals(ATTRIBUTE_PREFIX + "OperatingSystemVersion", "Intel x86_64" );
    result.assertAttributeEquals(ATTRIBUTE_PREFIX + "AgentClass",             "Browser"      );
    result.assertAttributeEquals(ATTRIBUTE_PREFIX + "AgentName",              "Chrome"       );
    result.assertAttributeEquals(ATTRIBUTE_PREFIX + "AgentNameVersionMajor",  "Chrome 48"    );

    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "DeviceName"                      );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "OperatingSystemClass"            );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "LayoutEngineClass"               );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "LayoutEngineName"                );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "LayoutEngineVersion"             );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "AgentVersion"                    );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "AgentVersionMajor"               );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "AgentNameVersion"                );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "AgentBuild"                      );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "AgentInformationEmail"           );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "AgentInformationUrl"             );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "AgentLanguage"                   );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "AgentSecurity"                   );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "AgentUuid"                       );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "Anonymized"                      );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "DeviceBrand"                     );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "DeviceCpu"                       );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "DeviceFirmwareVersion"           );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "DeviceVersion"                   );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "FacebookCarrier"                 );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "FacebookDeviceClass"             );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "FacebookDeviceName"              );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "FacebookDeviceVersion"           );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "FacebookFBOP"                    );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "FacebookFBSS"                    );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "FacebookOperatingSystemName"     );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "FacebookOperatingSystemVersion"  );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "HackerAttackVector"              );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "HackerToolkit"                   );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "KoboAffiliate"                   );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "KoboPlatformId"                  );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "LayoutEngineBuild"               );
    result.assertAttributeNotExists(ATTRIBUTE_PREFIX + "OperatingSystemVersionBuild"     );

    // Test attributes and content
    result.assertContentEquals(content);
}
 
Example 18
Source File: TestSiteToSiteStatusReportingTask.java    From nifi with Apache License 2.0 4 votes vote down vote up
public static FlowFile createFlowFile(final long id, final Map<String, String> attributes) {
    MockFlowFile mockFlowFile = new MockFlowFile(id);
    mockFlowFile.putAttributes(attributes);
    return mockFlowFile;
}
 
Example 19
Source File: PriorityAttributePrioritizerTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testPrioritizer() throws InstantiationException, IllegalAccessException {
    final Processor processor = new SimpleProcessor();
    final AtomicLong idGenerator = new AtomicLong(0L);
    final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, idGenerator), Mockito.mock(Processor.class));

    final MockFlowFile ffNoPriority = session.create();
    final MockFlowFile ffPri1 = session.create();
    ffPri1.putAttributes(attrsPri1);
    final MockFlowFile ffPri2 = session.create();
    ffPri2.putAttributes(attrsPri2);
    final MockFlowFile ffPrin1 = session.create();
    ffPrin1.putAttributes(attrsPrin1);
    final MockFlowFile ffPriA = session.create();
    ffPriA.putAttributes(attrsPriA);
    final MockFlowFile ffPriB = session.create();
    ffPriB.putAttributes(attrsPriB);
    final MockFlowFile ffPriLP = session.create();
    ffPriLP.putAttributes(attrsPriLP);
    final MockFlowFile ffPriLN = session.create();
    ffPriLN.putAttributes(attrsPriLN);

    final PriorityAttributePrioritizer prioritizer = new PriorityAttributePrioritizer();
    assertEquals(0, prioritizer.compare(null, null));
    assertEquals(-1, prioritizer.compare(ffNoPriority, null));
    assertEquals(1, prioritizer.compare(null, ffNoPriority));

    assertEquals(0, prioritizer.compare(ffNoPriority, ffNoPriority));
    assertEquals(-1, prioritizer.compare(ffPri1, ffNoPriority));
    assertEquals(1, prioritizer.compare(ffNoPriority, ffPri1));

    assertEquals(0, prioritizer.compare(ffPri1, ffPri1));
    assertEquals(-1, prioritizer.compare(ffPri1, ffPri2));
    assertEquals(1, prioritizer.compare(ffPri2, ffPri1));
    assertEquals(-1, prioritizer.compare(ffPrin1, ffPri1));
    assertEquals(1, prioritizer.compare(ffPri1, ffPrin1));

    assertEquals(-1, prioritizer.compare(ffPri1, ffPriA));
    assertEquals(1, prioritizer.compare(ffPriA, ffPri1));

    assertEquals(0, prioritizer.compare(ffPriA, ffPriA));
    assertEquals(-1, prioritizer.compare(ffPriA, ffPriB));
    assertEquals(1, prioritizer.compare(ffPriB, ffPriA));

    assertEquals(1, prioritizer.compare(ffPriLP, ffPri1));
    assertEquals(-1, prioritizer.compare(ffPri1, ffPriLP));
    assertEquals(-1, prioritizer.compare(ffPriLN, ffPri1));
    assertEquals(1, prioritizer.compare(ffPri1, ffPriLN));
}
 
Example 20
Source File: TestSiteToSiteProvenanceReportingTask.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public static FlowFile createFlowFile(final long id, final Map<String, String> attributes) {
    MockFlowFile mockFlowFile = new MockFlowFile(id);
    mockFlowFile.putAttributes(attributes);
    return mockFlowFile;
}