@Test public void driverPropertyInfoWithoutValues() throws SQLException { Driver driver = getDriver(); DriverPropertyInfo[] properties = driver.getPropertyInfo("jdbc:cloudspanner://localhost", null); assertEquals(12, properties.length); for (DriverPropertyInfo property : properties) { if (property.name.equals("AllowExtendedMode") || property.name.equals("AsyncDdlOperations") || property.name.equals("AutoBatchDdlOperations")) assertEquals("false", property.value); else if (property.name.equals("ReportDefaultSchemaAsNull")) assertEquals("true", property.value); else assertNull(property.value); } }
public void testPropertiesDescriptionsKeys() throws Exception { DriverPropertyInfo[] dpi = new NonRegisteringDriver().getPropertyInfo(dbUrl, null); for (int i = 0; i < dpi.length; i++) { String description = dpi[i].description; String propertyName = dpi[i].name; if (description.indexOf("Missing error message for key '") != -1 || description.startsWith("!")) { fail("Missing message for configuration property " + propertyName); } if (description.length() < 10) { fail("Suspiciously short description for configuration property " + propertyName); } } }
/** * Fix for BUG#22628 - Driver.getPropertyInfo() throws NullPointerException * for URL that only specifies host and/or port. * * @throws Exception * if the test fails. */ public void testBug22628() throws Exception { DriverPropertyInfo[] dpi = new NonRegisteringDriver().getPropertyInfo("jdbc:mysql://bogus:9999", new Properties()); boolean foundHost = false; boolean foundPort = false; for (int i = 0; i < dpi.length; i++) { if ("bogus".equals(dpi[i].value)) { foundHost = true; } if ("9999".equals(dpi[i].value)) { foundPort = true; } } assertTrue(foundHost && foundPort); }
public DriverPropertyInfo[] getPropertyInfo( String url, Properties info) throws SQLException { List<DriverPropertyInfo> list = new ArrayList<DriverPropertyInfo>(); // First, add the contents of info for (Map.Entry<Object, Object> entry : info.entrySet()) { list.add( new DriverPropertyInfo( (String) entry.getKey(), (String) entry.getValue())); } // Next, add property definitions not mentioned in info for (ConnectionProperty p : getConnectionProperties()) { if (info.containsKey(p.name())) { continue; } list.add(new DriverPropertyInfo(p.name(), null)); } return list.toArray(new DriverPropertyInfo[list.size()]); }
@Test(groups = {"unit", "base"}) public void testGetPropertyInfo() { CassandraDriver driver = new CassandraDriver(); try { String url = "jdbc:c*:datastax://host1,host2/keyspace1?key=value"; DriverPropertyInfo[] info = driver.getPropertyInfo(url, new Properties()); assertNotNull(info); assertTrue(info.length > 1); for (DriverPropertyInfo i : info) { if (i.name.equals("consistencyLevel")) { assertNotNull(i.choices); assertTrue(i.choices.length > 1); } } } catch (Exception e) { e.printStackTrace(); fail("Exception happened during test: " + e.getMessage()); } }
public void testPropertiesDescriptionsKeys() throws Exception { DriverPropertyInfo[] dpi = new NonRegisteringDriver().getPropertyInfo( dbUrl, null); for (int i = 0; i < dpi.length; i++) { String description = dpi[i].description; String propertyName = dpi[i].name; if (description.indexOf("Missing error message for key '") != -1 || description.startsWith("!")) { fail("Missing message for configuration property " + propertyName); } if (description.length() < 10) { fail("Suspiciously short description for configuration property " + propertyName); } } }
/** * Fix for BUG#22628 - Driver.getPropertyInfo() throws NullPointerException * for URL that only specifies host and/or port. * * @throws Exception * if the test fails. */ public void testBug22628() throws Exception { DriverPropertyInfo[] dpi = new NonRegisteringDriver().getPropertyInfo( "jdbc:mysql://bogus:9999", new Properties()); boolean foundHost = false; boolean foundPort = false; for (int i = 0; i < dpi.length; i++) { if ("bogus".equals(dpi[i].value)) { foundHost = true; } if ("9999".equals(dpi[i].value)) { foundPort = true; } } assertTrue(foundHost && foundPort); }
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { if(info == null) { info = new Properties(); } else { info = PropertiesUtils.clone(info); } // construct list of driverPropertyInfo objects List<DriverPropertyInfo> driverProps = new LinkedList<DriverPropertyInfo>(); parseURL(url, info); for (String property: JDBCURL.KNOWN_PROPERTIES.keySet()) { DriverPropertyInfo dpi = new DriverPropertyInfo(property, info.getProperty(property)); if (property.equals(BaseDataSource.VDB_NAME)) { dpi.required = true; } driverProps.add(dpi); } // create an array of DriverPropertyInfo objects DriverPropertyInfo [] propInfo = new DriverPropertyInfo[driverProps.size()]; // copy the elements from the list to the array return driverProps.toArray(propInfo); }
/** * Tests that the {@link DriverPropertyInfo} array returned from * {@link Driver#getPropertyInfo(String, Properties)} contains * the correct <code>required</code> value on each of the objects. */ public void test_getPropertyInfo_Required() { Map requiredTrueMap = new HashMap(); requiredTrueMap.put(Messages.get(Driver.SERVERNAME), Boolean.TRUE); requiredTrueMap.put(Messages.get(Driver.SERVERTYPE), Boolean.TRUE); final Map infoMap = new HashMap(); loadDriverPropertyInfoMap(infoMap); final Iterator iterator = infoMap.keySet().iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); DriverPropertyInfo info = (DriverPropertyInfo) infoMap.get(key); if (requiredTrueMap.containsKey(key)) { assertTrue("The 'required' field is not true for key " + key, info.required); } else { assertFalse("The 'required' field is not false for key " + key, info.required); } } }
public void testPublicFields() { // Constructor here... DriverPropertyInfo aDriverPropertyInfo = new DriverPropertyInfo( validName, validValue); assertTrue(Arrays.equals(testChoices, aDriverPropertyInfo.choices)); assertEquals(testValue, aDriverPropertyInfo.value); assertEquals(testRequired, aDriverPropertyInfo.required); assertEquals(testDescription, aDriverPropertyInfo.description); assertEquals(testName, aDriverPropertyInfo.name); aDriverPropertyInfo.choices = updateChoices; aDriverPropertyInfo.value = updateValue; aDriverPropertyInfo.required = updateRequired; aDriverPropertyInfo.description = updateDescription; aDriverPropertyInfo.name = updateName; assertTrue(Arrays.equals(updateChoices, aDriverPropertyInfo.choices)); assertEquals(updateValue, aDriverPropertyInfo.value); assertEquals(updateRequired, aDriverPropertyInfo.required); assertEquals(updateDescription, aDriverPropertyInfo.description); assertEquals(updateName, aDriverPropertyInfo.name); }
@Override public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { if (!acceptsURL(url)) return new DriverPropertyInfo[0]; ConnectionProperties properties = ConnectionProperties.parse(url); properties.setAdditionalConnectionProperties(info); return properties.getPropertyInfo(); }
@Test public void driverPropertyInfoWithURLValues() throws SQLException { Driver driver = getDriver(); DriverPropertyInfo[] properties = driver.getPropertyInfo( "jdbc:cloudspanner://localhost;Project=adroit-hall-xxx;Instance=test-instance;Database=testdb;PvtKeyPath=C:\\Users\\MyUserName\\Documents\\CloudSpannerKeys\\cloudspanner3.json;SimulateProductName=PostgreSQL", null); assertEquals(12, properties.length); assertEquals("adroit-hall-xxx", properties[0].value); assertEquals("test-instance", properties[1].value); assertEquals("testdb", properties[2].value); assertEquals("C:\\Users\\MyUserName\\Documents\\CloudSpannerKeys\\cloudspanner3.json", properties[3].value); assertNull(properties[4].value); assertEquals("PostgreSQL", properties[5].value); }
private DriverPropertyInfo[] getPropertyInfos() { try { String e = this.hostTextField.getText(); if(e == null || "".equals(e)) { e = "192.168.0.0"; } String port = this.portTextField.getText(); if(port == null || "".equals(port)) { port = "1234"; } String db = this.databaseTextField.getText(); if(db == null || "".equals(db)) { db = "test"; } String prop = this.propertyTextField.getText(); if (prop == null || "".equals(prop)) { prop = ""; } String driverURL = FieldConnectionEntry.createURL(this.getJDBCProperties(), e, port, db, prop); Driver driver = DriverManager.getDriver(driverURL); Properties givenProperties = this.currentlyEditedEntry.getConnectionProperties(); DriverPropertyInfo[] propertyInfo = driver.getPropertyInfo(driverURL, givenProperties); if(propertyInfo == null) { propertyInfo = new DriverPropertyInfo[0]; } return propertyInfo; } catch (SQLException var8) { LogService.getRoot().log(Level.SEVERE, "com.rapidminer.gui.tools.dialogs.DatabaseConnectionDialog.loading_jdbc_driver_properties_error", var8); return null; } }
private DriverPropertyInfoTableModel(DriverPropertyInfo[] propInfo, Properties currentProperties) { this.propInfo = propInfo; this.override = new ArrayList(propInfo.length); for(int i = 0; i < this.propInfo.length; ++i) { if(currentProperties.get(propInfo[i].name) != null) { this.override.add(Boolean.valueOf(true)); } else { this.override.add(Boolean.valueOf(false)); } } }