This is an automated email from the ASF dual-hosted git repository.
agingade pushed a commit to branch feature/GEODE-3781
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-3781 by this
push:
new 5348bed Added JDBCConfiguration class and test
5348bed is described below
commit 5348bed12da9221e75a5302d35d3db41526c0d4a
Author: Anil <[email protected]>
AuthorDate: Tue Oct 24 16:18:13 2017 -0700
Added JDBCConfiguration class and test
---
.../geode/connectors/jdbc/JDBCConfiguration.java | 60 +++++++++++++++++
.../connectors/jdbc/JDBCConfigurationUnitTest.java | 77 ++++++++++++++++++++++
2 files changed, 137 insertions(+)
diff --git
a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCConfiguration.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCConfiguration.java
new file mode 100644
index 0000000..2e3e061
--- /dev/null
+++
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCConfiguration.java
@@ -0,0 +1,60 @@
+package org.apache.geode.connectors.jdbc;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+public class JDBCConfiguration {
+
+ private static final String DRIVER = "driver";
+
+ private static final String URL = "url";
+
+ private static final String USER = "user";
+
+ private static final String PASSWORD = "password";
+
+ private static final List<String> knownProperties =
Collections.unmodifiableList(Arrays.asList(DRIVER, URL, USER, PASSWORD));
+
+ private static final List<String> requiredProperties =
Collections.unmodifiableList(Arrays.asList(DRIVER, URL));
+
+ private final String driver;
+
+ private String url;
+
+ JDBCConfiguration(Properties configProps) {
+ validateKnownProperties(configProps);
+ validateRequiredProperties(configProps);
+ this.driver = configProps.getProperty(DRIVER);
+ this.url = configProps.getProperty(URL);
+ }
+
+ 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());
+ if (!reqKeys.isEmpty()) {
+ Collections.sort(reqKeys);
+ throw new IllegalArgumentException("missing required properties: " +
reqKeys);
+ }
+ }
+
+ public String getDriver() {
+ return this.driver;
+ }
+ public String getURL() {
+ return this.url;
+ }
+
+}
diff --git
a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCConfigurationUnitTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCConfigurationUnitTest.java
new file mode 100644
index 0000000..afefb16
--- /dev/null
+++
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCConfigurationUnitTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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;
+
+import static org.assertj.core.api.Assertions.*;
+
+import java.util.Properties;
+
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.*;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category(UnitTest.class)
+public class JDBCConfigurationUnitTest {
+
+ @Rule
+ 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);
+ expectedException.expectMessage("missing required properties: [driver,
url]");
+ new JDBCConfiguration(props);
+ }
+
+ @Test
+ public void testMissingDriverRequiredProperties() {
+ Properties props = new Properties();
+ props.setProperty("url", "");
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("missing required properties: [driver]");
+ new JDBCConfiguration(props);
+ }
+
+ @Test
+ public void testDriverProperty() {
+ Properties props = new Properties();
+ props.setProperty("url", "");
+ props.setProperty("driver", "myDriver");
+ JDBCConfiguration config = new JDBCConfiguration(props);
+ assertThat(config.getDriver()).isEqualTo("myDriver");
+ }
+
+ @Test
+ public void testURLProperty() {
+ Properties props = new Properties();
+ props.setProperty("url", "myUrl");
+ props.setProperty("driver", "");
+ JDBCConfiguration config = new JDBCConfiguration(props);
+ assertThat(config.getURL()).isEqualTo("myUrl");
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].