1   package com.mccrory.scott.base.test;
2   
3   ////////////////////////////////////////////////////////////////////////////////
4   // Copyright (C) 2002  Scott McCrory
5   //
6   // This program is free software; you can redistribute it and/or
7   // modify it under the terms of the GNU General Public License
8   // as published by the Free Software Foundation; either version 2
9   // of the License, or (at your option) any later version.
10  //
11  // This program is distributed in the hope that it will be useful,
12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  // GNU General Public License for more details.
15  //
16  // You should have received a copy of the GNU General Public License
17  // along with this program; if not, write to the Free Software
18  // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  ////////////////////////////////////////////////////////////////////////////////
20  
21  import junit.framework.TestCase;
22  
23  import com.mccrory.scott.base.ExecRunner;
24  
25  /**
26   * <P>JUnit test case for ExecRunner class.</P>
27   *
28   * @author <a href="mailto:smccrory@users.sourceforge.net">Scott McCrory</a>.
29   * @version CVS $Id: ExecRunnerTest.java,v 1.2 2002/08/04 22:04:53 smccrory Exp $
30   */
31  public class ExecRunnerTest extends TestCase {
32  
33      /** A class-wide storage container for the command-line arguments **/
34      private static String[] myargs;
35  
36      /**
37       * StatsCollectorTest constructor
38       * @param name java.lang.String
39       */
40      public ExecRunnerTest(String name) {
41          super(name);
42      }
43  
44      /**
45       * Runs the JUnit test from the command line.
46       * @param args java.lang.String[]
47       */
48      public static void main(String[] args) {
49  
50          myargs = args;
51          junit.textui.TestRunner.run(ExecRunnerTest.class);
52  
53      }
54  
55      /**
56       * Tests the StatsCollector operations.
57       * Creation date: (1/12/2002 7:22:47 PM)
58       */
59      public void testCollectStats() {
60  
61          try {
62  
63              // Test the exec operation
64  
65              ExecRunner er = new ExecRunner();
66              er.setMaxRunTimeSecs(5);
67              er.exec("ls -l");
68  
69              assertTrue(!er.getMaxRunTimeExceeded());
70              assertNotNull(er.getOutString());
71              assertNotNull(er.getErrString());
72  
73          }
74          catch (Exception e) {
75              e.printStackTrace();
76              fail("Should not encounter " + e.getMessage());
77          }
78  
79      }
80  
81  }