You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by bo...@apache.org on 2016/02/16 19:33:42 UTC
[6/9] storm git commit: Added in unit test for CLI
Added in unit test for CLI
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/0867b801
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/0867b801
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/0867b801
Branch: refs/heads/master
Commit: 0867b8017678f55fd24fee80408d7c7041e953e8
Parents: 415310a
Author: Robert (Bobby) Evans <ev...@yahoo-inc.com>
Authored: Sat Feb 13 15:11:48 2016 -0600
Committer: Robert (Bobby) Evans <ev...@yahoo-inc.com>
Committed: Sat Feb 13 15:11:48 2016 -0600
----------------------------------------------------------------------
.../src/jvm/org/apache/storm/command/CLI.java | 2 +-
.../jvm/org/apache/storm/command/TestCLI.java | 59 ++++++++++++++++++++
2 files changed, 60 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/0867b801/storm-core/src/jvm/org/apache/storm/command/CLI.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/org/apache/storm/command/CLI.java b/storm-core/src/jvm/org/apache/storm/command/CLI.java
index f360d2f..e7d0ece 100644
--- a/storm-core/src/jvm/org/apache/storm/command/CLI.java
+++ b/storm-core/src/jvm/org/apache/storm/command/CLI.java
@@ -158,7 +158,7 @@ public class CLI {
return this;
}
- public Map<String, Object> parse(String[] rawArgs) throws Exception {
+ public Map<String, Object> parse(String ... rawArgs) throws Exception {
Options options = new Options();
for (Opt opt: opts) {
options.addOption(Option.builder(opt.s).longOpt(opt.l).hasArg().build());
http://git-wip-us.apache.org/repos/asf/storm/blob/0867b801/storm-core/test/jvm/org/apache/storm/command/TestCLI.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/org/apache/storm/command/TestCLI.java b/storm-core/test/jvm/org/apache/storm/command/TestCLI.java
new file mode 100644
index 0000000..b647458
--- /dev/null
+++ b/storm-core/test/jvm/org/apache/storm/command/TestCLI.java
@@ -0,0 +1,59 @@
+/**
+ * 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.storm.command;
+
+import java.util.Map;
+import java.util.List;
+import java.util.Arrays;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestCLI {
+ @Test
+ public void testSimple() throws Exception {
+ Map<String, Object> values = CLI.opt("a", "aa", null)
+ .opt("b", "bb", 1, CLI.AS_INT)
+ .opt("c", "cc", 1, CLI.AS_INT, CLI.FIRST_WINS)
+ .opt("d", "dd", null, CLI.AS_STRING, CLI.INTO_LIST)
+ .arg("A")
+ .arg("B", CLI.AS_INT)
+ .parse("-a100", "--aa", "200", "-c2", "-b", "50", "--cc", "100", "A-VALUE", "1", "2", "3", "-b40", "-d1", "-d2", "-d3");
+ assertEquals(6, values.size());
+ assertEquals("200", (String)values.get("a"));
+ assertEquals((Integer)40, (Integer)values.get("b"));
+ assertEquals((Integer)2, (Integer)values.get("c"));
+
+ List<String> d = (List<String>)values.get("d");
+ assertEquals(3, d.size());
+ assertEquals("1", d.get(0));
+ assertEquals("2", d.get(1));
+ assertEquals("3", d.get(2));
+
+ List<String> A = (List<String>)values.get("A");
+ assertEquals(1, A.size());
+ assertEquals("A-VALUE", A.get(0));
+
+ List<Integer> B = (List<Integer>)values.get("B");
+ assertEquals(3, B.size());
+ assertEquals((Integer)1, B.get(0));
+ assertEquals((Integer)2, B.get(1));
+ assertEquals((Integer)3, B.get(2));
+ }
+}