You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2016/05/13 17:25:17 UTC

[3/3] incubator-geode git commit: GEODE-1390: Move gfsh help tests from closed to open

GEODE-1390: Move gfsh help tests from closed to open


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/04a00042
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/04a00042
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/04a00042

Branch: refs/heads/develop
Commit: 04a000422103887da13d7fd6422995a5bbe06a51
Parents: 7051c7a
Author: Jens Deppe <jd...@pivotal.io>
Authored: Thu May 12 13:53:49 2016 -0700
Committer: Jens Deppe <jd...@pivotal.io>
Committed: Fri May 13 10:24:38 2016 -0700

----------------------------------------------------------------------
 .../cli/commands/CliCommandTestBase.java        |    4 +-
 .../cli/commands/HelpCommandsJUnitTest.java     |  120 +
 .../cli/commands/golden-help-offline.properties | 2997 ++++++++++++++++++
 .../cli/commands/golden-help-online.properties  |  657 ++++
 4 files changed, 3775 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/04a00042/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
index 0486c5a..4b25165 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
@@ -43,8 +43,6 @@ import com.gemstone.gemfire.management.internal.security.JSONAuthorization;
 import com.gemstone.gemfire.test.dunit.Host;
 import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase;
 
-import org.junit.runners.Parameterized;
-
 import org.junit.Rule;
 import org.junit.rules.TemporaryFolder;
 
@@ -396,7 +394,7 @@ public abstract class CliCommandTestBase extends JUnit4CacheTestCase {
     printStream.print(commandResultToString(commandResult));
   }
 
-  protected String commandResultToString(final CommandResult commandResult) {
+  protected static String commandResultToString(final CommandResult commandResult) {
     assertNotNull(commandResult);
 
     commandResult.resetToFirstLine();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/04a00042/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/HelpCommandsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/HelpCommandsJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/HelpCommandsJUnitTest.java
new file mode 100644
index 0000000..7cbe85a
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/HelpCommandsJUnitTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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 com.gemstone.gemfire.management.internal.cli.commands;
+
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.AvailablePortHelper;
+import com.gemstone.gemfire.management.internal.cli.CommandManager;
+import com.gemstone.gemfire.management.internal.cli.parser.CommandTarget;
+import com.gemstone.gemfire.management.internal.cli.result.CommandResult;
+import com.gemstone.gemfire.management.internal.cli.shell.Gfsh;
+import com.gemstone.gemfire.management.internal.cli.shell.GfshConfig;
+import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Map;
+import java.util.Properties;
+
+import static com.gemstone.gemfire.management.internal.cli.commands.CliCommandTestBase.commandResultToString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@Category(IntegrationTest.class)
+public class HelpCommandsJUnitTest extends JUnit4DistributedTestCase {
+
+  private int jmxPort;
+
+  @Before
+  public void setup() {
+    jmxPort = AvailablePortHelper.getRandomAvailableTCPPort();
+
+    Properties localProps = new Properties();
+    localProps.setProperty(DistributionConfig.JMX_MANAGER_NAME, "true");
+    localProps.setProperty(DistributionConfig.JMX_MANAGER_START_NAME, "true");
+    localProps.setProperty(DistributionConfig.JMX_MANAGER_PORT_NAME, String.valueOf(jmxPort));
+    getSystem(localProps);
+
+  }
+
+  @Test
+  public void testOfflineHelp() throws Exception {
+    Properties helpProps = new Properties();
+    helpProps.load(HelpCommandsJUnitTest.class.getResourceAsStream("golden-help-offline.properties"));
+
+    Gfsh gfsh = Gfsh.getInstance(false, new String[0], new GfshConfig());
+
+    CommandManager cm = CommandManager.getInstance();
+    for (Map.Entry<String, CommandTarget> e : cm.getCommands().entrySet()) {
+      // Mock commands may have been produced in the VM by other tests
+      // 'quit' is an alias for 'exit' and doesn't produce help
+      if (e.getKey().contains("mock") || e.getKey().contains("quit")) {
+        continue;
+      }
+
+      CommandResult cr = (CommandResult) gfsh.executeCommand("help " + e.getKey()).getResult();
+      String gfshResult = commandResultToString(cr);
+
+      String goldParam = e.getKey().replace(" ", "-") + ".help";
+      String goldResult = helpProps.getProperty(goldParam);
+      assertNotNull("No golden text for: " + goldParam, goldResult);
+      assertEquals(goldResult.trim(), gfshResult.trim());
+
+      helpProps.remove(goldParam);
+    }
+
+    // No help should remain unchecked
+    assertEquals(0, helpProps.size());
+  }
+
+  @Test
+  public void testOnlineHelp() throws Exception {
+    Properties helpProps = new Properties();
+    helpProps.load(HelpCommandsJUnitTest.class.getResourceAsStream("golden-help-online.properties"));
+
+    Gfsh gfsh = Gfsh.getInstance(false, new String[0], new GfshConfig());
+    gfsh.executeCommand("connect --jmx-manager=localhost[" + jmxPort + "]");
+
+    CommandManager cm = CommandManager.getInstance();
+    for (Map.Entry<String, CommandTarget> e : cm.getCommands().entrySet()) {
+      // Mock commands may have been produced in the VM by other tests
+      // 'quit' is an alias for 'exit' and doesn't produce help
+      if (e.getKey().contains("mock") || e.getKey().contains("quit")) {
+        continue;
+      }
+
+      CommandResult cr = (CommandResult) gfsh.executeCommand("help " + e.getKey()).getResult();
+      String gfshResult = commandResultToString(cr);
+
+      String goldParam = e.getKey().replace(" ", "-") + ".help";
+      String goldResult = helpProps.getProperty(goldParam);
+      assertNotNull("No golden text for: " + goldParam, goldResult);
+
+      String[] lines = gfshResult.split("\n");
+      gfshResult = String.join("\n", lines[0], lines[1], lines[2], lines[3]);
+
+      assertEquals(goldResult.trim(), gfshResult.trim());
+
+      helpProps.remove(goldParam);
+    }
+
+    // No help should remain unchecked
+    assertEquals(0, helpProps.size());
+  }
+}