@Test public void testClientLibResourcesLoaded() throws InitializationException, URISyntaxException { TestRunner runner = TestRunners.newTestRunner(mock(Processor.class)); runner.setValidateExpressionUsage(true); JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider(); String clientLib = this.getClass().getResource("/dummy-lib.jar").toURI().toString() + "," + this.getClass().getResource("/dummy-lib-2.jar").toURI().toString() + "," + this.getClass().getResource("/dummy.conf").toURI().toString() + ","; runner.addControllerService("cfProvider", cfProvider); runner.setVariable("broker.uri", "tcp: runner.setVariable("client.lib", clientLib); runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI, "${broker.uri}"); runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, "${client.lib}"); runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL, "org.apache.nifi.jms.testcflib.TestConnectionFactory"); runner.assertValid(cfProvider); ClassLoader loader = runner.getClass().getClassLoader(); Assert.assertTrue(loader.getResource("dummy.conf") != null); Assert.assertTrue(loader.getResource("dummy-lib.jar") != null); Assert.assertTrue(loader.getResource("dummy-lib-2.jar") != null); }
private void setProperty(String propertyName, Object propertyValue) { String methodName = this.toMethodName(propertyName); Method[] methods = Utils.findMethods(methodName, this.connectionFactory.getClass()); if (methods != null && methods.length > 0) { try { for (Method method : methods) { Class<?> returnType = method.getParameterTypes()[0]; if (String.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, propertyValue); return; } else if (int.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Integer.parseInt((String) propertyValue)); return; } else if (long.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Long.parseLong((String) propertyValue)); return; } else if (boolean.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Boolean.parseBoolean((String) propertyValue)); return; } } methods[0].invoke(this.connectionFactory, propertyValue); } catch (Exception e) { throw new IllegalStateException("Failed to set property " + propertyName, e); } } else if (propertyName.equals("hostName")) { this.setProperty("host", propertyValue); } }
JMSConnectionFactoryProvider extends AbstractControllerService implements JMSConnectionFactoryProviderDefinition { private void setProperty(String propertyName, Object propertyValue) { String methodName = this.toMethodName(propertyName); Method[] methods = Utils.findMethods(methodName, this.connectionFactory.getClass()); if (methods != null && methods.length > 0) { try { for (Method method : methods) { Class<?> returnType = method.getParameterTypes()[0]; if (String.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, propertyValue); return; } else if (int.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Integer.parseInt((String) propertyValue)); return; } else if (long.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Long.parseLong((String) propertyValue)); return; } else if (boolean.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Boolean.parseBoolean((String) propertyValue)); return; } } methods[0].invoke(this.connectionFactory, propertyValue); } catch (Exception e) { throw new IllegalStateException("Failed to set property " + propertyName, e); } } else if (propertyName.equals("hostName")) { this.setProperty("host", propertyValue); } } }
JMSConnectionFactoryProvider extends AbstractControllerService implements JMSConnectionFactoryProviderDefinition { private void setProperty(String propertyName, Object propertyValue) { String methodName = this.toMethodName(propertyName); Method[] methods = Utils.findMethods(methodName, this.connectionFactory.getClass()); if (methods != null && methods.length > 0) { try { for (Method method : methods) { Class<?> returnType = method.getParameterTypes()[0]; if (String.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, propertyValue); return; } else if (int.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Integer.parseInt((String) propertyValue)); return; } else if (long.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Long.parseLong((String) propertyValue)); return; } else if (boolean.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Boolean.parseBoolean((String) propertyValue)); return; } } methods[0].invoke(this.connectionFactory, propertyValue); } catch (Exception e) { throw new IllegalStateException("Failed to set property " + propertyName, e); } } else if (propertyName.equals("hostName")) { this.setProperty("host", propertyValue); } }  }
JMSConnectionFactoryProvider extends AbstractControllerService implements JMSConnectionFactoryProviderDefinition { private void setProperty(String propertyName, Object propertyValue) { String methodName = this.toMethodName(propertyName); Method[] methods = Utils.findMethods(methodName, this.connectionFactory.getClass()); if (methods != null && methods.length > 0) { try { for (Method method : methods) { Class<?> returnType = method.getParameterTypes()[0]; if (String.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, propertyValue); return; } else if (int.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Integer.parseInt((String) propertyValue)); return; } else if (long.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Long.parseLong((String) propertyValue)); return; } else if (boolean.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Boolean.parseBoolean((String) propertyValue)); return; } } methods[0].invoke(this.connectionFactory, propertyValue); } catch (Exception e) { throw new IllegalStateException("Failed to set property " + propertyName, e); } } else if (propertyName.equals("hostName")) { this.setProperty("host", propertyValue); } }  @Override ConnectionFactory getConnectionFactory(); @OnEnabled void enable(ConfigurationContext context); @OnDisabled void disable(); }
JMSConnectionFactoryProvider extends AbstractControllerService implements JMSConnectionFactoryProviderDefinition { private void setProperty(String propertyName, Object propertyValue) { String methodName = this.toMethodName(propertyName); Method[] methods = Utils.findMethods(methodName, this.connectionFactory.getClass()); if (methods != null && methods.length > 0) { try { for (Method method : methods) { Class<?> returnType = method.getParameterTypes()[0]; if (String.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, propertyValue); return; } else if (int.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Integer.parseInt((String) propertyValue)); return; } else if (long.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Long.parseLong((String) propertyValue)); return; } else if (boolean.class.isAssignableFrom(returnType)) { method.invoke(this.connectionFactory, Boolean.parseBoolean((String) propertyValue)); return; } } methods[0].invoke(this.connectionFactory, propertyValue); } catch (Exception e) { throw new IllegalStateException("Failed to set property " + propertyName, e); } } else if (propertyName.equals("hostName")) { this.setProperty("host", propertyValue); } }  @Override ConnectionFactory getConnectionFactory(); @OnEnabled void enable(ConfigurationContext context); @OnDisabled void disable(); static final PropertyDescriptor CONNECTION_FACTORY_IMPL; static final PropertyDescriptor CLIENT_LIB_DIR_PATH; static final PropertyDescriptor BROKER_URI; static final PropertyDescriptor SSL_CONTEXT_SERVICE; }