Java Code Examples for java.util.Properties#clear()

The following examples show how to use java.util.Properties#clear() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: tn5250j   File: KeyMapper.java    License: GNU General Public License v2.0 6 votes vote down vote up
public final static void saveKeyMap() {

		Properties map = ConfigureFactory.getInstance().getProperties(ConfigureFactory.KEYMAP);

		map.clear();

		// save off the keystrokes in the keymap
		Collection<String> v = mappedKeys.values();
		Set<KeyStroker> o = mappedKeys.keySet();
		Iterator<KeyStroker> k = o.iterator();
		Iterator<String> i = v.iterator();
		while (k.hasNext()) {
			KeyStroker ks = k.next();
			map.put(i.next(),ks.toString());
		}

		ConfigureFactory.getInstance().saveSettings(ConfigureFactory.KEYMAP,
				"------ Key Map key=keycode,isShiftDown,isControlDown,isAltDown,isAltGrDown,location --------");
	}
 
Example 2
/**
 * Convert the supplied <em>inlined properties</em> (in the form of <em>key-value</em>
 * pairs) into a map keyed by property name, preserving the ordering of property names
 * in the returned map.
 * <p>Parsing of the key-value pairs is achieved by converting all pairs
 * into <em>virtual</em> properties files in memory and delegating to
 * {@link Properties#load(java.io.Reader)} to parse each virtual file.
 * <p>For a full discussion of <em>inlined properties</em>, consult the Javadoc
 * for {@link TestPropertySource#properties}.
 * @param inlinedProperties the inlined properties to convert; potentially empty
 * but never {@code null}
 * @return a new, ordered map containing the converted properties
 * @throws IllegalStateException if a given key-value pair cannot be parsed, or if
 * a given inlined property contains multiple key-value pairs
 * @since 4.1.5
 * @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
 */
public static Map<String, Object> convertInlinedPropertiesToMap(String... inlinedProperties) {
	Assert.notNull(inlinedProperties, "'inlinedProperties' must not be null");
	Map<String, Object> map = new LinkedHashMap<>();
	Properties props = new Properties();

	for (String pair : inlinedProperties) {
		if (!StringUtils.hasText(pair)) {
			continue;
		}
		try {
			props.load(new StringReader(pair));
		}
		catch (Exception ex) {
			throw new IllegalStateException("Failed to load test environment property from [" + pair + "]", ex);
		}
		Assert.state(props.size() == 1, () -> "Failed to load exactly one test environment property from [" + pair + "]");
		for (String name : props.stringPropertyNames()) {
			map.put(name, props.getProperty(name));
		}
		props.clear();
	}

	return map;
}
 
Example 3
/**
 *
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 *
 */
public void clearConfig()
        throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {

    Config config = Config.getConfig();

    // Set the private static variable Config.config = null
    java.lang.reflect.Field configInstance = config.getClass().getDeclaredField("config");
    configInstance.setAccessible(true);
    configInstance.set(null, null);

    // Clear the sdkProperties map - Config.sdkProperties.clear()
    java.lang.reflect.Field sdkPropInstance = config.getClass().getDeclaredField("sdkProperties");
    sdkPropInstance.setAccessible(true);
    Properties sdkProperties = (Properties) sdkPropInstance.get(config);
    sdkProperties.clear();

}
 
Example 4
Source Project: zeppelin   File: JDBCInterpreterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void concurrentSettingTest() {
  Properties properties = new Properties();
  properties.setProperty("zeppelin.jdbc.concurrent.use", "true");
  properties.setProperty("zeppelin.jdbc.concurrent.max_connection", "10");
  JDBCInterpreter jdbcInterpreter = new JDBCInterpreter(properties);

  assertTrue(jdbcInterpreter.isConcurrentExecution());
  assertEquals(10, jdbcInterpreter.getMaxConcurrentConnection());

  Scheduler scheduler = jdbcInterpreter.getScheduler();
  assertTrue(scheduler instanceof ParallelScheduler);

  properties.clear();
  properties.setProperty("zeppelin.jdbc.concurrent.use", "false");
  jdbcInterpreter = new JDBCInterpreter(properties);

  assertFalse(jdbcInterpreter.isConcurrentExecution());

  scheduler = jdbcInterpreter.getScheduler();
  assertTrue(scheduler instanceof FIFOScheduler);
}
 
