本文整理汇总了Java中org.apache.nifi.util.TestRunners类的典型用法代码示例。如果您正苦于以下问题:Java TestRunners类的具体用法?Java TestRunners怎么用?Java TestRunners使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TestRunners类属于org.apache.nifi.util包,在下文中一共展示了TestRunners类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: single_host_without_credentials
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void single_host_without_credentials() throws InitializationException {
final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
final StandardMongoClientService service = new StandardMongoClientService();
runner.addControllerService("test-good1", service);
runner.setProperty(service, StandardMongoClientService.HOSTS, "localhost:27017");
runner.enableControllerService(service);
runner.assertValid(service);
StandardMongoClientService mongoService = (StandardMongoClientService) runner.getProcessContext().getControllerServiceLookup().getControllerService("test-good1");
assertNotNull(mongoService);
MongoClient mongoClient = mongoService.getMongoClient();
assertNotNull(mongoClient);
assertEquals(0, mongoClient.getDatabase(MONGO_DATABASE_NAME).getCollection("sample").count());
mongoClient.dropDatabase(MONGO_DATABASE_NAME);
}
示例2: 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));
}
示例3: validateFailedPublishAndTransferToFailureOverJNDI
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void validateFailedPublishAndTransferToFailureOverJNDI() 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: validateFullConfigWithUserLib
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void validateFullConfigWithUserLib() throws Exception {
TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
JNDIConnectionFactoryProvider cfProvider = new JNDIConnectionFactoryProvider();
//when(cfProvider.getConnectionFactory()).thenReturn(mcf);
runner.addControllerService("cfProvider", cfProvider);
runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.BROKER_URI, "vm://localhost?broker.persistent=false");
runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.JNDI_CF_LOOKUP, "ConnectionFactory");
runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.CLIENT_LIB_DIR_PATH,
TestUtils.setupActiveMqLibForTesting(false)); // see README in 'test-lib' dir for more info
runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
runner.enableControllerService(cfProvider);
runner.assertValid(cfProvider);
ConnectionFactory cf = cfProvider.getConnectionFactory();
assertNotNull(cf);
assertEquals("org.apache.activemq.ActiveMQConnectionFactory", cf.getClass().getName());
}
示例6: 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);
}
示例7: validateFactoryCreationWithActiveMQLibraries
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
/**
* This test simply validates that {@link ConnectionFactory} can be setup by
* pointing to the location of the client libraries at runtime. It uses
* ActiveMQ which is not present at the POM but instead pulled from Maven
* repo using {@link TestUtils#setupActiveMqLibForTesting(boolean)}, which
* implies that for this test to run the computer must be connected to the
* Internet. If computer is not connected to the Internet, this test will
* quietly fail logging a message.
*/
@Test
public void validateFactoryCreationWithActiveMQLibraries() throws Exception {
try {
String libPath = TestUtils.setupActiveMqLibForTesting(true);
TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
runner.addControllerService("cfProvider", cfProvider);
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI,
"vm://localhost?broker.persistent=false");
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, libPath);
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
"org.apache.activemq.ActiveMQConnectionFactory");
runner.enableControllerService(cfProvider);
runner.assertValid(cfProvider);
Connection connection = cfProvider.getConnectionFactory().createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination queue = session.createQueue("myqueue");
MessageProducer producer = session.createProducer(queue);
MessageConsumer consumer = session.createConsumer(queue);
TextMessage message = session.createTextMessage("Hello");
producer.send(message);
assertEquals("Hello", ((TextMessage) consumer.receive()).getText());
connection.stop();
connection.close();
} catch (Exception e) {
logger.error("'validateFactoryCreationWithActiveMQLibraries' failed due to ", e);
}
}
示例8: testMixOfSuccessAndFailure
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void testMixOfSuccessAndFailure() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new StoreInMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.BATCH_SIZE, "50");
String successOne = FileUtils.readFileToString(Paths.get("src/test/resources/payload.json").toFile());
runner.enqueue(successOne.getBytes());
runner.enqueue("bad payload".getBytes());
runner.enqueue("{\"a\":\"a\"}".getBytes());
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 1);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 2);
FlowFile failure = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_FAILURE).get(0);
String parseException = failure.getAttribute("mongo.exception");
assertTrue(StringUtils.isNotBlank(parseException));
}
示例9: payloadWithoutSubstitutions
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void payloadWithoutSubstitutions() {
String payload = "{\"a\": \"a\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
runner.enqueue(payload.getBytes());
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
final MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
assertEquals(payload, new String(out.toByteArray()));
}
示例10: payloadWithSubstitutions
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void payloadWithSubstitutions() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"boolean\": {{boolean}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.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("boolean", "true");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"boolean\": true}";
final MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
assertEquals(expected, new String(out.toByteArray()));
}
示例11: payloadWithMissingAttributes
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void payloadWithMissingAttributes() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"boolean\": {{boolean}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.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");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"boolean\": null}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例12: testNoResults
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void testNoResults() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new QueryMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.QUERY, "{\"criteria\": \"${test_attribute}\"}");
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
ff = session.putAttribute(ff, "test_attribute", "98765");
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 0);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 0);
}
示例13: payloadWithDoubleQuotes
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void payloadWithDoubleQuotes() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"text\": {{text}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.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(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": \"here is some \"text\"\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例14: payloadWithSpacesWithinDelimiters
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void payloadWithSpacesWithinDelimiters() {
String payload = "{\"a\": {{ from}}, \"pi\": {{pi }}, \"text\": {{ text }}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.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(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": \"here is some text\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例15: payloadWithSpanishCharacters
import org.apache.nifi.util.TestRunners; //导入依赖的package包/类
@Test
public void payloadWithSpanishCharacters() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"text\": {{text}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.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", "\"Mañana se me va un amigo capas el mejor que tuve y que voy a tener, te re quiero turrasdf Pasa que cada cosa que pienso/hago quiero contarle a mi él. Quiero gelatina y la bastarda no se hace mas -.-\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": \"Mañana se me va un amigo capas el mejor que tuve y que voy a tener, te re quiero turrasdf Pasa que cada cosa que pienso/hago quiero contarle a mi él. Quiero gelatina y la bastarda no se hace mas -.-\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}