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

The following are Jave code examples for showing how to use clear() of the java.util.Properties class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ProyectoPacientes   File: ResultSetRegressionTest.java   View Source Code Vote up 6 votes
public void testBug24886() throws Exception {
    Properties props = new Properties();
    props.setProperty("blobsAreStrings", "true");

    Connection noBlobConn = getConnectionWithProps(props);

    createTable("testBug24886", "(sepallength double, sepalwidth double, petallength double, petalwidth double, Class mediumtext, fy TIMESTAMP)");

    noBlobConn.createStatement().executeUpdate("INSERT INTO testBug24886 VALUES (1,2,3,4,'1234', now()),(5,6,7,8,'12345678', now())");
    this.rs = noBlobConn.createStatement()
            .executeQuery("SELECT concat(Class,petallength), COUNT(*) FROM `testBug24886` GROUP BY `concat(Class,petallength)`");
    this.rs.next();
    assertEquals("java.lang.String", this.rs.getObject(1).getClass().getName());

    props.clear();
    props.setProperty("functionsNeverReturnBlobs", "true");
    noBlobConn = getConnectionWithProps(props);
    this.rs = noBlobConn.createStatement()
            .executeQuery("SELECT concat(Class,petallength), COUNT(*) FROM `testBug24886` GROUP BY `concat(Class,petallength)`");
    this.rs.next();

    if (versionMeetsMinimum(4, 1)) {
        assertEquals("java.lang.String", this.rs.getObject(1).getClass().getName());

    }
}
 
Example 2
Project: oscm-app   File: ServiceInstance.java   View Source Code Vote up 6 votes
public void prepareRollback() throws BadResultException {
    Properties actualProperties = new Properties();
    actualProperties.put(ROLLBACK_SUBSCRIPTIONID, this.getSubscriptionId());
    if (this.getReferenceId() != null) {
        actualProperties.put(ROLLBACK_SUBSCRIPTIONREF,
                this.getReferenceId());
    } else {
        actualProperties.put(ROLLBACK_SUBSCRIPTIONREF, "");
    }
    actualProperties.putAll(this.getParameterMap());
    this.setRollbackParameters(
            this.convertPropertiesToXML(actualProperties));
    actualProperties.clear();
    actualProperties.putAll(getAttributeMap());
    this.setRollbackInstanceAttributes(
            this.convertPropertiesToXML(actualProperties));
}
 
Example 3
Project: BibliotecaPS   File: ResultSetRegressionTest.java   View Source Code Vote up 6 votes
public void testBug24886() throws Exception {
    Properties props = new Properties();
    props.setProperty("blobsAreStrings", "true");

    Connection noBlobConn = getConnectionWithProps(props);

    createTable("testBug24886", "(sepallength double, sepalwidth double, petallength double, petalwidth double, Class mediumtext, fy TIMESTAMP)");

    noBlobConn.createStatement().executeUpdate("INSERT INTO testBug24886 VALUES (1,2,3,4,'1234', now()),(5,6,7,8,'12345678', now())");
    this.rs = noBlobConn.createStatement()
            .executeQuery("SELECT concat(Class,petallength), COUNT(*) FROM `testBug24886` GROUP BY `concat(Class,petallength)`");
    this.rs.next();
    assertEquals("java.lang.String", this.rs.getObject(1).getClass().getName());

    props.clear();
    props.setProperty("functionsNeverReturnBlobs", "true");
    noBlobConn = getConnectionWithProps(props);
    this.rs = noBlobConn.createStatement()
            .executeQuery("SELECT concat(Class,petallength), COUNT(*) FROM `testBug24886` GROUP BY `concat(Class,petallength)`");
    this.rs.next();

    if (versionMeetsMinimum(4, 1)) {
        assertEquals("java.lang.String", this.rs.getObject(1).getClass().getName());

    }
}
 
Example 4
Project: gemini.blueprint   File: PropertiesUtil.java   View Source Code Vote up 6 votes
/**
 * Merges the given map into the target properties object. Additionally it checks if there are any given local
 * properties and whether these can override the source.
 * 
 * @return a new (Properties) object mergeing the local properties and the source
 */
