@Test @Ignore public void performDataDownloadADALAPItest() throws Exception { URL testURL = new URL("http://testurl/kit.edu"); File downloadDestination = new File("C:\\destination"); AbstractFile abstractFile = new AbstractFile(downloadDestination); Configuration config = new CombinedConfiguration(); PowerMockito.whenNew(AbstractFile.class.getConstructor(URL.class, Configuration.class)).withArguments(testURL, config).thenReturn(abstractFile); PowerMockito.whenNew(AbstractFile.class.getConstructor(File.class)).withArguments(downloadDestination).thenReturn(abstractFile); Mockito.when(abstractFile.downloadDirectory(abstractFile)).thenReturn(abstractFile); DownloadInformation dataToDownload = new DownloadInformation(); AbstractFile performDataDownloadADALAPI = clientHelper.performDataDownloadADALAPI("accessMethod", dataToDownload, downloadDestination); Assert.assertNotNull(performDataDownloadADALAPI); }
/** * Recursively assemble the combined configuration. * * @param path Path in the configuration object of the current configuration reference. * May be {@code null} for the root path. * @param combinedConfig Configuration object to write the configuration to. * @param configReference Configuration reference to process. */ void assembleConfigSection(String path, CombinedConfiguration combinedConfig, ConfigReference configReference) { // Give every configuration part a unique name. String name = (path == null ? "" : path) + "->" + configReference.getName(); if (configReference.configuration != null) { combinedConfig.addConfiguration(configReference.configuration, name, path); } // Includes. These take precedence over the configuration parts that are extended. configReference.referencedByMe.forEach((includeReference, reference) -> { if (includeReference.getConfigPath() == null) return; String newPath = path == null ? includeReference.getConfigPath() : path + "." + includeReference.getConfigPath(); assembleConfigSection(newPath, combinedConfig, reference); }); // Extends. configReference.referencedByMe.forEach((includeReference, reference) -> { if (includeReference.getConfigPath() != null) return; assembleConfigSection(path, combinedConfig, reference); }); }
/** * Common method to load content of all configuration resources defined in * 'config-definition.xml'. * * @param configDefFilePath * the config def file path * @return Configuration */ public static Configuration getConfiguration(String configDefFilePath) { if (configurationsCache.containsKey(configDefFilePath)) { return configurationsCache.get(configDefFilePath); } CombinedConfiguration configuration = null; synchronized (configurationsCache) { if (configurationsCache.containsKey(configDefFilePath)) { return configurationsCache.get(configDefFilePath); } DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); String filePath = getConfigDefFilePath(configDefFilePath); LOGGER.info("loading from 'configDefFilePath' : {}", filePath); builder.setFile(new File(filePath)); try { configuration = builder.getConfiguration(true); configurationsCache.put(filePath, configuration); } catch (ConfigurationException|ConfigurationRuntimeException e) { LOGGER.info("Exception in loading property files.", e); } } return configuration; }
/** * Common method to load content of all configuration resources defined in * 'config-definition.xml'. * * @param configDefFilePath * the config def file path * @return Configuration */ public static Configuration getConfiguration(String configDefFilePath) { if (configurationsCache.containsKey(configDefFilePath)) { return configurationsCache.get(configDefFilePath); } CombinedConfiguration configuration = null; synchronized (configurationsCache) { if (configurationsCache.containsKey(configDefFilePath)) { return configurationsCache.get(configDefFilePath); } DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); String fielPath = getConfigDefFilePath(configDefFilePath); LOGGER.info("loading from 'configDefFilePath' :" + fielPath); builder.setFile(new File(fielPath)); try { configuration = builder.getConfiguration(true); configurationsCache.put(fielPath, configuration); } catch (ConfigurationException e) { LOGGER.info("Exception in loading property files.", e); } } return configuration; }
private void registerHandlersPackage(HandlersPackage handlersPackage, HierarchicalConfiguration handlerConfig, List<HierarchicalConfiguration> children) throws ConfigurationException{ List<String> c = handlersPackage.getHandlers(); for (Iterator<String> i = c.iterator(); i.hasNext();) { String cName = i.next(); try { CombinedConfiguration conf = new CombinedConfiguration(); HierarchicalConfiguration cmdConf = addHandler(cName); conf.addConfiguration(cmdConf); if (handlerConfig != null) { conf.addConfiguration(handlerConfig); } children.add(conf); } catch (ConfigurationException e) { throw new ConfigurationException("Unable to create configuration for handler " + cName, e); } } }
/** * Loads the streams-agent.properties file from the classpath * * @return * @throws ConfigurationException */ @Bean public org.apache.commons.configuration.Configuration appConfig() { URL url = Thread.currentThread().getContextClassLoader() .getResource("streams-agent.properties"); if (url == null) { throw new RuntimeException( "cant find configuration streams-agent.properties"); } // SystemConfiguration sys = new SystemConfiguration(); CombinedConfiguration cc = new CombinedConfiguration(); // cc.addConfiguration(sys); PropertiesConfiguration props; try { props = new PropertiesConfiguration(url); cc.addConfiguration(props); } catch (ConfigurationException e) { RuntimeException rte = new RuntimeException(e); rte.setStackTrace(e.getStackTrace()); throw rte; } return cc; }
/** * Loads the streams-agent.properties file from the classpath * * @return * @throws ConfigurationException */ @Bean public org.apache.commons.configuration.Configuration appConfig() { URL url = Thread.currentThread().getContextClassLoader() .getResource("streams-collector.properties"); if (url == null) { throw new RuntimeException( "cant find configuration streams-collector.properties"); } // SystemConfiguration sys = new SystemConfiguration(); CombinedConfiguration cc = new CombinedConfiguration(); // cc.addConfiguration(sys); PropertiesConfiguration props; try { props = new PropertiesConfiguration(url); cc.addConfiguration(props); } catch (ConfigurationException e) { RuntimeException rte = new RuntimeException(e); rte.setStackTrace(e.getStackTrace()); throw rte; } return cc; }
/** * Loads the streams-agent.properties file from the classpath * * @return * @throws ConfigurationException */ @Bean public org.apache.commons.configuration.Configuration appConfig() { URL url = Thread.currentThread().getContextClassLoader() .getResource("streams-coordination.properties"); if (url == null) { throw new RuntimeException( "cant find configuration streams-coordination.properties"); } // SystemConfiguration sys = new SystemConfiguration(); CombinedConfiguration cc = new CombinedConfiguration(); // cc.addConfiguration(sys); PropertiesConfiguration props; try { props = new PropertiesConfiguration(url); cc.addConfiguration(props); } catch (ConfigurationException e) { RuntimeException rte = new RuntimeException(e); rte.setStackTrace(e.getStackTrace()); throw rte; } return cc; }
public void withConfiguration(Consumer<CombinedConfiguration> consumer) { writeLock.lock(); try { consumer.accept(wrapped); // Mark the time of modification. markAsModified(); } finally { writeLock.unlock(); } }
@Test public void modifyConfigurationTest() { CombinedConfiguration allConfig = new CombinedConfiguration(new OverrideCombiner()); HierarchicalConfiguration confA = new HierarchicalConfiguration(); HierarchicalConfiguration confB = new HierarchicalConfiguration(); confA.setProperty("a.a", 1); confB.setProperty("a.a", 2); allConfig.addConfiguration(confA, "a"); allConfig.addConfiguration(confB, "b"); allConfig.addConfiguration(confB, "d", "b.b"); allConfig.addConfiguration(confB, "c", "c.c"); System.out.println(allConfig.getInt("a.a")); System.out.println(allConfig.getInt("b.b.a.a")); System.out.println(allConfig.getInt("c.c.a.a")); ConcurrentConfiguration concurrentConfiguration = new ConcurrentConfiguration(allConfig); System.out.println(concurrentConfiguration.getInt("a.a")); concurrentConfiguration.withConfiguration(cc -> { cc.clear(); cc.addConfiguration(confB, "b"); cc.addConfiguration(confA, "a"); }); System.out.println(concurrentConfiguration.getInt("a.a")); }
@SuppressWarnings("unchecked") public static List<HierarchicalConfiguration> configurationsAt(String key) { // return configuration.configurationsAt(key); // return configurationsAtAndCache(key); try { return ((CombinedConfiguration) factory.getConfiguration()).configurationsAt(key); } catch (Exception ex) { ex.printStackTrace(); } return null; }
public static SubnodeConfiguration configurationAt(String key, boolean supportUpdates) { // return configuration.configurationAt(key, supportUpdates); // return configurationAtAndCache(key); try { return ((CombinedConfiguration) factory.getConfiguration()).configurationAt(key, supportUpdates); } catch (Exception ex) { ex.printStackTrace(); } return null; }
/** * @throws Exception * If anything went wrong */ @Before public void setup() throws Exception { config = new CombinedConfiguration(); // Flume channel configuration BaseConfiguration channelConfig = new BaseConfiguration(); channelConfig.addProperty("keep-alive", "1"); // Speeds up test channelConfig.addProperty("capacity", "" + NB_EVENTS); config.addConfiguration(channelConfig, CHANNEL_CONFIG); MemoryStorage.getInstance().clear(); }
public ConcurrentConfiguration(CombinedConfiguration wrapped, ConfigurationSource configurationSource) { this.wrapped = wrapped; this.configurationSource = configurationSource; logger.info("Dynamic Configuration instance created."); }
public ConcurrentConfiguration(CombinedConfiguration wrapped) { this(wrapped, null); }
@Test public void testMethodWrappers() { CombinedConfiguration mockConfiguration = mock(CombinedConfiguration.class); Configuration concurrentConfiguration = new ConcurrentConfiguration(mockConfiguration, null); concurrentConfiguration.subset("subset"); concurrentConfiguration.isEmpty(); concurrentConfiguration.containsKey("key"); concurrentConfiguration.getProperty("getprop"); concurrentConfiguration.getKeys("getkeys"); concurrentConfiguration.getKeys(); concurrentConfiguration.getProperties("getprops"); concurrentConfiguration.getBoolean("getboolean1"); concurrentConfiguration.getBoolean("getboolean2", true); concurrentConfiguration.getBoolean("getboolean3", Boolean.FALSE); concurrentConfiguration.getByte("getbyte1"); concurrentConfiguration.getByte("getbyte2", (byte) 0); concurrentConfiguration.getByte("getbyte3", Byte.valueOf((byte) 0)); concurrentConfiguration.getDouble("getdouble1"); concurrentConfiguration.getDouble("getdouble2", 0.2); concurrentConfiguration.getDouble("getdouble3", Double.valueOf(0.2)); concurrentConfiguration.getFloat("getfloat1"); concurrentConfiguration.getFloat("getfloat2", 0f); concurrentConfiguration.getFloat("getfloat3", Float.valueOf(0f)); concurrentConfiguration.getInt("getint1"); concurrentConfiguration.getInt("getint2", 0); concurrentConfiguration.getInteger("getint3", 0); concurrentConfiguration.getLong("getlong1"); concurrentConfiguration.getLong("getlong2", 0L); concurrentConfiguration.getLong("getlong3", Long.valueOf(0L)); concurrentConfiguration.getShort("getshort1"); concurrentConfiguration.getShort("getshort2", (short) 0); concurrentConfiguration.getShort("getshort3", Short.valueOf((short) 0)); concurrentConfiguration.getBigDecimal("getbigd1"); concurrentConfiguration.getBigDecimal("getbigd2", BigDecimal.valueOf(0.4)); concurrentConfiguration.getBigInteger("getbigi1"); concurrentConfiguration.getBigInteger("getbigi2", BigInteger.valueOf(2L)); concurrentConfiguration.getString("getstring1"); concurrentConfiguration.getString("getstring2", "def"); concurrentConfiguration.getStringArray("stringarray"); concurrentConfiguration.getList("getlist1"); concurrentConfiguration.getList("getlist2", Arrays.asList("a", "b")); verify(mockConfiguration, times(1)).subset("subset"); verify(mockConfiguration, times(1)).isEmpty(); verify(mockConfiguration, times(1)).containsKey("key"); verify(mockConfiguration, times(1)).getProperty("getprop"); verify(mockConfiguration, times(1)).getKeys("getkeys"); verify(mockConfiguration, times(1)).getKeys(); verify(mockConfiguration, times(1)).getProperties("getprops"); verify(mockConfiguration, times(1)).getBoolean("getboolean1"); verify(mockConfiguration, times(1)).getBoolean("getboolean2", true); verify(mockConfiguration, times(1)).getBoolean("getboolean3", Boolean.FALSE); verify(mockConfiguration, times(1)).getByte("getbyte1"); verify(mockConfiguration, times(1)).getByte("getbyte2", (byte) 0); verify(mockConfiguration, times(1)).getByte("getbyte3", Byte.valueOf((byte) 0)); verify(mockConfiguration, times(1)).getDouble("getdouble1"); verify(mockConfiguration, times(1)).getDouble("getdouble2", 0.2); verify(mockConfiguration, times(1)).getDouble("getdouble3", Double.valueOf(0.2)); verify(mockConfiguration, times(1)).getFloat("getfloat1"); verify(mockConfiguration, times(1)).getFloat("getfloat2", 0f); verify(mockConfiguration, times(1)).getFloat("getfloat3", Float.valueOf(0f)); verify(mockConfiguration, times(1)).getInt("getint1"); verify(mockConfiguration, times(1)).getInt("getint2", 0); verify(mockConfiguration, times(1)).getInteger("getint3", Integer.valueOf(0)); verify(mockConfiguration, times(1)).getLong("getlong1"); verify(mockConfiguration, times(1)).getLong("getlong2", 0L); verify(mockConfiguration, times(1)).getLong("getlong3", Long.valueOf(0L)); verify(mockConfiguration, times(1)).getShort("getshort1"); verify(mockConfiguration, times(1)).getShort("getshort2", (short) 0); verify(mockConfiguration, times(1)).getShort("getshort3", Short.valueOf((short) 0)); verify(mockConfiguration, times(1)).getBigDecimal("getbigd1"); verify(mockConfiguration, times(1)).getBigDecimal("getbigd2", BigDecimal.valueOf(0.4)); verify(mockConfiguration, times(1)).getBigInteger("getbigi1"); verify(mockConfiguration, times(1)).getBigInteger("getbigi2", BigInteger.valueOf(2L)); verify(mockConfiguration, times(1)).getString("getstring1"); verify(mockConfiguration, times(1)).getString("getstring2", "def"); verify(mockConfiguration, times(1)).getStringArray("stringarray"); verify(mockConfiguration, times(1)).getList("getlist1"); verify(mockConfiguration, times(1)).getList("getlist2", Arrays.asList("a", "b")); }
@Test(expected = UnsupportedOperationException.class) public void addPropertyTest() { CombinedConfiguration mockConfiguration = mock(CombinedConfiguration.class); Configuration concurrentConfiguration = new ConcurrentConfiguration(mockConfiguration, null); concurrentConfiguration.addProperty("test", "test"); }
@Test(expected = UnsupportedOperationException.class) public void setPropertyTest() { CombinedConfiguration mockConfiguration = mock(CombinedConfiguration.class); Configuration concurrentConfiguration = new ConcurrentConfiguration(mockConfiguration, null); concurrentConfiguration.setProperty("test", "test"); }
@Test(expected = UnsupportedOperationException.class) public void clearPropertyTest() { CombinedConfiguration mockConfiguration = mock(CombinedConfiguration.class); Configuration concurrentConfiguration = new ConcurrentConfiguration(mockConfiguration, null); concurrentConfiguration.clearProperty("test"); }
@Test(expected = UnsupportedOperationException.class) public void clearTest() { CombinedConfiguration mockConfiguration = mock(CombinedConfiguration.class); Configuration concurrentConfiguration = new ConcurrentConfiguration(mockConfiguration, null); concurrentConfiguration.clear(); }
public static CombinedConfiguration getConfiguration() { return configuration; }
/** * Integration test with the test implementation of the Location Service and * the Connection API * * @throws Exception * If anything went wrong */ // @Test public void testTestImpl() throws Exception { // Base storm sink configuration BaseConfiguration sinkBaseConfig = new BaseConfiguration(); sinkBaseConfig.addProperty(StormSinkConfiguration.LOCATION_SERVICE_FACTORY_CLASS, SimpleLocationServiceFactory.class.getName()); sinkBaseConfig.addProperty(StormSinkConfiguration.SERVICE_PROVIDER_SERIALIZATION_CLASS, SimpleServiceProviderSerialization.class.getName()); sinkBaseConfig.addProperty(StormSinkConfiguration.EVENT_SENDER_FACTORY_CLASS, SimpleEventSenderFactory.class.getName()); sinkBaseConfig.addProperty(StormSinkConfiguration.CONNECTION_PARAMETERS_FACTORY_CLASS, SimpleConnectionParametersFactory.class.getName()); // First storm sink configuration BaseConfiguration sink1ConnectionParameters = new BaseConfiguration(); sink1ConnectionParameters.addProperty(SimpleConnectionParameters.HOSTNAME, "host1"); sink1ConnectionParameters.addProperty(SimpleConnectionParameters.PORT, 7001); CombinedConfiguration sink1Config = new CombinedConfiguration(); sink1Config.addConfiguration(sinkBaseConfig); sink1Config.addConfiguration(sink1ConnectionParameters, "connectionParams", SimpleConnectionParametersFactory.CONFIG_BASE_NAME); config.addConfiguration(sink1Config, SINK1_CONFIG); // Second storm sink configuration BaseConfiguration sink2ConnectionParameters = new BaseConfiguration(); sink2ConnectionParameters.addProperty(SimpleConnectionParameters.HOSTNAME, "host2"); sink2ConnectionParameters.addProperty(SimpleConnectionParameters.PORT, 7002); CombinedConfiguration sink2Config = new CombinedConfiguration(); sink2Config.addConfiguration(sinkBaseConfig); sink2Config.addConfiguration(sink2ConnectionParameters, "connectionParams", SimpleConnectionParametersFactory.CONFIG_BASE_NAME); config.addConfiguration(sink2Config, SINK2_CONFIG); // Flume-spout configuration BaseConfiguration flumeSpoutConfig = new BaseConfiguration(); flumeSpoutConfig.addProperty(FlumeSpoutConfiguration.LOCATION_SERVICE_FACTORY_CLASS, SimpleLocationServiceFactory.class.getName()); flumeSpoutConfig.addProperty(FlumeSpoutConfiguration.SERVICE_PROVIDER_SERIALIZATION_CLASS, SimpleServiceProviderSerialization.class.getName()); flumeSpoutConfig.addProperty(FlumeSpoutConfiguration.EVENT_RECEPTOR_FACTORY_CLASS, SimpleEventReceptorFactory.class.getName()); config.addConfiguration(flumeSpoutConfig, SPOUT_CONFIG); testAll(); }
/** * Assemble the full configuration as represented by this composition. * * @param combinedConfig Configuration object to place the configuration in. */ public synchronized void assembleConfigTree(CombinedConfiguration combinedConfig) { combinedConfig.clear(); assembleConfigSection(null, combinedConfig, root); }