You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2018/04/06 15:21:53 UTC

[geode] branch develop updated: GEODE-4830: modify the message when no jndi-binding is found. (#1732)

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

jinmeiliao 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 ced3d00  GEODE-4830: modify the message when no jndi-binding is found. (#1732)
ced3d00 is described below

commit ced3d005e6a81cd72dd147abb885bb2bb88bfd03
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Fri Apr 6 08:21:48 2018 -0700

    GEODE-4830: modify the message when no jndi-binding is found. (#1732)
---
 .../cli/commands/ListJndiBindingCommand.java       | 19 ++++--
 .../cli/commands/ListJndiBindingCommandTest.java   | 74 ++++++++++++++++++++++
 2 files changed, 86 insertions(+), 7 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommand.java
index cc27b3e..9b352d7 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommand.java
@@ -58,14 +58,18 @@ public class ListJndiBindingCommand extends InternalGfshCommand {
         (InternalClusterConfigurationService) getConfigurationService();
     if (ccService != null) {
       configTable = resultSection.addTable();
-      configTable.setHeader("Configured JNDI bindings: ");
       // we don't support creating jndi binding with random group name yet
       CacheConfig cacheConfig = ccService.getCacheConfig("cluster");
       List<JndiBindingsType.JndiBinding> jndiBindings = cacheConfig.getJndiBindings();
-      for (JndiBindingsType.JndiBinding jndiBinding : jndiBindings) {
-        configTable.accumulate("Group Name", "cluster");
-        configTable.accumulate("JNDI Name", jndiBinding.getJndiName());
-        configTable.accumulate("JDBC Driver Class", jndiBinding.getJdbcDriverClass());
+      if (jndiBindings.size() == 0) {
+        configTable.setHeader("No JNDI-bindings found in cluster configuration");
+      } else {
+        configTable.setHeader("Configured JNDI bindings: ");
+        for (JndiBindingsType.JndiBinding jndiBinding : jndiBindings) {
+          configTable.accumulate("Group Name", "cluster");
+          configTable.accumulate("JNDI Name", jndiBinding.getJndiName());
+          configTable.accumulate("JDBC Driver Class", jndiBinding.getJdbcDriverClass());
+        }
       }
     }
 
@@ -75,12 +79,14 @@ public class ListJndiBindingCommand extends InternalGfshCommand {
       if (configTable == null) {
         return ResultBuilder.createUserErrorResult("No members found");
       }
+      configTable.setFooter("No members found");
       return ResultBuilder.buildResult(resultData);
     }
 
     memberTable = resultSection.addTable();
-    memberTable.setHeader("Active JNDI bindings found on each member: ");
     List<CliFunctionResult> rc = executeAndGetFunctionResult(LIST_BINDING_FUNCTION, null, members);
+
+    memberTable.setHeader("Active JNDI bindings found on each member: ");
     for (CliFunctionResult oneResult : rc) {
       Serializable[] serializables = oneResult.getSerializables();
       for (int i = 0; i < serializables.length; i += 2) {
@@ -89,7 +95,6 @@ public class ListJndiBindingCommand extends InternalGfshCommand {
         memberTable.accumulate("JDBC Driver Class", serializables[i + 1]);
       }
     }
-
     return ResultBuilder.buildResult(resultData);
   }
 }
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommandTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommandTest.java
new file mode 100644
index 0000000..5fa36fc
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommandTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.management.internal.cli.commands;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.configuration.CacheConfig;
+import org.apache.geode.distributed.internal.InternalClusterConfigurationService;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.apache.geode.test.junit.rules.GfshParserRule;
+
+
+@Category(UnitTest.class)
+public class ListJndiBindingCommandTest {
+  @ClassRule
+  public static GfshParserRule gfsh = new GfshParserRule();
+
+  private ListJndiBindingCommand command;
+  private InternalClusterConfigurationService ccService;
+  private CacheConfig cacheConfig;
+
+
+  @Before
+  public void setUp() throws Exception {
+    command = spy(ListJndiBindingCommand.class);
+    ccService = mock(InternalClusterConfigurationService.class);
+    doReturn(ccService).when(command).getConfigurationService();
+    cacheConfig = mock(CacheConfig.class);
+    when(ccService.getCacheConfig("cluster")).thenReturn(cacheConfig);
+  }
+
+  @Test
+  public void noServiceNoMember() {
+    doReturn(null).when(command).getConfigurationService();
+    doReturn(Collections.emptySet()).when(command).findMembers(null, null);
+    gfsh.executeAndAssertThat(command, "list jndi-binding").statusIsError()
+        .containsOutput("No members found");
+  }
+
+  @Test
+  public void hasServiceNoBindingNoMember() {
+    doReturn(ccService).when(command).getConfigurationService();
+    when(cacheConfig.getJndiBindings()).thenReturn(Collections.emptyList());
+    doReturn(Collections.emptySet()).when(command).findMembers(null, null);
+    gfsh.executeAndAssertThat(command, "list jndi-binding").statusIsSuccess()
+        .containsOutput("No JNDI-bindings found in cluster configuration")
+        .containsOutput("No members found");
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
jinmeiliao@apache.org.