Example 5
Source Project: spork   File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Method to apply pig properties to JobConf (replaces properties with
 * resulting jobConf values).
 *
 * @param conf JobConf with appropriate hadoop resource files
 * @param properties Pig properties that will override hadoop properties;
 * properties might be modified
 */
public static void recomputeProperties(JobConf jobConf, Properties properties) {
    // We need to load the properties from the hadoop configuration
    // We want to override these with any existing properties we have.
    if (jobConf != null && properties != null) {
        // set user properties on the jobConf to ensure that defaults
        // and deprecation is applied correctly
        Enumeration<Object> propertiesIter = properties.keys();
        while (propertiesIter.hasMoreElements()) {
            String key = (String) propertiesIter.nextElement();
            String val = properties.getProperty(key);
            // We do not put user.name, See PIG-1419
            if (!key.equals("user.name")) {
                jobConf.set(key, val);
            }
        }
        // clear user defined properties and re-populate
        properties.clear();
        Iterator<Map.Entry<String, String>> iter = jobConf.iterator();
        while (iter.hasNext()) {
            Map.Entry<String, String> entry = iter.next();
            properties.put(entry.getKey(), entry.getValue());
        }
    }
}
 
Example 6
Source Project: netbeans   File: AntBasedTestUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testReplaceInFile() throws Exception {
    clearWorkDir();
    File workdir = getWorkDir();
    File props = new File(workdir, "test.properties");
    Properties p = new Properties();
    p.setProperty("key1", "val1");
    p.setProperty("key2", "val2");
    OutputStream os = new FileOutputStream(props);
    try {
        p.store(os, null);
    } finally {
        os.close();
    }
    assertEquals("two replacements", 2, AntBasedTestUtil.replaceInFile(props, "val", "value"));
    p.clear();
    InputStream is = new FileInputStream(props);
    try {
        p.load(is);
    } finally {
        is.close();
    }
    assertEquals("correct key1", "value1", p.getProperty("key1"));
    assertEquals("correct key2", "value2", p.getProperty("key2"));
}
 
Example 7
private Properties getAllRemoteProperties(){
	if(remoteProperties != null)return remoteProperties;
	Properties properties = new Properties();

	Map<String,Object> map = fetchConfigFromServer();
	if(map == null){
		throw new RuntimeException("fetch remote config error!");
	}
	
	//解密密匙
	secret =  Objects.toString(map.remove("jeesuite.configcenter.encrypt-secret"),null);
	globalSecret = Objects.toString(map.remove("jeesuite.configcenter.global-encrypt-secret"),null);
	remoteFirst = Boolean.parseBoolean(Objects.toString(map.remove("jeesuite.configcenter.remote-config-first"),"false"));
	zkSyncServers = Objects.toString(map.remove("jeesuite.configcenter.sync-zk-servers"),null);
	properties.putAll(map);
	properties.clear();
	
	Set<String> keys = map.keySet();
	for (String key : keys) {
		Object value = decodeEncryptIfRequire(map.get(key));
		properties.put(key, value);
	}
	
	return properties;
}
 
Example 8
Source Project: gemfirexd-oss   File: ShellCommands.java    License: Apache License 2.0 5 votes vote down vote up
private static Map<String, String> loadPropertiesFromURL(URL gfSecurityPropertiesUrl) {
  Map<String, String> propsMap = Collections.emptyMap();

  if (gfSecurityPropertiesUrl != null) {
    InputStream inputStream = null;
    try {
      Properties props = new Properties();
      inputStream = gfSecurityPropertiesUrl.openStream();
      props.load(inputStream);
      if (!props.isEmpty()) {
        Set<String> jmxSpecificProps = new HashSet<String>();
        propsMap = new LinkedHashMap<String, String>();
        Set<Entry<Object, Object>> entrySet = props.entrySet();
        for (Entry<Object, Object> entry : entrySet) {

          String key = (String)entry.getKey();
          if (key.endsWith(DistributionConfig.JMX_SSL_PROPS_SUFFIX)) {
            key = key.substring(0, key.length() - DistributionConfig.JMX_SSL_PROPS_SUFFIX.length());
            jmxSpecificProps.add(key);

            propsMap.put(key, (String)entry.getValue());
          } else if (!jmxSpecificProps.contains(key)) {// Prefer properties ending with "-jmx" over default SSL props.
            propsMap.put(key, (String)entry.getValue());
          }
        }
        props.clear();
        jmxSpecificProps.clear();
      }
    } catch (IOException io) {
      throw new RuntimeException(CliStrings.format(
          CliStrings.CONNECT__MSG__COULD_NOT_READ_CONFIG_FROM_0,
              CliUtil.decodeWithDefaultCharSet(gfSecurityPropertiesUrl.getPath())), io);
    } finally {
      IOUtils.close(inputStream);
    }
  }
  return propsMap;
}
 
