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-3991 updated: GEODE-3991 Add list region mapping command
Date Mon, 11 Dec 2017 05:27:25 GMT
This is an automated email from the ASF dual-hosted git repository.

lgallinat pushed a commit to branch feature/GEODE-3991
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-3991 by this push:
     new f24c10b  GEODE-3991 Add list region mapping command
f24c10b is described below

commit f24c10b823033bc7be7717c32d232093b30dc032
Author: Lynn Gallinat <lgallinat@pivotal.io>
AuthorDate: Sun Dec 10 21:23:15 2017 -0800

    GEODE-3991 Add list region mapping command
---
 .../internal/InternalJdbcConnectorService.java     |   3 +
 .../jdbc/internal/JdbcConnectorService.java        |   7 +
 .../jdbc/internal/cli/ListConnectionCommand.java   |   2 +-
 ...nCommand.java => ListRegionMappingCommand.java} |  52 +++----
 .../internal/cli/ListRegionMappingFunction.java    |  43 ++++++
 .../org.springframework.shell.core.CommandMarker   |   1 +
 .../cli/ListRegionMappingCommandDUnitTest.java     | 123 +++++++++++++++
 .../ListRegionMappingCommandIntegrationTest.java   | 108 ++++++++++++++
 .../cli/ListRegionMappingFunctionTest.java         | 166 +++++++++++++++++++++
 9 files changed, 478 insertions(+), 27 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java
index baa4b99..43d1be5 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java
@@ -41,4 +41,7 @@ public interface InternalJdbcConnectorService extends Extension<Cache>,
CacheSer
   void destroyRegionMapping(String regionName);
 
   RegionMapping getMappingForRegion(String regionName);
+
+  Set<RegionMapping> getRegionMappings();
+
 }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JdbcConnectorService.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JdbcConnectorService.java
index 475e330..2761f51 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JdbcConnectorService.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JdbcConnectorService.java
@@ -77,6 +77,13 @@ public class JdbcConnectorService implements InternalJdbcConnectorService
{
   }
 
   @Override
