当前位置: 首页>>代码示例>>Java>>正文


Java MockFlowFile.assertContentEquals方法代码示例

本文整理汇总了Java中org.apache.nifi.util.MockFlowFile.assertContentEquals方法的典型用法代码示例。如果您正苦于以下问题:Java MockFlowFile.assertContentEquals方法的具体用法?Java MockFlowFile.assertContentEquals怎么用?Java MockFlowFile.assertContentEquals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.nifi.util.MockFlowFile的用法示例。


在下文中一共展示了MockFlowFile.assertContentEquals方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testValidInput

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testValidInput() throws Exception {
    // run once to begin the reporting interval timer
    runner.run();

    // sleep for the remainder of the reporting interval
    Thread.sleep(1000);

    // send 20 files through
    for (int i = 0; i < 20; i++) {
        runner.enqueue(data, attributes);
    }
    runner.run();

    // all 20 originals emitted
    runner.assertTransferCount(AbstractStatsProcessor.REL_ORIGINAL, 20);
    for (MockFlowFile f : runner.getFlowFilesForRelationship(AbstractStatsProcessor.REL_ORIGINAL)) {
        f.assertContentEquals(data);
    }

    // 1 stats report emitted
    runner.assertTransferCount(AbstractStatsProcessor.REL_STATS, 1);
    MockFlowFile flowFile = runner.getFlowFilesForRelationship(AbstractStatsProcessor.REL_STATS).get(0);
    assertEquals(0, flowFile.getSize());
    assertStatAttributesPresent(flowFile);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:27,代码来源:CalculateLatencyStatisticsTest.java

示例2: testInputMissingAttributeName

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testInputMissingAttributeName() throws Exception {
    runner.setProperty(CalculateLatencyStatistics.ATTR_NAME, "DOES_NOT_EXIST");
    runner.assertValid();

    for (int i = 0; i < 20; i++) {
        runner.enqueue(data, attributes);
    }
    runner.run();

    // nothing was aggregated, so no stats emitted
    runner.assertTransferCount(AbstractStatsProcessor.REL_STATS, 0);

    // nothing was aggregated, so originals are emitted without additional stat attributes
    runner.assertTransferCount(AbstractStatsProcessor.REL_ORIGINAL, 20);
    for (MockFlowFile f : runner.getFlowFilesForRelationship(AbstractStatsProcessor.REL_ORIGINAL)) {
        f.assertContentEquals(data);
        assertStatAttributesNotPresent(f);
    }
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:21,代码来源:CalculateLatencyStatisticsTest.java

示例3: testFailure

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testFailure() {
    runner.setProperty(DuplicateByAttribute.ATTRIBUTE_TO_DUPLICATE_BY, "list_of_things");
    runner.setProperty(DuplicateByAttribute.OUTPUT_ATTRIBUTE, "thing");

    final Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("list_of_things", "\"lions,\"tigers\",\"bears\"");

    runner.enqueue("some content".getBytes(), attributes);
    runner.run();

    runner.assertTransferCount(DuplicateByAttribute.REL_SUCCESS, 0);
    runner.assertTransferCount(DuplicateByAttribute.REL_FAILURE, 1);
    runner.assertTransferCount(DuplicateByAttribute.REL_ORIGINAL, 0);

    for (final MockFlowFile flowFile : runner.getFlowFilesForRelationship(DuplicateByAttribute.REL_FAILURE)) {
        flowFile.assertAttributeExists("list_of_things");
        flowFile.assertAttributeEquals("list_of_things", "\"lions,\"tigers\",\"bears\"");
        flowFile.assertAttributeNotExists("thing");
        flowFile.assertContentEquals("some content");
    }
}
 
开发者ID:jfrazee,项目名称:nifi-put-site-to-site-bundle,代码行数:23,代码来源:TestDuplicateByAttribute.java

示例4: validateSuccessfulConsumeAndTransferToSuccess

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void validateSuccessfulConsumeAndTransferToSuccess() throws Exception {
    final String destinationName = "cooQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
    JMSPublisher sender = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    final Map<String, String> senderAttributes = new HashMap<>();
    senderAttributes.put("filename", "message.txt");
    senderAttributes.put("attribute_from_sender", "some value");
    sender.publish(destinationName, "Hey dude!".getBytes(), senderAttributes);
    TestRunner runner = TestRunners.newTestRunner(new ConsumeJMS());
    JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
    when(cs.getIdentifier()).thenReturn("cfProvider");
    when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory());
    runner.addControllerService("cfProvider", cs);
    runner.enableControllerService(cs);

    runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
    runner.setProperty(ConsumeJMS.DESTINATION, destinationName);
    runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE);
    runner.run(1, false);
    //
    final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0);
    assertNotNull(successFF);
    successFF.assertAttributeExists(JmsHeaders.DESTINATION);
    successFF.assertAttributeEquals(JmsHeaders.DESTINATION, destinationName);
    successFF.assertAttributeExists("filename");
    successFF.assertAttributeEquals("filename", "message.txt");
    successFF.assertAttributeExists("attribute_from_sender");
    successFF.assertAttributeEquals("attribute_from_sender", "some value");
    successFF.assertContentEquals("Hey dude!".getBytes());
    String sourceDestination = successFF.getAttribute(ConsumeJMS.JMS_SOURCE_DESTINATION_NAME);
    assertNotNull(sourceDestination);

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:36,代码来源:ConsumeJMSTest.java