Example 9
Source Project: bamboobsc   File: ToolBar.java    License: Apache License 2.0 5 votes vote down vote up
private void setLabelNameFromProperties(Map<String, Object> params, String language) {
	String propFileName = "META-INF/resource/toolbar/ui.toolbar_" + language + ".properties";
	InputStream is = null;
	is = TextBox.class.getClassLoader().getResourceAsStream(propFileName);
	if (is != null) {
		Properties prop = new Properties();
		try {
			prop.load(is);
			params.put("createNewName", prop.get("createNewName"));
			params.put("saveName", prop.get("saveName"));	
			params.put("exportName", prop.get("exportName"));
			params.put("importName", prop.get("importName"));
			params.put("refreshName", prop.get("refreshName"));
			params.put("cancelName", prop.get("cancelName"));		
			params.put("fullscreenName", prop.get("fullscreenName"));
		} catch (IOException e1) {
			e1.printStackTrace();
		} finally {
			try {
				is.close();
			} catch (IOException e2) {
				e2.printStackTrace();
			}
		}				
		prop.clear();
		prop = null;					
	}	
	is = null;			
}
 
Example 10
/**
 * Convert the supplied <em>inlined properties</em> (in the form of <em>key-value</em>
 * pairs) into a map keyed by property name, preserving the ordering of property names
 * in the returned map.
 * <p>Parsing of the key-value pairs is achieved by converting all pairs
 * into <em>virtual</em> properties files in memory and delegating to
 * {@link Properties#load(java.io.Reader)} to parse each virtual file.
 * <p>For a full discussion of <em>inlined properties</em>, consult the Javadoc
 * for {@link TestPropertySource#properties}.
 * @param inlinedProperties the inlined properties to convert; potentially empty
 * but never {@code null}
 * @return a new, ordered map containing the converted properties
 * @since 4.1.5
 * @throws IllegalStateException if a given key-value pair cannot be parsed, or if
 * a given inlined property contains multiple key-value pairs
 * @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
 */
public static Map<String, Object> convertInlinedPropertiesToMap(String[] inlinedProperties) {
	Assert.notNull(inlinedProperties, "inlinedProperties must not be null");
	Map<String, Object> map = new LinkedHashMap<String, Object>();

	Properties props = new Properties();
	for (String pair : inlinedProperties) {
		if (!StringUtils.hasText(pair)) {
			continue;
		}

		try {
			props.load(new StringReader(pair));
		}
		catch (Exception e) {
			throw new IllegalStateException("Failed to load test environment property from [" + pair + "].", e);
		}
		Assert.state(props.size() == 1, "Failed to load exactly one test environment property from [" + pair + "].");

		for (String name : props.stringPropertyNames()) {
			map.put(name, props.getProperty(name));
		}
		props.clear();
	}

	return map;
}
 
Example 11
/**
 * Update created pom.xml file with necessary dependencies and plug-ins so
 * that it works with WSO2 MSF4J server
 * 
 * @throws IOException
 * @throws XmlPullParserException
 *
 */
private void updatePom(IProject project) throws IOException, XmlPullParserException {
	File mavenProjectPomLocation = project.getFile(POM_FILE).getLocation().toFile();
	MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
	Parent msf4jParent = new Parent();
	msf4jParent.setGroupId(MSF4J_SERVICE_PARENT_GROUP_ID);
	msf4jParent.setArtifactId(MSF4J_SERVICE_PARENT_ARTIFACT_ID);
	msf4jParent.setVersion(MSF4JArtifactConstants.getMSF4JServiceParentVersion());
	mavenProject.getModel().setParent(msf4jParent);

	Properties generatedProperties = mavenProject.getModel().getProperties();
	generatedProperties.clear();

}
 
