001: package net.firstpartners.nounit.ui.test;
002:
003: /**
004: * Title: NoUnit - Identify Classes that are not being unit Tested
005: *
006: * Copyright (C) 2001 Paul Browne , FirstPartners.net
007: *
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * @author Paul Browne
024: * @version 0.7
025: */
026:
027: import java.util.HashMap;
028: import java.util.Iterator;
029: import java.util.Vector;
030:
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034: import net.firstpartners.nounit.ui.common.CommandPackage;
035:
036: /**
037: * Test the Command package class in the Junit testrunner
038: */
039: public class TestCommandPackage extends TestCase {
040:
041: /**
042: * Call the Junit test constructor
043: * @param name
044: */
045: public TestCommandPackage(String name) {
046: super (name);
047: }
048:
049: /**
050: * Enable Junit to run this Class individually
051: * @param args
052: */
053: public static void main(String[] args) {
054: junit.textui.TestRunner.run(suite());
055: }
056:
057: /**
058: * Enable Junit to run this class
059: * @return TestSuite
060: */
061: public static Test suite() {
062: return new TestSuite(TestCommandPackage.class);
063: }
064:
065: /**
066: * Test the creation of the Command Package (Method1) and retrieving Values
067: * from the command line
068: * @exception NoUnitException
069: */
070: public void testCommandPackageCreation() throws Exception {
071:
072: String[] tmpSeparateArray = TestUserData.getCommandLineValues();
073:
074: //Create Command Package
075: CommandPackage testCommandPackage = new CommandPackage(
076: tmpSeparateArray);
077:
078: //Check that Value Pairs come out ok
079: }
080:
081: /**
082: * Test getting of keys from Command Package
083: */
084: public void testGetKeys() throws Exception {
085:
086: CommandPackage newWP = new CommandPackage();
087: assertTrue(newWP.getStoreNames() != null);
088: assertTrue(newWP.getStoreNames().hasNext()); //pre populated with base defaults
089:
090: //Add values to CommandPackage
091: newWP.addValue("key1", "value1");
092: newWP.addValue("key2", "value2");
093: newWP.addValue("key3", "value3");
094:
095: Iterator myEnum = newWP.getStoreNames();
096: assertTrue(newWP.getStoreNames() != null);
097: }
098:
099: /**
100: * Test adding of Keys
101: */
102: public void testAddHashTable() throws Exception {
103:
104: CommandPackage newWP = new CommandPackage();
105: assertTrue(!newWP.getValuePairs().isEmpty()); //pre populated with base defaults
106:
107: //Create New Hashtable and add values
108: HashMap newHash = new HashMap();
109: newHash.put("key1", "value1");
110: newHash.put("key2", "value2");
111: newHash.put("key3", "value3");
112: newWP.addValues(newHash);
113:
114: assertTrue(newWP.getValuePairs() != null);
115: HashMap outHash = newWP.getValuePairs();
116: assertTrue(!outHash.isEmpty());
117: assertTrue(outHash.containsKey("key1"));
118: assertTrue(outHash.containsKey("key2"));
119: assertTrue(outHash.containsKey("key3"));
120: assertTrue(outHash.containsKey("key1"));
121: assertTrue(outHash.containsKey("key2"));
122: assertTrue(outHash.containsKey("key3"));
123:
124: }
125:
126: /**
127: * Test Storage / Retrieval of Ints
128: */
129: public void testStoreGetInt() throws Exception {
130:
131: CommandPackage newWP = new CommandPackage();
132:
133: newWP.addValue("num1", new Integer(1024));
134: newWP.addValue("num2", "876");
135: newWP.addValue("letters", "xyz");
136:
137: assertTrue(newWP.getInt("num1") == 1024);
138: assertTrue(newWP.getInt("num2") == 876);
139: assertTrue(newWP.getInt("letters") == 0);
140: assertTrue(newWP.getInt("some-randon-non-existant-key") == 0);
141:
142: }
143:
144: /**
145: * Test Storage / Retrieval of Ints
146: */
147: public void testMultipleValues() throws Exception {
148:
149: CommandPackage newWP = new CommandPackage();
150:
151: String[] valuesAdd = { "samekey", "value1", "samekey",
152: "value2", "samekey", "value3" };
153:
154: newWP.addValues(valuesAdd);
155:
156: Object tmpObject = newWP.getValue("samekey");
157: assertTrue(tmpObject != null);
158: assertTrue(tmpObject instanceof Vector);
159:
160: //Try with normal get object method
161: Vector tmpVector = (Vector) tmpObject;
162: assertTrue(!tmpVector.isEmpty());
163: assertTrue(tmpVector.contains("value1"));
164: assertTrue(tmpVector.contains("value2"));
165: assertTrue(tmpVector.contains("value3"));
166: assertTrue(tmpVector.size() == 3);
167:
168: //Try with getVector method
169: tmpVector = newWP.getVector("samekey");
170: assertTrue(!tmpVector.isEmpty());
171: assertTrue(tmpVector.contains("value1"));
172: assertTrue(tmpVector.contains("value2"));
173: assertTrue(tmpVector.contains("value3"));
174: assertTrue(tmpVector.size() == 3);
175:
176: }
177:
178: /**
179: * Check Double Add
180: * Objects added at differenct times should not be vectorized...
181: */
182: public void testDoubleAdd() throws Exception {
183:
184: CommandPackage myWP = new CommandPackage();
185:
186: myWP.addValue("key1", "value1");
187:
188: //Unique Values
189: String[] valuesAdd = { "key1", "value1", "key2", "value2",
190: "key3", "value3" };
191:
192: //Add Twice to try and force vectoization
193: myWP.addValues(valuesAdd);
194: myWP.addValues(valuesAdd);
195:
196: //Test Results
197: Object tmpObject = myWP.getValue("key1");
198: assertTrue(tmpObject instanceof String);
199:
200: }
201:
202: /**
203: * test add additional data
204: */
205: public void testAddAdditionalData() {
206:
207: CommandPackage myWp = new CommandPackage();
208: myWp.addAdditionalValue("somerandomkeyxxx", "someobject");
209:
210: Object tmpObject = myWp.getValue("somerandomkeyxxx");
211: assertTrue(tmpObject != null);
212: assertTrue(tmpObject instanceof String);
213:
214: //now add another value
215: myWp.addAdditionalValue("somerandomkeyxxx", "someotherobject");
216: tmpObject = myWp.getValue("somerandomkeyxxx");
217: assertTrue(tmpObject != null);
218: assertTrue(tmpObject instanceof Vector);
219:
220: //Test contents of Vector
221: Vector tmpVector = (Vector) tmpObject;
222: assertTrue(!tmpVector.isEmpty());
223: assertTrue(tmpVector.contains("someobject"));
224: assertTrue(tmpVector.contains("someotherobject"));
225:
226: }
227:
228: /**
229: * test remove method
230: */
231: public void testRemove() {
232:
233: CommandPackage myWp = new CommandPackage();
234: myWp.addValue("X2345", "LLL");
235: assertTrue(myWp.getValue("X2345") != null);
236: myWp.remove("X2345");
237: assertTrue(myWp.getValue("X2345") == null);
238:
239: }
240:
241: /**
242: * Test Move Method
243: */
244: public void testMove() {
245:
246: CommandPackage myWp = new CommandPackage();
247:
248: myWp.addValue("SomeKey1", "SomeValue");
249: assertTrue(myWp.getValue("SomeKey1") != null);
250: assertTrue(myWp.getValue("SomeNewKey1") == null);
251:
252: myWp.move("SomeKey1", "SomeNewKey1");
253: assertTrue(myWp.getValue("SomeKey1") == null);
254: assertTrue(myWp.getValue("SomeNewKey1") != null);
255:
256: }
257:
258: }
|