You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/06/21 17:24:13 UTC
incubator-geode git commit: GEODE-1565: add quotes around any value
starting with hyphen
Repository: incubator-geode
Updated Branches:
refs/heads/develop de6105f98 -> 170919bcc
GEODE-1565: add quotes around any value starting with hyphen
* refactor OptionJFormatter into HyphenFormatter to format all values starting with hypen
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/170919bc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/170919bc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/170919bc
Branch: refs/heads/develop
Commit: 170919bcc33dcb48d931b5c4ad707df7eec4a2f0
Parents: de6105f
Author: Kirk Lund <kl...@pivotal.io>
Authored: Tue Jun 21 10:22:29 2016 -0700
Committer: Kirk Lund <kl...@pivotal.io>
Committed: Tue Jun 21 10:24:09 2016 -0700
----------------------------------------------------------------------
.../management/internal/cli/GfshParser.java | 4 +-
.../cli/parser/jopt/JoptOptionParser.java | 4 +-
.../internal/cli/remote/CommandProcessor.java | 1 -
.../internal/cli/util/HyphenFormatter.java | 92 +++++++++
.../internal/cli/util/OptionJFormatter.java | 115 -----------
.../internal/cli/GfshParserIntegrationTest.java | 38 ++++
.../commands/GemfireDataCommandsDUnitTest.java | 42 +++-
.../internal/cli/util/HyphenFormatterTest.java | 201 +++++++++++++++++++
.../internal/cli/util/OptionJFormatterTest.java | 189 -----------------
.../cli/commands/CommandOverHttpDUnitTest.java | 2 +-
10 files changed, 367 insertions(+), 321 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/170919bc/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/GfshParser.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/GfshParser.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/GfshParser.java
index 0bf2f66..9023ebe 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/GfshParser.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/GfshParser.java
@@ -893,7 +893,7 @@ public class GfshParser implements Parser {
preConfigureConverters(commandTarget);
try {
- // TODO: next call invokes OptionJFormatter
+ // TODO: next call invokes HyphenFormatter
parse = commandTarget.getOptionParser().parse(gfshMethodTarget.getRemainingBuffer());
} catch (CliException ce) {
if (ce instanceof CliCommandOptionException) {
@@ -925,7 +925,7 @@ public class GfshParser implements Parser {
} else {
if (coe != null) {
logWrapper.fine("Handling exception: " + coe.getMessage());
- ExceptionHandler.handleException(coe);
+ ExceptionHandler.handleException(coe); // TODO: this eats exception that would make it easier to debug GemfireDataCommandsDUnitTest
// ExceptionHandler.handleException() only logs it on console.
// When on member, we need to handle this.
if (!CliUtil.isGfshVM()) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/170919bc/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java
index 04590ed..de47ce6 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java
@@ -39,7 +39,7 @@ import com.gemstone.gemfire.management.internal.cli.parser.SyntaxConstants;
import com.gemstone.gemfire.management.internal.cli.parser.preprocessor.Preprocessor;
import com.gemstone.gemfire.management.internal.cli.parser.preprocessor.PreprocessorUtils;
import com.gemstone.gemfire.management.internal.cli.parser.preprocessor.TrimmedInput;
-import com.gemstone.gemfire.management.internal.cli.util.OptionJFormatter;
+import com.gemstone.gemfire.management.internal.cli.util.HyphenFormatter;
/**
* Implementation of {@link GfshOptionParser} which internally makes use of
@@ -115,7 +115,7 @@ public class JoptOptionParser implements GfshOptionParser {
optionSet.setUserInput(userInput!=null?userInput.trim():"");
if (userInput != null) {
TrimmedInput input = PreprocessorUtils.trim(userInput);
- String[] preProcessedInput = preProcess(new OptionJFormatter().formatCommand(input.getString()));
+ String[] preProcessedInput = preProcess(new HyphenFormatter().formatCommand(input.getString()));
joptsimple.OptionSet joptOptionSet = null;
CliCommandOptionException ce = null;
// int factor = 0;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/170919bc/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/remote/CommandProcessor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/remote/CommandProcessor.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/remote/CommandProcessor.java
index b62f922..790dd6c 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/remote/CommandProcessor.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/remote/CommandProcessor.java
@@ -30,7 +30,6 @@ import com.gemstone.gemfire.management.internal.cli.GfshParser;
import com.gemstone.gemfire.management.internal.cli.LogWrapper;
import com.gemstone.gemfire.management.internal.cli.result.ResultBuilder;
import com.gemstone.gemfire.management.internal.cli.util.CommentSkipHelper;
-import com.gemstone.gemfire.management.internal.cli.util.OptionJFormatter;
import com.gemstone.gemfire.management.internal.security.ResourceOperation;
import com.gemstone.gemfire.security.NotAuthorizedException;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/170919bc/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/util/HyphenFormatter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/util/HyphenFormatter.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/util/HyphenFormatter.java
new file mode 100644
index 0000000..0fb4fcd
--- /dev/null
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/util/HyphenFormatter.java
@@ -0,0 +1,92 @@
+/*
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Inserts quotes around the values of any option values that begin with hyphen.
+ */
+public class HyphenFormatter {
+
+ private static final String OPTION_PATTERN = "\\-\\-[a-zA-Z]+\\-?[a-zA-Z]*\\=";
+
+ private static final String QUOTE = "\"";
+ private static final String EQUAL_HYPHEN = "=-";
+ private static final String EQUAL = "=";
+ private static final String SPACE = " ";
+
+ private StringBuilder formatted;
+
+ /**
+ * Returns command with quotes around the values of any option values that begin with hyphen.
+ */
+ public String formatCommand(String command){
+ if (!containsOption(command)) {
+ return command;
+ }
+ this.formatted = new StringBuilder();
+
+ List<String> strings = split(command);
+ for (String string : strings) {
+ if (string.contains(EQUAL_HYPHEN)) {
+ int indexOfEquals = string.indexOf(EQUAL);
+ formatted.append(string.substring(0, indexOfEquals + 1));
+ formatted.append(QUOTE);
+ formatted.append(string.substring(indexOfEquals + 1));
+ formatted.append(QUOTE);
+ } else {
+ formatted.append(string);
+ }
+ formatted.append(SPACE);
+ }
+ return formatted.toString().trim();
+ }
+
+ /**
+ * Returns true if command contains any options.
+ */
+ boolean containsOption(String cmd) {
+ return Pattern.compile(OPTION_PATTERN).matcher(cmd).find();
+ }
+
+ private List<String> split(String cmd) {
+ List<String> strings = new ArrayList<>();
+
+ Matcher matcher = Pattern.compile(OPTION_PATTERN).matcher(cmd);
+
+ int index = 0; // first index of --option=
+
+ while (matcher.find()) {
+ if (matcher.start() - index > 0) {
+ String option = cmd.substring(index, matcher.start()).trim();
+ strings.add(option);
+ }
+ index = matcher.start();
+ }
+
+ String lastOne = cmd.substring(index);
+ if (lastOne != null) {
+ strings.add(lastOne);
+ }
+
+ return strings;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/170919bc/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/util/OptionJFormatter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/util/OptionJFormatter.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/util/OptionJFormatter.java
deleted file mode 100644
index 0e3265a..0000000
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/util/OptionJFormatter.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.util;
-
-/**
- * Inserts quotes around the values of any --J options.
- */
-public class OptionJFormatter {
-
- private static final String J_OPTION = "--J=";
- private static final char QUOTE = '\"';
- private static final char SPACE = ' ';
-
- private boolean quotesOpened;
- private int previousSpace;
- private String command;
- private StringBuilder formatted;
-
- /**
- * Returns command with quotes inserted around the values of any --J options.
- */
- public String formatCommand(String command){
- if (!containsJopt(command)) {
- return command;
- }
- this.command = command;
- this.formatted = new StringBuilder();
- quotesOpened = false;
-
- int nextJ = this.command.indexOf(J_OPTION);
-
- while (nextJ > -1) {
- String stringBeforeJ = this.command.substring(0, nextJ+4);
- if (quotesOpened && stringBeforeJ.contains("--")){
- previousSpace = stringBeforeJ.indexOf("--") - 1;
- while (stringBeforeJ.charAt(previousSpace) == SPACE){
- previousSpace--;
- }
- stringBeforeJ = stringBeforeJ.substring(0,previousSpace + 1) + QUOTE + stringBeforeJ.substring(previousSpace + 1);
- quotesOpened = false;
- }
-
- this.command = this.command.substring(nextJ+4);
-
- this.formatted.append(stringBeforeJ);
- if (!this.command.startsWith(""+QUOTE)){
- this.formatted.append(QUOTE);
- quotesOpened = true;
- }
- quotesOpened = true;
-
- int nextSpace = this.command.indexOf(SPACE);
- String stringAfterJ = null;
- if (nextSpace > -1) {
- stringAfterJ = this.command.substring(0, nextSpace);
- this.command = this.command.substring(nextSpace);
- } else {
- stringAfterJ = this.command.substring(0);
- this.command = "";
- }
-
- this.formatted.append(stringAfterJ);
- if (stringAfterJ.endsWith("\"")){
- quotesOpened = false;
- }
-
- nextSpace = this.command.indexOf(SPACE);
-
- if (nextSpace == -1) {
- if (!stringAfterJ.endsWith("" + QUOTE)) {
- this.formatted.append(QUOTE);
- quotesOpened = false;
- }
- } else if (!this.formatted.toString().endsWith(""+QUOTE)) {
- if(this.command.startsWith(" --")){
- this.formatted.append(QUOTE);
- quotesOpened = false;
- }
- }
-
- if (!containsJopt(this.command)){
- this.formatted.append(this.command);
- }
-
- nextJ = this.command.indexOf(J_OPTION);
- }
-
- return formatted.toString();
- }
-
- /**
- * Returns true if command contains any --J options.
- */
- boolean containsJopt(String cmd){
- if (cmd.contains("--J")){
- return true;
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/170919bc/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/GfshParserIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/GfshParserIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/GfshParserIntegrationTest.java
index 17e78a5..b8f0d10 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/GfshParserIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/GfshParserIntegrationTest.java
@@ -63,6 +63,44 @@ public class GfshParserIntegrationTest {
}
@Test
+ public void optionStartsWithHyphenWithoutQuotes() throws Exception {
+ String input = "rebalance --exclude-region=/GemfireDataCommandsDUnitTestRegion2 --simulate=true --time-out=-1";
+ Map<String, String> params = params(input, "rebalance", "rebalance");
+
+ assertThat(params.get("exclude-region")).isEqualTo("/GemfireDataCommandsDUnitTestRegion2");
+ assertThat(params.get("simulate")).isEqualTo("true");
+ assertThat(params.get("time-out")).isEqualTo("\"-1\"");
+ }
+
+ @Test
+ public void optionStartsWithHyphenWithQuotes() throws Exception {
+ String input = "rebalance --exclude-region=/GemfireDataCommandsDUnitTestRegion2 --simulate=true --time-out=\"-1\"";
+ Map<String, String> params = params(input, "rebalance", "rebalance");
+
+ assertThat(params.get("exclude-region")).isEqualTo("/GemfireDataCommandsDUnitTestRegion2");
+ assertThat(params.get("simulate")).isEqualTo("true");
+ assertThat(params.get("time-out")).isEqualTo("\"-1\"");
+ }
+
+ @Test
+ public void optionContainingHyphen() throws Exception {
+ String input = "rebalance --exclude-region=/The-Region --simulate=true";
+ Map<String, String> params = params(input, "rebalance", "rebalance");
+
+ assertThat(params.get("exclude-region")).isEqualTo("/The-Region");
+ assertThat(params.get("simulate")).isEqualTo("true");
+ }
+
+ @Test
+ public void optionContainingUnderscore() throws Exception {
+ String input = "rebalance --exclude-region=/The_region --simulate=true";
+ Map<String, String> params = params(input, "rebalance", "rebalance");
+
+ assertThat(params.get("exclude-region")).isEqualTo("/The_region");
+ assertThat(params.get("simulate")).isEqualTo("true");
+ }
+
+ @Test
public void oneJOptionWithQuotes() throws Exception {
String input = "start locator --J=\"-Dgemfire.http-service-port=8080\" --name=loc1";
Map<String, String> params = params(input, "start locator", "startLocator");
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/170919bc/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
index 68fe0ae..b0272b2 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
@@ -34,6 +34,10 @@ import java.util.Properties;
import java.util.Random;
import java.util.Set;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.DataPolicy;
@@ -80,9 +84,6 @@ import com.gemstone.gemfire.test.dunit.WaitCriterion;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;
import com.gemstone.gemfire.test.junit.categories.FlakyTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
/**
* Dunit class for testing gemfire data commands : get, put, remove, select, rebalance
*/
@@ -1765,7 +1766,6 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase {
}
}
- @Category(FlakyTest.class) // GEODE-1484
@Test
public void testRebalanceCommandForSimulate() {
setupTestRebalanceForEntireDS();
@@ -1787,7 +1787,6 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase {
}
}
- @Category(FlakyTest.class)
@Test
public void testRebalanceCommandForSimulateWithNoMember() {
setupTestRebalanceForEntireDS();
@@ -1812,7 +1811,6 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase {
}
}
- @Category(FlakyTest.class) // GEODE-1483
@Test
public void testRebalanceForIncludeRegionFunction() {
// setup();
@@ -1834,7 +1832,6 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase {
}
}
- @Category(FlakyTest.class) // GEODE-1551: org.eclipse.jetty.io.EofException
@Test
public void testSimulateForEntireDS() {
setupTestRebalanceForEntireDS();
@@ -1842,7 +1839,7 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase {
final VM manager = Host.getHost(0).getVM(0);
manager.invoke(checkRegionMBeans);
- getLogWriter().info("testSimulateForEntireDS verified Mbean and executin command");
+ getLogWriter().info("testSimulateForEntireDS verified MBean and executing command");
String command = "rebalance --simulate=true";
@@ -1859,7 +1856,31 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase {
}
}
- @Category(FlakyTest.class) // GEODE-1487
+ @Ignore("TODO: enable test after GEODE-1574 is fixed")
+ @Test
+ public void testSimulateForEntireDSWithTimeout() {
+ setupTestRebalanceForEntireDS();
+ //check if DistributedRegionMXBean is available so that command will not fail
+ final VM manager = Host.getHost(0).getVM(0);
+ manager.invoke(checkRegionMBeans);
+
+ getLogWriter().info("testSimulateForEntireDS verified MBean and executing command");
+
+ String command = "rebalance --simulate=true --time-out=-1";
+
+ CommandResult cmdResult = executeCommand(command);
+
+ getLogWriter().info("testSimulateForEntireDS just after executing " + cmdResult);
+
+ if (cmdResult != null) {
+ String stringResult = commandResultToString(cmdResult);
+ getLogWriter().info("testSimulateForEntireDS stringResult : " + stringResult);
+ assertEquals(Result.Status.OK, cmdResult.getStatus());
+ } else {
+ fail("testRebalanceForIncludeRegionFunction failed as did not get CommandResult");
+ }
+ }
+
@Test
public void testRebalanceForEntireDS() {
setupTestRebalanceForEntireDS();
@@ -1950,7 +1971,6 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase {
}
}
- @Category(FlakyTest.class)
@Test
public void testRebalanceForExcludeRegionFunction() {
setupWith2Regions();
@@ -1968,7 +1988,7 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase {
if (cmdResult != null) {
String stringResult = commandResultToString(cmdResult);
getLogWriter().info("testRebalanceForExcludeRegionFunction stringResult : " + stringResult);
- assertEquals(Result.Status.OK, cmdResult.getStatus());
+ assertEquals("CommandResult=" + cmdResult, Result.Status.OK, cmdResult.getStatus());
} else {
fail("testRebalanceForIncludeRegionFunction failed as did not get CommandResult");
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/170919bc/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/HyphenFormatterTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/HyphenFormatterTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/HyphenFormatterTest.java
new file mode 100644
index 0000000..fedc597
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/HyphenFormatterTest.java
@@ -0,0 +1,201 @@
+/*
+ * 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.util;
+
+import static org.assertj.core.api.Assertions.*;
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class HyphenFormatterTest {
+
+ private HyphenFormatter formatter;
+
+ @Before
+ public void setUp() {
+ this.formatter = new HyphenFormatter();
+ }
+
+ @Test
+ public void containsOptionWithOneOptionReturnsTrue() {
+ String cmd = "start locator --name=loc1";
+ assertTrue(this.formatter.containsOption(cmd));
+ }
+
+ @Test
+ public void containsOptionWithNoOptionReturnsFalse() {
+ String cmd = "start locator";
+ assertFalse(this.formatter.containsOption(cmd));
+ }
+
+ @Test
+ public void containsOptionWithMultipleOptionsReturnsTrue() {
+ String cmd = "start locator --name=loc1 --J=-Dfoo=bar --J=-Dbar=foo";
+ assertTrue(this.formatter.containsOption(cmd));
+ }
+
+ @Test
+ public void valueWithoutQuotesReturnsWithQuotes() {
+ String cmd = "start locator --name=loc1 --J=-Dfoo=bar";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\"";
+ assertThat(formattedCmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void valueWithoutQuotesReturnsWithQuotes_2() {
+ String cmd = "start locator --J=-Dfoo=bar --name=loc1";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+
+ String expected = "start locator --J=\"-Dfoo=bar\" --name=loc1";
+ assertThat(formattedCmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void valueWithHyphenWithoutQuotesFails() {
+ String cmd = "rebalance --exclude-region=/GemfireDataCommandsDUnitTestRegion2 --simulate=true --time-out=-1";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+
+ String expected = "rebalance --exclude-region=/GemfireDataCommandsDUnitTestRegion2 --simulate=true --time-out=\"-1\"";
+ assertThat(formattedCmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void valueWithHyphenWithoutQuotes() {
+ String cmd = "rebalance --exclude-region=/GemfireDataCommandsDUnitTestRegion2 --simulate=true --time-out=-1";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+
+ String expected = "rebalance --exclude-region=/GemfireDataCommandsDUnitTestRegion2 --simulate=true --time-out=\"-1\"";
+ assertThat(formattedCmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void nullShouldThrowNullPointerException() {
+ assertThatThrownBy(() -> this.formatter.formatCommand(null)).isExactlyInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void emptyShouldThrowNullPointerException() {
+ assertThat(this.formatter.formatCommand("")).isEqualTo("");
+ }
+
+ @Test
+ public void multipleJOptions() {
+ String cmd = "start locator --name=loc1 --J=-Dfoo=bar --J=-Dbar=foo";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=\"-Dbar=foo\"";
+ assertThat(formattedCmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void multipleJOptionsWithSomethingAfter() {
+ String cmd = "start locator --name=loc1 --J=-Dfoo=bar --J=-Dbar=foo --group=locators";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=\"-Dbar=foo\" --group=locators";
+ assertThat(formattedCmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void multipleJOptionsWithSomethingBetween() {
+ String cmd = "start locator --name=loc1 --J=-Dfoo=bar --group=locators --J=-Dbar=foo";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --group=locators --J=\"-Dbar=foo\"";
+ assertThat(formattedCmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void valueWithQuotes() {
+ String cmd = "start locator --name=loc1 --J=\"-Dfoo=bar\"";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+ assertThat(formattedCmd).isEqualTo(cmd);
+ }
+
+ @Test
+ public void oneValueWithQuotesOneWithout() {
+ String cmd = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=-Dfoo=bar";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=\"-Dfoo=bar\"";
+ assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void oneValueWithoutQuotesOneWith() {
+ String cmd = "start locator --name=loc1 --J=-Dfoo=bar --J=\"-Dfoo=bar\"";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=\"-Dfoo=bar\"";
+ assertThat(formattedCmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void twoValuesWithQuotes() {
+ String cmd = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=\"-Dfoo=bar\"";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+ assertThat(formattedCmd).as(cmd).isEqualTo(cmd);
+ }
+
+ @Test
+ public void valueContainingQuotes() {
+ String cmd = "start locator --name=loc1 --J=\"-Dfoo=region\"";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=region\"";
+ assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void valueContainingQuotesAndSpace() {
+ String cmd = "start locator --name=loc1 --J=\"-Dfoo=my phrase\"";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=my phrase\"";
+ assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void valueContainingQuotesAndMultipleSpaces() {
+ String cmd = "start locator --name=loc1 --J=\"-Dfoo=this is a phrase\"";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=this is a phrase\"";
+ assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void valueContainingMultipleJWithSpaces() {
+ String cmd = "start locator --name=loc1 --J=-Dfoo=this is a phrase --J=\"-Dfoo=a short sentence\"";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=this is a phrase\" --J=\"-Dfoo=a short sentence\"";
+ assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+ }
+
+ @Test
+ public void valueContainingMultipleJWithSpaces2() {
+ String cmd = "start locator --name=loc1 --J=\"-Dfoo=this is a phrase \" --J=\"-Dfoo=a short sentence\"";
+ String formattedCmd = this.formatter.formatCommand(cmd);
+ String expected = "start locator --name=loc1 --J=\"-Dfoo=this is a phrase \" --J=\"-Dfoo=a short sentence\"";
+ assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/170919bc/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/OptionJFormatterTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/OptionJFormatterTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/OptionJFormatterTest.java
deleted file mode 100644
index 12dcd5e..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/OptionJFormatterTest.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * 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.util;
-
-import static org.assertj.core.api.Assertions.*;
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
-
-@Category(UnitTest.class)
-public class OptionJFormatterTest {
-
- private OptionJFormatter formatter;
-
- @Before
- public void setUp() {
- this.formatter = new OptionJFormatter();
- }
-
- @Test
- public void containsJoptShouldReturnTrueIfCmdHasJ() {
- String cmd = "start locator --name=loc1 --J=-Dfoo=bar";
- assertTrue(this.formatter.containsJopt(cmd));
- }
-
- @Test
- public void containsJoptShouldReturnFalseIfCmdDoesntHaveJ() {
- String cmd = "start locator --name=loc1 ";
- assertFalse(this.formatter.containsJopt(cmd));
- }
-
- @Test
- public void containsJoptShouldReturnTrueIfCmdHasMultipleJ() {
- String cmd = "start locator --name=loc1 --J=-Dfoo=bar --J=-Dbar=foo";
- assertTrue(this.formatter.containsJopt(cmd));
- }
-
- @Test
- public void valueWithoutQuotesReturnsWithQuotes() {
- String cmd = "start locator --name=loc1 --J=-Dfoo=bar";
- String formattedCmd = this.formatter.formatCommand(cmd);
-
- String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\"";
- assertThat(formattedCmd).isEqualTo(expected);
- }
-
- @Test
- public void valueWithoutQuotesReturnsWithQuotes_2() {
- String cmd = "start locator --J=-Dfoo=bar --name=loc1";
- String formattedCmd = this.formatter.formatCommand(cmd);
-
- String expected = "start locator --J=\"-Dfoo=bar\" --name=loc1";
- assertThat(formattedCmd).isEqualTo(expected);
- }
-
- @Test
- public void nullShouldThrowNullPointerException() {
- assertThatThrownBy(() -> this.formatter.formatCommand(null)).isExactlyInstanceOf(NullPointerException.class);
- }
-
- @Test
- public void emptyShouldThrowNullPointerException() {
- assertThat(this.formatter.formatCommand("")).isEqualTo("");
- }
-
- @Test
- public void multipleJOptions() {
- String cmd = "start locator --name=loc1 --J=-Dfoo=bar --J=-Dbar=foo";
- String formattedCmd = this.formatter.formatCommand(cmd);
-
- String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=\"-Dbar=foo\"";
- assertThat(formattedCmd).isEqualTo(expected);
- }
-
- @Test
- public void multipleJOptionsWithSomethingAfter() {
- String cmd = "start locator --name=loc1 --J=-Dfoo=bar --J=-Dbar=foo --group=locators";
- String formattedCmd = this.formatter.formatCommand(cmd);
-
- String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=\"-Dbar=foo\" --group=locators";
- assertThat(formattedCmd).isEqualTo(expected);
- }
-
- @Test
- public void multipleJOptionsWithSomethingBetween() {
- String cmd = "start locator --name=loc1 --J=-Dfoo=bar --group=locators --J=-Dbar=foo";
- String formattedCmd = this.formatter.formatCommand(cmd);
-
- String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --group=locators --J=\"-Dbar=foo\"";
- assertThat(formattedCmd).isEqualTo(expected);
- }
-
- @Test
- public void valueWithQuotes() {
- String cmd = "start locator --name=loc1 --J=\"-Dfoo=bar\"";
- String formattedCmd = this.formatter.formatCommand(cmd);
- assertThat(formattedCmd).isEqualTo(cmd);
- }
-
- @Test
- public void valueWithMissingEndQuote() {
- String cmd = "start locator --J=\"-Dfoo=bar --name=loc1";
- String formattedCmd = this.formatter.formatCommand(cmd);
- String expected = "start locator --J=\"-Dfoo=bar\" --name=loc1";
- assertThat(formattedCmd).isEqualTo(expected);
- }
-
- @Test
- public void valueWithMissingStartQuote() {
- String cmd = "start locator --name=loc1 --J=-Dfoo=bar\"";
- String formattedCmd = this.formatter.formatCommand(cmd);
- String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\"";
- assertThat(formattedCmd).isEqualTo(expected);
- }
-
- @Test
- public void oneValueWithQuotesOneWithout() {
- String cmd = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=-Dfoo=bar";
- String formattedCmd = this.formatter.formatCommand(cmd);
- String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=\"-Dfoo=bar\"";
- assertThat(formattedCmd).as(cmd).isEqualTo(expected);
- }
-
- @Test
- public void oneValueWithoutQuotesOneWith() {
- String cmd = "start locator --name=loc1 --J=-Dfoo=bar --J=\"-Dfoo=bar\"";
- String formattedCmd = this.formatter.formatCommand(cmd);
- String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=\"-Dfoo=bar\"";
- assertThat(formattedCmd).isEqualTo(expected);
- }
-
- @Test
- public void twoValuesWithQuotes() {
- String cmd = "start locator --name=loc1 --J=\"-Dfoo=bar\" --J=\"-Dfoo=bar\"";
- String formattedCmd = this.formatter.formatCommand(cmd);
- assertThat(formattedCmd).as(cmd).isEqualTo(cmd);
- }
-
- @Test
- public void valueContainingQuotes() {
- String cmd = "start locator --name=loc1 --J=\"-Dfoo=region\"";
- String formattedCmd = this.formatter.formatCommand(cmd);
- String expected = "start locator --name=loc1 --J=\"-Dfoo=region\"";
- assertThat(formattedCmd).as(cmd).isEqualTo(expected);
- }
-
- @Test
- public void valueContainingQuotesAndSpace() {
- String cmd = "start locator --name=loc1 --J=\"-Dfoo=my phrase\"";
- String formattedCmd = this.formatter.formatCommand(cmd);
- String expected = "start locator --name=loc1 --J=\"-Dfoo=my phrase\"";
- assertThat(formattedCmd).as(cmd).isEqualTo(expected);
- }
-
- @Test
- public void valueContainingQuotesAndMultipleSpaces() {
- String cmd = "start locator --name=loc1 --J=\"-Dfoo=this is a phrase\"";
- String formattedCmd = this.formatter.formatCommand(cmd);
- String expected = "start locator --name=loc1 --J=\"-Dfoo=this is a phrase\"";
- assertThat(formattedCmd).as(cmd).isEqualTo(expected);
- }
-
- @Test
- public void valueContainingMultipleJWithSpaces() {
- String cmd = "start locator --name=loc1 --J=-Dfoo=this is a phrase --J=\"-Dfoo=a short sentence\"";
- String formattedCmd = this.formatter.formatCommand(cmd);
- String expected = "start locator --name=loc1 --J=\"-Dfoo=this is a phrase\" --J=\"-Dfoo=a short sentence\"";
- assertThat(formattedCmd).as(cmd).isEqualTo(expected);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/170919bc/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CommandOverHttpDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CommandOverHttpDUnitTest.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CommandOverHttpDUnitTest.java
index cad3f31..14a48c7 100644
--- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CommandOverHttpDUnitTest.java
+++ b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CommandOverHttpDUnitTest.java
@@ -42,7 +42,7 @@ import org.junit.runners.Suite;
DeployCommandsDUnitTest.class,
DiskStoreCommandsDUnitTest.class,
FunctionCommandsDUnitTest.class,
- //GemfireDataCommandsDUnitTest.class, restore when GEODE-1565 is fixed
+ GemfireDataCommandsDUnitTest.class,
GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.class,
IndexCommandsDUnitTest.class,
ListAndDescribeDiskStoreCommandsDUnitTest.class,