Example 12
Source Project: gcs   File: DocWriter.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
* Writes the markup attributes of the specified <CODE>MarkupAttributes</CODE>
* object to the <CODE>OutputStream</CODE>.
* @param markup   a <CODE>Properties</CODE> collection to write.
* @return true, if writing the markup attributes succeeded
* @throws IOException
*/
   protected boolean writeMarkupAttributes(Properties markup)
   throws IOException {
   	if (markup == null) return false;
   	Iterator attributeIterator = markup.keySet().iterator();
   	String name;
   	while (attributeIterator.hasNext()) {
   		name = String.valueOf(attributeIterator.next());
   		write(name, markup.getProperty(name));
   	}
   	markup.clear();
   	return true;
   }
 
Example 13
@Test
public void testTimeout() throws Exception {
    final String timeoutRuntimeConfigurationStateFileName = "timeoutRuntimeConfigurationState.txt";
    final String timeoutRunningStateFileName = "timeoutRunningState.txt";
    final Path timeoutRuntimeConfigurationStateChangeFile = data.resolve(timeoutRuntimeConfigurationStateFileName);
    final Path timeoutRunningStateChangeFile = data.resolve(timeoutRunningStateFileName);
    try {
        controller.startInAdminMode();
        // add listener with timeout
        final long hangListener = 1100; // ms
        final Integer timeout = 1; // s
        Properties p = new Properties();
        p.clear();
        p.setProperty(TestListener.TIMEOUT, Long.toString(hangListener));
        p.setProperty(TestListener.RUNTIME_CONFIGURATION_STATE_CHANGE_FILE, timeoutRuntimeConfigurationStateFileName);
        p.setProperty(TestListener.RUNNING_STATE_CHANGE_FILE, timeoutRunningStateFileName);
        addListener(TIMEOUT_LISTENER_ADDRESS, TestListener.class.getPackage().getName(), p, timeout);

        // this transition to restart-required should timeout runtimeConfigChanges, so there shouldn't be a record in file
        forceRestartRequired();
        // remove listener with timeout
        controller.getClient().executeForResult(Util.createRemoveOperation(TIMEOUT_LISTENER_ADDRESS));
        assertLogContains("WFLYCM0004");

        // should be empty as change RUNNING -> RESTART_REQUIRED shouldn't be logged due to timeout
        RuntimeConfigurationStateChanges timeoutRuntimeConfigChanges = new RuntimeConfigurationStateChanges(timeoutRuntimeConfigurationStateChangeFile);
        timeoutRuntimeConfigChanges.verify();

        RunningStateChanges timeoutRunningStateChanges = new RunningStateChanges(timeoutRunningStateChangeFile);
        timeoutRunningStateChanges.verify();
    } finally {
        controller.stop();
        PathUtil.deleteSilentlyRecursively(timeoutRuntimeConfigurationStateChangeFile);
        PathUtil.deleteSilentlyRecursively(timeoutRunningStateChangeFile);
    }
}
 
Example 14
Source Project: hop   File: ConcurrentMapPropertiesTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void runMapTests() throws IOException {
  Properties p = new Properties();
  ConcurrentMapProperties c = new ConcurrentMapProperties();

  for ( int i = 0; i < 10000; i++ ) {
    String unique = UUID.randomUUID().toString();
    p.put( unique, unique );
    c.put( unique, unique );
  }

  Assert.assertTrue( p.equals( c ) );
  Assert.assertEquals( p.size(), c.size() );

  List<String> removeKeys = new ArrayList<>( c.size() );

  for ( Object key : c.keySet() ) {
    if ( Math.random() > 0.2 ) {
      removeKeys.add( (String) key );
    }
  }

  for ( String rmKey : removeKeys ) {
    c.remove( rmKey );
    p.remove( rmKey );
  }

  Assert.assertEquals( p.size(), c.size() );
  Assert.assertTrue( p.equals( c ) );

  p.clear();
  c.clear();

  Assert.assertTrue( p.equals( c ) );
  Assert.assertEquals( 0, p.size() );
  Assert.assertEquals( 0, c.size() );

  Map<String, String> addKeys = removeKeys.stream().collect( Collectors.toMap( x -> x, x -> x ) );
  p.putAll( addKeys );
  c.putAll( addKeys );

  Assert.assertTrue( p.equals( c ) );

  for ( String property : removeKeys ) {
    Assert.assertEquals( p.getProperty( property ), c.getProperty( property ) );
  }

  Path tempFile = Files.createTempFile( "propstest", "props" );

  c.store( new FileOutputStream( tempFile.toFile() ), "No Comments" );
  c.clear();

  Assert.assertEquals( 0, c.size() );

  c.load( new FileInputStream( tempFile.toFile() ) );

  Assert.assertEquals( c, p );
}
 
