You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by nr...@apache.org on 2017/11/10 23:04:40 UTC
[geode] 01/02: simplify jdbc configuration
This is an automated email from the ASF dual-hosted git repository.
nreich pushed a commit to branch feature/GEODE-3781
in repository https://gitbox.apache.org/repos/asf/geode.git
commit 002f656c709cbe2ebd21e3dcf4d3a892e30b5637
Author: Nick Reich <nr...@pivotal.io>
AuthorDate: Mon Nov 6 17:46:31 2017 -0800
simplify jdbc configuration
---
.../jdbc/internal/JDBCConfiguration.java | 190 ++++++---------------
.../connectors/jdbc/internal/JDBCManager.java | 32 ++--
.../jdbc/internal/JDBCPropertyParser.java | 47 +++++
.../jdbc/internal/JDBCConfigurationUnitTest.java | 112 +-----------
.../jdbc/internal/JDBCManagerUnitTest.java | 6 +-
.../jdbc/internal/JDBCPropertyParserTest.java | 64 +++++++
6 files changed, 190 insertions(+), 261 deletions(-)
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCConfiguration.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCConfiguration.java
index d051b01..9e14112 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCConfiguration.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCConfiguration.java
@@ -18,15 +18,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.Set;
import java.util.function.Function;
-import java.util.function.IntPredicate;
public class JDBCConfiguration {
+ private static final boolean DEFAULT_KEY_IN_VALUE = false; //TODO: determine what default is
private static final String URL = "url";
private static final String USER = "user";
private static final String PASSWORD = "password";
@@ -61,83 +59,29 @@ public class JDBCConfiguration {
*/
private static final String FIELD_TO_COLUMN = "fieldToColumn";
- private static final List<String> knownProperties =
- Collections.unmodifiableList(Arrays.asList(URL, USER, PASSWORD, VALUE_CLASS_NAME,
- IS_KEY_PART_OF_VALUE, REGION_TO_TABLE, FIELD_TO_COLUMN));
-
private static final List<String> requiredProperties =
Collections.unmodifiableList(Arrays.asList(URL));
private final String url;
private final String user;
private final String password;
- private final String valueClassNameDefault;
private final Map<String, String> regionToClassMap;
- private final boolean keyPartOfValueDefault;
private final Map<String, Boolean> keyPartOfValueMap;
private final Map<String, String> regionToTableMap;
private final Map<RegionField, String> fieldToColumnMap;
public JDBCConfiguration(Properties configProps) {
- validateKnownProperties(configProps);
validateRequiredProperties(configProps);
this.url = configProps.getProperty(URL);
this.user = configProps.getProperty(USER);
this.password = configProps.getProperty(PASSWORD);
- String valueClassNameProp = configProps.getProperty(VALUE_CLASS_NAME);
- this.valueClassNameDefault = computeDefaultValueClassName(valueClassNameProp);
- this.regionToClassMap = computeRegionToClassMap(valueClassNameProp);
- String keyPartOfValueProp = configProps.getProperty(IS_KEY_PART_OF_VALUE);
- this.keyPartOfValueDefault = computeDefaultKeyPartOfValue(keyPartOfValueProp);
- this.keyPartOfValueMap = computeKeyPartOfValueMap(keyPartOfValueProp);
- this.regionToTableMap = computeRegionToTableMap(configProps.getProperty(REGION_TO_TABLE));
+ JDBCPropertyParser parser = new JDBCPropertyParser(configProps);
+ this.regionToClassMap = parser.getPropertiesMap(VALUE_CLASS_NAME, v -> v);
+ this.keyPartOfValueMap = parser.getPropertiesMap(IS_KEY_PART_OF_VALUE, Boolean::parseBoolean);
+ this.regionToTableMap = parser.getPropertiesMap(REGION_TO_TABLE, v -> v);
this.fieldToColumnMap = computeFieldToColumnMap(configProps.getProperty(FIELD_TO_COLUMN));
}
- public static class RegionField {
- private final String regionName; // may be null
- private final String fieldName;
-
- public RegionField(String regionName, String fieldName) {
- this.regionName = regionName;
- this.fieldName = fieldName;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + fieldName.hashCode();
- result = prime * result + ((regionName == null) ? 0 : regionName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- RegionField other = (RegionField) obj;
- if (!fieldName.equals(other.fieldName)) {
- return false;
- }
- if (regionName == null) {
- if (other.regionName != null) {
- return false;
- }
- } else if (!regionName.equals(other.regionName)) {
- return false;
- }
- return true;
- }
- }
-
private Map<RegionField, String> computeFieldToColumnMap(String prop) {
Function<String, RegionField> regionFieldParser = new Function<String, RegionField>() {
@Override
@@ -157,26 +101,6 @@ public class JDBCConfiguration {
return parseMap(prop, regionFieldParser, v -> v, true);
}
- private Map<String, String> computeRegionToTableMap(String prop) {
- return parseMap(prop, k -> k, v -> v, true);
- }
-
- private String computeDefaultValueClassName(String valueClassNameProp) {
- return parseDefault(VALUE_CLASS_NAME, valueClassNameProp, v -> v, null);
- }
-
- private Map<String, String> computeRegionToClassMap(String valueClassNameProp) {
- return parseMap(valueClassNameProp, k -> k, v -> v, false);
- }
-
- private boolean computeDefaultKeyPartOfValue(String keyPartOfValueProp) {
- return parseDefault(IS_KEY_PART_OF_VALUE, keyPartOfValueProp, Boolean::parseBoolean, false);
- }
-
- private Map<String, Boolean> computeKeyPartOfValueMap(String keyPartOfValueProp) {
- return parseMap(keyPartOfValueProp, k -> k, Boolean::parseBoolean, false);
- }
-
private <K, V> Map<K, V> parseMap(String propertyValue, Function<String, K> keyParser,
Function<String, V> valueParser, boolean failOnNoSeparator) {
if (propertyValue == null) {
@@ -203,87 +127,41 @@ public class JDBCConfiguration {
return result;
}
- private <V> V parseDefault(String propertyName, String propertyValue, Function<String, V> parser,
- V defaultValue) {
- if (propertyValue == null) {
- return defaultValue;
- }
- V result = null;
- List<String> items = Arrays.asList(propertyValue.split("\\s*,\\s*"));
- for (String item : items) {
- int idx = item.indexOf(getjdbcSeparator());
- if (idx != -1) {
- continue;
- }
- if (result != null) {
- throw new IllegalArgumentException(propertyName
- + " can have at most one item that does not have a " + getjdbcSeparator() + " in it.");
- }
- result = parser.apply(item);
- }
- if (result == null) {
- result = defaultValue;
- }
- return result;
- }
-
-
- private void validateKnownProperties(Properties configProps) {
- Set<Object> keys = new HashSet<>(configProps.keySet());
- keys.removeAll(knownProperties);
- if (!keys.isEmpty()) {
- throw new IllegalArgumentException("unknown properties: " + keys);
- }
- }
-
private void validateRequiredProperties(Properties configProps) {
List<String> reqKeys = new ArrayList<>(requiredProperties);
- reqKeys.removeAll(configProps.keySet());
+ reqKeys.removeAll(configProps.stringPropertyNames());
if (!reqKeys.isEmpty()) {
Collections.sort(reqKeys);
throw new IllegalArgumentException("missing required properties: " + reqKeys);
}
}
- public String getURL() {
+ String getURL() {
return this.url;
}
- public String getUser() {
+ String getUser() {
return this.user;
}
- public String getPassword() {
+ String getPassword() {
return this.password;
}
- public String getValueClassName(String regionName) {
- if (this.regionToClassMap == null) {
- return this.valueClassNameDefault;
- }
- String result = this.regionToClassMap.get(regionName);
- if (result == null) {
- result = this.valueClassNameDefault;
- }
- return result;
+ String getValueClassName(String regionName) {
+ return regionToClassMap.get(regionName);
}
- public boolean getIsKeyPartOfValue(String regionName) {
- if (this.keyPartOfValueMap == null) {
- return this.keyPartOfValueDefault;
- }
+ boolean getIsKeyPartOfValue(String regionName) {
Boolean result = this.keyPartOfValueMap.get(regionName);
- if (result == null) {
- return this.keyPartOfValueDefault;
- }
- return result;
+ return result != null ? result : DEFAULT_KEY_IN_VALUE;
}
- protected String getjdbcSeparator() {
+ String getjdbcSeparator() {
return JDBC_SEPARATOR;
}
- public String getTableForRegion(String regionName) {
+ String getTableForRegion(String regionName) {
if (this.regionToTableMap == null) {
return regionName;
}
@@ -294,7 +172,7 @@ public class JDBCConfiguration {
return result;
}
- public String getColumnForRegionField(String regionName, String fieldName) {
+ String getColumnForRegionField(String regionName, String fieldName) {
if (this.fieldToColumnMap == null) {
return fieldName;
}
@@ -309,4 +187,40 @@ public class JDBCConfiguration {
}
return result;
}
+
+ public static class RegionField {
+ private final String regionName; // may be null
+ private final String fieldName;
+
+ public RegionField(String regionName, String fieldName) {
+ this.regionName = regionName;
+ this.fieldName = fieldName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ RegionField that = (RegionField) o;
+
+ if (regionName != null ? !regionName.equals(that.regionName) : that.regionName != null) {
+ return false;
+ }
+ return fieldName.equals(that.fieldName);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = regionName != null ? regionName.hashCode() : 0;
+ result = 31 * result + fieldName.hashCode();
+ return result;
+ }
+ }
+
}
+
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCManager.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCManager.java
index b228924..e1d7cad 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCManager.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCManager.java
@@ -286,29 +286,31 @@ public class JDBCManager {
}
@Override
- public int hashCode() {
- return operation.hashCode() + pdxTypeId + tableName.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
+ public boolean equals(Object o) {
+ if (this == o) {
return true;
}
- if (obj == null) {
- return false;
- }
- StatementKey other = (StatementKey) obj;
- if (!operation.equals(other.operation)) {
+ if (o == null || getClass() != o.getClass()) {
return false;
}
- if (pdxTypeId != other.pdxTypeId) {
+
+ StatementKey that = (StatementKey) o;
+
+ if (pdxTypeId != that.pdxTypeId) {
return false;
}
- if (!tableName.equals(other.tableName)) {
+ if (operation != null ? !operation.equals(that.operation) : that.operation != null) {
return false;
}
- return true;
+ return tableName != null ? tableName.equals(that.tableName) : that.tableName == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = pdxTypeId;
+ result = 31 * result + (operation != null ? operation.hashCode() : 0);
+ result = 31 * result + (tableName != null ? tableName.hashCode() : 0);
+ return result;
}
}
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCPropertyParser.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCPropertyParser.java
new file mode 100644
index 0000000..167a079
--- /dev/null
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCPropertyParser.java
@@ -0,0 +1,47 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * * copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * * or implied. See the License for the specific language governing permissions and limitations under
+ * * the License.
+ *
+ */
+package org.apache.geode.connectors.jdbc.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.function.Function;
+
+class JDBCPropertyParser {
+ private final Properties properties;
+
+ private static final String PROPERTY_PREFIX_SEPARATOR = "-";
+ private static final String COMPOUND_VALUE_SEPARATOR = ":";
+
+
+ JDBCPropertyParser(Properties properties) {
+ this.properties = properties;
+ }
+
+ <V> Map<String, V> getPropertiesMap(String propertyPrefix, Function<String, V> valueParser) {
+ Map<String, V> map = new HashMap<>();
+ for(String propertyName : properties.stringPropertyNames()) {
+ if (propertyName.startsWith(propertyPrefix)) {
+ V value = valueParser.apply(properties.getProperty(propertyName));
+ int prefixEnd = propertyName.indexOf(PROPERTY_PREFIX_SEPARATOR);
+ String key = propertyName.substring(prefixEnd + 1);
+ map.put(key, value);
+ }
+ }
+ return map;
+ }
+}
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCConfigurationUnitTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCConfigurationUnitTest.java
index 2eb2804..8e557f5 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCConfigurationUnitTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCConfigurationUnitTest.java
@@ -31,16 +31,6 @@ public class JDBCConfigurationUnitTest {
public ExpectedException expectedException = ExpectedException.none();
@Test
- public void testInvalidProperty() {
- Properties props = new Properties();
- props.setProperty("invalid", "");
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("unknown properties: [invalid]");
- new JDBCConfiguration(props);
- }
-
- @Test
public void testMissingAllRequiredProperties() {
Properties props = new Properties();
expectedException.expect(IllegalArgumentException.class);
@@ -99,27 +89,12 @@ public class JDBCConfigurationUnitTest {
}
@Test
- public void testValueClassName() {
- Properties props = new Properties();
- props.setProperty("url", "");
- props.setProperty("valueClassName", "myPackage.myDomainClass");
- JDBCConfiguration config = new JDBCConfiguration(props);
- assertThat(config.getValueClassName("foo")).isEqualTo("myPackage.myDomainClass");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void verifyThatTwoClassNamesWithNoRegionNameThrows() {
- Properties props = new Properties();
- props.setProperty("url", "");
- props.setProperty("valueClassName", "myClass1, myClass2");
- new JDBCConfiguration(props);
- }
-
- @Test
public void testValueClassNameWithRegionNames() {
Properties props = new Properties();
props.setProperty("url", "");
- props.setProperty("valueClassName", "reg1:cn1 , reg2:pack2.cn2,myPackage.myDomainClass");
+ props.setProperty("valueClassName-reg1", "cn1");
+ props.setProperty("valueClassName-reg2", "pack2.cn2");
+ props.setProperty("valueClassName-foo", "myPackage.myDomainClass");
JDBCConfiguration config = new JDBCConfiguration(props);
assertThat(config.getValueClassName("foo")).isEqualTo("myPackage.myDomainClass");
assertThat(config.getValueClassName("reg1")).isEqualTo("cn1");
@@ -134,59 +109,18 @@ public class JDBCConfigurationUnitTest {
assertThat(config.getIsKeyPartOfValue("foo")).isEqualTo(false);
}
- @Test(expected = IllegalArgumentException.class)
- public void verifyThatTwoDefaultsKeyPartOfValueThrows() {
- Properties props = new Properties();
- props.setProperty("url", "");
- props.setProperty("isKeyPartOfValue", "true, reg1:true , reg2:false, true");
- new JDBCConfiguration(props);
- }
-
@Test
public void testIsKeyPartOfValueWithRegionNames() {
Properties props = new Properties();
props.setProperty("url", "");
- props.setProperty("isKeyPartOfValue", "true, reg1:true , reg2:false,");
+ props.setProperty("isKeyPartOfValue-reg1", "true");
+ props.setProperty("isKeyPartOfValue-reg2", "false");
JDBCConfiguration config = new JDBCConfiguration(props);
- assertThat(config.getIsKeyPartOfValue("foo")).isEqualTo(true);
- assertThat(config.getIsKeyPartOfValue("reg1")).isEqualTo(true);
- assertThat(config.getIsKeyPartOfValue("reg2")).isEqualTo(false);
- }
-
- @Test
- public void testIsKeyPartOfValueWithjdbcSeparator() {
- Properties props = new Properties();
- props.setProperty("url", "");
- props.setProperty("isKeyPartOfValue", "true, reg1->true , reg2->false");
- JDBCConfiguration config = new TestableJDBCConfiguration(props);
- assertThat(config.getIsKeyPartOfValue("foo")).isEqualTo(true);
- assertThat(config.getIsKeyPartOfValue("reg1")).isEqualTo(true);
- assertThat(config.getIsKeyPartOfValue("reg2")).isEqualTo(false);
- }
-
-
- @Test
- public void testIsKeyPartOfValueWithjdbcSeparatorNoDefaultValue() {
- Properties props = new Properties();
- props.setProperty("url", "");
- props.setProperty("isKeyPartOfValue", "reg1->true,reg2->false");
- JDBCConfiguration config = new TestableJDBCConfiguration(props);
assertThat(config.getIsKeyPartOfValue("foo")).isEqualTo(false);
assertThat(config.getIsKeyPartOfValue("reg1")).isEqualTo(true);
assertThat(config.getIsKeyPartOfValue("reg2")).isEqualTo(false);
}
- public static class TestableJDBCConfiguration extends JDBCConfiguration {
- public TestableJDBCConfiguration(Properties configProps) {
- super(configProps);
- }
-
- @Override
- protected String getjdbcSeparator() {
- return "->";
- }
- }
-
@Test
public void testDefaultRegionToTableMap() {
Properties props = new Properties();
@@ -199,37 +133,13 @@ public class JDBCConfigurationUnitTest {
public void testRegionToTableMap() {
Properties props = new Properties();
props.setProperty("url", "");
- props.setProperty("regionToTable", "reg1:table1");
- JDBCConfiguration config = new JDBCConfiguration(props);
- assertThat(config.getTableForRegion("reg1")).isEqualTo("table1");
- }
-
- @Test
- public void testRegionsToTablesMap() {
- Properties props = new Properties();
- props.setProperty("url", "");
- props.setProperty("regionToTable", "reg1:table1, reg2:table2");
+ props.setProperty("regionToTable-reg1", "table1");
+ props.setProperty("regionToTable-reg2", "table2");
JDBCConfiguration config = new JDBCConfiguration(props);
assertThat(config.getTableForRegion("reg1")).isEqualTo("table1");
assertThat(config.getTableForRegion("reg2")).isEqualTo("table2");
}
- @Test(expected = IllegalArgumentException.class)
- public void verifyRegionToTableThrows() {
- Properties props = new Properties();
- props.setProperty("url", "");
- props.setProperty("regionToTable", "reg1:table1, reg2:table2, reg3");
- new JDBCConfiguration(props);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void verifyDuplicateRegionToTableThrows() {
- Properties props = new Properties();
- props.setProperty("url", "");
- props.setProperty("regionToTable", "reg1:table1, reg2:table2, reg2:table3");
- new JDBCConfiguration(props);
- }
-
@Test
public void testDefaultFieldToColumnMap() {
Properties props = new Properties();
@@ -276,12 +186,4 @@ public class JDBCConfigurationUnitTest {
props.setProperty("fieldToColumn", "reg1:field1:column1, reg1:field1:column2");
new JDBCConfiguration(props);
}
-
- @Test(expected = IllegalArgumentException.class)
- public void verifyFieldToColumnRequiresSeparator() {
- Properties props = new Properties();
- props.setProperty("url", "");
- props.setProperty("regionToTable", "reg1:table1, reg2:table2, noSeparator");
- new JDBCConfiguration(props);
- }
}
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCManagerUnitTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCManagerUnitTest.java
index 36b401b..0e9d85b 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCManagerUnitTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCManagerUnitTest.java
@@ -557,7 +557,7 @@ public class JDBCManagerUnitTest {
@Test
public void verifyReadWithValueClassName() throws SQLException {
- createManager("valueClassName", regionName + ":myValueClass");
+ createManager("valueClassName-" + regionName, "myValueClass");
GemFireCacheImpl cache = Fakes.cache();
PdxInstanceFactory factory = mock(PdxInstanceFactory.class);
PdxInstance pi = mock(PdxInstance.class);
@@ -586,7 +586,7 @@ public class JDBCManagerUnitTest {
@Test
public void verifyReadWithKeyPartOfValue() throws SQLException {
- createManager("isKeyPartOfValue", "true");
+ createManager("isKeyPartOfValue-" + regionName, "true");
GemFireCacheImpl cache = Fakes.cache();
PdxInstanceFactory factory = mock(PdxInstanceFactory.class);
PdxInstance pi = mock(PdxInstance.class);
@@ -616,7 +616,7 @@ public class JDBCManagerUnitTest {
@Test
public void verifyRegionToTable() throws SQLException {
String tableName = "mySqlTable";
- createManagerWithTableName(tableName, "regionToTable", regionName + ":" + tableName);
+ createManagerWithTableName(tableName, "regionToTable-" + regionName, tableName);
GemFireCacheImpl cache = Fakes.cache();
PdxInstanceFactory factory = mock(PdxInstanceFactory.class);
PdxInstance pi = mock(PdxInstance.class);
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCPropertyParserTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCPropertyParserTest.java
new file mode 100644
index 0000000..ccdb2e0
--- /dev/null
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCPropertyParserTest.java
@@ -0,0 +1,64 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * * copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * * or implied. See the License for the specific language governing permissions and limitations under
+ * * the License.
+ *
+ */
+package org.apache.geode.connectors.jdbc.internal;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.Test;
+
+public class JDBCPropertyParserTest {
+ @Test
+ public void returnsEmptyMapIfNoPropertiesPresent() {
+ Properties props = new Properties();
+ JDBCPropertyParser parser = new JDBCPropertyParser(props);
+ Map<String, String> map = parser.getPropertiesMap("test", v -> v);
+ assertThat(map).isEmpty();
+ }
+
+ @Test
+ public void returnsMapWithKeyValuePair() {
+ Properties props = new Properties();
+ props.setProperty("name-key", "value");
+ JDBCPropertyParser parser = new JDBCPropertyParser(props);
+ Map<String, String> map = parser.getPropertiesMap("name", v -> v);
+ assertThat(map).hasSize(1).containsKey("key").containsValue("value");
+ }
+
+ @Test
+ public void returnsMapWithMultipleKeyValuePairs() {
+ Properties props = new Properties();
+ props.setProperty("name-key1", "value1");
+ props.setProperty("name-key2", "value2");
+ JDBCPropertyParser parser = new JDBCPropertyParser(props);
+ Map<String, String> map = parser.getPropertiesMap("name", v -> v);
+ assertThat(map).hasSize(2).containsExactly(entry("key1", "value1"), entry("key2", "value2"));
+ }
+
+ @Test
+ public void returnsMapWithBooleanValues() {
+ Properties props = new Properties();
+ props.setProperty("name-key1", "true");
+ props.setProperty("name-key2", "false");
+ JDBCPropertyParser parser = new JDBCPropertyParser(props);
+ Map<String, Boolean> map = parser.getPropertiesMap("name", Boolean::parseBoolean);
+ assertThat(map).hasSize(2).containsExactly(entry("key1", true), entry("key2", false));
+ }
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.