|
StatsValueListTest |
|
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.StatsValue; 26 import com.mccrory.scott.spumoni.StatsValueList; 27 28 /** 29 * <P>JUnit test case for the StatsValueList class.</P> 30 * 31 * @author <a href="mailto:smccrory@users.sourceforge.net">Scott McCrory</a>. 32 * @version CVS $Id: StatsValueListTest.java,v 1.2 2002/08/04 22:04:53 smccrory Exp $ 33 */ 34 public class StatsValueListTest extends TestCase { 35 36 /** A class-wide storage container for the command-line arguments **/ 37 private static String[] myargs; 38 39 /** 40 * StatsValueListTest constructor 41 * @param name java.lang.String 42 */ 43 public StatsValueListTest(String name) { 44 super(name); 45 } 46 47 /** 48 * Runs the JUnit test from the command line. 49 * @param args java.lang.String[] 50 */ 51 public static void main(String[] args) { 52 53 myargs = args; 54 junit.textui.TestRunner.run(StatsValueListTest.class); 55 56 } 57 58 /** 59 * Tests the StatsValueList operations. 60 * Creation date: (1/12/2002 7:22:47 PM) 61 */ 62 public void testStatsValueList() { 63 64 try { 65 66 // Contruct the StatsValueList 67 StatsValue sv = new StatsValue( 68 "pingMin", 69 "1.2.3.1", 70 50, 71 100); 72 sv.setValue("1567"); 73 StatsValueList svl = new StatsValueList(sv); 74 assertNotNull(svl); 75 76 // Test some g/setters 77 assertEquals(svl.getValueByOid("1.2.3.1"), "1567"); 78 79 try { 80 // This should generate a java.util.NoSuchElementException 81 assertNull(svl.getValueByOid("1.2.3.0")); 82 fail("Should not have been able to getValueByOid(\"1.2.3.0\") (non-existent!)"); 83 } 84 catch (java.util.NoSuchElementException e) { 85 // Its OK to get here 86 } 87 88 // Now add a second StatsValue to the list 89 sv = new StatsValue( 90 "pingMin", 91 "1.2.3.4", 92 50, 93 100); 94 sv.setValue("1568"); 95 svl.add(sv); 96 assertEquals(svl.getValueByOid("1.2.3.4"), "1568"); 97 assertEquals(svl.size(), 2); 98 99 // Add a third, but with the same OID - old value should still be the 100 // first to pop up. 101 sv = new StatsValue( 102 "pingMin", 103 "1.2.3.4", 104 50, 105 100); 106 sv.setValue("1569"); 107 svl.add(sv); 108 assertEquals(svl.getValueByOid("1.2.3.4"), "1568"); 109 assertEquals(svl.size(), 3); 110 111 //Make sure the getOids() method works 112 Vector oids = svl.getOids(); 113 assertEquals(oids.size(), 3); 114 115 } 116 catch (Exception e) { 117 e.printStackTrace(); 118 fail("Should not encounter " + e.getMessage()); 119 } 120 121 } 122 123 } 124
|
StatsValueListTest |
|