Example 15
Source Project: gemfirexd-oss   File: DBSynchronizer.java    License: Apache License 2.0 4 votes vote down vote up
protected synchronized void instantiateConnection() {
  if (this.driver == null) {
    initConnection();
    return;
  }
  String maskedPasswordDbUrl = null;
  try {
    // use Driver directly for connect instead of looping through all
    // drivers as DriverManager.getConnection() would do, to avoid
    // hitting any broken drivers in the process (vertica driver is known to
    //   fail in acceptsURL with this set of properties)
    final Properties props = new Properties();
    // the user/password property names are standard ones also used by
    // DriverManager.getConnection(String, String, String) itself, so
    // will work for all drivers
    if (this.userName != null) {
      props.put("user", this.userName);
    }
    if (this.passwd != null) {
      // password is now stored encrypted
      String decPasswd = AsyncEventHelper.decryptPassword(this.userName,
          this.passwd, this.transformation, this.keySize);
      props.put("password", decPasswd);
      decPasswd = null;
    }

    this.conn = this.driver.connect(this.dbUrl, props);
    // null to GC password as soon as possible
    props.clear();
    try {
      // try to set the default isolation to at least READ_COMMITTED
      // need it for proper HA handling
      if (this.conn.getTransactionIsolation() < Connection
          .TRANSACTION_READ_COMMITTED && this.conn.getMetaData()
          .supportsTransactionIsolationLevel(
              Connection.TRANSACTION_READ_COMMITTED)) {
        this.conn
            .setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        if (this.dbUrl != null) {
          maskedPasswordDbUrl = maskPassword(this.dbUrl);
        }
        logger.info("explicitly set the transaction isolation level to "
            + "READ_COMMITTED for URL: " + maskedPasswordDbUrl);
      }
    } catch (SQLException sqle) {
      // ignore any exception here
    }
    this.conn.setAutoCommit(false);
    this.shutDown = false;
  } catch (Exception e) {
    if (this.dbUrl != null) {
      maskedPasswordDbUrl = maskPassword(this.dbUrl);
    }
    // throttle retries for connection failures
    try {
      Thread.sleep(200);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
    }
    throw helper.newRuntimeException(String.format(Gfxd_DB_SYNCHRONIZER__6,
        this.driverClass, maskedPasswordDbUrl), e);
  }
}
 
Example 16
public void testTinyint1IsBit() throws Exception {
    String tableName = "testTinyint1IsBit";
    // Can't use 'BIT' or boolean
    createTable(tableName, "(field1 TINYINT(1))");
    this.stmt.executeUpdate("INSERT INTO " + tableName + " VALUES (1)");

    Properties props = new Properties();
    props.setProperty(PropertyKey.tinyInt1isBit.getKeyName(), "true");
    props.setProperty(PropertyKey.transformedBitIsBoolean.getKeyName(), "true");
    Connection boolConn = getConnectionWithProps(props);

    this.rs = boolConn.createStatement().executeQuery("SELECT field1 FROM " + tableName);
    checkBitOrBooleanType(false);

    this.rs = boolConn.prepareStatement("SELECT field1 FROM " + tableName).executeQuery();
    checkBitOrBooleanType(false);

    this.rs = boolConn.getMetaData().getColumns(boolConn.getCatalog(), null, tableName, "field1");
    assertTrue(this.rs.next());

    assertEquals(Types.BOOLEAN, this.rs.getInt("DATA_TYPE"));

    assertEquals("BOOLEAN", this.rs.getString("TYPE_NAME"));

    props.clear();
    props.setProperty(PropertyKey.transformedBitIsBoolean.getKeyName(), "false");
    props.setProperty(PropertyKey.tinyInt1isBit.getKeyName(), "true");

    Connection bitConn = getConnectionWithProps(props);

    this.rs = bitConn.createStatement().executeQuery("SELECT field1 FROM " + tableName);
    checkBitOrBooleanType(true);

    this.rs = bitConn.prepareStatement("SELECT field1 FROM " + tableName).executeQuery();
    checkBitOrBooleanType(true);

    this.rs = bitConn.getMetaData().getColumns(boolConn.getCatalog(), null, tableName, "field1");
    assertTrue(this.rs.next());

    assertEquals(Types.BIT, this.rs.getInt("DATA_TYPE"));

    assertEquals("BIT", this.rs.getString("TYPE_NAME"));
}
 
