本文整理汇总了Java中org.apache.nifi.util.TestRunners.newTestRunner方法的典型用法代码示例。如果您正苦于以下问题:Java TestRunners.newTestRunner方法的具体用法?Java TestRunners.newTestRunner怎么用?Java TestRunners.newTestRunner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.util.TestRunners
的用法示例。
在下文中一共展示了TestRunners.newTestRunner方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: payloadWithBadIntSubstitution
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void payloadWithBadIntSubstitution() {
String payload = "{\"time\": \"{{time:int}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("time", "2015-06-22T13:45:23.000Z");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 1);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 0);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
FlowFile actualFlowFile = runner.getFlowFilesForRelationship(CreateJsonContent.REL_FAILURE).get(0);
assertEquals("$.time", actualFlowFile.getAttribute("json.error.key"));
assertEquals("2015-06-22T13:45:23.000Z", actualFlowFile.getAttribute("json.error.value"));
}
示例2: payloadWithTokenAttributes
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void payloadWithTokenAttributes() {
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"text\": \"{{text}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
props.put("text", "\"here is some {{text}}\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":3.14,\"text\":\"\\\"here is some {{text}}\\\"\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例3: validateFailedPublishAndTransferToFailure
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void validateFailedPublishAndTransferToFailure() throws Exception {
ConnectionFactory cf = mock(ConnectionFactory.class);
PublishJMS pubProc = new PublishJMS();
TestRunner runner = TestRunners.newTestRunner(pubProc);
JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
when(cs.getIdentifier()).thenReturn("cfProvider");
when(cs.getConnectionFactory()).thenReturn(cf);
runner.addControllerService("cfProvider", cs);
runner.enableControllerService(cs);
runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
runner.setProperty(PublishJMS.DESTINATION, "fooQueue");
runner.enqueue("Hello Joe".getBytes());
runner.run();
Thread.sleep(200);
assertTrue(runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).isEmpty());
assertNotNull(runner.getFlowFilesForRelationship(PublishJMS.REL_FAILURE).get(0));
}
示例4: validateFullConfigWithUserLib
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void validateFullConfigWithUserLib() throws Exception {
TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
runner.addControllerService("cfProvider", cfProvider);
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI, "myhost:1234");
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH,
new File("test-lib").getAbsolutePath()); // see README in 'test-lib' dir for more info
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
"org.apache.nifi.jms.testcflib.TestConnectionFactory");
runner.setProperty(cfProvider, "Foo", "foo");
runner.setProperty(cfProvider, "Bar", "3");
runner.enableControllerService(cfProvider);
runner.assertValid(cfProvider);
ConnectionFactory cf = cfProvider.getConnectionFactory();
assertNotNull(cf);
assertEquals("org.apache.nifi.jms.testcflib.TestConnectionFactory", cf.getClass().getName());
assertEquals("myhost", this.get("getHost", cf));
assertEquals(1234, ((Integer) this.get("getPort", cf)).intValue());
assertEquals("foo", this.get("getFoo", cf));
assertEquals(3, ((Integer) this.get("getBar", cf)).intValue());
}
示例5: testMalformedJsonUpdate
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void testMalformedJsonUpdate() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new UpdateMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.UPDATE_QUERY_KEYS, "d.id");
runner.setProperty(MongoProps.UPDATE_KEYS, "d.media");
runner.setProperty(MongoProps.UPDATE_OPERATOR, "$push");
runner.enqueue("bad payload".getBytes());
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 1);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 0);
}
示例6: payloadWithSubstitutions
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void payloadWithSubstitutions() {
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"boolean\": \"{{boolean:bool}}\", \"long\": \"{{long:int}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
props.put("long", "12345678901234");
props.put("boolean", "true");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":3.14,\"boolean\":true,\"long\":12345678901234}";
final MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
assertEquals(expected, new String(out.toByteArray()));
}
示例7: validateOnConfigureFailsIfCNFonConnectionFactory
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test(expected = AssertionError.class)
public void validateOnConfigureFailsIfCNFonConnectionFactory() throws Exception {
TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
runner.addControllerService("cfProvider", cfProvider);
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI, "myhost:1234");
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, "test-lib");
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
"foo.bar.NonExistingConnectionFactory");
runner.enableControllerService(cfProvider);
}
示例8: setup
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Before
public void setup() throws InitializationException {
final DBCPService dbcp = new DBCPServiceSimpleImpl();
runner = TestRunners.newTestRunner(new ExecuteOracleSQL());
runner.addControllerService("dbcp", dbcp, new HashMap<>());
runner.enableControllerService(dbcp);
runner.setProperty(ExecuteOracleSQL.DBCP_SERVICE, "dbcp");
}
示例9: payloadWithUnicode
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void payloadWithUnicode() {
StringBuffer sb = new StringBuffer();
sb.append(Character.toChars(127467));
sb.append(Character.toChars(127479));
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"text\": \"{{text}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
props.put("text", sb.toString());
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":3.14,\"text\":\"" + sb.toString() + "\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例10: validateOnConfigureFailsIfCNFonConnectionFactory
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test(expected = AssertionError.class)
public void validateOnConfigureFailsIfCNFonConnectionFactory() throws Exception {
TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
JNDIConnectionFactoryProvider cfProvider = new JNDIConnectionFactoryProvider();
runner.addControllerService("cfProvider", cfProvider);
runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.BROKER_URI, "myhost:1234");
runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.JNDI_CF_LOOKUP, "ConnectonFactory");
runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, "test-lib");
runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
"foo.bar.NonExistingConnectionFactory");
runner.enableControllerService(cfProvider);
}
示例11: testExpireMultipleFilesSimultaneously
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void testExpireMultipleFilesSimultaneously() throws InterruptedException {
TestRunner runner = TestRunners.newTestRunner(DelayProcessor.class);
runner.setValidateExpressionUsage(false);
runner.setProperty(DelayProcessor.TIME_PERIOD, "1 sec");
runner.enqueue(new byte[0], ImmutableMap.of(CoreAttributes.FILENAME.key(), "file1"));
runner.enqueue(new byte[0], ImmutableMap.of(CoreAttributes.FILENAME.key(), "file2"));
runner.run();
// nothing transferred, 2 files still on queue and cached
runner.assertTransferCount(DelayProcessor.REL_SUCCESS, 0);
assertEquals(2, runner.getQueueSize().getObjectCount());
assertEquals(2, ((DelayProcessor) runner.getProcessor()).delayMap.size());
runner.enqueue(new byte[0], ImmutableMap.of(CoreAttributes.FILENAME.key(), "file3"));
// wait until delay has passed
Thread.sleep(1010);
runner.run();
// 1st 2 files transferred, 3rd still on queue and cached
runner.assertAllFlowFilesTransferred(DelayProcessor.REL_SUCCESS, 2);
assertEquals(1, ((DelayProcessor) runner.getProcessor()).delayMap.size());
runner.clearTransferState();
// wait until delay has passed
Thread.sleep(1010);
runner.run();
// 3rd file now transferred, cache empty
runner.assertAllFlowFilesTransferred(DelayProcessor.REL_SUCCESS, 1);
assertEquals(0, ((DelayProcessor) runner.getProcessor()).delayMap.size());
}
示例12: validating_incomplete_auth_inputs_4
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void validating_incomplete_auth_inputs_4() throws InitializationException {
final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
final StandardMongoClientService service = new StandardMongoClientService();
Map<String, String> props = new HashMap<>();
props.put(StandardMongoClientService.HOSTS.getName(), "localhost:27017");
props.put(StandardMongoClientService.USERNAME.getName(), "mongouser");
props.put(StandardMongoClientService.PASSWORD.getName(), "mongouser");
runner.addControllerService("test_hosts", service, props);
runner.assertNotValid(service);
}
示例13: setUp
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
final DBCPService dbcp = new DBCPServiceSimpleImpl();
final Map<String, String> dbcpProperties = new HashMap<>();
runner = TestRunners.newTestRunner(GenerateOracleTableFetch.class);
runner.addControllerService("dbcp", dbcp, dbcpProperties);
runner.enableControllerService(dbcp);
runner.setProperty(GenerateOracleTableFetch.DBCP_SERVICE, "dbcp");
}
示例14: attributeIsNotEmpty
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void attributeIsNotEmpty() throws IOException {
TestRunner runner = TestRunners.newTestRunner(new InspectZipContents());
byte[] bytes = readBytes("sample.zip");
runner.enqueue(bytes);
runner.run();
MockFlowFile ffOut = runner.getFlowFilesForRelationship(InspectZipContents.REL_SUCCESS).get(0);
String entry = ffOut.getAttribute(InspectZipContents.ATTR);
Assert.assertEquals("test.txt", entry);
}
示例15: testService
import org.apache.nifi.util.TestRunners; //导入方法依赖的package包/类
@Test
public void testService() throws InitializationException {
final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
final StandardMyService service = new StandardMyService();
runner.addControllerService("test-good", service);
runner.setProperty(service, StandardMyService.MY_PROPERTY, "test-value");
runner.enableControllerService(service);
runner.assertValid(service);
}