public static Properties initProperties(Properties localMap, boolean localOverride, Map<?, ?> source,
		Properties target) {

	synchronized (target) {
		target.clear();

		// merge the local properties (upfront)
		if (localMap != null && !localOverride) {
			CollectionUtils.mergePropertiesIntoMap(localMap, target);
		}

		if (source != null) {
			target.putAll(source);
		}

		// merge local properties (if needed)
		if (localMap != null && localOverride) {
			CollectionUtils.mergePropertiesIntoMap(localMap, target);
		}

		return target;
	}
}
 
Example 5
Project: OpenVertretung   File: ResultSetRegressionTest.java   View Source Code Vote up 6 votes
public void testBug24886() throws Exception {
    Properties props = new Properties();
    props.setProperty("blobsAreStrings", "true");

    Connection noBlobConn = getConnectionWithProps(props);

    createTable("testBug24886", "(sepallength double, sepalwidth double, petallength double, petalwidth double, Class mediumtext, fy TIMESTAMP)");

    noBlobConn.createStatement().executeUpdate("INSERT INTO testBug24886 VALUES (1,2,3,4,'1234', now()),(5,6,7,8,'12345678', now())");
    this.rs = noBlobConn.createStatement()
            .executeQuery("SELECT concat(Class,petallength), COUNT(*) FROM `testBug24886` GROUP BY `concat(Class,petallength)`");
    this.rs.next();
    assertEquals("java.lang.String", this.rs.getObject(1).getClass().getName());

    props.clear();
    props.setProperty("functionsNeverReturnBlobs", "true");
    noBlobConn = getConnectionWithProps(props);
    this.rs = noBlobConn.createStatement()
            .executeQuery("SELECT concat(Class,petallength), COUNT(*) FROM `testBug24886` GROUP BY `concat(Class,petallength)`");
    this.rs.next();

    if (versionMeetsMinimum(4, 1)) {
        assertEquals("java.lang.String", this.rs.getObject(1).getClass().getName());

    }
}
 
