Support Questions

Find answers, ask questions, and share your expertise

How to access custom properties in custom NiFi Controller Service?


I have custom controller service with few properties. Here is sample of one of them:

public static final PropertyDescriptor CONFIG_DELIMITER = new PropertyDescriptor.Builder()
        .name("Field delimiter to be used")
        .description("Field delimiter used to separate the fields in the cache data file...")

I have expressionLanguageSupported set to true for them with the idea of resolving them in onConfigred method of the service.

public void onConfigured(final ConfigurationContext context) throws InitializationException {
    configDelim = context.getProperty(CONFIG_DELIMITER).evaluateAttributeExpressions().getValue();

I have created a custom properties file with following content:


I have setup properties in my test as :

public void testService() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
    final MyService service = new MyService();
    runner.addControllerService("MyService", service);
    runner.setProperty(service, LookupService.CONFIG_DELIMITER , "${nifi.iSOS.MyService.delim}");

I need help with 2 things:

  1. How to pass the custom properties file to the test for MyService?
  2. Is context.getProperty(CONFIG_DELIMITER).evaluateAttributeExpressions().getValue(); correct way to evaluate the value of the custom property in the controller service?

Big thank you for all the help...


1) You can't set a whole properties file during unit testing, but TestRunner has the following method:

void setVariable(String name, String value);

So just call setVariable("nifi.iSOS.MyService.delim", ",");

2) Yes that is correct.


Thanks Bryan, it helped a lot.

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.