use of org.apache.nifi.util.MockProcessorInitializationContext in project nifi by apache.
the class TestFetchElasticsearch5 method testCreateElasticsearch5ClientWithException.
@Test(expected = ProcessException.class)
public void testCreateElasticsearch5ClientWithException() throws ProcessException {
FetchElasticsearch5TestProcessor processor = new FetchElasticsearch5TestProcessor(true) {
@Override
protected Client getTransportClient(Settings.Builder settingsBuilder, String xPackPath, String username, String password, List<InetSocketAddress> esHosts, ComponentLog log) throws MalformedURLException {
throw new MalformedURLException();
}
};
MockProcessContext context = new MockProcessContext(processor);
processor.initialize(new MockProcessorInitializationContext(processor, context));
processor.callCreateElasticsearchClient(context);
}
use of org.apache.nifi.util.MockProcessorInitializationContext in project nifi by apache.
the class TestFetchElasticsearch method testCreateElasticsearchClientWithException.
@Test(expected = ProcessException.class)
public void testCreateElasticsearchClientWithException() throws ProcessException {
FetchElasticsearchTestProcessor processor = new FetchElasticsearchTestProcessor(true) {
@Override
protected TransportClient getTransportClient(Settings.Builder settingsBuilder, String shieldUrl, String username, String password) throws MalformedURLException {
throw new MalformedURLException();
}
};
MockProcessContext context = new MockProcessContext(processor);
processor.initialize(new MockProcessorInitializationContext(processor, context));
processor.callCreateElasticsearchClient(context);
}
use of org.apache.nifi.util.MockProcessorInitializationContext in project nifi by apache.
the class TestInvokeJavascript method testScriptDefinedRelationship.
/**
* Tests a scripted processor written in Javascript reads the first line of text from the flowfiles content and
* stores the value in an attribute of the outgoing flowfile.
* Confirms that the scripted processor can return relationships defined in it.
*
* @throws Exception Any error encountered while testing
*/
@Test
public void testScriptDefinedRelationship() throws Exception {
InvokeScriptedProcessor processor = new InvokeScriptedProcessor();
MockProcessContext context = new MockProcessContext(processor);
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
processor.initialize(initContext);
context.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript");
context.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_reader.js");
context.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/javascript");
// State Manger is unused, and a null reference is specified
processor.customValidate(new MockValidationContext(context));
processor.setup(context);
Set<Relationship> relationships = processor.getRelationships();
assertNotNull(relationships);
assertTrue(relationships.size() > 0);
boolean found = false;
for (Relationship relationship : relationships) {
if (relationship.getName().equals("test")) {
found = true;
break;
}
}
assertTrue(found);
}
use of org.apache.nifi.util.MockProcessorInitializationContext in project nifi by apache.
the class TestJmsConsumer method testMap2FlowFileTextMessage.
@Test
public void testMap2FlowFileTextMessage() throws Exception {
TestRunner runner = TestRunners.newTestRunner(GetJMSQueue.class);
TextMessage textMessage = new ActiveMQTextMessage();
String payload = "Hello world!";
textMessage.setText(payload);
ProcessContext context = runner.getProcessContext();
ProcessSession session = runner.getProcessSessionFactory().createSession();
ProcessorInitializationContext pic = new MockProcessorInitializationContext(runner.getProcessor(), (MockProcessContext) runner.getProcessContext());
JmsProcessingSummary summary = JmsConsumer.map2FlowFile(context, session, textMessage, true, pic.getLogger());
assertEquals("TextMessage content length should equal to FlowFile content size", payload.length(), summary.getLastFlowFile().getSize());
final byte[] buffer = new byte[payload.length()];
runner.clearTransferState();
session.read(summary.getLastFlowFile(), new InputStreamCallback() {
@Override
public void process(InputStream in) throws IOException {
StreamUtils.fillBuffer(in, buffer, false);
}
});
String contentString = new String(buffer, "UTF-8");
assertEquals("", payload, contentString);
}
use of org.apache.nifi.util.MockProcessorInitializationContext in project nifi by apache.
the class ExecuteGroovyScriptTest method setup.
@Before
public void setup() throws Exception {
// init processor
proc = new ExecuteGroovyScript();
MockProcessContext context = new MockProcessContext(proc);
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(proc, context);
proc.initialize(initContext);
assertNotNull(proc.getSupportedPropertyDescriptors());
runner = TestRunners.newTestRunner(proc);
runner.addControllerService("dbcp", dbcp, new HashMap<>());
runner.enableControllerService(dbcp);
}
Aggregations