Example 17
public void testTinyint1IsBit() throws Exception {
    String tableName = "testTinyint1IsBit";
    // Can't use 'BIT' or boolean
    createTable(tableName, "(field1 TINYINT(1))");
    this.stmt.executeUpdate("INSERT INTO " + tableName + " VALUES (1)");

    Properties props = new Properties();
    props.setProperty("tinyint1IsBit", "true");
    props.setProperty("transformedBitIsBoolean", "true");
    Connection boolConn = getConnectionWithProps(props);

    this.rs = boolConn.createStatement().executeQuery("SELECT field1 FROM " + tableName);
    checkBitOrBooleanType(false);

    this.rs = boolConn.prepareStatement("SELECT field1 FROM " + tableName).executeQuery();
    checkBitOrBooleanType(false);

    this.rs = boolConn.getMetaData().getColumns(boolConn.getCatalog(), null, tableName, "field1");
    assertTrue(this.rs.next());

    if (versionMeetsMinimum(4, 1)) {
        assertEquals(Types.BOOLEAN, this.rs.getInt("DATA_TYPE"));
    } else {
        assertEquals(Types.BIT, this.rs.getInt("DATA_TYPE"));
    }

    if (versionMeetsMinimum(4, 1)) {
        assertEquals("BOOLEAN", this.rs.getString("TYPE_NAME"));
    } else {
        assertEquals("BIT", this.rs.getString("TYPE_NAME"));
    }

    props.clear();
    props.setProperty("transformedBitIsBoolean", "false");
    props.setProperty("tinyint1IsBit", "true");

    Connection bitConn = getConnectionWithProps(props);

    this.rs = bitConn.createStatement().executeQuery("SELECT field1 FROM " + tableName);
    checkBitOrBooleanType(true);

    this.rs = bitConn.prepareStatement("SELECT field1 FROM " + tableName).executeQuery();
    checkBitOrBooleanType(true);

    this.rs = bitConn.getMetaData().getColumns(boolConn.getCatalog(), null, tableName, "field1");
    assertTrue(this.rs.next());

    assertEquals(Types.BIT, this.rs.getInt("DATA_TYPE"));

    assertEquals("BIT", this.rs.getString("TYPE_NAME"));
}
 
Example 18
/**
 * Tests fix for Bug #27652379, NPE FROM GETSESSION(PROPERTIES) WHEN HOST PARAMETER IS GIVEN IN SMALL LETTER.
 */
@Test
public void testBug27652379() throws Exception {
    if (!this.isSetForXTests) {
        return;
    }

    Properties props = new Properties();

    // Upper case keys.
    props.clear();
    props.setProperty("HOST", getTestHost());
    props.setProperty("PORT", String.valueOf(getTestPort()));
    props.setProperty("USER", getTestUser());
    props.setProperty("PASSWORD", getTestPassword());
    props.setProperty("DBNAME", getTestDatabase());

    Session testSession = this.fact.getSession(props);
    assertEquals(getTestDatabase(), testSession.getDefaultSchemaName());
    testSession.close();

    testSession = this.fact.getSession(new Properties(props));
    assertEquals(getTestDatabase(), testSession.getDefaultSchemaName());
    testSession.close();

    // Lower case keys.
    props.clear();
    props.setProperty("host", getTestHost());
    props.setProperty("port", String.valueOf(getTestPort()));
    props.setProperty("user", getTestUser());
    props.setProperty("password", getTestPassword());
    props.setProperty("dbname", getTestDatabase());

    testSession = this.fact.getSession(props);
    assertEquals(getTestDatabase(), testSession.getDefaultSchemaName());
    testSession.close();

    testSession = this.fact.getSession(new Properties(props));
    assertEquals(getTestDatabase(), testSession.getDefaultSchemaName());
    testSession.close();

    // Random case keys.
    props.clear();
    props.setProperty("HOst", getTestHost());
    props.setProperty("poRT", String.valueOf(getTestPort()));
    props.setProperty("uSEr", getTestUser());
    props.setProperty("PassworD", getTestPassword());
    props.setProperty("DbNaMe", getTestDatabase());

    testSession = this.fact.getSession(props);
    assertEquals(getTestDatabase(), testSession.getDefaultSchemaName());
    testSession.close();

    testSession = this.fact.getSession(new Properties(props));
    assertEquals(getTestDatabase(), testSession.getDefaultSchemaName());
    testSession.close();
}
 
Example 19
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}
 
Example 20
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}