示例5: onTrigger

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void onTrigger() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(new ProtobufEncoder());

    HashMap<String, String> adressBookProperties = new HashMap<>();
    adressBookProperties.put("protobuf.schemaPath", ProtobufEncoderTest.class.getResource("/schemas/AddressBook.desc").getPath());
    adressBookProperties.put("protobuf.messageType", "AddressBook");

    // AddressBook test
    for (String filename: validTestFiles) {
        InputStream jsonFile = ProtobufEncoderTest.class.getResourceAsStream("/data/" + filename + ".json");
        adressBookProperties.put("testfile", filename);
        runner.enqueue(jsonFile, adressBookProperties);
    }

    // Ensure the configuration is valid as-is
    runner.assertValid();

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

    // Check if the data was processed without failure
    List<MockFlowFile> results = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS);
    Assert.assertEquals("All flowfiles should be returned to success", validTestFiles.length, results.size());

    // Check if the content of the flowfile is as expected
    for (MockFlowFile result: results) {
        result.assertContentEquals(ProtobufEncoderTest.class.getResourceAsStream("/data/" + result.getAttribute("testfile") + ".data"));
    }

}
 
开发者ID:whiver,项目名称:nifi-protobuf-processor,代码行数:33,代码来源:ProtobufEncoderTest.java

