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/13 23:56:16 UTC

incubator-geode git commit: Create OptionJFormatter and add unit tests

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-835 a8081779e -> e6e68e5b8


Create OptionJFormatter and add unit tests

* create CommentSkipHelperTest for CommentSkipHelper (GFSH)
* create OptionJFormatterTest for OptionJFormatter
* add failing higher level test to GfshParserIntegrationTest


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

Branch: refs/heads/feature/GEODE-835
Commit: e6e68e5b85f1b08a3c6f06deba67af5d1a4f4905
Parents: a808177
Author: Kirk Lund <kl...@apache.org>
Authored: Mon Jun 13 16:54:16 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Mon Jun 13 16:54:16 2016 -0700

----------------------------------------------------------------------
 .../internal/cli/util/OptionJFormatter.java     | 90 +++++++++++++++-----
 .../internal/cli/GfshParserIntegrationTest.java | 16 ++++
 .../cli/util/CommentSkipHelperTest.java         | 20 +++++
 .../internal/cli/util/OptionJFormatterTest.java | 37 +++++++-
 4 files changed, 141 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e6e68e5b/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
index 2bbb812..1aba057 100644
--- 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
@@ -1,29 +1,77 @@
+/*
+ * 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;
 
 public class OptionJFormatter {
 
-  public String formatCommand(String cmd){
-    if (!containsJopt(cmd)) {
-      return cmd;
+  private static final String J_OPTION = "--J=";
+  private static final String QUOTE = "\"";
+  private static final String SPACE = " ";
+
+  private String command;
+  private int index;
+  private StringBuilder formatted = new StringBuilder();
+
+  private void everythingBeforeJ() {
+    int indexOfJ = this.command.indexOf(J_OPTION);
+    this.formatted.append(this.command.substring(0, indexOfJ));
+  }
+
+  private int nextJ(int start) {
+    int startOfJ = this.command.indexOf(J_OPTION, start);
+    int nextSpace = this.command.indexOf(SPACE, startOfJ);
+    if (start+1 != startOfJ){
+      this.formatted.append(command.substring(start, startOfJ));
+    }
+    this.formatted.append(J_OPTION);
+    this.formatted.append(QUOTE);
+    if (nextSpace == -1) {
+      this.formatted.append(this.command.substring(startOfJ + 4));
+    } else {
+      this.formatted.append(this.command.substring(startOfJ + 4, nextSpace));
+    }
+    this.formatted.append(QUOTE);
+    return nextSpace;
+  }
+
+  public String formatCommand(String command){
+    if (!containsJopt(command)) {
+      return command;
     }
-    int indexOfJ = cmd.indexOf("--J=");
-    StringBuilder sb =  new StringBuilder();
-    sb.append(cmd.substring(0, indexOfJ+4));
-    sb.append("\"");
-    sb.append(cmd.substring(indexOfJ+4));
-    sb.append("\"");
-
-
-//    for () {
-//
-//    }
-//    while () {
-//
-//    }
-//    do {
-//
-//    } while();
-    return sb.toString();
+    this.command = command;
+
+    int start = 0;
+   // everythingBeforeJ();
+
+    while (start > -1) {
+      start = nextJ(start);
+
+      boolean noMoreJs = command.indexOf(J_OPTION, start) == -1;
+      boolean hasMoreOptions = start > -1;
+
+      if (noMoreJs){
+        formatted.append(command.substring(start));
+        break;
+      } else if (hasMoreOptions) {
+        this.formatted.append(SPACE);
+      }
+    }
+
+    return formatted.toString();
   }
 
   boolean containsJopt(String cmd){

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e6e68e5b/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 a5b6dd7..dd42028 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
@@ -1,3 +1,19 @@
+/*
+ * 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;
 
 import static org.assertj.core.api.Assertions.*;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e6e68e5b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/CommentSkipHelperTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/CommentSkipHelperTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/CommentSkipHelperTest.java
index d9f5f26..634271d 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/CommentSkipHelperTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/util/CommentSkipHelperTest.java
@@ -1,10 +1,30 @@
+/*
+ * 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 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 CommentSkipHelperTest {
 
   private CommentSkipHelper commentSkipHelper;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e6e68e5b/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
index 1dfc6d1..b73ccbe 100644
--- 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
@@ -1,3 +1,19 @@
+/*
+ * 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.*;
@@ -65,7 +81,6 @@ public class OptionJFormatterTest {
     assertThat(new OptionJFormatter().formatCommand("")).isEqualTo("");
   }
 
-  @Ignore
   @Test
   public void multipleJOptionsShould_something() {
     String cmd = "start locator --name=loc1 --J=-Dfoo=bar --J=-Dbar=foo";
@@ -76,4 +91,24 @@ public class OptionJFormatterTest {
     assertThat(formattedCmd).isEqualTo(expected);
   }
 
+  @Test
+  public void multipleJOptionsWithSomethingAfterShould_something() {
+    String cmd = "start locator --name=loc1 --J=-Dfoo=bar --J=-Dbar=foo --group=locators";
+    OptionJFormatter ojf = new OptionJFormatter();
+    String formattedCmd = ojf.formatCommand(cmd);
+
+    String expected = "start locator --name=loc1 --J=" + quote + "-Dfoo=bar" + quote + " --J=" + quote + "-Dbar=foo" + quote + " --group=locators";
+    assertThat(formattedCmd).isEqualTo(expected);
+  }
+
+  @Test
+  public void multipleJOptionsWithSomethingBetweenShould_something() {
+    String cmd = "start locator --name=loc1 --J=-Dfoo=bar --group=locators --J=-Dbar=foo";
+    OptionJFormatter ojf = new OptionJFormatter();
+    String formattedCmd = ojf.formatCommand(cmd);
+
+    String expected = "start locator --name=loc1 --J=" + quote + "-Dfoo=bar" + quote + " --group=locators --J=" + quote + "-Dbar=foo" + quote;
+    assertThat(formattedCmd).isEqualTo(expected);
+  }
+
 }