This is an automated email from the ASF dual-hosted git repository.

agingade 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 3bc3b51  GEODE-4241: Write region mapping to cluster configuration
3bc3b51 is described below

commit 3bc3b51f5175079d23b3bab0824817c98cecb19a
Author: Anil <aging...@pivotal.io>
AuthorDate: Tue Jan 9 15:30:46 2018 -0800

    GEODE-4241: Write region mapping to cluster configuration
    
    When field mapping is not provided, cluster configuration for
    region mapping was not working.
---
 .../xml/JdbcConnectorServiceXmlGenerator.java      | 13 +++++-----
 .../cli/CreateMappingCommandDUnitTest.java         | 22 ++++++++++++++++
 ...onnectorServiceXmlGeneratorIntegrationTest.java | 30 ++++++++++++++++++++++
 3 files changed, 59 insertions(+), 6 deletions(-)

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 70f9540..205fbf2 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
@@ -131,16 +131,17 @@ public class JdbcConnectorServiceXmlGenerator implements 
XmlGenerator<Cache> {
           Boolean.toString(mapping.isPrimaryKeyInValue()));
     }
 
-    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.startElement(handler, PREFIX, 
ElementType.REGION_MAPPING.getTypeName(),
+        attributes);
+    addFieldMappings(handler, mapping.getFieldToColumnMap());
+    XmlGeneratorUtils.endElement(handler, PREFIX, 
ElementType.REGION_MAPPING.getTypeName());
   }
 
   private void addFieldMappings(ContentHandler handler, Map<String, String> 
fieldMappings)
       throws SAXException {
+    if (fieldMappings == null) {
+      return;
+    }
     for (Map.Entry<String, String> fieldMapping : fieldMappings.entrySet()) {
       AttributesImpl fieldAttributes = new AttributesImpl();
       XmlGeneratorUtils.addAttribute(fieldAttributes, FIELD_NAME, 
fieldMapping.getKey());
diff --git 
a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandDUnitTest.java
 
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandDUnitTest.java
index 4ac9f67..552cd23 100644
--- 
a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandDUnitTest.java
+++ 
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandDUnitTest.java
@@ -78,6 +78,8 @@ public class CreateMappingCommandDUnitTest {
       String xml = 
InternalLocator.getLocator().getSharedConfiguration().getConfiguration("cluster")
           .getCacheXmlContent();
       assertThat(xml).isNotNull().contains("jdbc:connector-service");
+      assertThat(xml).isNotNull().contains("jdbc:region-mapping");
+      assertThat(xml).isNotNull().contains("jdbc:field-mapping");
     });
 
     server.invoke(() -> {
@@ -92,4 +94,24 @@ public class CreateMappingCommandDUnitTest {
           .containsEntry("field2", "column2");
     });
   }
+
+  @Test
+  public void createsRegionMappingWithoutFieldMap() {
+    CommandStringBuilder csb = new CommandStringBuilder(CREATE_MAPPING);
+    csb.addOption(CREATE_MAPPING__REGION_NAME, "testRegion");
+    csb.addOption(CREATE_MAPPING__CONNECTION_NAME, "connection");
+    csb.addOption(CREATE_MAPPING__TABLE_NAME, "myTable");
+    csb.addOption(CREATE_MAPPING__PDX_CLASS_NAME, "myPdxClass");
+    csb.addOption(CREATE_MAPPING__VALUE_CONTAINS_PRIMARY_KEY, "false");
+
+    gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
+
+    locator.invoke(() -> {
+      String xml = 
InternalLocator.getLocator().getSharedConfiguration().getConfiguration("cluster")
+          .getCacheXmlContent();
+      assertThat(xml).isNotNull().contains("jdbc:connector-service");
+      assertThat(xml).isNotNull().contains("jdbc:region-mapping");
+      assertThat(xml).isNotNull().doesNotContain("jdbc:field-mapping");
+    });
+  }
 }
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 1ba728f..a3caac5 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
@@ -161,6 +161,36 @@ public class 
JdbcConnectorServiceXmlGeneratorIntegrationTest {
   }
 
   @Test
+  public void generatesXmlContainingRegionMappingWithoutFieldMap() throws 
Exception {
+    JdbcConnectorService service = 
cache.getService(JdbcConnectorService.class);
+    RegionMappingBuilder regionMappingBuilder =
+        new 
RegionMappingBuilder().withRegionName("regionName").withPdxClassName("pdxClassName")
+            
.withTableName("tableName").withConnectionConfigName("connectionConfigName")
+            .withPrimaryKeyInValue("true").withFieldToColumnMappings(null);
+    RegionMapping regionMapping = regionMappingBuilder.build();
+    service.createRegionMapping(regionMapping);
+
+    generateXml();
+
+    Document document = getCacheXmlDocument();
+    NodeList serviceElements = getElementsByName(document, 
ElementType.CONNECTION_SERVICE);
+    assertThat(serviceElements.getLength()).isEqualTo(1);
+
+    NodeList mappingElements = getElementsByName(document, 
ElementType.REGION_MAPPING);
+    assertThat(mappingElements.getLength()).isEqualTo(1);
+
+    Element mappingElement = (Element) mappingElements.item(0);
+    assertThat(mappingElement.getAttribute(REGION)).isEqualTo("regionName");
+    
assertThat(mappingElement.getAttribute(PDX_CLASS)).isEqualTo("pdxClassName");
+    assertThat(mappingElement.getAttribute(TABLE)).isEqualTo("tableName");
+    
assertThat(mappingElement.getAttribute(CONNECTION_NAME)).isEqualTo("connectionConfigName");
+    
assertThat(mappingElement.getAttribute(PRIMARY_KEY_IN_VALUE)).isEqualTo("true");
+
+    NodeList fieldMappingElements = getElementsByName(mappingElement, 
ElementType.FIELD_MAPPING);
+    assertThat(fieldMappingElements.getLength()).isEqualTo(0);
+  }
+
+  @Test
   public void generatedXmlWithConnectionConfigurationCanBeParsed() 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>'].

Reply via email to