Example 6
Project: Uranium   File: Uranium.java   View Source Code Vote up 5 votes
private static void parseManifest() {
    if (sManifestParsed)
        return;
    sManifestParsed = true;

    try {
        Enumeration<URL> resources = Uranium.class.getClassLoader()
                .getResources("META-INF/MANIFEST.MF");
        Properties manifest = new Properties();
        while (resources.hasMoreElements()) {
            URL url = resources.nextElement();
            manifest.load(url.openStream());
            String version = manifest.getProperty("Uranium-Version");
            if (version != null) {
                String path = url.getPath();
                String jarFilePath = path.substring(path.indexOf(":") + 1,
                        path.indexOf("!"));
                jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
                sServerLocation = new File(jarFilePath);

                sCurrentVersion = version;
                sGroup = manifest.getProperty("Uranium-Group");
                sBranch = manifest.getProperty("Uranium-Branch");
                sChannel = manifest.getProperty("Uranium-Channel");
                sLegacy = Boolean.parseBoolean(manifest.getProperty("Uranium-Legacy"));
                sOfficial = Boolean.parseBoolean(manifest.getProperty("Uranium-Official"));
                break;
            }
            manifest.clear();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Project: LivroJavaComoProgramar10Edicao   File: PropertiesTest.java   View Source Code Vote up 5 votes
public static void main(String[] args)
{
   Properties table = new Properties(); 

   // set properties
   table.setProperty("color", "blue");
   table.setProperty("width", "200");

   System.out.println("After setting properties");
   listProperties(table); 

   // replace property value
   table.setProperty("color", "red");

   System.out.println("After replacing properties");
   listProperties(table); 

   saveProperties(table);

   table.clear(); // empty table

   System.out.println("After clearing properties");
   listProperties(table); 
   
   loadProperties(table);

   // get value of property color
   Object value = table.getProperty("color");

   // check if value is in table
   if (value != null)
      System.out.printf("Property color's value is %s%n", value);
   else
      System.out.println("Property color is not in table");
}
 
Example 8
Project: gemini.blueprint   File: PropertiesUtil.java   View Source Code Vote up 5 votes
/**
 * Merges the given dictionary into the target properties object. Additionally it checks if there are any given
 * local properties and whether these can override the source. Identical to
 * {@link #initProperties(Properties, boolean, Map, Properties)} excepts it reads the dictionary directly to avoid
 * any mapping overhead.
 * 
 * @param localMap
 * @param localOverride
 * @param source
 * @param target
 * @return
 */
public static Properties initProperties(Properties localMap, boolean localOverride, Dictionary source,
		Properties target) {

	synchronized (target) {
		target.clear();

		// merge the local properties (upfront)
		if (localMap != null && !localOverride) {
			CollectionUtils.mergePropertiesIntoMap(localMap, target);
		}

		if (source != null) {
			Enumeration<?> keys = source.keys();
			for (; keys.hasMoreElements();) {
				Object key = keys.nextElement();
				Object value = source.get(key);
				if (key != null && value != null) {
					target.put(key, value);
				}
			}
		}

		// merge local properties (if needed)
		if (localMap != null && localOverride) {
			CollectionUtils.mergePropertiesIntoMap(localMap, target);
		}

		return target;
	}
}
 
Example 9
Project: CustomWorldGen   File: FMLCommonHandler.java   View Source Code Vote up 5 votes
/**
 * Loads a lang file, first searching for a marker to enable the 'extended' format {escape characters}
 * If the marker is not found it simply returns and let the vanilla code load things.
 * The Marker is 'PARSE_ESCAPES' by itself on a line starting with '#' as such:
 * #PARSE_ESCAPES
 *
 * @param table The Map to load each key/value pair into.
 * @param inputstream Input stream containing the lang file.
 * @return A new InputStream that vanilla uses to load normal Lang files, Null if this is a 'enhanced' file and loading is done.
 */
public InputStream loadLanguage(Map<String, String> table, InputStream inputstream) throws IOException
{
    byte[] data = IOUtils.toByteArray(inputstream);

    boolean isEnhanced = false;
    for (String line : IOUtils.readLines(new ByteArrayInputStream(data), Charsets.UTF_8))
    {
        if (!line.isEmpty() && line.charAt(0) == '#')
        {
            line = line.substring(1).trim();
            if (line.equals("PARSE_ESCAPES"))
            {
                isEnhanced = true;
                break;
            }
        }
    }

    if (!isEnhanced)
        return new ByteArrayInputStream(data);

    Properties props = new Properties();
    props.load(new InputStreamReader(new ByteArrayInputStream(data), Charsets.UTF_8));
    for (Entry<Object, Object> e : props.entrySet())
    {
        table.put((String)e.getKey(), (String)e.getValue());
    }
    props.clear();
    return null;
}
 
Example 10
Project: ProyectoPacientes   File: ConnectionRegressionTest.java   View Source Code Vote up 4 votes
/**
 * Tests fix for Bug#77171 - On every connect getting sql_mode from server creates unnecessary exception.
 * 
 * This fix is a refactoring on ConnectorImpl.initializePropsFromServer() to improve performance when processing the SQL_MODE value. No behavior was
 * changed. This test guarantees that nothing was broken in these matters, for the relevant MySQL versions, after this fix.
 */
public void testBug77171() throws Exception {
    String sqlMode = getMysqlVariable("sql_mode");
    sqlMode = removeSqlMode("ANSI_QUOTES", sqlMode);
    sqlMode = removeSqlMode("NO_BACKSLASH_ESCAPES", sqlMode);
    String newSqlMode = sqlMode;
    if (sqlMode.length() > 0) {
        sqlMode += ",";
    }

    Properties props = new Properties();
    props.put("sessionVariables", "sql_mode='" + newSqlMode + "'");
    Connection testConn = getConnectionWithProps(props);
    assertFalse(((MySQLConnection) testConn).useAnsiQuotedIdentifiers());
    assertFalse(((MySQLConnection) testConn).isNoBackslashEscapesSet());
    testConn.close();

    props.clear();
    newSqlMode = sqlMode + "ANSI_QUOTES";
    props.put("sessionVariables", "sql_mode='" + newSqlMode + "'");
    testConn = getConnectionWithProps(props);
    assertTrue(((MySQLConnection) testConn).useAnsiQuotedIdentifiers());
    assertFalse(((MySQLConnection) testConn).isNoBackslashEscapesSet());
    testConn.close();

    props.clear();
    newSqlMode = sqlMode + "NO_BACKSLASH_ESCAPES";
    props.put("sessionVariables", "sql_mode='" + newSqlMode + "'");
    testConn = getConnectionWithProps(props);
    assertFalse(((MySQLConnection) testConn).useAnsiQuotedIdentifiers());
    assertTrue(((MySQLConnection) testConn).isNoBackslashEscapesSet());
    testConn.close();

    props.clear();
    newSqlMode = sqlMode + "ANSI_QUOTES,NO_BACKSLASH_ESCAPES";
    props.put("sessionVariables", "sql_mode='" + newSqlMode + "'");
    testConn = getConnectionWithProps(props);
    assertTrue(((MySQLConnection) testConn).useAnsiQuotedIdentifiers());
    assertTrue(((MySQLConnection) testConn).isNoBackslashEscapesSet());
    testConn.close();
}
 
Example 11
Project: incubator-netbeans   File: J2SEActionProviderTest.java   View Source Code Vote up 4 votes
public void testBuildWithDirtyList() throws Exception { // #104508
    EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    ep.put(ProjectProperties.TRACK_FILE_CHANGES, "true");
    helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
    Properties p = new Properties();
    assertEquals("[jar]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_BUILD, Lookup.EMPTY, p)));
    assertEquals("{}", p.toString());
    TestFileUtils.touch(someSource1.getPrimaryFile(), null);
    assertEquals("[jar]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_BUILD, Lookup.EMPTY, p)));
    assertEquals("{}", p.toString());
    ep = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
    ep.put(ProjectProperties.DO_JAR, "false");
    helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep);
    assertEquals("[compile]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_BUILD, Lookup.EMPTY, p)));
    assertEquals("{}", p.toString());
    ep.put(ProjectProperties.DO_DEPEND, "false");
    helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep);
    assertEquals("[compile]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_BUILD, Lookup.EMPTY, p)));
    assertEquals("{}", p.toString());
    TestFileUtils.touch(someSource1.getPrimaryFile(), null);
    assertEquals("[compile]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_BUILD, Lookup.EMPTY, p)));
    assertEquals("{includes=foo/Bar.java}", p.toString());
    p.clear();
    TestFileUtils.touch(someSource2.getPrimaryFile(), null);
    TestFileUtils.touch(someSource1.getPrimaryFile(), null);
    assertEquals("[compile]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_BUILD, Lookup.EMPTY, p)));
    assertEquals("{includes=foo/Bar.java,foo/Main.java}", p.toString());
    p.clear();
    assertEquals("[compile]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_BUILD, Lookup.EMPTY, p)));
    assertEquals("{}", p.toString());
    TestFileUtils.touch(someTest1.getPrimaryFile(), null);
    assertEquals("[compile]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_BUILD, Lookup.EMPTY, p)));
    assertEquals("{}", p.toString());
    sources.createData("x.properties");
    assertEquals("[compile]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_BUILD, Lookup.EMPTY, p)));
    assertEquals("{includes=x.properties}", p.toString());
    p.clear();
    someSource1.setModified(true);
    assertEquals("[compile]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_BUILD, Lookup.EMPTY, p)));
    assertEquals("{includes=foo/Bar.java}", p.toString());
    p.clear();
    TestFileUtils.touch(someSource1.getPrimaryFile(), null);
    assertEquals("[clean, compile]", Arrays.toString(actionProvider.getTargetNames(ActionProvider.COMMAND_REBUILD, Lookup.EMPTY, p)));
    assertEquals("{}", p.toString());
}
 
Example 12
Project: ProyectoPacientes   File: MetadataTest.java   View Source Code Vote up 4 votes
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 13
Project: BibliotecaPS   File: ConnectionRegressionTest.java   View Source Code Vote up 4 votes
/**
 * Tests fix for BUG#20685022 - SSL CONNECTION TO MYSQL 5.7.6 COMMUNITY SERVER FAILS
 * 
 * This test is duplicated in testuite.regression.ConnectionRegressionTest.jdbc4.testBug20685022().
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20685022() throws Exception {
    if (!isCommunityEdition()) {
        return;
    }

    final Properties props = new Properties();

    /*
     * case 1: non verifying server certificate
     */
    props.clear();
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("verifyServerCertificate", "false");

    getConnectionWithProps(props);

    /*
     * case 2: verifying server certificate using key store provided by connection properties
     */
    props.clear();
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("verifyServerCertificate", "true");
    props.setProperty("trustCertificateKeyStoreUrl", "file:src/testsuite/ssl-test-certs/ca-truststore");
    props.setProperty("trustCertificateKeyStoreType", "JKS");
    props.setProperty("trustCertificateKeyStorePassword", "password");

    getConnectionWithProps(props);

    /*
     * case 3: verifying server certificate using key store provided by system properties
     */
    props.clear();
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("verifyServerCertificate", "true");

    String trustStorePath = "src/testsuite/ssl-test-certs/ca-truststore";
    System.setProperty("javax.net.ssl.keyStore", trustStorePath);
    System.setProperty("javax.net.ssl.keyStorePassword", "password");
    System.setProperty("javax.net.ssl.trustStore", trustStorePath);
    System.setProperty("javax.net.ssl.trustStorePassword", "password");

    getConnectionWithProps(props);
}
 
Example 14
Project: the-vigilantes   File: MetadataTest.java   View Source Code Vote up 4 votes
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 15
Project: the-vigilantes   File: ConnectionRegressionTest.java   View Source Code Vote up 4 votes
/**
 * Tests fix for BUG#20685022 - SSL CONNECTION TO MYSQL 5.7.6 COMMUNITY SERVER FAILS
 * 
 * This test is duplicated in testuite.regression.ConnectionRegressionTest.jdbc4.testBug20685022().
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20685022() throws Exception {
    if (!isCommunityEdition()) {
        return;
    }

    final Properties props = new Properties();

    /*
     * case 1: non verifying server certificate
     */
    props.clear();
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("verifyServerCertificate", "false");

    getConnectionWithProps(props);

    /*
     * case 2: verifying server certificate using key store provided by connection properties
     */
    props.clear();
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("verifyServerCertificate", "true");
    props.setProperty("trustCertificateKeyStoreUrl", "file:src/testsuite/ssl-test-certs/ca-truststore");
    props.setProperty("trustCertificateKeyStoreType", "JKS");
    props.setProperty("trustCertificateKeyStorePassword", "password");

    getConnectionWithProps(props);

    /*
     * case 3: verifying server certificate using key store provided by system properties
     */
    props.clear();
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("verifyServerCertificate", "true");

    String trustStorePath = "src/testsuite/ssl-test-certs/ca-truststore";
    System.setProperty("javax.net.ssl.keyStore", trustStorePath);
    System.setProperty("javax.net.ssl.keyStorePassword", "password");
    System.setProperty("javax.net.ssl.trustStore", trustStorePath);
    System.setProperty("javax.net.ssl.trustStorePassword", "password");

    getConnectionWithProps(props);
}
 
Example 16
Project: ProyectoPacientes   File: ConnectionRegressionTest.java   View Source Code Vote up 4 votes
/**
 * Tests fix for BUG#20685022 - SSL CONNECTION TO MYSQL 5.7.6 COMMUNITY SERVER FAILS
 * 
 * This test is duplicated in testuite.regression.ConnectionRegressionTest.testBug20685022().
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20685022() throws Exception {
    if (!isCommunityEdition()) {
        return;
    }

    final Properties props = new Properties();

    /*
     * case 1: non verifying server certificate
     */
    props.clear();
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("verifyServerCertificate", "false");

    getConnectionWithProps(props);

    /*
     * case 2: verifying server certificate using key store provided by connection properties
     */
    props.clear();
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("verifyServerCertificate", "true");
    props.setProperty("trustCertificateKeyStoreUrl", "file:src/testsuite/ssl-test-certs/ca-truststore");
    props.setProperty("trustCertificateKeyStoreType", "JKS");
    props.setProperty("trustCertificateKeyStorePassword", "password");

    getConnectionWithProps(props);

    /*
     * case 3: verifying server certificate using key store provided by system properties
     */
    props.clear();
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("verifyServerCertificate", "true");

    String trustStorePath = "src/testsuite/ssl-test-certs/ca-truststore";
    System.setProperty("javax.net.ssl.keyStore", trustStorePath);
    System.setProperty("javax.net.ssl.keyStorePassword", "password");
    System.setProperty("javax.net.ssl.trustStore", trustStorePath);
    System.setProperty("javax.net.ssl.trustStorePassword", "password");

    getConnectionWithProps(props);
}
 
Example 17
Project: monarch   File: GemFireCacheImplTest.java   View Source Code Vote up 4 votes
@Test
public void testIsMisConfigured() {
  Properties clusterProps = new Properties();
  Properties serverProps = new Properties();

  // both does not have the key
  assertFalse(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));

  // cluster has the key, not the server
  clusterProps.setProperty("key", "value");
  assertFalse(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));
  clusterProps.setProperty("key", "");
  assertFalse(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));

  // server has the key, not the cluster
  clusterProps.clear();
  serverProps.clear();
  serverProps.setProperty("key", "value");
  assertTrue(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));
  serverProps.setProperty("key", "");
  assertFalse(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));

  // server has the key, not the cluster
  clusterProps.clear();
  serverProps.clear();
  clusterProps.setProperty("key", "");
  serverProps.setProperty("key", "value");
  assertTrue(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));
  serverProps.setProperty("key", "");
  assertFalse(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));

  // server and cluster has the same value
  clusterProps.clear();
  serverProps.clear();
  clusterProps.setProperty("key", "value");
  serverProps.setProperty("key", "value");
  assertFalse(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));
  clusterProps.setProperty("key", "");
  serverProps.setProperty("key", "");
  assertFalse(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));

  // server and cluster has the different value
  clusterProps.clear();
  serverProps.clear();
  clusterProps.setProperty("key", "value1");
  serverProps.setProperty("key", "value2");
  assertTrue(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));
  clusterProps.setProperty("key", "value1");
  serverProps.setProperty("key", "");
  assertFalse(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));
}
 