示例6: testValidInput

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testValidInput() throws Exception {
    // run once to begin the reporting interval timer
    runner.run();

    // sleep for the remainder of the reporting interval
    Thread.sleep(1000);

    // send 20 files through
    for (int i = 0; i < 20; i++) {
        runner.enqueue(data);
        runner.run();
    }

    // all 20 originals emitted
    runner.assertTransferCount(AbstractStatsProcessor.REL_ORIGINAL, 20);
    for (MockFlowFile f : runner.getFlowFilesForRelationship(AbstractStatsProcessor.REL_ORIGINAL)) {
        f.assertContentEquals(data);
    }

    // 1 stats report emitted
    runner.assertTransferCount(AbstractStatsProcessor.REL_STATS, 1);
    MockFlowFile flowFile = runner.getFlowFilesForRelationship(AbstractStatsProcessor.REL_STATS).get(0);
    assertEquals(0, flowFile.getSize());
    assertStatAttributesPresent(flowFile);
    assertEquals(1, Integer.parseInt(flowFile.getAttribute("CalculateVolumeStatistics.count")));
    assertEquals(1, Integer.parseInt(flowFile.getAttribute("CalculateVolumeStatistics.min")));
    assertEquals(1, Integer.parseInt(flowFile.getAttribute("CalculateVolumeStatistics.max")));
    assertEquals(1, Integer.parseInt(flowFile.getAttribute("CalculateVolumeStatistics.avg")));
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:31,代码来源:CalculateVolumeStatisticsTest.java

示例7: testRenameFlatDocument

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testRenameFlatDocument() throws IOException {
    final String inputJson = "{" +
                    "\"field1\":123," +
                    "\"field2\":\"abc\"," +
                    "\"field3\":\"xyz\"" +
                    "}";

    final String fieldMappings = "field1=fieldA,field3=fieldB";
    final String expectedJson =
            "{\"fieldA\":123,\"field2\":\"abc\"," +
                    "\"fieldB\":\"xyz\"}";

    testRunner.setProperty(RenameJSONFields.FIELD_MAPPINGS, fieldMappings);

    testRunner.enqueue(inputJson.getBytes("UTF-8"));
    testRunner.run();

    testRunner.assertAllFlowFilesTransferred(RenameJSONFields.REL_SUCCESS, 1);

    List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(
            RenameJSONFields.REL_SUCCESS);
    Assert.assertEquals(1, flowFiles.size());

    MockFlowFile flowFile = flowFiles.get(0);
    flowFile.assertContentEquals(expectedJson);
}
 
开发者ID:bbende,项目名称:nifi-example-bundles,代码行数:28,代码来源:RenameJSONFieldsTest.java

示例8: testRenameComplexDocument

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testRenameComplexDocument() throws IOException {
    final String inputJson = "{" +
            "\"field1\":123," +
            "\"field2\":[" +
                "{\"field11\":11}," +
                "{\"field22\":22}" +
            "]," +
            "\"field3\":\"xyz\"" +
            "}";

    final String fieldMappings = "field11=fieldXX,field3=fieldB";

    final String expectedJson = "{" +
            "\"field1\":123," +
            "\"field2\":[" +
                "{\"fieldXX\":11}," +
                "{\"field22\":22}" +
            "]," +
            "\"fieldB\":\"xyz\"" +
            "}";

    testRunner.setProperty(RenameJSONFields.FIELD_MAPPINGS, fieldMappings);

    testRunner.enqueue(inputJson.getBytes("UTF-8"));
    testRunner.run();

    testRunner.assertAllFlowFilesTransferred(RenameJSONFields.REL_SUCCESS, 1);

    List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(
            RenameJSONFields.REL_SUCCESS);
    Assert.assertEquals(1, flowFiles.size());

    MockFlowFile flowFile = flowFiles.get(0);
    flowFile.assertContentEquals(expectedJson);
}
 
开发者ID:bbende,项目名称:nifi-example-bundles,代码行数:37,代码来源:RenameJSONFieldsTest.java

示例9: testExcludeFirstField

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testExcludeFirstField() throws IOException {
    final String inputJson = "{" +
            "\"field1\":123," +
            "\"field2\":\"abc\"," +
            "\"field3\":\"xyz\"" +
            "}";

    final String fieldMappings = "field1=fieldA,field3=fieldB";
    final String excludeFields = "field1";

    final String expectedJson =
            "{\"field2\":\"abc\",\"fieldB\":\"xyz\"}";

    testRunner.setProperty(RenameJSONFields.FIELD_MAPPINGS, fieldMappings);
    testRunner.setProperty(RenameJSONFields.EXCLUDE_FIELDS, excludeFields);

    testRunner.enqueue(inputJson.getBytes("UTF-8"));
    testRunner.run();

    testRunner.assertAllFlowFilesTransferred(RenameJSONFields.REL_SUCCESS, 1);

    List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(
            RenameJSONFields.REL_SUCCESS);
    Assert.assertEquals(1, flowFiles.size());

    MockFlowFile flowFile = flowFiles.get(0);
    flowFile.assertContentEquals(expectedJson);
}
 
开发者ID:bbende,项目名称:nifi-example-bundles,代码行数:30,代码来源:RenameJSONFieldsTest.java

示例10: testExcludeMultipleFields

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testExcludeMultipleFields() throws IOException {
    final String inputJson = "{" +
            "\"field1\":123," +
            "\"field2\":\"abc\"," +
            "\"field3\":\"xyz\"" +
            "}";

    final String fieldMappings = "field1=fieldA,field3=fieldB";
    final String excludeFields = "field1,field3";

    final String expectedJson =
            "{\"field2\":\"abc\"}";

    testRunner.setProperty(RenameJSONFields.FIELD_MAPPINGS, fieldMappings);
    testRunner.setProperty(RenameJSONFields.EXCLUDE_FIELDS, excludeFields);

    testRunner.enqueue(inputJson.getBytes("UTF-8"));
    testRunner.run();

    testRunner.assertAllFlowFilesTransferred(RenameJSONFields.REL_SUCCESS, 1);

    List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(
            RenameJSONFields.REL_SUCCESS);
    Assert.assertEquals(1, flowFiles.size());

    MockFlowFile flowFile = flowFiles.get(0);
    flowFile.assertContentEquals(expectedJson);
}
 
开发者ID:bbende,项目名称:nifi-example-bundles,代码行数:30,代码来源:RenameJSONFieldsTest.java

示例11: validateSuccessfulConsumeAndTransferToSuccessOverJNDI

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void validateSuccessfulConsumeAndTransferToSuccessOverJNDI() {
    final String destinationName = "cooQueue";
    
    try {
        JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

        JMSPublisher sender = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
        final Map<String, String> senderAttributes = new HashMap<>();
        senderAttributes.put("filename", "message.txt");
        senderAttributes.put("attribute_from_sender", "some value");
        sender.publish(destinationName, "Hey dude!".getBytes(), senderAttributes);
        TestRunner runner = TestRunners.newTestRunner(new ConsumeJMS());
        JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
        when(cs.getIdentifier()).thenReturn("cfProvider");
        when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory());
        runner.addControllerService("cfProvider", cs);
        runner.enableControllerService(cs);

        runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
        runner.setProperty(ConsumeJMS.DESTINATION, destinationName);
        runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE);
        runner.run(1, false);
        //
        final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0);
        assertNotNull(successFF);
        successFF.assertAttributeExists(JmsHeaders.DESTINATION);
        successFF.assertAttributeEquals(JmsHeaders.DESTINATION, destinationName);
        successFF.assertAttributeExists("filename");
        successFF.assertAttributeEquals("filename", "message.txt");
        successFF.assertAttributeExists("attribute_from_sender");
        successFF.assertAttributeEquals("attribute_from_sender", "some value");
        successFF.assertContentEquals("Hey dude!".getBytes());
        String sourceDestination = successFF.getAttribute(ConsumeJMS.JMS_SOURCE_DESTINATION_NAME);
        assertNotNull(sourceDestination);

        ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
    } catch (Exception ex) {
        Logger.getLogger(ConsumeJMSTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:42,代码来源:ConsumeJMSTest.java

示例12: testAttributesToJsonContentJavascript

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
/**
 * Customized transformation of FlowFile attributes into JSON output content
 * @throws Exception
 */
@Test
public void testAttributesToJsonContentJavascript() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
    runner.setValidateExpressionUsage(false);
    runner.setProperty(SCRIPT_ENGINE, "ECMAScript");
    runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/content/attributesToJSON.js");
    runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
    runner.assertValid();

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("customer", "{\n" +
            "        \"name\": \"Some Customer\",\n" +
            "        \"phone\" : \"+1.234.567.8901\",\n" +
            "        \"email\" : \"[email protected]\"\n" +
            "       }");
    attributes.put("product", "{\n" +
            "        \"title\" : \"Avocado Toast\",\n" +
            "        \"price\" : \"10.50\"\n" +
            "       }");
    attributes.put("payment", "{\n" +
            "        \"category\" : \"Credit Card\",\n" +
            "        \"type\" : \"Super Card Titanium\"\n" +
            "       }");
    runner.enqueue("test", attributes);
    runner.run();

    runner.assertAllFlowFilesTransferred("success", 1);
    final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
    MockFlowFile result = successFlowFiles.get(0);
    result.assertContentEquals("{\n" +
            "  \"customer\": {\n" +
            "    \"name\": \"Some Customer\",\n" +
            "    \"phone\": \"+1.234.567.8901\",\n" +
            "    \"email\": \"[email protected]\"\n" +
            "  },\n" +
            "  \"product\": {\n" +
            "    \"title\": \"Avocado Toast\",\n" +
            "    \"price\": \"10.50\"\n" +
            "  },\n" +
            "  \"payment\": {\n" +
            "    \"category\": \"Credit Card\",\n" +
            "    \"type\": \"Super Card Titanium\"\n" +
            "  }\n" +
            "}");
}
 
开发者ID:BatchIQ,项目名称:nifi-scripting-samples,代码行数:50,代码来源:TestContent.java

示例13: onPropertyModified

import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void onPropertyModified() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(new ProtobufEncoder());

    HashMap<String, String> addressBookProperties = new HashMap<>();
    addressBookProperties.put("protobuf.messageType", "AddressBook");


    /*
        First try to decode using a schema set in a processor property
     */

    runner.setProperty("protobuf.schemaPath", ProtobufEncoderTest.class.getResource("/schemas/AddressBook.desc").getPath());
    runner.assertValid();

    runner.enqueue(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.json"), addressBookProperties);

    runner.run(1);

    // Check if the flowfile has been successfully processed
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(ProtobufDecoder.SUCCESS);

    // Finally check the content
    MockFlowFile result = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS).get(0);
    result.assertContentEquals(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.data"));


    /*
        Then try to remove the schema from the processor property and see if it still parse
     */

    runner.clearTransferState();
    runner.removeProperty(runner.getProcessor().getPropertyDescriptor("protobuf.schemaPath"));
    Assert.assertFalse("The schema property should now be null", runner.getProcessContext().getProperty("protobuf.schemaPath").isSet());
    runner.assertValid();

    runner.enqueue(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.json"), addressBookProperties);

    runner.run(1);

    // Check if the flowfile has been successfully processed
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(ProtobufDecoder.INVALID_SCHEMA);


    /*
        Finally add the property again to see if it works again
     */

    runner.clearTransferState();
    runner.setProperty("protobuf.schemaPath", ProtobufEncoderTest.class.getResource("/schemas/AddressBook.desc").getPath());
    runner.assertValid();

    runner.enqueue(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.json"), addressBookProperties);

    runner.run(1);

    // Check if the flowfile has been successfully processed
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(ProtobufDecoder.SUCCESS);

    // Finally check the content
    result = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS).get(0);
    result.assertContentEquals(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.data"));

}
 
开发者ID:whiver,项目名称:nifi-protobuf-processor,代码行数:68,代码来源:ProtobufEncoderTest.java


注:本文中的org.apache.nifi.util.MockFlowFile.assertContentEquals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。