You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sg...@apache.org on 2010/09/20 22:03:15 UTC
svn commit: r999093 - in /commons/proper/exec/trunk/src:
main/java/org/apache/commons/exec/LogOutputStream.java
test/java/org/apache/commons/exec/LogOutputStreamTest.java
Author: sgoeschl
Date: Mon Sep 20 20:03:15 2010
New Revision: 999093
URL: http://svn.apache.org/viewvc?rev=999093&view=rev
Log:
Added test for LogOutputStream since it was completely untested
Added:
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/LogOutputStreamTest.java
Modified:
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/LogOutputStream.java
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/LogOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/LogOutputStream.java?rev=999093&r1=999092&r2=999093&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/LogOutputStream.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/LogOutputStream.java Mon Sep 20 20:03:15 2010
@@ -26,7 +26,7 @@ import java.io.OutputStream;
* Base class to connect a logging system to the output and/or
* error stream of then external process. The implementation
* parses the incoming data to construct a line and passes
- * the complete line to an user-defiend implementation.
+ * the complete line to an user-defined implementation.
*/
public abstract class LogOutputStream
extends OutputStream {
Added: commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/LogOutputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/LogOutputStreamTest.java?rev=999093&view=auto
==============================================================================
--- commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/LogOutputStreamTest.java (added)
+++ commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/LogOutputStreamTest.java Mon Sep 20 20:03:15 2010
@@ -0,0 +1,78 @@
+/*
+ * 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.commons.exec;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.io.OutputStream;
+
+/**
+ * Test the LogOutputStream.
+ */
+public class LogOutputStreamTest extends TestCase
+{
+
+ private Executor exec = new DefaultExecutor();
+ private File testDir = new File("src/test/scripts");
+ private OutputStream systemOut;
+ private File environmentScript = TestUtil.resolveScriptForOS(testDir + "/environment");
+
+ static{
+ // turn on debug mode and throw an exception for each encountered problem
+ System.setProperty("org.apache.commons.exec.lenient", "false");
+ System.setProperty("org.apache.commons.exec.debug", "true");
+ }
+
+
+ protected void setUp() throws Exception {
+ System.out.println(">>> Executing " + getName() + " ...");
+ this.systemOut = new SystemLogOutputStream(1);
+ this.exec.setStreamHandler(new PumpStreamHandler(systemOut, systemOut));
+ }
+
+ protected void tearDown() throws Exception {
+ this.systemOut.close();
+ }
+
+ // ======================================================================
+ // Start of regression tests
+ // ======================================================================
+
+ public void testStdout() throws Exception {
+ CommandLine cl = new CommandLine(environmentScript);
+ int exitValue = exec.execute(cl);
+ assertFalse(exec.isFailure(exitValue));
+ }
+
+ // ======================================================================
+ // Helper classes
+ // ======================================================================
+
+ private class SystemLogOutputStream extends LogOutputStream {
+
+ private SystemLogOutputStream(int level) {
+ super(level);
+ }
+
+ protected void processLine(String line, int level) {
+ System.out.println(line);
+ }
+ }
+
+}