KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > data > StateMapTestCases


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: StateMapTestCases.java,v 1.4 2004/02/01 05:16:33 christianc Exp $
19  */

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 /**
32  * Test case for any StateMap. The idea is that you can test any
33  * StateMap object by extending this test case and adding tests
34  * for the specific implementation details. All you really have
35  * to do is override teh factory StateMap methods.
36  */

37 public abstract class StateMapTestCases extends DefaultTestCase {
38     //common vars (customize for every test class)
39
protected static String JavaDoc testClass = StateMapTestCases.class.getName();
40     protected static Logger logger = Logger.getLogger("test."+testClass);
41
42     //variables
43

44     //-------------------- Basics --------------------------------
45
/**
46      * Public Constructor
47      */

48     public StateMapTestCases(String JavaDoc name) {
49         super(name);
50     }
51     
52     //-------------------- Actual Tests --------------------------
53
//Note: all the methods herein should follow the testXXXX naming convention
54
//Also keep in mind that local vars set in one test method are NOT retained
55
//when the next method is invoked because JUnit makes a separate instance of
56
//the test class for each testXXXX method!!!
57

58     /**
59      * Verify the statemap aspects
60      */

61     public void testStateMap() {
62         if (logger.isInfoEnabled()) logger.info("testing statemap methods");
63         StateMap map = getStateMap();
64         String JavaDoc key1 = "foo1";
65         String JavaDoc key2 = "foo2";
66         String JavaDoc key3 = "foo3";
67         String JavaDoc s1 = "blah1";
68         Integer JavaDoc i1 = new Integer JavaDoc(99);
69         String JavaDoc s2 = null;
70
71         //simple tests
72
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     //-------------------- Abstract methods ----------------------
98
public abstract StateMap getStateMap();
99
100 }
101
Popular Tags