FileBasedSecStoreConfig(File userFile, File roleFile) throws Exception { Configurations configs = new Configurations(); userBuilder = configs.propertiesBuilder(userFile); roleBuilder = configs.propertiesBuilder(roleFile); userConfig = userBuilder.getConfiguration(); roleConfig = roleBuilder.getConfiguration(); String roleHeader = roleConfig.getLayout().getHeaderComment(); String userHeader = userConfig.getLayout().getHeaderComment(); if (userHeader == null) { if (userConfig.isEmpty()) { //clean and reset header userConfig.clear(); userConfig.setHeader(LICENSE_HEADER); } } if (roleHeader == null) { if (roleConfig.isEmpty()) { //clean and reset header roleConfig.clear(); roleConfig.setHeader(LICENSE_HEADER); } } }
public static void init() throws ConfigurationException { configManager = new Configurations(); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFile(App.appFileUtil.getHotkeysFile())); config = builder.getConfiguration(); loadHotkeys(); }
public static void init(String worldLocation) throws ConfigurationException { log.debug("World Location for properties: " + worldLocation); configManager = new Configurations(); if(worldLocation == null){ builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFileName(defaultWorldPropertiesLocation)); }else { builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFileName(worldLocation)); } config = builder.getConfiguration(); }
public static void init() throws ConfigurationException { configManager = new Configurations(); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFile(App.appFileUtil.getAppPropFile())); config = builder.getConfiguration(); }
public static void firstInit() throws Exception{ configManager = new Configurations(); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFileName("src/main/resources/app.properties")); config = builder.getConfiguration(); }
@Override public Configuration get() { Configurations configs = new Configurations(); try { return configs.properties(new File(getPropertyFilePath())); } catch (ConfigurationException e) { log.error(" error on build configuration", e); throw new IllegalStateException(e); } }
/** * Read config file and store in {@code Config}. * * @param configFile the config file. * @throws ConfigurationException - if an error occurred when loading the configuration * @throws BiremeException - wrap and throw Exception which cannot be handled */ public Config(String configFile) throws ConfigurationException, BiremeException { Configurations configs = new Configurations(); config = configs.properties(new File(configFile)); basicConfig(); connectionConfig("target"); dataSourceConfig(); logConfig(); }
private HashMap<String, String> fetchTableMap(String dataSource) throws ConfigurationException, BiremeException { Configurations configs = new Configurations(); Configuration tableConfig = null; tableConfig = configs.properties(new File(DEFAULT_TABLEMAP_DIR + dataSource + ".properties")); String originTable, mappedTable; HashMap<String, String> localTableMap = new HashMap<String, String>(); Iterator<String> tables = tableConfig.getKeys(); while (tables.hasNext()) { originTable = tables.next(); mappedTable = tableConfig.getString(originTable); if (originTable.split("\\.").length != 2 || mappedTable.split("\\.").length != 2) { String message = "Wrong format: " + originTable + ", " + mappedTable; logger.fatal(message); throw new BiremeException(message); } localTableMap.put(dataSource + "." + originTable, mappedTable); if (!tableMap.values().contains(mappedTable)) { loadersCount++; } tableMap.put(dataSource + "." + originTable, mappedTable); } return localTableMap; }
@Test public void testCreateConfiguration() throws Exception { Configuration conf = target.createConfiguration(); for (Object name : Collections.list(System.getProperties().propertyNames())) { // All system properties must exist. assertTrue(conf.containsKey(name.toString()), "Missing system : " + name); } Configuration v = new Configurations().properties(getResource(ConfigurationType.VERSION.getPath())); Configuration s = new Configurations().properties(getResource(ConfigurationType.SITE.getPath())); // 1st should be version. assertEquals(VERSION.fetch(conf), v.getString(VERSION.getKey())); assertNotEquals(VERSION.fetch(conf), s.getString(VERSION.getKey())); assertEquals(s.getString(VERSION.getKey()), "test"); // 2nd should be system. (Should not be overridden.) String system = "java.version"; assertEquals(conf.getString(system), System.getProperty(system)); assertNotEquals(conf.getString(system), s.getString(system)); assertEquals(s.getString(system), "test"); // 3rd should be site. assertEquals(SITE.fetch(conf), s.getString(SITE.getKey())); assertEquals(s.getString(SITE.getKey()), "test"); // Last should be default. assertEquals(HTTP_URL.fetch(conf), HTTP_URL.getDefaultValue()); }
private Config() { Configuration configuration; try { Configurations configurations = new Configurations(); configuration = configurations.properties(new File("configuration.properties")); } catch (ConfigurationException ce) { ce.printStackTrace(); configuration = null; } this.properties = configuration; this.initSuccess = configuration != null; }
@Test(enabled = false) public void test() throws Exception { Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader"); target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile())); doCallRealMethod().when(target).request(any(), any(), any(), any()); Key key = Key.builder().instrument("XBT_QT").timestamp(Instant.now()).build(); // Tick System.out.println("Ask : " + target.getBestAskPrice(key)); System.out.println("Bid : " + target.getBestBidPrice(key)); System.out.println("Mid : " + target.getMidPrice(key)); System.out.println("Ltp : " + target.getLastPrice(key)); // Book System.out.println("ASZ : " + target.getBestAskSize(key)); System.out.println("BSZ : " + target.getBestBidSize(key)); // Trade System.out.println("TRD : " + target.listTrades(key, null)); // Account System.out.println("IPS : " + target.getInstrumentPosition(key)); System.out.println("FPS : " + target.getFundingPosition(key)); // Reference System.out.println("COM : " + target.getCommissionRate(key)); System.out.println("MGN : " + target.isMarginable(key)); System.out.println("EXP : " + target.getExpiry(key)); // Order Query System.out.println("ORD : " + target.findOrders(key)); System.out.println("EXC : " + target.listExecutions(key)); }
@Test(enabled = false) public void test_Order() throws Exception { Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader"); target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile())); doCallRealMethod().when(target).request(any(), any(), any(), any()); Key key = Key.builder().instrument("XBJ_QT").timestamp(Instant.now()).build(); Map<CreateInstruction, String> ids = target.createOrders( key, Sets.newHashSet( CreateInstruction.builder() .price(new BigDecimal("1000000")) .size(new BigDecimal("10E-1")).build(), CreateInstruction.builder() .price(new BigDecimal("1000000")) .size(new BigDecimal("0.2E1")).build() )); System.out.println("NEW : " + ids); Thread.sleep(TimeUnit.SECONDS.toMillis(5)); System.out.println("CND : " + target.cancelOrders(key, ids.values().stream() .map(id -> CancelInstruction.builder().id(id).build()).collect(Collectors.toSet()) )); }
@Test(enabled = false) public void test() throws ConfigurationException { Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader"); target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile())); Key key = Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build(); System.out.println("AP: " + target.getBestAskPrice(key)); System.out.println("BP: " + target.getBestBidPrice(key)); System.out.println("AS: " + target.getBestAskSize(key)); System.out.println("BS: " + target.getBestBidSize(key)); System.out.println("MP: " + target.getMidPrice(key)); System.out.println("AD: " + target.getAskPrices(key)); System.out.println("BD: " + target.getBidPrices(key)); System.out.println("LP:" + target.getLastPrice(key)); System.out.println("TD:" + target.listTrades(key, null)); System.out.println("IC:" + target.getInstrumentCurrency(key)); System.out.println("FC:" + target.getFundingCurrency(key)); System.out.println("FP:" + target.findProduct(key, BTC, JPY)); System.out.println("P1:" + target.getConversionPrice(key, BTC)); System.out.println("P2:" + target.getConversionPrice(key, JPY)); System.out.println("IP:" + target.getInstrumentPosition(key)); System.out.println("FP:" + target.getFundingPosition(key)); }
@Test(enabled = false) public void test() throws Exception { Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader"); target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile())); doCallRealMethod().when(target).request(any(), any(), any(), any()); doCallRealMethod().when(target).scheduleSocket(any(), any()); Key key = Key.builder().instrument(BTC_JPY.name()).timestamp(Instant.now()).build(); System.out.println("APX : " + target.getBestAskPrice(key)); System.out.println("ASZ : " + target.getBestAskSize(key)); System.out.println("BPX : " + target.getBestBidPrice(key)); System.out.println("BSZ : " + target.getBestBidSize(key)); System.out.println("MID : " + target.getMidPrice(key)); System.out.println("LTP : " + target.getLastPrice(key)); System.out.println("TRD : " + target.listTrades(key, null)); System.out.println("CYI : " + target.getInstrumentCurrency(key)); System.out.println("CYF : " + target.getFundingCurrency(key)); System.out.println("CVB : " + target.getConversionPrice(key, CurrencyType.BTC)); System.out.println("CVJ : " + target.getConversionPrice(key, CurrencyType.JPY)); System.out.println("PSI : " + target.getInstrumentPosition(key)); System.out.println("PSF : " + target.getFundingPosition(key)); System.out.println("RIU : " + target.roundLotSize(key, new BigDecimal("1.23456"), UP)); System.out.println("RID : " + target.roundLotSize(key, new BigDecimal("1.23456"), DOWN)); System.out.println("RTU : " + target.roundTickSize(key, new BigDecimal("1.23456"), UP)); System.out.println("RTD : " + target.roundTickSize(key, new BigDecimal("1.23456"), DOWN)); System.out.println("COM : " + target.getCommissionRate(key)); System.out.println("FDO : " + target.findOrder(key, "some_order_id")); System.out.println("LAO : " + target.listActiveOrders(key)); System.out.println("LSE : " + target.listExecutions(key)); }
@Test(enabled = false) public void test_Order() throws Exception { Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader"); target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile())); doCallRealMethod().when(target).request(any(), any(), any(), any()); Key key = Key.builder().instrument(BTC_JPY.name()).timestamp(Instant.now()).build(); Map<CreateInstruction, String> creates = target.createOrders(key, Sets.newHashSet( CreateInstruction.builder() .price(new BigDecimal("1000001")) .size(new BigDecimal("0.005")).build(), CreateInstruction.builder() .price(new BigDecimal("1000002")) .size(new BigDecimal("0.005")).build() )); creates.forEach((instruction, id) -> System.out.println(instruction + " -> " + id)); TimeUnit.SECONDS.sleep(10); Map<CancelInstruction, String> cancels = target.cancelOrders(key, creates.values().stream() .filter(StringUtils::isNotEmpty) .map(id -> CancelInstruction.builder().id(id).build()) .collect(Collectors.toSet()) ); cancels.forEach((instruction, id) -> System.out.println(instruction + " -> " + id)); }
public DoctorKafkaConfig(String configPath) throws Exception { try { Configurations configurations = new Configurations(); configuration = configurations.properties(new File(configPath)); operatorConfiguration = new SubsetConfiguration(configuration, DOCTORKAFKA_PREFIX); this.initialize(); } catch (Exception e) { LOG.error("Failed to initialize configuration file {}", configPath, e); } }
private static Configuration loadConfiguration() throws IOException, ConfigurationException { Configurations configurations = new Configurations(); File file = Constants.SETTINGS_FILE_XML; if (!file.exists()) { XMLConfiguration tempConfiguration = new XMLConfiguration(); new FileHandler(tempConfiguration).save(file); } FileBasedConfigurationBuilder<XMLConfiguration> builder = configurations.xmlBuilder(file); builder.setAutoSave(true); return builder.getConfiguration(); }
/** * Loads the default properties from the classpath. * * @return the default properties */ private Configuration getDefaultConfiguration() { Configurations configs = new Configurations(); try { return configs.properties(PROPERTIES_DEFAULT); } catch (ConfigurationException e) { throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT), e); } }
public void swagger2MarkupConfigFromCommonsConfiguration() throws IOException, ConfigurationException { Path localSwaggerFile = Paths.get("/path/to/swagger.yaml"); // tag::swagger2MarkupConfigFromCommonsConfiguration[] Configurations configs = new Configurations(); Configuration configuration = configs.properties("config.properties"); //<1> Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configuration) //<2> .build(); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(localSwaggerFile) .withConfig(config) .build(); // end::swagger2MarkupConfigFromCommonsConfiguration[] }
public void run() { Swagger2MarkupConfig swagger2MarkupConfig = null; if(StringUtils.isNotBlank(configFile)) { Configurations configs = new Configurations(); Configuration config; try { config = configs.properties(configFile); } catch (ConfigurationException e) { throw new IllegalArgumentException("Failed to read configFile", e); } swagger2MarkupConfig = new Swagger2MarkupConfigBuilder(config).build(); } Swagger2MarkupConverter.Builder converterBuilder = Swagger2MarkupConverter.from(URIUtils.create(swaggerInput)); if(swagger2MarkupConfig != null){ converterBuilder.withConfig(swagger2MarkupConfig); } Swagger2MarkupConverter converter = converterBuilder.build(); if(StringUtils.isNotBlank(outputFile)){ converter.toFile(Paths.get(outputFile).toAbsolutePath()); }else if (StringUtils.isNotBlank(outputDir)){ converter.toFolder(Paths.get(outputDir).toAbsolutePath()); }else { throw new IllegalArgumentException("Either outputFile or outputDir option must be used"); } }
private void checkRole(String user, File roleFile, String... roles) throws Exception { Configurations configs = new Configurations(); FileBasedConfigurationBuilder<PropertiesConfiguration> roleBuilder = configs.propertiesBuilder(roleFile); PropertiesConfiguration roleConfig = roleBuilder.getConfiguration(); for (String r : roles) { String storedUsers = (String) roleConfig.getProperty(r); System.out.println("users in role: " + r + " ; " + storedUsers); List<String> userList = StringUtil.splitStringList(storedUsers, ","); assertTrue(userList.contains(user)); } }
private boolean checkPassword(String user, String password, File userFile) throws Exception { Configurations configs = new Configurations(); FileBasedConfigurationBuilder<PropertiesConfiguration> userBuilder = configs.propertiesBuilder(userFile); PropertiesConfiguration userConfig = userBuilder.getConfiguration(); String storedPassword = (String) userConfig.getProperty(user); HashProcessor processor = PasswordMaskingUtil.getHashProcessor(storedPassword); return processor.compare(password.toCharArray(), storedPassword); }
private Optional<Configuration> createFilePath(String path) throws Exception { Path file = Paths.get(path); if (!Files.exists(file)) { log.warn("Skipped filepath configuration : {}", path); return Optional.empty(); } log.debug("Loading filepath configuration : {}", path); URL url = file.toUri().toURL(); return Optional.of(new Configurations().properties(url)); }
@Test public void testDefaults() throws Exception { URL url = Resources.getResource("cryptotrader-default.properties"); Configuration c = new Configurations().properties(url); for (PropertyType type : PropertyType.values()) { String key = type.getKey(); assertTrue(c.containsKey(key), "Missing default : " + key); } }
public void init() throws ConfigurationException { configuration = new Configurations().xmlBuilder("BiliRecorderConfig.xml").getConfiguration(); }
private Optional<Configuration> createClasspath(String path) throws ConfigurationException { log.debug("Loading classpath configuration : {}", path); URL url = Resources.getResource(path); return Optional.of(new Configurations().properties(url)); }
public TestModule() throws ConfigurationException { this.injector = Guice.createInjector(); ExecutorService service = setMock(ExecutorService.class, newDirectExecutorService()); when(getMock(ExecutorFactory.class).get(any(Class.class), anyInt())).thenReturn(service); Configuration configuration = spy(new Configurations().properties(getResource(CONFIGURATION))); setMock(Configuration.class, configuration); setMock(ImmutableConfiguration.class, configuration); }
@BeforeMethod public void setUp() throws Exception { configuration = new Configurations().properties(getResource("cryptotrader-test.properties")); target = spy(new BitmexContext()); target.setConfiguration(configuration); doReturn(null).when(target).request(any(), any(), any(), any()); }
@BeforeMethod public void setUp() throws Exception { configuration = new Configurations().properties(getResource("cryptotrader-test.properties")); target = spy(new OandaContext()); target.setConfiguration(configuration); doReturn(null).when(target).request(any(), any(), any(), any()); }
@Test(enabled = false) public void test() throws Exception { Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader"); target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile())); doCallRealMethod().when(target).request(any(), any(), any(), any()); Key key = Key.builder().instrument("USD_JPY").build(); System.out.println("ASK : " + target.getBestAskPrice(key)); System.out.println("BID : " + target.getBestBidPrice(key)); }
@BeforeMethod public void setUp() throws Exception { URL url = Resources.getResource("cryptotrader-default.properties"); conf = spy(new Configurations().properties(url)); target = new PropertyManagerImpl(conf); site = "site"; inst = "inst"; }
/** * only used for unit testing -- loads * @param heapSpankPropertiesFile * @throws ConfigurationException * @throws MultiPropertyException */ public ApacheCommonsConfigFile(File heapSpankPropertiesFile) throws ConfigurationException, MultiPropertyException { Configurations configurations = new Configurations(); PropertiesConfiguration config = configurations.properties(heapSpankPropertiesFile); this.compositeConfiguration.addConfiguration( config ); }