You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/07/25 13:16:58 UTC
git commit: updated refs/heads/master to 76e2836
Updated Branches:
refs/heads/master 36d900472 -> 76e283687
test for Script
a unit test for the most frequently used methods in the Script class
Signed-off-by: Laszlo Hornyak <la...@gmail.com>
Signed-off-by: Prasanna Santhanam <ts...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/76e28368
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/76e28368
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/76e28368
Branch: refs/heads/master
Commit: 76e283687f8a9014d85e766c2543f3c98dcb6062
Parents: 36d9004
Author: Laszlo Hornyak <la...@gmail.com>
Authored: Thu Jul 18 17:09:47 2013 +0200
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Thu Jul 25 16:46:10 2013 +0530
----------------------------------------------------------------------
utils/test/com/cloud/utils/ScriptTest.java | 100 ++++++++++++++++++++++++
1 file changed, 100 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76e28368/utils/test/com/cloud/utils/ScriptTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/ScriptTest.java b/utils/test/com/cloud/utils/ScriptTest.java
new file mode 100644
index 0000000..f10f3bc
--- /dev/null
+++ b/utils/test/com/cloud/utils/ScriptTest.java
@@ -0,0 +1,100 @@
+// 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
+// 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.cloud.utils;
+
+import org.apache.commons.lang.SystemUtils;
+import org.apache.log4j.Logger;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.cloud.utils.script.OutputInterpreter;
+import com.cloud.utils.script.Script;
+
+public class ScriptTest {
+ @Test
+ public void testEcho() {
+ Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
+ Script script = new Script("/bin/echo");
+ script.add("bar");
+ OutputInterpreter.AllLinesParser resultParser = new OutputInterpreter.AllLinesParser();
+ String result = script.execute(resultParser);
+ // With allLinesParser, result is not comming from the return value
+ Assert.assertNull(result);
+ Assert.assertEquals("bar\n", resultParser.getLines());
+ }
+
+ @Test
+ public void testLogger() {
+ Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
+ Logger mock = Mockito.mock(Logger.class);
+ Mockito.doNothing().when(mock).debug(Mockito.any());
+ Script script = new Script("/bin/echo", mock);
+ script.execute();
+ }
+
+ @Test
+ public void testToString() {
+ Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
+ Script script = new Script("/bin/echo");
+ script.add("foo");
+ Assert.assertEquals("/bin/echo foo ", script.toString());
+ }
+
+ @Test
+ public void testSet() {
+ Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
+ Script script = new Script("/bin/echo");
+ script.add("foo");
+ script.add("bar", "baz");
+ script.set("blah", "blah");
+ Assert.assertEquals("/bin/echo foo bar baz blah blah ", script.toString());
+ }
+
+ @Test
+ @Ignore
+ public void testExecute() {
+ Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
+ Logger mock = Mockito.mock(Logger.class);
+ Mockito.doNothing().when(mock).debug(Mockito.any());
+ for (int i = 0; i < 100000; i++) {
+ Script script = new Script("/bin/false", mock);
+ script.execute();
+ }
+ }
+
+ @Test
+ public void testRunSimpleBashScript() {
+ Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
+ Assert.assertEquals("hello world!", Script.runSimpleBashScript("echo 'hello world!'"));
+ }
+
+ @Test
+ public void testRunSimpleBashScriptWithTimeout() {
+ Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
+ Assert.assertEquals("hello world!", Script.runSimpleBashScript("echo 'hello world!'", 1000));
+ }
+
+ @Test
+ public void testFindScript() {
+ Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
+ String script = Script.findScript("/usr/bin", "cat");
+ Assert.assertNotNull("/usr/bin/cat shoud be there on linux",script);
+ }
+}