1   package com.mccrory.scott.spumoni.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 java.util.Vector;
22  
23  import junit.framework.TestCase;
24  
25  import com.mccrory.scott.spumoni.StatsProgram;
26  import com.mccrory.scott.spumoni.StatsProgramList;
27  import com.mccrory.scott.spumoni.StatsValue;
28  import com.mccrory.scott.spumoni.StatsValueList;
29  
30  /**
31   * <P>JUnit test case for the StatsProgramList class.</P>
32   *
33   * @author <a href="mailto:smccrory@users.sourceforge.net">Scott McCrory</a>.
34   * @version CVS $Id: StatsProgramListTest.java,v 1.2 2002/08/04 22:04:53 smccrory Exp $
35   */
36  public class StatsProgramListTest extends TestCase {
37  
38      /** A class-wide storage container for the command-line arguments **/
39      private static String[] myargs;
40  
41      /** The StatsValue object we'll pre-initialize **/
42      private StatsValue sv = new StatsValue();
43  
44      /** The StatsValueList object we'll pre-initialize **/
45      private StatsValueList svl = new StatsValueList();
46  
47      /** The StatsProgram object we'll pre-initialize **/
48      private StatsProgram sProg = new StatsProgram();
49  
50      /** The Vector object we'll pre-initialize **/
51      private Vector reqModules = new Vector();
52  
53      /** The StatsProgramList object we'll pre-initialize **/
54      private StatsProgramList spl = new StatsProgramList();
55  
56      /**
57       * StatsProgramListTest constructor
58       * @param name java.lang.String
59       */
60      public StatsProgramListTest(String name) {
61          super(name);
62  
63          try {
64  
65              // Contruct the StatsValueList
66              sv = new StatsValue("pingMin", "1.2.3.1", 50, 100);
67              sv.setValue("1567");
68              svl = new StatsValueList(sv);
69  
70              // Now add a second StatsValue to the list
71              sv = new StatsValue("pingMin", "1.2.3.4", 50, 100);
72              sv.setValue("1568");
73              svl.add(sv);
74  
75              // Add a third, but with the same OID
76              sv = new StatsValue("pingMin", "1.2.3.4", 50, 100);
77              sv.setValue("1569");
78              svl.add(sv);
79  
80              // Create the StatsProgram and StatsProgramList   
81              reqModules.add("nt");
82              sProg = new StatsProgram("nt_ping.xml", "dir", "(\\d+)", reqModules, 30, svl);
83              spl = new StatsProgramList(sProg);
84  
85          }
86          catch (Exception e) {
87              e.printStackTrace();
88              fail("Should not encounter " + e.getMessage());
89          }
90  
91      }
92  
93      /**
94       * Runs the JUnit test from the command line.
95       * @param args java.lang.String[]
96       */
97      public static void main(String[] args) {
98  
99          myargs = args;
100         junit.textui.TestRunner.run(StatsProgramListTest.class);
101 
102     }
103 
104     /**
105      * Tests the StatsProgramList getOidConflicts method
106      */
107     public void testOidConflicts() {
108 
109         try {
110 
111             // Test for OID conflicts
112             assertNotNull(spl.getOidConflicts());
113             assertEquals((spl.getOidConflicts()).size(), 2);
114 
115         }
116         catch (Exception e) {
117             e.printStackTrace();
118             fail("Should not encounter " + e.getMessage());
119         }
120 
121     }
122 
123     /**
124      * Tests some StatsProgramList operations.
125      */
126     public void testStatsProgramList() {
127 
128         try {
129 
130             // Test for NULLs, g/setters and correct values
131             assertNotNull(spl);
132             assertEquals(spl.size(), 1);
133             assertEquals(spl.getValueByOid("1.2.3.1"), "1567");
134             assertEquals(spl.getValueByOid("1.2.3.4"), "1568");
135 
136             //Make sure the getOids() method works
137             Vector oids = spl.getOids();
138             assertEquals(oids.size(), 3);
139 
140         }
141         catch (Exception e) {
142             e.printStackTrace();
143             fail("Should not encounter " + e.getMessage());
144         }
145 
146     }
147 
148 }