+  public Set<RegionMapping> getRegionMappings() {
+    Set<RegionMapping> regionMappings = new HashSet<>();
+    regionMappings.addAll(mappingsByRegion.values());
+    return regionMappings;
+  }
+
+  @Override
   public void createRegionMapping(RegionMapping mapping) throws RegionMappingExistsException
{
     registerAsExtension();
     RegionMapping existing = mappingsByRegion.putIfAbsent(mapping.getRegionName(), mapping);
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java
index f78191a..8da6e93 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java
@@ -35,7 +35,7 @@ import org.apache.geode.security.ResourcePermission;
 
 public class ListConnectionCommand implements GfshCommand {
 
-  static final String LIST_JDBC_CONNECTION = "list jdbc-connection";
+  static final String LIST_JDBC_CONNECTION = "list jdbc-connections";
   static final String LIST_JDBC_CONNECTION__HELP = "Display jdbc connections for all members.";
 
   static final String LIST_OF_CONNECTIONS = "List of connections";
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingCommand.java
similarity index 59%
copy from geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java
copy to geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingCommand.java
index f78191a..67df211 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingCommand.java
@@ -22,7 +22,7 @@ import java.util.Set;
 import org.springframework.shell.core.annotation.CliCommand;
 
 import org.apache.geode.cache.execute.ResultCollector;
-import org.apache.geode.connectors.jdbc.internal.ConnectionConfiguration;
+import org.apache.geode.connectors.jdbc.internal.RegionMapping;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.Result;
@@ -33,19 +33,19 @@ import org.apache.geode.management.internal.cli.result.TabularResultData;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
 
-public class ListConnectionCommand implements GfshCommand {
+public class ListRegionMappingCommand implements GfshCommand {
 
-  static final String LIST_JDBC_CONNECTION = "list jdbc-connection";
-  static final String LIST_JDBC_CONNECTION__HELP = "Display jdbc connections for all members.";
+  static final String LIST_MAPPING = "list jdbc-mappings";
+  static final String LIST_MAPPING__HELP = "Display jdbc mappings for all members.";
 
-  static final String LIST_OF_CONNECTIONS = "List of connections";
-  static final String NO_CONNECTIONS_FOUND = "No connections found";
+  static final String LIST_OF_MAPPINGS = "List of mappings";
+  static final String NO_MAPPINGS_FOUND = "No mappings found";
 
-  @CliCommand(value = LIST_JDBC_CONNECTION, help = LIST_JDBC_CONNECTION__HELP)
+  @CliCommand(value = LIST_MAPPING, help = LIST_MAPPING__HELP)
   @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE)
   @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
       operation = ResourcePermission.Operation.MANAGE)
-  public Result listConnection() {
+  public Result listMapping() {
 
     // input
     Set<DistributedMember> targetMembers = getMembers(null, null);
@@ -54,27 +54,27 @@ public class ListConnectionCommand implements GfshCommand {
     }
 
     // action
-    ResultCollector<ConnectionConfiguration, List<ConnectionConfiguration[]>>
resultCollector =
-        execute(new ListConnectionFunction(), targetMembers.iterator().next());
+    ResultCollector<RegionMapping, List<RegionMapping[]>> resultCollector =
+        execute(new ListRegionMappingFunction(), targetMembers.iterator().next());
 
     // output
     TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
-    boolean connectionsExist = fillTabularResultData(resultCollector, tabularResultData);
-    return createResult(tabularResultData, connectionsExist);
+    boolean mappingsExist = fillTabularResultData(resultCollector, tabularResultData);
+    return createResult(tabularResultData, mappingsExist);
   }
 
-  ResultCollector<ConnectionConfiguration, List<ConnectionConfiguration[]>> execute(
-      ListConnectionFunction function, DistributedMember targetMember) {
-    return (ResultCollector<ConnectionConfiguration, List<ConnectionConfiguration[]>>)
executeFunction(
-        function, null, targetMember);
+  ResultCollector<RegionMapping, List<RegionMapping[]>> execute(ListRegionMappingFunction
function,
+      DistributedMember targetMember) {
+    return (ResultCollector<RegionMapping, List<RegionMapping[]>>) executeFunction(function,
null,
+        targetMember);
   }
 
-  private Result createResult(TabularResultData tabularResultData, boolean connectionsExist)
{
-    if (connectionsExist) {
+  private Result createResult(TabularResultData tabularResultData, boolean mappingsExist)
{
+    if (mappingsExist) {
       return ResultBuilder.buildResult(tabularResultData);
 
     } else {
-      return ResultBuilder.createInfoResult(NO_CONNECTIONS_FOUND);
+      return ResultBuilder.createInfoResult(NO_MAPPINGS_FOUND);
     }
   }
 
@@ -82,13 +82,13 @@ public class ListConnectionCommand implements GfshCommand {
    * Returns true if any connections exist
    */
   private boolean fillTabularResultData(
-      ResultCollector<ConnectionConfiguration, List<ConnectionConfiguration[]>>
resultCollector,
+      ResultCollector<RegionMapping, List<RegionMapping[]>> resultCollector,
       TabularResultData tabularResultData) {
-    Set<ConnectionConfiguration> connectionConfigs = new HashSet<>();
+    Set<RegionMapping> regionMappings = new HashSet<>();
 
     for (Object resultObject : resultCollector.getResult()) {
-      if (resultObject instanceof ConnectionConfiguration[]) {
-        connectionConfigs.addAll(Arrays.asList((ConnectionConfiguration[]) resultObject));
+      if (resultObject instanceof RegionMapping[]) {
+        regionMappings.addAll(Arrays.asList((RegionMapping[]) resultObject));
       } else if (resultObject instanceof Throwable) {
         throw new IllegalStateException((Throwable) resultObject);
       } else {
@@ -96,10 +96,10 @@ public class ListConnectionCommand implements GfshCommand {
       }
     }
 
-    for (ConnectionConfiguration connectionConfig : connectionConfigs) {
-      tabularResultData.accumulate(LIST_OF_CONNECTIONS, connectionConfig.getName());
+    for (RegionMapping mapping : regionMappings) {
+      tabularResultData.accumulate(LIST_OF_MAPPINGS, mapping.getRegionName());
     }
 
-    return !connectionConfigs.isEmpty();
+    return !regionMappings.isEmpty();
   }
 }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingFunction.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingFunction.java
new file mode 100644
index 0000000..1e16b41
--- /dev/null
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingFunction.java
@@ -0,0 +1,43 @@
+/*
+ * 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.internal.cli;
+
+import java.util.Set;
+
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.RegionMapping;
+
+public class ListRegionMappingFunction extends JdbcCliFunction<Void, RegionMapping[]>
{
+
+  ListRegionMappingFunction() {
+    super(new FunctionContextArgumentProvider(), new ExceptionHandler());
+  }
+
+  @Override
+  RegionMapping[] getFunctionResult(InternalJdbcConnectorService service,
+      FunctionContext<Void> context) {
+    return getRegionMappingsAsArray(service);
+  }
+
+  RegionMapping[] getRegionMappingsAsArray(InternalJdbcConnectorService service) {
+    Set<RegionMapping> regionMappings = getRegionMappings(service);
+    return regionMappings.toArray(new RegionMapping[regionMappings.size()]);
+  }
+
+  private Set<RegionMapping> getRegionMappings(InternalJdbcConnectorService service)
{
+    return service.getRegionMappings();
+  }
+}
diff --git a/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker
b/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker
index ceab250..897e7d7 100644
--- a/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker
+++ b/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker
@@ -23,3 +23,4 @@ org.apache.geode.connectors.jdbc.internal.cli.AlterConnectionCommand
 org.apache.geode.connectors.jdbc.internal.cli.CreateRegionMappingCommand
 org.apache.geode.connectors.jdbc.internal.cli.AlterRegionMappingCommand
 org.apache.geode.connectors.jdbc.internal.cli.DestroyRegionMappingCommand
+org.apache.geode.connectors.jdbc.internal.cli.ListRegionMappingCommand
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingCommandDUnitTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingCommandDUnitTest.java
new file mode 100644
index 0000000..d0bc5c4
--- /dev/null
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingCommandDUnitTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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.internal.cli;
+
+import static org.apache.geode.connectors.jdbc.internal.cli.ListRegionMappingCommand.LIST_MAPPING;
+import static org.apache.geode.connectors.jdbc.internal.cli.ListRegionMappingCommand.LIST_OF_MAPPINGS;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.RegionMappingBuilder;
+import org.apache.geode.connectors.jdbc.internal.RegionMappingExistsException;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.assertions.CommandResultAssert;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+
+@Category(DistributedTest.class)
+public class ListRegionMappingCommandDUnitTest implements Serializable {
+
+  @Rule
+  public transient GfshCommandRule gfsh = new GfshCommandRule();
+
+  @Rule
+  public LocatorServerStartupRule startupRule = new LocatorServerStartupRule();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  private MemberVM locator;
+  private MemberVM server;
+
+  private String regionName;
+
+  @Before
+  public void before() throws Exception {
+    regionName = "testRegion";
+
+    locator = startupRule.startLocatorVM(0);
+    server = startupRule.startServerVM(1, locator.getPort());
+
+    gfsh.connectAndVerify(locator);
+  }
+
+  @Test
+  public void listsOneRegionMapping() throws Exception {
+    server.invoke(() -> createOneRegionMapping());
+    CommandStringBuilder csb = new CommandStringBuilder(LIST_MAPPING);
+
+    CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
+
+    commandResultAssert.statusIsSuccess();
+    commandResultAssert.tableHasRowCount(LIST_OF_MAPPINGS, 1);
+    commandResultAssert.tableHasColumnOnlyWithValues(LIST_OF_MAPPINGS, regionName);
+  }
+
+  @Test
+  public void listsMultipleRegionMappings() throws Exception {
+    server.invoke(() -> createNRegionMappings(3));
+    CommandStringBuilder csb = new CommandStringBuilder(LIST_MAPPING);
+
+    CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
+
+    commandResultAssert.statusIsSuccess();
+    commandResultAssert.tableHasRowCount(LIST_OF_MAPPINGS, 3);
+    commandResultAssert.tableHasColumnOnlyWithValues(LIST_OF_MAPPINGS, regionName + "-1",
+        regionName + "-2", regionName + "-3");
+  }
+
+  @Test
+  public void reportsNoRegionMappingsFound() throws Exception {
+    CommandStringBuilder csb = new CommandStringBuilder(LIST_MAPPING);
+
+    CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
+
+    commandResultAssert.statusIsSuccess();
+    commandResultAssert.containsOutput("No mappings found");
+  }
+
+  private void createOneRegionMapping() throws RegionMappingExistsException {
+    InternalCache cache = LocatorServerStartupRule.getCache();
+    InternalJdbcConnectorService service = cache.getService(InternalJdbcConnectorService.class);
+
+    service.createRegionMapping(new RegionMappingBuilder().withRegionName(regionName)
+        .withPdxClassName("x.y.MyPdxClass").withPrimaryKeyInValue(true).build());
+
+    assertThat(service.getMappingForRegion(regionName)).isNotNull();
+  }
+
+  private void createNRegionMappings(int N) throws RegionMappingExistsException {
+    InternalCache cache = LocatorServerStartupRule.getCache();
+    InternalJdbcConnectorService service = cache.getService(InternalJdbcConnectorService.class);
+    for (int i = 1; i <= N; i++) {
+      String name = regionName + "-" + i;
+      service.createRegionMapping(new RegionMappingBuilder().withRegionName(name)
+          .withPdxClassName("x.y.MyPdxClass").withPrimaryKeyInValue(true).build());
+      assertThat(service.getMappingForRegion(name)).isNotNull();
+    }
+  }
+
+}
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingCommandIntegrationTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingCommandIntegrationTest.java
new file mode 100644
index 0000000..c10ee95
--- /dev/null
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingCommandIntegrationTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.internal.cli;
+
+import static org.apache.geode.connectors.jdbc.internal.cli.ListConnectionCommand.LIST_OF_CONNECTIONS;
+import static org.apache.geode.connectors.jdbc.internal.cli.ListConnectionCommand.NO_CONNECTIONS_FOUND;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.connectors.jdbc.internal.ConnectionConfigBuilder;
+import org.apache.geode.connectors.jdbc.internal.ConnectionConfiguration;
+import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+@Category(IntegrationTest.class)
+public class ListRegionMappingCommandIntegrationTest {
+
+  private InternalCache cache;
+  private InternalJdbcConnectorService service;
+
+  private ConnectionConfiguration connectionConfig1;
+  private ConnectionConfiguration connectionConfig2;
+  private ConnectionConfiguration connectionConfig3;
+
+  private ListConnectionCommand command;
+
+  @Before
+  public void setup() throws Exception {
+    String[] params = new String[] {"param1:value1", "param2:value2"};
+
+    connectionConfig1 = new ConnectionConfigBuilder().withName("connection1").withUrl("url1")
+        .withUser("user1").withPassword("password1").withParameters(params).build();
+    connectionConfig2 = new ConnectionConfigBuilder().withName("connection2").withUrl("url2")
+        .withUser("user2").withPassword("password2").withParameters(params).build();
+    connectionConfig3 = new ConnectionConfigBuilder().withName("connection3").withUrl("url3")
+        .withUser("user3").withPassword("password3").withParameters(params).build();
+
+    cache = (InternalCache) new CacheFactory().set(ENABLE_CLUSTER_CONFIGURATION, "true").create();
+    service = cache.getService(InternalJdbcConnectorService.class);
+
+    command = new ListConnectionCommand();
+  }
+
+  @After
+  public void tearDown() {
+    cache.close();
+  }
+
+  @Test
+  public void displaysNoConnectionsFoundWhenZeroConnectionsExist() throws Exception {
+    Result result = command.listConnection();
+
+    assertThat(result.getStatus()).isSameAs(Result.Status.OK);
+    CommandResult commandResult = (CommandResult) result;
+    String tableContent = commandResult.getTableContent().toString();
+    assertThat(tableContent).contains(NO_CONNECTIONS_FOUND);
+    assertThat(tableContent).doesNotContain(connectionConfig1.getName())
+        .doesNotContain(connectionConfig2.getName()).doesNotContain(connectionConfig3.getName());
+  }
+
+  @Test
+  public void displaysListOfConnectionsHeaderWhenOneConnectionExists() throws Exception {
+    service.createConnectionConfig(connectionConfig1);
+
+    Result result = command.listConnection();
+
+    assertThat(result.getStatus()).isSameAs(Result.Status.OK);
+    CommandResult commandResult = (CommandResult) result;
+    String tableContent = commandResult.getTableContent().toString();
+    assertThat(tableContent).contains(LIST_OF_CONNECTIONS);
+    assertThat(tableContent).contains(connectionConfig1.getName());
+  }
+
+  @Test
+  public void displaysMultipleConnectionsByName() throws Exception {
+    service.createConnectionConfig(connectionConfig1);
+    service.createConnectionConfig(connectionConfig2);
+    service.createConnectionConfig(connectionConfig3);
+
+    Result result = command.listConnection();
+
+    assertThat(result.getStatus()).isSameAs(Result.Status.OK);
+    CommandResult commandResult = (CommandResult) result;
+    assertThat(commandResult.getTableContent().toString()).contains(connectionConfig1.getName())
+        .contains(connectionConfig2.getName()).contains(connectionConfig3.getName());
+  }
+}
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingFunctionTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingFunctionTest.java
new file mode 100644
index 0000000..f40d132
--- /dev/null
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListRegionMappingFunctionTest.java
@@ -0,0 +1,166 @@
+/*
+ * 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.internal.cli;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang.SerializationUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.ArgumentCaptor;
+
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.execute.ResultSender;
+import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.RegionMapping;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.distributed.DistributedSystem;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class ListRegionMappingFunctionTest {
+
+  private FunctionContext<Void> context;
+  private ResultSender<Object> resultSender;
+  private InternalJdbcConnectorService service;
+
+  private RegionMapping regionMapping1;
+  private RegionMapping regionMapping2;
+  private RegionMapping regionMapping3;
+
+  private Set<RegionMapping> expected;
+
+  private ListRegionMappingFunction function;
+
+  @Before
+  public void setUp() {
+    InternalCache cache = mock(InternalCache.class);
+    context = mock(FunctionContext.class);
+    DistributedMember member = mock(DistributedMember.class);
+    resultSender = mock(ResultSender.class);
+    service = mock(InternalJdbcConnectorService.class);
+    DistributedSystem system = mock(DistributedSystem.class);
+
+    regionMapping1 = mock(RegionMapping.class);
+    regionMapping2 = mock(RegionMapping.class);
+    regionMapping3 = mock(RegionMapping.class);
+
+    expected = new HashSet<>();
+
+    when(context.getResultSender()).thenReturn(resultSender);
+    when(context.getCache()).thenReturn(cache);
+    when(cache.getDistributedSystem()).thenReturn(system);
+    when(system.getDistributedMember()).thenReturn(member);
+    when(cache.getService(eq(InternalJdbcConnectorService.class))).thenReturn(service);
+    when(service.getRegionMappings()).thenReturn(expected);
+
+    function = new ListRegionMappingFunction();
+  }
+
+  @Test
+  public void isHAReturnsFalse() {
+    assertThat(function.isHA()).isFalse();
+  }
+
+  @Test
+  public void getIdReturnsNameOfClass() {
+    assertThat(function.getId()).isEqualTo(function.getClass().getName());
+  }
+
+  @Test
+  public void serializes() {
+    Serializable original = function;
+
+    Object copy = SerializationUtils.clone(original);
+
+    assertThat(copy).isNotSameAs(original).isInstanceOf(ListRegionMappingFunction.class);
+  }
+
+  @Test
+  public void getRegionMappingsReturnsMultiple() {
+    expected.add(regionMapping1);
+    expected.add(regionMapping2);
+    expected.add(regionMapping3);
+
+    RegionMapping[] actual = function.getRegionMappingsAsArray(service);
+
+    assertThat(actual).containsExactlyInAnyOrder(regionMapping1, regionMapping2, regionMapping3);
+  }
+
+  @Test
+  public void getRegionMappingsReturnsEmpty() {
+    RegionMapping[] actual = function.getRegionMappingsAsArray(service);
+
+    assertThat(actual).isEmpty();
+  }
+
+  @Test
+  public void executeReturnsResultWithAllRegionMappings() {
+    expected.add(regionMapping1);
+    expected.add(regionMapping2);
+    expected.add(regionMapping3);
+
+    function.execute(context);
+
+    ArgumentCaptor<Object[]> argument = ArgumentCaptor.forClass(Object[].class);
+    verify(resultSender, times(1)).lastResult(argument.capture());
+    assertThat(argument.getValue()).containsExactlyInAnyOrder(regionMapping1, regionMapping2,
+        regionMapping3);
+  }
+
+  @Test
+  public void executeReturnsEmptyResultForNoRegionMappings() {
+    function.execute(context);
+
+    ArgumentCaptor<Object[]> argument = ArgumentCaptor.forClass(Object[].class);
+    verify(resultSender, times(1)).lastResult(argument.capture());
+    assertThat(argument.getValue()).isEmpty();
+  }
+
+  @Test
+  public void executeReturnsResultForExceptionWithoutMessage() {
+    when(service.getRegionMappings()).thenThrow(new NullPointerException());
+
+    function.execute(context);
+
+    ArgumentCaptor<CliFunctionResult> argument = ArgumentCaptor.forClass(CliFunctionResult.class);
+    verify(resultSender, times(1)).lastResult(argument.capture());
+    assertThat(argument.getValue().getMessage()).contains(NullPointerException.class.getName());
+  }
+
+  @Test
+  public void executeReturnsResultForExceptionWithMessage() {
+    when(service.getRegionMappings()).thenThrow(new IllegalArgumentException("some message"));
+
+    function.execute(context);
+
+    ArgumentCaptor<CliFunctionResult> argument = ArgumentCaptor.forClass(CliFunctionResult.class);
+    verify(resultSender, times(1)).lastResult(argument.capture());
+    assertThat(argument.getValue().getMessage()).contains("some message")
+        .doesNotContain(IllegalArgumentException.class.getName());
+  }
+}

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

Mime
View raw message