public static Properties overWriteProperties(Properties bp, Properties ovp) { for (String propertyName : ovp.stringPropertyNames()) { bp.setProperty(propertyName,ovp.getProperty(propertyName)); } return bp; }
private static Properties updatePropertiesWithOptions(Properties props, String[] args) { Properties allProperties = new Properties(); // copy it so props isn't changed but can be overridden by args for (String key : props.stringPropertyNames()) { allProperties.setProperty(key, props.getProperty(key)); } Properties options = StringUtils.argsToProperties(args); for (String key : options.stringPropertyNames()) { allProperties.setProperty(key, options.getProperty(key)); } return allProperties; }
private static void configLog(String configFile) { if(new File(configFile).exists()) { PropertyConfigurator.configure(configFile); return; } Properties properties = new Properties(); properties.setProperty("log4j.rootLogger", "DEBUG, CA"); properties.setProperty("log4j.appender.CA", "org.apache.log4j.ConsoleAppender"); properties.setProperty("log4j.appender.CA.layout", "org.apache.log4j.PatternLayout"); properties.setProperty("log4j.appender.CA.layout.ConversionPattern", "%d{yyyy-MM-dd HH:mm:ss.SSS} %-4r [%t] %-5p %c %x - %m%n"); PropertyConfigurator.configure(properties); } }
@Test public void testWithMultipleProperties() { String text = "foo=${foo},bar=${bar}"; Properties props = new Properties(); props.setProperty("foo", "bar"); props.setProperty("bar", "baz"); assertEquals("foo=bar,bar=baz", this.helper.replacePlaceholders(text, props)); }
/** * @throws Exception If failed. */ @Test public void testCache1() throws Exception { Properties cfg = new Properties(); cfg.setProperty(PROP_NODE_ID, grid(0).localNode().id().toString()); Connection conn = null; try { conn = DriverManager.getConnection(URL, cfg); ResultSet rs = conn.createStatement().executeQuery("select _val from Integer order by _val"); int cnt = 0; while (rs.next()) assertEquals(++cnt, rs.getInt(1)); assertEquals(2, cnt); } finally { if (conn != null) conn.close(); } }
/** * Attempts to establish a connection to the given database URL. * * @param url * a URL string representing the database target to connect with. * @param user * a user ID used to login to the database. * @param password * a password for the user ID to login to the database. * @return a {@code Connection} to the database identified by the URL. * {@code null} if no connection can be established. * @throws SQLException * if there is an error while attempting to connect to the * database identified by the URL. */ public static Connection getConnection(String url, String user, String password) throws SQLException { Properties theProperties = new Properties(); if (user != null) { theProperties.setProperty("user", user); } if (password != null) { theProperties.setProperty("password", password); } return getConnection(url, theProperties); }
private Properties getProperties() throws IOException { Properties jobProperties = GobblinLocalJobLauncherUtils.getJobProperties("runtime_test/writer_output_format_test.properties"); FileUtils.copyFile(new File(GobblinLocalJobLauncherUtils.RESOURCE_DIR + SAMPLE_FILE), new File(GobblinLocalJobLauncherUtils.RESOURCE_DIR + GobblinLocalJobLauncherUtils.SAMPLE_DIR + SAMPLE_FILE)); jobProperties.setProperty(ConfigurationKeys.SOURCE_FILEBASED_FILES_TO_PULL, GobblinLocalJobLauncherUtils.RESOURCE_DIR + GobblinLocalJobLauncherUtils.SAMPLE_DIR + SAMPLE_FILE); return jobProperties; } }
@Test public void testSysPropReplace() { System.getProperties().setProperty("ehcache.match", Number.class.getName()); XmlConfiguration xmlConfig = new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/systemprops.xml")); assertThat(xmlConfig.getCacheConfigurations().get("bar").getKeyType(), sameInstance((Class)Number.class)); DefaultPersistenceConfiguration persistenceConfiguration = (DefaultPersistenceConfiguration)xmlConfig.getServiceCreationConfigurations().iterator().next(); assertThat(persistenceConfiguration.getRootDirectory(), is(new File(System.getProperty("user.home") + "/ehcache"))); }
public static void updateTerm(long term) throws Exception { File file = new File(META_FILE_NAME); if (!file.exists() && !file.getParentFile().mkdirs() && !file.createNewFile()) { throw new IllegalStateException("failed to create meta file"); } try (FileOutputStream outStream = new FileOutputStream(file)) { // write meta meta.setProperty("term", String.valueOf(term)); meta.store(outStream, null); } }
/** * Stores the data in {@code config} into {@code stream} in a standard java * {@link Properties} format. * @param config the data to store in the properties file. * @param stream the {@link OutputStream} to store the properties in. * @throws IOException IO error. */ public static void store( Map<String, String> config, OutputStream stream ) throws IOException { Properties properties = new Properties(); for ( Map.Entry<String, String> property : config.entrySet() ) { properties.setProperty( property.getKey(), property.getValue() ); } properties.store( stream, null ); }
@Test public void testRecurseInProperty() { String text = "foo=${bar}"; Properties props = new Properties(); props.setProperty("bar", "${baz}"); props.setProperty("baz", "bar"); assertEquals("foo=bar", this.helper.replacePlaceholders(text, props)); }
private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) { String relativePath = suite.getName() + File.separatorChar + FILE_NAME; File suiteFile = new File(config.getOutputDirectory(), relativePath); Properties attrs = new Properties(); attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath); xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs); return suiteFile; }
/** * @throws Exception If failed. */ @Test public void testCache1() throws Exception { Properties cfg = new Properties(); cfg.setProperty(PROP_NODE_ID, grid(0).localNode().id().toString()); Connection conn = null; try { conn = DriverManager.getConnection(BASE_URL, cfg); ResultSet rs = conn.createStatement().executeQuery("select _val from Integer order by _val"); int cnt = 0; while (rs.next()) assertEquals(++cnt, rs.getInt(1)); assertEquals(2, cnt); } finally { if (conn != null) conn.close(); } }
/** * @param allowOverwrite Allow overwriting of existing keys. * @return Connection to use for the test. * @throws Exception if failed. */ protected Connection createConnection(boolean allowOverwrite) throws Exception { Properties props = new Properties(); props.setProperty(IgniteJdbcDriver.PROP_STREAMING, "true"); props.setProperty(IgniteJdbcDriver.PROP_STREAMING_FLUSH_FREQ, "500"); if (allowOverwrite) props.setProperty(IgniteJdbcDriver.PROP_STREAMING_ALLOW_OVERWRITE, "true"); return DriverManager.getConnection(BASE_URL, props); }
@Override public NacosDataSource getObject() throws Exception { if (!StringUtils.isEmpty(System.getProperties() .getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT))) { Properties properties = new Properties(); properties.setProperty(PropertyKeyConst.ACCESS_KEY, this.accessKey); properties.setProperty(PropertyKeyConst.SERVER_ADDR, this.secretKey); properties.setProperty(PropertyKeyConst.ENDPOINT, this.endpoint); properties.setProperty(PropertyKeyConst.NAMESPACE, this.namespace); return new NacosDataSource(properties, groupId, dataId, converter); } return new NacosDataSource(serverAddr, groupId, dataId, converter); }
private Properties getProperties() throws IOException { Properties jobProperties = GobblinLocalJobLauncherUtils.getJobProperties("runtime_test/task_skip_err_records.properties"); FileUtils.copyFile(new File(GobblinLocalJobLauncherUtils.RESOURCE_DIR + SAMPLE_FILE), new File(GobblinLocalJobLauncherUtils.RESOURCE_DIR + GobblinLocalJobLauncherUtils.SAMPLE_DIR + SAMPLE_FILE)); jobProperties.setProperty(ConfigurationKeys.SOURCE_FILEBASED_FILES_TO_PULL, GobblinLocalJobLauncherUtils.RESOURCE_DIR + GobblinLocalJobLauncherUtils.SAMPLE_DIR + SAMPLE_FILE); return jobProperties; } }
FileInputStream in = new FileInputStream("First.properties"); Properties props = new Properties(); props.load(in); in.close(); FileOutputStream out = new FileOutputStream("First.properties"); props.setProperty("country", "america"); props.store(out, null); out.close();
public static Properties noClobberWriteProperties(Properties bp, Properties ovp) { for (String propertyName : ovp.stringPropertyNames()) { if (bp.containsKey(propertyName)) continue; bp.setProperty(propertyName,ovp.getProperty(propertyName)); } return bp; }
@Test public void testUnresolvedPlaceholderIsIgnored() { String text = "foo=${foo},bar=${bar}"; Properties props = new Properties(); props.setProperty("foo", "bar"); assertEquals("foo=bar,bar=${bar}", this.helper.replacePlaceholders(text, props)); }
private File referenceSuiteResult(XMLStringBuffer xmlBuffer, String parentDir, ISuiteResult suiteResult) { Properties attrs = new Properties(); String suiteResultName = suiteResult.getTestContext().getName() + ".xml"; attrs.setProperty(XMLReporterConfig.ATTR_URL, suiteResultName); xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_TEST, attrs); return new File(parentDir + File.separatorChar + suiteResultName); }