geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgalli...@apache.org
Subject [geode] branch feature/GEODE-3781 updated: Add validation for region mapping and connection params mapping.
Date Sat, 16 Dec 2017 00:02:45 GMT
This is an automated email from the ASF dual-hosted git repository.

lgallinat 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 3019cf5  Add validation for region mapping and connection params mapping.
3019cf5 is described below

commit 3019cf54144e5e9cb78ffb5879d149de473208a5
Author: Lynn Gallinat <lgallinat@pivotal.io>
AuthorDate: Fri Dec 15 16:01:25 2017 -0800

    Add validation for region mapping and connection params mapping.
---
 .../jdbc/internal/ConnectionConfigBuilder.java         | 11 +++++++++++
 .../connectors/jdbc/internal/RegionMappingBuilder.java | 11 +++++++++++
 .../apache/geode/connectors/jdbc/JdbcDUnitTest.java    |  3 +--
 .../jdbc/internal/xml/ConnectionConfigBuilderTest.java | 14 ++++++++++++++
 .../jdbc/internal/xml/RegionMappingBuilderTest.java    | 18 ++++++++++++++++++
 5 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionConfigBuilder.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionConfigBuilder.java
index 503b60d..308f61e 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionConfigBuilder.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionConfigBuilder.java
@@ -55,7 +55,11 @@ public class ConnectionConfigBuilder {
       parameters = null;
     } else {
       for (String param : params) {
+        if (param.isEmpty()) {
+          continue;
+        }
         String[] keyValuePair = param.split(PARAMS_DELIMITER);
+        validateParam(keyValuePair, param);
         if (keyValuePair.length == 2) {
           parameters.put(keyValuePair[0], keyValuePair[1]);
         }
@@ -64,6 +68,13 @@ public class ConnectionConfigBuilder {
     return this;
   }
 
+  private void validateParam(String[] paramKeyValue, String param) {
+    if ((paramKeyValue.length <= 1) || paramKeyValue[0].isEmpty() || paramKeyValue[1].isEmpty())
{
+      throw new IllegalArgumentException("Parameter '" + param
+          + "' is not of the form 'parameterName" + PARAMS_DELIMITER + "value'");
+    }
+  }
+
   public ConnectionConfiguration build() {
     return new ConnectionConfiguration(name, url, user, password, parameters);
   }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingBuilder.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingBuilder.java
index 300c2d4..302f6cd 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingBuilder.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingBuilder.java
@@ -71,7 +71,11 @@ public class RegionMappingBuilder {
       fieldToColumnMap = null;
     } else {
       for (String mapping : mappings) {
+        if (mapping.isEmpty()) {
+          continue;
+        }
         String[] keyValuePair = mapping.split(MAPPINGS_DELIMITER);
+        validateParam(keyValuePair, mapping);
         if (keyValuePair.length == 2) {
           fieldToColumnMap.put(keyValuePair[0], keyValuePair[1]);
         }
@@ -80,6 +84,13 @@ public class RegionMappingBuilder {
     return this;
   }
 
+  private void validateParam(String[] paramKeyValue, String mapping) {
+    if (paramKeyValue.length <= 1 || paramKeyValue[0].isEmpty() || paramKeyValue[1].isEmpty())
{
+      throw new IllegalArgumentException("Field to column mapping '" + mapping
+          + "' is not of the form 'Field" + MAPPINGS_DELIMITER + "Column'");
+    }
+  }
+
   public RegionMapping build() {
     return new RegionMapping(regionName, pdxClassName, tableName, connectionConfigName,
         primaryKeyInValue, fieldToColumnMap);
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JdbcDUnitTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JdbcDUnitTest.java
index 63a1161..293fc51 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JdbcDUnitTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JdbcDUnitTest.java
@@ -245,8 +245,7 @@ public class JdbcDUnitTest implements Serializable {
 
   private void createJdbcConnection() {
     final String commandStr = "create jdbc-connection --name=" + CONNECTION_NAME + " --url="
-        + CONNECTION_URL
-        + " --params=param1:value1,this.is.param2:value.2,this-is-value-3,value-3,this_is_param_4:value_4";
+        + CONNECTION_URL;
     gfsh.executeAndAssertThat(commandStr).statusIsSuccess();
   }
 
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/ConnectionConfigBuilderTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/ConnectionConfigBuilderTest.java
index cd83690..7afcf83 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/ConnectionConfigBuilderTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/ConnectionConfigBuilderTest.java
@@ -15,6 +15,7 @@
 package org.apache.geode.connectors.jdbc.internal.xml;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -49,4 +50,17 @@ public class ConnectionConfigBuilderTest {
     assertThat(config.getConnectionProperties()).containsEntry("param1", "value1")
         .containsEntry("param2", "value2");
   }
+
+  @Test
+  public void throwsExceptionWithInvalidParams() {
+    ConnectionConfigBuilder config = new ConnectionConfigBuilder();
+    assertThatThrownBy(() -> config.withParameters(new String[] {"param1value1"}))
+        .isInstanceOf(IllegalArgumentException.class);
+    assertThatThrownBy(() -> config.withParameters(new String[] {":param1value1"}))
+        .isInstanceOf(IllegalArgumentException.class);
+    assertThatThrownBy(() -> config.withParameters(new String[] {"param1value1:"}))
+        .isInstanceOf(IllegalArgumentException.class);
+    assertThatThrownBy(() -> config.withParameters(new String[] {":"}))
+        .isInstanceOf(IllegalArgumentException.class);
+  }
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/RegionMappingBuilderTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/RegionMappingBuilderTest.java
index 695556d..d7f31a5 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/RegionMappingBuilderTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/RegionMappingBuilderTest.java
@@ -15,6 +15,7 @@
 package org.apache.geode.connectors.jdbc.internal.xml;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -61,4 +62,21 @@ public class RegionMappingBuilderTest {
     assertThat(regionMapping.getColumnNameForField("field1")).isEqualTo("column1");
     assertThat(regionMapping.getColumnNameForField("field2")).isEqualTo("column2");
   }
+
+  @Test
+  public void throwsExceptionForInvalidFieldMappings() {
+    RegionMappingBuilder regionMappingbuilder = new RegionMappingBuilder();
+
+    assertThatThrownBy(
+        () -> regionMappingbuilder.withFieldToColumnMappings(new String[] {"field1column1"}))
+            .isInstanceOf(IllegalArgumentException.class);
+    assertThatThrownBy(
+        () -> regionMappingbuilder.withFieldToColumnMappings(new String[] {":field1column1"}))
+            .isInstanceOf(IllegalArgumentException.class);
+    assertThatThrownBy(
+        () -> regionMappingbuilder.withFieldToColumnMappings(new String[] {"field1column1:"}))
+            .isInstanceOf(IllegalArgumentException.class);
+    assertThatThrownBy(() -> regionMappingbuilder.withFieldToColumnMappings(new String[]
{":"}))
+        .isInstanceOf(IllegalArgumentException.class);
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message