本文整理汇总了Java中org.apache.nifi.util.TestRunner.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java TestRunner.setProperty方法的具体用法?Java TestRunner.setProperty怎么用?Java TestRunner.setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.util.TestRunner
的用法示例。
在下文中一共展示了TestRunner.setProperty方法的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: singleAttributeTest
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void singleAttributeTest() {
TestRunner runner = TestRunners.newTestRunner(Md5HashAttributes.class);
runner.setProperty("hash", "${attribute1}");
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
ff = session.putAttribute(ff, "attribute1", "pbs.twimg.com/media/ClvFsHiUgAE4fT6.jpg");
runner.enqueue(ff);
runner.run();
// All results were processed with out failure
runner.assertQueueEmpty();
runner.assertTransferCount(Md5HashAttributes.REL_SUCCESS, 1);
// If you need to read or do additional tests on results you can access the content
List<MockFlowFile> results = runner.getFlowFilesForRelationship(Md5HashAttributes.REL_SUCCESS);
assertTrue("1 match", results.size() == 1);
MockFlowFile result = results.get(0);
result.assertAttributeEquals("hash", "e2c26a2479f497562a615a42ecb1ef7e");
}
示例3: testMixOfSuccessAndFailure
import org.apache.nifi.util.TestRunner; //导入方法依赖的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));
}
示例4: testInvalid
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testInvalid() {
TestRunner runner = TestRunners.newTestRunner(DelayProcessor.class);
runner.setValidateExpressionUsage(false);
runner.setProperty(DelayProcessor.TIME_PERIOD, "10 kb");
runner.assertNotValid();
}
示例5: testDuplicateKeyFailureWithoutBatching
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testDuplicateKeyFailureWithoutBatching() 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, "1");
runner.setProperty(MongoProps.ORDERED, "true");
ObjectId objectId = ObjectId.get();
String success = FileUtils.readFileToString(Paths.get("src/test/resources/payload.json").toFile());
String successTwo = "{\"a\":\"a\"}";
String payloadOne = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"first value\"}";
String payloadTwo = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"second value\"}";
runner.enqueue(payloadOne.getBytes());
runner.enqueue(success.getBytes());
runner.enqueue(payloadTwo.getBytes());
runner.enqueue(successTwo.getBytes()); // add another successful message
runner.run(runner.getQueueSize().getObjectCount()); // run through the entire queue
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 1);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 3);
FlowFile failure = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_FAILURE).get(0);
String errorCode = failure.getAttribute("mongo.errorcode");
assertEquals("11000", errorCode); // duplicate key error code
String errorMessage = failure.getAttribute("mongo.errormessage");
assertTrue(StringUtils.isNotBlank(errorMessage));
}
示例6: testKeepIndexOutsideNamespace
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testKeepIndexOutsideNamespace() throws Exception {
TestRunner runner = TestRunners.newTestRunner(new StoreInMongo());
addMongoService(runner);
MongoCollection<Document> collection = mongo.getMongoClient().getDatabase(MONGO_DATABASE_NAME).getCollection("index_test");
Document index = new Document().append("_id", "hashed");
collection.createIndex(index);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "index_test");
runner.assertValid();
runner.run();
Set<String> indexNames = AbstractMongoProcessor.getIndexNames(collection);
String normalizedIndexName = AbstractMongoProcessor.normalizeIndexName("", index.toJson());
assertTrue(indexNames.contains(normalizedIndexName));
}
示例7: 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();
}
示例8: testService
import org.apache.nifi.util.TestRunner; //导入方法依赖的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);
}
示例9: testUnsetUpdate
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testUnsetUpdate() 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.g");
runner.setProperty(MongoProps.UPDATE_OPERATOR, "$unset");
String contents = FileUtils.readFileToString(Paths.get("src/test/resources/update_payload.json").toFile());
runner.enqueue(contents.getBytes());
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 0);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 1);
// Verify whether the update was made
MongoClient client = mongo.getMongoClient();
MongoDatabase db = client.getDatabase(MONGO_DATABASE_NAME);
if (db != null) {
MongoCollection<Document> collection = db.getCollection("insert_test");
Document query = buildQuery("d.id", (JsonObject) JSON_PROVIDER.parse(contents));
assertEquals(collection.count(query.append("d.g", new Document("$exists", true))), 0);
}
}
示例10: 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"));
}
示例11: insertRefinedPayload
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
protected void insertRefinedPayload() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new StoreInMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
String contents = FileUtils.readFileToString(Paths.get("src/test/resources/payload.json").toFile());
runner.enqueue(contents.getBytes());
runner.run();
}
示例12: 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"));
}
示例13: 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);
}
示例14: multipleAttributeTest
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void multipleAttributeTest() {
TestRunner runner = TestRunners.newTestRunner(Md5HashAttributes.class);
runner.setProperty("hash", "${attribute1}");
runner.setProperty("hash2", "${attribute2}");
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
ff = session.putAttribute(ff, "attribute1", "pbs.twimg.com/media/ClvFsHiUgAE4fT6.jpg");
ff = session.putAttribute(ff, "attribute2", "");
runner.enqueue(ff);
runner.run();
// All results were processed with out failure
runner.assertQueueEmpty();
runner.assertTransferCount(Md5HashAttributes.REL_SUCCESS, 1);
// If you need to read or do additional tests on results you can access the content
List<MockFlowFile> results = runner.getFlowFilesForRelationship(Md5HashAttributes.REL_SUCCESS);
assertTrue("1 match", results.size() == 1);
MockFlowFile result = results.get(0);
result.assertAttributeEquals("hash", "e2c26a2479f497562a615a42ecb1ef7e");
result.assertAttributeEquals("hash2", "d41d8cd98f00b204e9800998ecf8427e");
}
示例15: testTrueHeaderCreation
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testTrueHeaderCreation() {
TestRunner runner = TestRunners.newTestRunner(new GenerateTimeSeriesFlowFile());
runner.setProperty(GenerateTimeSeriesFlowFile.PRINT_HEADER, "true");
runner.setProperty(GenerateTimeSeriesFlowFile.SIMULATOR_CONFIG, getClass().getResource("/configs/unitTestConfig.json").getPath());
runner.setProperty(GenerateTimeSeriesFlowFile.DATA_FORMAT, "CSV");
runner.run();
runner.assertTransferCount(GenerateTimeSeriesFlowFile.SUCCESS, 1);
runner.getFlowFilesForRelationship(GenerateTimeSeriesFlowFile.SUCCESS).get(0).assertContentEquals("name, ts, value" + System.lineSeparator() + "test,2016-01-01T00:00:00.000,17.5");
}