本文整理汇总了Java中org.apache.nifi.util.TestRunner.enableControllerService方法的典型用法代码示例。如果您正苦于以下问题:Java TestRunner.enableControllerService方法的具体用法?Java TestRunner.enableControllerService怎么用?Java TestRunner.enableControllerService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.util.TestRunner
的用法示例。
在下文中一共展示了TestRunner.enableControllerService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: single_host_without_credentials
import org.apache.nifi.util.TestRunner; //导入方法依赖的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.TestRunner; //导入方法依赖的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.TestRunner; //导入方法依赖的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.TestRunner; //导入方法依赖的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.TestRunner; //导入方法依赖的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: test_mongoservice_not_enabled
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void test_mongoservice_not_enabled() throws InitializationException {
final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
final StandardMongoClientService service = new StandardMongoClientService();
runner.addControllerService("test-mongo-closed", service);
runner.enableControllerService(service);
// Close MongoClient
MongoClient client = service.getMongoClient();
// NOTE: This test requires mongo to be running
assertEquals("localhost:27017", client.getConnectPoint());
// Close the mongo connection
client.close();
// Now, this should throw an illegal state exception
thrown.expect(IllegalStateException.class);
client.getConnectPoint();
}
示例7: validateSuccessfulPublishAndTransferToSuccess
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void validateSuccessfulPublishAndTransferToSuccess() throws Exception {
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
final String destinationName = "fooQueue";
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, destinationName);
Map<String, String> attributes = new HashMap<>();
attributes.put("foo", "foo");
attributes.put(JmsHeaders.REPLY_TO, "cooQueue");
runner.enqueue("Hey dude!".getBytes(), attributes);
runner.run(1, false);
final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0);
assertNotNull(successFF);
JmsTemplate jmst = new JmsTemplate(cf);
BytesMessage message = (BytesMessage) jmst.receive(destinationName);
byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message);
assertEquals("Hey dude!", new String(messageBytes));
assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName());
assertEquals("foo", message.getStringProperty("foo"));
}
示例8: validateSuccessfulPublishAndTransferToSuccessWithELOverJNDI
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void validateSuccessfulPublishAndTransferToSuccessWithELOverJNDI() throws Exception {
ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) CommonTest.buildJmsJndiConnectionFactory();
final String destinationNameExpression = "${foo}Queue";
final String destinationName = "fooQueue";
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, destinationNameExpression);
Map<String, String> attributes = new HashMap<>();
attributes.put("foo", "foo");
attributes.put(JmsHeaders.REPLY_TO, "cooQueue");
runner.enqueue("Hey dude!".getBytes(), attributes);
runner.run(1, false);
final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0);
assertNotNull(successFF);
JmsTemplate jmst = new JmsTemplate(cf);
BytesMessage message = (BytesMessage) jmst.receive(destinationName);
byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message);
assertEquals("Hey dude!", new String(messageBytes));
assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName());
assertEquals("foo", message.getStringProperty("foo"));
}
示例9: validateFailsIfURICfAndNotSolace
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test(expected = AssertionError.class)
public void validateFailsIfURICfAndNotSolace() 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,
"org.apache.nifi.jms.testcflib.TestConnectionFactory");
runner.enableControllerService(cfProvider);
runner.assertNotValid(cfProvider);
}
示例10: validateOnConfigureFailsIfCNFonConnectionFactory
import org.apache.nifi.util.TestRunner; //导入方法依赖的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);
}
示例11: addMongoService
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
protected void addMongoService(TestRunner runner) throws InitializationException {
HashMap<String, String> props = new HashMap<>();
// Add mongo controller service
runner.addControllerService(MONGO_CONTROLLER_SERVICE, mongo, props);
runner.setProperty(MongoProps.MONGO_SERVICE, MONGO_CONTROLLER_SERVICE);
runner.enableControllerService(mongo);
}
示例12: validateSuccessfulConsumeAndTransferToSuccess
import org.apache.nifi.util.TestRunner; //导入方法依赖的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();
}
示例13: validateOnConfigureFailsIfCNFonConnectionFactory
import org.apache.nifi.util.TestRunner; //导入方法依赖的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);
}
示例14: validateSuccessfulPublishAndTransferToSuccessWithEL
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void validateSuccessfulPublishAndTransferToSuccessWithEL() throws Exception {
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
final String destinationNameExpression = "${foo}Queue";
final String destinationName = "fooQueue";
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, destinationNameExpression);
Map<String, String> attributes = new HashMap<>();
attributes.put("foo", "foo");
attributes.put(JmsHeaders.REPLY_TO, "cooQueue");
runner.enqueue("Hey dude!".getBytes(), attributes);
runner.run(1, false);
final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0);
assertNotNull(successFF);
JmsTemplate jmst = new JmsTemplate(cf);
BytesMessage message = (BytesMessage) jmst.receive(destinationName);
byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message);
assertEquals("Hey dude!", new String(messageBytes));
assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName());
assertEquals("foo", message.getStringProperty("foo"));
}
示例15: validateSuccessfulConsumeAndTransferToSuccessOverJNDI
import org.apache.nifi.util.TestRunner; //导入方法依赖的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);
}
}