1 20 package org.enhydra.barracuda.plankton.data; 21 22 import java.io.*; 23 import java.util.*; 24 25 import junit.framework.*; 26 27 import org.apache.log4j.*; 28 import org.enhydra.barracuda.testbed.*; 29 30 31 37 public abstract class StateMapTestCases extends DefaultTestCase { 38 protected static String testClass = StateMapTestCases.class.getName(); 40 protected static Logger logger = Logger.getLogger("test."+testClass); 41 42 44 48 public StateMapTestCases(String name) { 49 super(name); 50 } 51 52 58 61 public void testStateMap() { 62 if (logger.isInfoEnabled()) logger.info("testing statemap methods"); 63 StateMap map = getStateMap(); 64 String key1 = "foo1"; 65 String key2 = "foo2"; 66 String key3 = "foo3"; 67 String s1 = "blah1"; 68 Integer i1 = new Integer (99); 69 String s2 = null; 70 71 map.putState(key1, s1); 73 map.putState(key2, i1); 74 map.putState(key3, s2); 75 assertTrue("Error 1a set/get state", map.getState(key1)==s1); 76 assertTrue("Error 1b set/get state", map.getState(key2)==i1); 77 assertTrue("Error 1c set/get state", map.getState(key3)==s2); 78 List keys = map.getStateKeys(); 79 assertTrue("Error 2a - Key list length is wrong", keys.size()==3); 80 assertTrue("Error 2b - Key missing", keys.contains(key1)); 81 assertTrue("Error 2c - Key missing", keys.contains(key2)); 82 assertTrue("Error 2d - Key missing", keys.contains(key3)); 83 Map values = map.getStateValues(); 84 assertTrue("Error 3a - Value list length is wrong", values.size()==3); 85 assertTrue("Error 3b - Value missing", values.get(key1)==s1); 86 assertTrue("Error 3c - Value missing", values.get(key2)==i1); 87 assertTrue("Error 3d - Value missing", values.get(key3)==s2); 88 map.removeState(key1); 89 map.removeState(key2); 90 map.removeState(key3); 91 assertTrue("Error 4a remove state", map.getState(key1)==null); 92 assertTrue("Error 4b remove state", map.getState(key2)==null); 93 assertTrue("Error 4c remove state", map.getState(key3)==null); 94 } 95 96 97 public abstract StateMap getStateMap(); 99 100 } 101 | Popular Tags |