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-6187: Added sorting and hid empty attributes for DescribeMappingCommand (#3079)
Date Wed, 16 Jan 2019 20:32:44 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 f383899  GEODE-6187: Added sorting and hid empty attributes for DescribeMappingCommand
(#3079)
f383899 is described below

commit f38389928e575cf2d18825c93ac4f69b7edae3c9
Author: BenjaminPerryRoss <39068135+BenjaminPerryRoss@users.noreply.github.com>
AuthorDate: Wed Jan 16 12:32:32 2019 -0800

    GEODE-6187: Added sorting and hid empty attributes for DescribeMappingCommand (#3079)
    
    
    Co-authored-by: Ben Ross <bross@pivotal.io>
    Co-authored-by: Rob Day-Reynolds <rdayreynolds@pivotal.io>
---
 .../jdbc/internal/cli/DescribeMappingCommand.java  |  2 +-
 .../jdbc/internal/cli/DescribeMappingFunction.java | 17 +++++++++++------
 .../util/internal/DescribeMappingResult.java       |  4 ++--
 .../internal/cli/DescribeMappingFunctionTest.java  | 14 +++++++++-----
 .../util/DescribeMappingCommandTest.java           |  8 +++++---
 .../util/internal/DescribeMappingResultTest.java   |  2 +-
 .../test/junit/assertions/CommandResultAssert.java | 22 +++++++++++++++++++++-
 7 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommand.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommand.java
index 80edb95..2d6d803 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommand.java
@@ -44,7 +44,7 @@ public class DescribeMappingCommand extends GfshCommand {
   private static final String DESCRIBE_MAPPING__REGION_NAME__HELP =
       "Region name of the JDBC mapping to be described.";
 
-  private static final String RESULT_SECTION_NAME = "MappingDescription";
+  public static final String RESULT_SECTION_NAME = "MappingDescription";
 
   @CliCommand(value = DESCRIBE_MAPPING, help = DESCRIBE_MAPPING__HELP)
   @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE)
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingFunction.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingFunction.java
index e94d6a9..2cd9f9e 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingFunction.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingFunction.java
@@ -23,7 +23,7 @@ import static org.apache.geode.connectors.util.internal.MappingConstants.SCHEMA_
 import static org.apache.geode.connectors.util.internal.MappingConstants.SYNCHRONOUS_NAME;
 import static org.apache.geode.connectors.util.internal.MappingConstants.TABLE_NAME;
 
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.geode.cache.execute.FunctionContext;
@@ -49,14 +49,12 @@ public class DescribeMappingFunction extends CliFunction<String>
{
       return null;
     }
 
-    Map<String, String> attributes = new HashMap<>();
+    Map<String, String> attributes = new LinkedHashMap<>();
     attributes.put(REGION_NAME, mapping.getRegionName());
-    attributes.put(DATA_SOURCE_NAME, mapping.getDataSourceName());
     attributes.put(TABLE_NAME, mapping.getTableName());
-    attributes.put(PDX_NAME, mapping.getPdxName());
+    attributes.put(DATA_SOURCE_NAME, mapping.getDataSourceName());
     attributes.put(ID_NAME, mapping.getIds());
-    attributes.put(SCHEMA_NAME, mapping.getSchema());
-    attributes.put(CATALOG_NAME, mapping.getCatalog());
+    attributes.put(PDX_NAME, mapping.getPdxName());
 
     try {
       attributes.put(SYNCHRONOUS_NAME,
@@ -66,6 +64,13 @@ public class DescribeMappingFunction extends CliFunction<String>
{
       attributes.put(SYNCHRONOUS_NAME, "Not found.");
     }
 
+    if (mapping.getCatalog() != null) {
+      attributes.put(CATALOG_NAME, mapping.getCatalog());
+    }
+    if (mapping.getSchema() != null) {
+      attributes.put(SCHEMA_NAME, mapping.getSchema());
+    }
+
     return new DescribeMappingResult(attributes);
   }
 }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/util/internal/DescribeMappingResult.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/util/internal/DescribeMappingResult.java
index 83afca0..ca3e704 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/util/internal/DescribeMappingResult.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/util/internal/DescribeMappingResult.java
@@ -17,7 +17,7 @@ package org.apache.geode.connectors.util.internal;
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.geode.DataSerializable;
@@ -27,7 +27,7 @@ public class DescribeMappingResult implements DataSerializable {
   private final Map<String, String> attributeMap;
 
   public DescribeMappingResult() {
-    this.attributeMap = new HashMap<>();
+    this.attributeMap = new LinkedHashMap<>();
   }
 
   public DescribeMappingResult(Map<String, String> attributeMap) {
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingFunctionTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingFunctionTest.java
index 2e19080..2e29dd1 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingFunctionTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingFunctionTest.java
@@ -31,7 +31,8 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.io.Serializable;
-import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.commons.lang3.SerializationUtils;
@@ -118,20 +119,23 @@ public class DescribeMappingFunctionTest {
 
     function.execute(context);
 
-    Map<String, String> expectedAttributes = new HashMap<>();
+    Map<String, String> expectedAttributes = new LinkedHashMap<>();
     expectedAttributes.put(REGION_NAME, TEST_REGION);
-    expectedAttributes.put(PDX_NAME, TEST_PDX);
     expectedAttributes.put(TABLE_NAME, TEST_TABLE);
     expectedAttributes.put(DATA_SOURCE_NAME, TEST_DATASOURCE);
-    expectedAttributes.put(SYNCHRONOUS_NAME, TEST_SYNCHRONOUS);
     expectedAttributes.put(ID_NAME, TEST_ID);
-    expectedAttributes.put(SCHEMA_NAME, TEST_SCHEMA);
+    expectedAttributes.put(PDX_NAME, TEST_PDX);
+    expectedAttributes.put(SYNCHRONOUS_NAME, TEST_SYNCHRONOUS);
     expectedAttributes.put(CATALOG_NAME, TEST_CATALOG);
+    expectedAttributes.put(SCHEMA_NAME, TEST_SCHEMA);
 
     ArgumentCaptor<CliFunctionResult> argument = ArgumentCaptor.forClass(CliFunctionResult.class);
     verify(resultSender, times(1)).lastResult(argument.capture());
     DescribeMappingResult result = (DescribeMappingResult) argument.getValue().getResultObject();
     assertThat(result.getAttributeMap()).isEqualTo(expectedAttributes);
+
+    assertThat(new ArrayList<String>(result.getAttributeMap().keySet()))
+        .isEqualTo(new ArrayList<String>(expectedAttributes.keySet()));
   }
 
   @Test
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/org/apache/geode/connectors/util/DescribeMappingCommandTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/org/apache/geode/connectors/util/DescribeMappingCommandTest.java
index 0bbbf05..2ad9006 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/org/apache/geode/connectors/util/DescribeMappingCommandTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/org/apache/geode/connectors/util/DescribeMappingCommandTest.java
@@ -32,7 +32,7 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.util.Collections;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -78,15 +78,15 @@ public class DescribeMappingCommandTest {
   public void whenMemberExists() {
     doReturn(Collections.singleton(mock(DistributedMember.class))).when(command).findMembers(null,
         null);
-    Map<String, String> attributes = new HashMap<>();
+    Map<String, String> attributes = new LinkedHashMap<>();
     attributes.put(REGION_NAME, "region");
     attributes.put(PDX_NAME, "class1");
     attributes.put(TABLE_NAME, "table1");
     attributes.put(DATA_SOURCE_NAME, "name1");
     attributes.put(SYNCHRONOUS_NAME, "true");
     attributes.put(ID_NAME, "myId");
-    attributes.put(SCHEMA_NAME, "mySchema");
     attributes.put(CATALOG_NAME, "myCatalog");
+    attributes.put(SCHEMA_NAME, "mySchema");
 
     DescribeMappingResult mappingResult = new DescribeMappingResult(attributes);
 
@@ -99,6 +99,8 @@ public class DescribeMappingCommandTest {
 
 
     gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
+        .containsOrderedOutput(DescribeMappingCommand.RESULT_SECTION_NAME, REGION_NAME, PDX_NAME,
+            TABLE_NAME, DATA_SOURCE_NAME, SYNCHRONOUS_NAME, ID_NAME, CATALOG_NAME, SCHEMA_NAME)
         .containsOutput(REGION_NAME, "region")
         .containsOutput(DATA_SOURCE_NAME, "name1").containsOutput(TABLE_NAME, "table1")
         .containsOutput(PDX_NAME, "class1").containsOutput(ID_NAME, "myId")
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/util/internal/DescribeMappingResultTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/util/internal/DescribeMappingResultTest.java
index 06e2638..c2e75d8 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/util/internal/DescribeMappingResultTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/util/internal/DescribeMappingResultTest.java
@@ -36,8 +36,8 @@ public class DescribeMappingResultTest {
   public void testSeriazilabeToAndFromByteArray() throws IOException {
     Map<String, String> attributesMap = new HashMap<>();
     attributesMap.put(REGION_NAME, "myRegion");
-    attributesMap.put(PDX_NAME, "myPdx");
     attributesMap.put(TABLE_NAME, "myTable");
+    attributesMap.put(PDX_NAME, "myPdx");
     attributesMap.put(DATA_SOURCE_NAME, "myDatasource");
     attributesMap.put(SYNCHRONOUS_NAME, "false");
     attributesMap.put(ID_NAME, "myId");
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/CommandResultAssert.java
b/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/CommandResultAssert.java
index d1c71d0..2a0afd0 100644
--- a/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/CommandResultAssert.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/CommandResultAssert.java
@@ -19,12 +19,14 @@ import static org.assertj.core.api.Assertions.fail;
 
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.lang3.StringUtils;
 import org.assertj.core.api.AbstractAssert;
 import org.assertj.core.api.Assertions;
+import org.junit.Assert;
 
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.result.CommandResult;
@@ -34,7 +36,6 @@ import org.apache.geode.management.internal.cli.result.model.InfoResultModel;
 import org.apache.geode.management.internal.cli.result.model.ResultModel;
 import org.apache.geode.management.internal.cli.result.model.TabularResultModel;
 
-
 public class CommandResultAssert
     extends AbstractAssert<CommandResultAssert, CommandResultExecution> {
 
@@ -88,6 +89,25 @@ public class CommandResultAssert
     return this;
   }
 
+  public CommandResultAssert containsOrderedOutput(String dataSectionName,
+      String... expectedOutputs) {
+    LinkedHashMap<String, String> outputMap =
+        ((LinkedHashMap) actual.getCommandResult().getMapFromSection(dataSectionName));
+    String outputString = outputMap.toString();
+    int outputIndex = 0;
+
+    for (int i = 0; i < expectedOutputs.length; i++) {
+      outputIndex = outputString.indexOf(expectedOutputs[i]);
+      if (outputIndex == -1) {
+        Assert.fail("Expected output " + expectedOutputs[i]
+            + " was not found, or isn't in the specified order.");
+      }
+      outputString = outputString.substring(outputIndex);
+    }
+
+    return this;
+  }
+
   /**
    * Verifies the gfsh output does not contain the given output
    */


Mime
View raw message