Example 18
Project: BibliotecaPS   File: MetadataTest.java   View Source Code Vote up 4 votes
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 19
Project: OpenVertretung   File: MetadataTest.java   View Source Code Vote up 4 votes
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 20
Project: OpenVertretung   File: ConnectionRegressionTest.java   View Source Code Vote up 4 votes
/**
 * Tests fix for Bug#77171 - On every connect getting sql_mode from server creates unnecessary exception.
 * 
 * This fix is a refactoring on ConnectorImpl.initializePropsFromServer() to improve performance when processing the SQL_MODE value. No behavior was
 * changed. This test guarantees that nothing was broken in these matters, for the relevant MySQL versions, after this fix.
 */
public void testBug77171() throws Exception {
    String sqlMode = getMysqlVariable("sql_mode");
    sqlMode = removeSqlMode("ANSI_QUOTES", sqlMode);
    sqlMode = removeSqlMode("NO_BACKSLASH_ESCAPES", sqlMode);
    String newSqlMode = sqlMode;
    if (sqlMode.length() > 0) {
        sqlMode += ",";
    }

    Properties props = new Properties();
    props.put("sessionVariables", "sql_mode='" + newSqlMode + "'");
    Connection testConn = getConnectionWithProps(props);
    assertFalse(((MySQLConnection) testConn).useAnsiQuotedIdentifiers());
    assertFalse(((MySQLConnection) testConn).isNoBackslashEscapesSet());
    testConn.close();

    props.clear();
    newSqlMode = sqlMode + "ANSI_QUOTES";
    props.put("sessionVariables", "sql_mode='" + newSqlMode + "'");
    testConn = getConnectionWithProps(props);
    assertTrue(((MySQLConnection) testConn).useAnsiQuotedIdentifiers());
    assertFalse(((MySQLConnection) testConn).isNoBackslashEscapesSet());
    testConn.close();

    props.clear();
    newSqlMode = sqlMode + "NO_BACKSLASH_ESCAPES";
    props.put("sessionVariables", "sql_mode='" + newSqlMode + "'");
    testConn = getConnectionWithProps(props);
    assertFalse(((MySQLConnection) testConn).useAnsiQuotedIdentifiers());
    assertTrue(((MySQLConnection) testConn).isNoBackslashEscapesSet());
    testConn.close();

    props.clear();
    newSqlMode = sqlMode + "ANSI_QUOTES,NO_BACKSLASH_ESCAPES";
    props.put("sessionVariables", "sql_mode='" + newSqlMode + "'");
    testConn = getConnectionWithProps(props);
    assertTrue(((MySQLConnection) testConn).useAnsiQuotedIdentifiers());
    assertTrue(((MySQLConnection) testConn).isNoBackslashEscapesSet());
    testConn.close();
}