geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [geode] branch develop updated: GEODE-4160: fix gfsh describe jdbc-connection (#1223)
Date Fri, 05 Jan 2018 19:17:34 GMT
This is an automated email from the ASF dual-hosted git repository.

dschneider pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 92ced79  GEODE-4160: fix gfsh describe jdbc-connection (#1223)
92ced79 is described below

commit 92ced7912800128c078bccc65ad7476cc25cacee
Author: Darrel Schneider <dschneider@pivotal.io>
AuthorDate: Fri Jan 5 11:17:32 2018 -0800

    GEODE-4160: fix gfsh describe jdbc-connection (#1223)
    
    * GEODE-4160: fix gfsh describe jdbc-connection
    
    If the connection had no parameters set, then running
    gfsh describe jdbc-connection would fail with an NPE.
---
 .../jdbc/internal/ConnectionConfigBuilder.java     | 17 ++++----
 .../jdbc/internal/ConnectionConfiguration.java     |  3 --
 .../jdbc/internal/RegionMappingBuilder.java        | 19 ++++-----
 .../internal/cli/DescribeConnectionCommand.java    | 10 +++--
 .../connectors/jdbc/internal/xml/ElementType.java  | 19 ++++-----
 .../xml/JdbcConnectorServiceXmlGenerator.java      | 45 +++++++++++++---------
 .../{xml => }/ConnectionConfigBuilderTest.java     | 28 +++++++++++++-
 .../{xml => }/RegionMappingBuilderTest.java        | 35 ++++++++++++++++-
 .../DescribeConnectionCommandIntegrationTest.java  | 24 ++++++++++++
 .../jdbc/internal/xml/ElementTypeTest.java         | 25 ++++++++++++
 ...onnectorServiceXmlGeneratorIntegrationTest.java | 43 +++++++++++++++++++++
 11 files changed, 215 insertions(+), 53 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 308f61e..4ab2b7f 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
@@ -28,7 +28,7 @@ public class ConnectionConfigBuilder {
   private String url;
   private String user;
   private String password;
-  private Map<String, String> parameters = new HashMap<>();
+  private Map<String, String> parameters;
 
   public ConnectionConfigBuilder withName(String name) {
     this.name = name;
@@ -51,25 +51,26 @@ public class ConnectionConfigBuilder {
   }
 
   public ConnectionConfigBuilder withParameters(String[] params) {
-    if (params == null) {
-      parameters = null;
-    } else {
+    if (params != null) {
+      parameters = new HashMap<>();
       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]);
-        }
+        parameters.put(keyValuePair[0], keyValuePair[1]);
       }
+    } else {
+      parameters = null;
     }
     return this;
   }
 
   private void validateParam(String[] paramKeyValue, String param) {
-    if ((paramKeyValue.length <= 1) || paramKeyValue[0].isEmpty() || paramKeyValue[1].isEmpty())
{
+    // paramKeyValue is produced by split which will never give us
+    // an empty second element
+    if ((paramKeyValue.length != 2) || paramKeyValue[0].isEmpty()) {
       throw new IllegalArgumentException("Parameter '" + param
           + "' is not of the form 'parameterName" + PARAMS_DELIMITER + "value'");
     }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionConfiguration.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionConfiguration.java
index 6a69079..c80e146 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionConfiguration.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionConfiguration.java
@@ -23,9 +23,6 @@ import org.apache.geode.annotations.Experimental;
 
 @Experimental
 public class ConnectionConfiguration implements Serializable {
-  private static final Object USER = "user";
-  private static final Object PASSWORD = "password";
-
   private final String name;
   private final String url;
   private final String user;
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 302f6cd..0d989a4 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
@@ -50,14 +50,15 @@ public class RegionMappingBuilder {
     return this;
   }
 
-  // TODO: delete withPrimaryKeyInValue(String)
-  public RegionMappingBuilder withPrimaryKeyInValue(String primaryKeyInValue) {
-    this.primaryKeyInValue = Boolean.parseBoolean(primaryKeyInValue);
+  public RegionMappingBuilder withPrimaryKeyInValue(String v) {
+    if (v != null) {
+      withPrimaryKeyInValue(Boolean.parseBoolean(v));
+    }
     return this;
   }
 
-  public RegionMappingBuilder withPrimaryKeyInValue(Boolean primaryKeyInValue) {
-    this.primaryKeyInValue = primaryKeyInValue;
+  public RegionMappingBuilder withPrimaryKeyInValue(Boolean v) {
+    this.primaryKeyInValue = v;
     return this;
   }
 
@@ -76,16 +77,16 @@ public class RegionMappingBuilder {
         }
         String[] keyValuePair = mapping.split(MAPPINGS_DELIMITER);
         validateParam(keyValuePair, mapping);
-        if (keyValuePair.length == 2) {
-          fieldToColumnMap.put(keyValuePair[0], keyValuePair[1]);
-        }
+        fieldToColumnMap.put(keyValuePair[0], keyValuePair[1]);
       }
     }
     return this;
   }
 
   private void validateParam(String[] paramKeyValue, String mapping) {
-    if (paramKeyValue.length <= 1 || paramKeyValue[0].isEmpty() || paramKeyValue[1].isEmpty())
{
+    // paramKeyValue is produced by split which will never give us
+    // an empty second element
+    if (paramKeyValue.length != 2 || paramKeyValue[0].isEmpty()) {
       throw new IllegalArgumentException("Field to column mapping '" + mapping
           + "' is not of the form 'Field" + MAPPINGS_DELIMITER + "Column'");
     }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommand.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommand.java
index 9ecf900..3295340 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommand.java
@@ -103,9 +103,11 @@ public class DescribeConnectionCommand implements GfshCommand {
     }
     TabularResultData tabularResultData = sectionResult.addTable(CREATE_CONNECTION__PARAMS);
     tabularResultData.setHeader("Additional connection parameters:");
-    config.getParameters().entrySet().forEach((entry) -> {
-      tabularResultData.accumulate("Param Name", entry.getKey());
-      tabularResultData.accumulate("Value", entry.getValue());
-    });
+    if (config.getParameters() != null) {
+      config.getParameters().entrySet().forEach((entry) -> {
+        tabularResultData.accumulate("Param Name", entry.getKey());
+        tabularResultData.accumulate("Value", entry.getValue());
+      });
+    }
   }
 }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/xml/ElementType.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/xml/ElementType.java
index eac053a..716e15f 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/xml/ElementType.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/xml/ElementType.java
@@ -51,21 +51,22 @@ public enum ElementType {
         throw new CacheXmlException(
             "jdbc <connection> elements must occur within <connector-service>
elements");
       }
-      ConnectionConfigBuilder connectionConfig = new ConnectionConfigBuilder()
+      ConnectionConfigBuilder connectionConfigBuilder = new ConnectionConfigBuilder()
           .withName(attributes.getValue(JdbcConnectorServiceXmlParser.NAME))
           .withUrl(attributes.getValue(JdbcConnectorServiceXmlParser.URL))
           .withUser(attributes.getValue(JdbcConnectorServiceXmlParser.USER))
-          .withPassword(attributes.getValue(JdbcConnectorServiceXmlParser.PASSWORD));
-      addParameters(connectionConfig,
-          attributes.getValue(JdbcConnectorServiceXmlParser.PARAMETERS));
-      stack.push(connectionConfig);
+          .withPassword(attributes.getValue(JdbcConnectorServiceXmlParser.PASSWORD))
+          .withParameters(parseParameters(attributes));
+      stack.push(connectionConfigBuilder);
     }
 
-    private void addParameters(ConnectionConfigBuilder connectionConfig, String value) {
-      if (value == null) {
-        return;
+    private String[] parseParameters(Attributes attributes) {
+      String[] result = null;
+      String value = attributes.getValue(JdbcConnectorServiceXmlParser.PARAMETERS);
+      if (value != null) {
+        result = value.split(",");
       }
-      connectionConfig.withParameters(value.split(","));
+      return result;
     }
 
     @Override
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/xml/JdbcConnectorServiceXmlGenerator.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/xml/JdbcConnectorServiceXmlGenerator.java
index 8fa59c8..70f9540 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/xml/JdbcConnectorServiceXmlGenerator.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/xml/JdbcConnectorServiceXmlGenerator.java
@@ -102,9 +102,15 @@ public class JdbcConnectorServiceXmlGenerator implements XmlGenerator<Cache>
{
     AttributesImpl attributes = new AttributesImpl();
     XmlGeneratorUtils.addAttribute(attributes, NAME, config.getName());
     XmlGeneratorUtils.addAttribute(attributes, URL, config.getUrl());
-    XmlGeneratorUtils.addAttribute(attributes, USER, config.getUser());
-    XmlGeneratorUtils.addAttribute(attributes, PASSWORD, config.getPassword());
-    XmlGeneratorUtils.addAttribute(attributes, PARAMETERS, createParametersString(config));
+    if (config.getUser() != null) {
+      XmlGeneratorUtils.addAttribute(attributes, USER, config.getUser());
+    }
+    if (config.getPassword() != null) {
+      XmlGeneratorUtils.addAttribute(attributes, PASSWORD, config.getPassword());
+    }
+    if (config.getParameters() != null) {
+      XmlGeneratorUtils.addAttribute(attributes, PARAMETERS, createParametersString(config));
+    }
     XmlGeneratorUtils.emptyElement(handler, PREFIX, ElementType.CONNECTION.getTypeName(),
         attributes);
   }
@@ -114,17 +120,23 @@ public class JdbcConnectorServiceXmlGenerator implements XmlGenerator<Cache>
{
     AttributesImpl attributes = new AttributesImpl();
     XmlGeneratorUtils.addAttribute(attributes, CONNECTION_NAME, mapping.getConnectionConfigName());
     XmlGeneratorUtils.addAttribute(attributes, REGION, mapping.getRegionName());
-    XmlGeneratorUtils.addAttribute(attributes, TABLE, mapping.getTableName());
-    XmlGeneratorUtils.addAttribute(attributes, PDX_CLASS, mapping.getPdxClassName());
-    XmlGeneratorUtils.addAttribute(attributes, PRIMARY_KEY_IN_VALUE,
-        Boolean.toString(mapping.isPrimaryKeyInValue()));
+    if (mapping.getTableName() != null) {
+      XmlGeneratorUtils.addAttribute(attributes, TABLE, mapping.getTableName());
+    }
+    if (mapping.getPdxClassName() != null) {
+      XmlGeneratorUtils.addAttribute(attributes, PDX_CLASS, mapping.getPdxClassName());
+    }
+    if (mapping.isPrimaryKeyInValue() != null) {
+      XmlGeneratorUtils.addAttribute(attributes, PRIMARY_KEY_IN_VALUE,
+          Boolean.toString(mapping.isPrimaryKeyInValue()));
+    }
 
-    XmlGeneratorUtils.startElement(handler, PREFIX, ElementType.REGION_MAPPING.getTypeName(),
-        attributes);
     if (mapping.getFieldToColumnMap() != null) {
+      XmlGeneratorUtils.startElement(handler, PREFIX, ElementType.REGION_MAPPING.getTypeName(),
+          attributes);
       addFieldMappings(handler, mapping.getFieldToColumnMap());
+      XmlGeneratorUtils.endElement(handler, PREFIX, ElementType.REGION_MAPPING.getTypeName());
     }
-    XmlGeneratorUtils.endElement(handler, PREFIX, ElementType.REGION_MAPPING.getTypeName());
   }
 
   private void addFieldMappings(ContentHandler handler, Map<String, String> fieldMappings)
@@ -139,16 +151,13 @@ public class JdbcConnectorServiceXmlGenerator implements XmlGenerator<Cache>
{
   }
 
   private String createParametersString(ConnectionConfiguration config) {
-    Properties properties = config.getConnectionProperties();
+    assert config.getParameters() != null;
     StringBuilder stringBuilder = new StringBuilder();
-    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
-      Object key = entry.getKey();
-      if (!key.equals(USER) && !key.equals(PASSWORD)) {
-        if (stringBuilder.length() > 0) {
-          stringBuilder.append(",");
-        }
-        stringBuilder.append(key).append(PARAMS_DELIMITER).append(entry.getValue());
+    for (Map.Entry<String, String> entry : config.getParameters().entrySet()) {
+      if (stringBuilder.length() > 0) {
+        stringBuilder.append(",");
       }
+      stringBuilder.append(entry.getKey()).append(PARAMS_DELIMITER).append(entry.getValue());
     }
     return stringBuilder.toString();
   }
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/ConnectionConfigBuilderTest.java
similarity index 71%
rename from geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/ConnectionConfigBuilderTest.java
rename to geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/ConnectionConfigBuilderTest.java
index 7afcf83..4e4b18c 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/ConnectionConfigBuilderTest.java
@@ -12,7 +12,7 @@
  * or implied. See the License for the specific language governing permissions and limitations
under
  * the License.
  */
-package org.apache.geode.connectors.jdbc.internal.xml;
+package org.apache.geode.connectors.jdbc.internal;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -52,6 +52,30 @@ public class ConnectionConfigBuilderTest {
   }
 
   @Test
+  public void createsObjectWithEmptyParameterElement() {
+    ConnectionConfiguration config = new ConnectionConfigBuilder().withName("name").withUrl("url")
+        .withUser("user").withPassword("password")
+        .withParameters(new String[] {"param1:value1", "", "param2:value2"}).build();
+
+    assertThat(config.getName()).isEqualTo("name");
+    assertThat(config.getUrl()).isEqualTo("url");
+    assertThat(config.getUser()).isEqualTo("user");
+    assertThat(config.getPassword()).isEqualTo("password");
+    assertThat(config.getConnectionProperties()).containsEntry("param1", "value1")
+        .containsEntry("param2", "value2");
+  }
+
+  @Test
+  public void createsObjectWithNullParameters() {
+    ConnectionConfiguration config =
+        new ConnectionConfigBuilder().withName("name").withUrl("url").withParameters(null).build();
+
+    assertThat(config.getName()).isEqualTo("name");
+    assertThat(config.getUrl()).isEqualTo("url");
+    assertThat(config.getParameters()).isNull();
+  }
+
+  @Test
   public void throwsExceptionWithInvalidParams() {
     ConnectionConfigBuilder config = new ConnectionConfigBuilder();
     assertThatThrownBy(() -> config.withParameters(new String[] {"param1value1"}))
@@ -60,6 +84,8 @@ public class ConnectionConfigBuilderTest {
         .isInstanceOf(IllegalArgumentException.class);
     assertThatThrownBy(() -> config.withParameters(new String[] {"param1value1:"}))
         .isInstanceOf(IllegalArgumentException.class);
+    assertThatThrownBy(() -> config.withParameters(new String[] {"1:2:3"}))
+        .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/RegionMappingBuilderTest.java
similarity index 69%
rename from geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/RegionMappingBuilderTest.java
rename to geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/RegionMappingBuilderTest.java
index d7f31a5..5abfd74 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/RegionMappingBuilderTest.java
@@ -12,7 +12,7 @@
  * or implied. See the License for the specific language governing permissions and limitations
under
  * the License.
  */
-package org.apache.geode.connectors.jdbc.internal.xml;
+package org.apache.geode.connectors.jdbc.internal;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -54,6 +54,26 @@ public class RegionMappingBuilderTest {
   }
 
   @Test
+  public void createsMappingWithNullAsPrimaryKeyInValue() {
+    RegionMapping regionMapping = new RegionMappingBuilder().withRegionName("regionName")
+        .withConnectionConfigName("configName").withPrimaryKeyInValue((String) null).build();
+
+    assertThat(regionMapping.getRegionName()).isEqualTo("regionName");
+    assertThat(regionMapping.getConnectionConfigName()).isEqualTo("configName");
+    assertThat(regionMapping.isPrimaryKeyInValue()).isNull();
+  }
+
+  @Test
+  public void createsMappingWithNullFieldToColumnMappings() {
+    RegionMapping regionMapping = new RegionMappingBuilder().withRegionName("regionName")
+        .withConnectionConfigName("configName").withFieldToColumnMappings(null).build();
+
+    assertThat(regionMapping.getRegionName()).isEqualTo("regionName");
+    assertThat(regionMapping.getConnectionConfigName()).isEqualTo("configName");
+    assertThat(regionMapping.getFieldToColumnMap()).isNull();
+  }
+
+  @Test
   public void createsFieldMappingsFromArray() {
     String[] fieldMappings = new String[] {"field1:column1", "field2:column2"};
     RegionMapping regionMapping =
@@ -64,6 +84,16 @@ public class RegionMappingBuilderTest {
   }
 
   @Test
+  public void createsFieldMappingsFromArrayWithEmptyElement() {
+    String[] fieldMappings = new String[] {"field1:column1", "", "field2:column2"};
+    RegionMapping regionMapping =
+        new RegionMappingBuilder().withFieldToColumnMappings(fieldMappings).build();
+
+    assertThat(regionMapping.getColumnNameForField("field1")).isEqualTo("column1");
+    assertThat(regionMapping.getColumnNameForField("field2")).isEqualTo("column2");
+  }
+
+  @Test
   public void throwsExceptionForInvalidFieldMappings() {
     RegionMappingBuilder regionMappingbuilder = new RegionMappingBuilder();
 
@@ -74,6 +104,9 @@ public class RegionMappingBuilderTest {
         () -> regionMappingbuilder.withFieldToColumnMappings(new String[] {":field1column1"}))
             .isInstanceOf(IllegalArgumentException.class);
     assertThatThrownBy(
+        () -> regionMappingbuilder.withFieldToColumnMappings(new String[] {"field1:column1:extra"}))
+            .isInstanceOf(IllegalArgumentException.class);
+    assertThatThrownBy(
         () -> regionMappingbuilder.withFieldToColumnMappings(new String[] {"field1column1:"}))
             .isInstanceOf(IllegalArgumentException.class);
     assertThatThrownBy(() -> regionMappingbuilder.withFieldToColumnMappings(new String[]
{":"}))
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandIntegrationTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandIntegrationTest.java
index 05b5051..84e93c3 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandIntegrationTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandIntegrationTest.java
@@ -107,6 +107,30 @@ public class DescribeConnectionCommandIntegrationTest {
   }
 
   @Test
+  public void displaysConnectionInformationForConfigurationWithNullParameters() throws Exception
{
+    connectionConfig = new ConnectionConfigBuilder().withName(CONNECTION).withUrl("myUrl")
+        .withParameters(null).build();
+    service.createConnectionConfig(connectionConfig);
+    Result result = command.describeConnection(CONNECTION);
+
+    assertThat(result.getStatus()).isSameAs(Result.Status.OK);
+    CommandResult commandResult = (CommandResult) result;
+    GfJsonObject sectionContent = commandResult.getTableContent()
+        .getJSONObject(SECTION_DATA_ACCESSOR + "-" + RESULT_SECTION_NAME);
+
+    assertThat(sectionContent.get(CREATE_CONNECTION__NAME)).isEqualTo(connectionConfig.getName());
+    assertThat(sectionContent.get(CREATE_CONNECTION__URL)).isEqualTo(connectionConfig.getUrl());
+    assertThat(sectionContent.get(CREATE_CONNECTION__USER)).isEqualTo(connectionConfig.getUser());
+    assertThat(sectionContent.get(CREATE_CONNECTION__PASSWORD)).isEqualTo(null);
+
+    GfJsonObject tableContent =
+        sectionContent.getJSONObject(TABLE_DATA_ACCESSOR + "-" + CREATE_CONNECTION__PARAMS)
+            .getJSONObject("content");
+    assertThat(tableContent.get("Param Name")).isNull();
+    assertThat(tableContent.get("Value")).isNull();
+  }
+
+  @Test
   public void doesNotDisplayParametersWithNoValue() throws Exception {
     connectionConfig = new ConnectionConfigBuilder().withName(CONNECTION).withUrl("myUrl").build();
 
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/ElementTypeTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/ElementTypeTest.java
index 144d1fa..7612527 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/ElementTypeTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/ElementTypeTest.java
@@ -34,6 +34,8 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Stack;
 
 import org.junit.Before;
@@ -136,6 +138,29 @@ public class ElementTypeTest {
     assertThat(config.getUrl()).isEqualTo("url");
     assertThat(config.getUser()).isEqualTo("username");
     assertThat(config.getPassword()).isEqualTo("secret");
+    assertThat(config.getParameters()).isNull();
+  }
+
+  @Test
+  public void startElementConnectionWithParameters() {
+    JdbcServiceConfiguration serviceConfiguration = mock(JdbcServiceConfiguration.class);
+    stack.push(serviceConfiguration);
+    when(attributes.getValue(JdbcConnectorServiceXmlParser.NAME)).thenReturn("connectionName");
+    when(attributes.getValue(JdbcConnectorServiceXmlParser.URL)).thenReturn("url");
+    when(attributes.getValue(JdbcConnectorServiceXmlParser.PARAMETERS))
+        .thenReturn("key1:value1,key2:value2");
+
+    CONNECTION.startElement(stack, attributes);
+
+    ConnectionConfiguration config = ((ConnectionConfigBuilder) stack.pop()).build();
+    assertThat(config.getName()).isEqualTo("connectionName");
+    assertThat(config.getUrl()).isEqualTo("url");
+    assertThat(config.getUser()).isNull();
+    assertThat(config.getPassword()).isNull();
+    Map<String, String> expectedParams = new HashMap<>();
+    expectedParams.put("key1", "value1");
+    expectedParams.put("key2", "value2");
+    assertThat(config.getParameters()).isEqualTo(expectedParams);
   }
 
   @Test
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/JdbcConnectorServiceXmlGeneratorIntegrationTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/JdbcConnectorServiceXmlGeneratorIntegrationTest.java
index d59aaaf..1ba728f 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/JdbcConnectorServiceXmlGeneratorIntegrationTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/JdbcConnectorServiceXmlGeneratorIntegrationTest.java
@@ -175,6 +175,35 @@ public class JdbcConnectorServiceXmlGeneratorIntegrationTest {
   }
 
   @Test
+  public void generatedXmlWithConnectionConfigurationWithNoUserNameAndPasswordCanBeParsed()
+      throws Exception {
+    JdbcConnectorService service = cache.getService(JdbcConnectorService.class);
+    ConnectionConfiguration config =
+        new ConnectionConfigBuilder().withName("name").withUrl("url").build();
+    service.createConnectionConfig(config);
+    generateXml();
+    cache.close();
+
+    createCacheUsingXml();
+    service = cache.getService(JdbcConnectorService.class);
+    assertThat(service.getConnectionConfig("name")).isEqualTo(config);
+  }
+
+  @Test
+  public void generatedXmlWithConnectionConfigurationWithParametersCanBeParsed() throws Exception
{
+    JdbcConnectorService service = cache.getService(JdbcConnectorService.class);
+    ConnectionConfiguration config = new ConnectionConfigBuilder().withName("name").withUrl("url")
+        .withParameters(new String[] {"key1:value1", "key2:value2"}).build();
+    service.createConnectionConfig(config);
+    generateXml();
+    cache.close();
+
+    createCacheUsingXml();
+    service = cache.getService(JdbcConnectorService.class);
+    assertThat(service.getConnectionConfig("name")).isEqualTo(config);
+  }
+
+  @Test
   public void generatedXmlWithRegionMappingCanBeParsed() throws Exception {
     JdbcConnectorService service = cache.getService(JdbcConnectorService.class);
     RegionMapping mapping = new RegionMappingBuilder().withRegionName("region")
@@ -191,6 +220,20 @@ public class JdbcConnectorServiceXmlGeneratorIntegrationTest {
   }
 
   @Test
+  public void generatedXmlWithRegionMappingWithNoOptionalParametersCanBeParsed() throws Exception
{
+    JdbcConnectorService service = cache.getService(JdbcConnectorService.class);
+    RegionMapping mapping = new RegionMappingBuilder().withRegionName("region")
+        .withConnectionConfigName("connection").build();
+    service.createRegionMapping(mapping);
+    generateXml();
+    cache.close();
+
+    createCacheUsingXml();
+    service = cache.getService(JdbcConnectorService.class);
+    assertThat(service.getMappingForRegion("region")).isEqualTo(mapping);
+  }
+
+  @Test
   public void generatedXmlWithEverythingCanBeParsed() throws Exception {
     JdbcConnectorService service = cache.getService(JdbcConnectorService.class);
     ConnectionConfiguration config = new ConnectionConfigBuilder().withName("name").withUrl("url")

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

Mime
View raw message