Created 06-23-2017 01:22 AM
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...") .defaultValue(",") .expressionLanguageSupported(true) .required(true) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .build();
I have expressionLanguageSupported set to true for them with the idea of resolving them in onConfigred method of the service.
@OnEnabled public void onConfigured(final ConfigurationContext context) throws InitializationException { configDelim = context.getProperty(CONFIG_DELIMITER).evaluateAttributeExpressions().getValue(); .......... }
I have created a custom properties file custom.properties with following content:
nifi.iSOS.MyService.delim=,
I have setup properties in my test as :
@Test 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:
Big thank you for all the help...
Created 06-23-2017 01:50 PM
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.
Created 06-23-2017 06:16 PM
Thanks Bryan, it helped a lot.