KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestParam.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 import java.security.*;
25 import javax.servlet.*;
26 import javax.servlet.http.*;
27
28 import org.w3c.dom.*;
29 import junit.framework.*;
30
31 import org.enhydra.barracuda.plankton.*;
32 import org.enhydra.barracuda.plankton.data.*;
33 import org.enhydra.barracuda.core.util.dom.*;
34 import org.apache.log4j.*;
35 import org.enhydra.barracuda.core.view.*;
36 import org.enhydra.barracuda.examples.xmlc.*;
37 import org.enhydra.barracuda.testbed.*;
38
39
40 /**
41  * This test verifies the Param object
42  */

43 public class TestParam extends DefaultTestCase {
44     //common vars (customize for every test class)
45
private static String JavaDoc testClass = TestParam.class.getName();
46     private static Logger logger = Logger.getLogger("test."+testClass);
47
48     //variables
49

50     //-------------------- Basics --------------------------------
51
/**
52      * Public Constructor
53      */

54     public TestParam(String JavaDoc name) {
55         super(name);
56     }
57
58     /**
59      * Every test class should have a main method so it can be run
60      * directly (when debugging tests you often will not want to run
61      * the whole suite)
62      *
63      * @param args defined in test.util.TestUtil
64      */

65     public static void main(String JavaDoc args[]) {
66         //check for standard runtime parameters
67
TestUtil.parseParams(args);
68
69         //launch the test
70
if (TestUtil.BATCH_MODE) junit.textui.TestRunner.main(new String JavaDoc[] {testClass});
71         else junit.swingui.TestRunner.main(new String JavaDoc[] {testClass});
72     }
73
74
75     //-------------------- Actual Tests --------------------------
76
//Note: all the methods herein should follow the testXXXX naming convention
77
//Also keep in mind that local vars set in one test method are NOT retained
78
//when the next method is invoked because JUnit makes a separate instance of
79
//the test class for each testXXXX method!!!
80

81     /**
82      * Simple test to make sure the Param object works
83      */

84     public void testParam() {
85         if (logger.isInfoEnabled()) logger.info("testing param");
86
87         //vars
88
Param p = null;
89         Param p2 = null;
90         String JavaDoc key1 = "foo1";
91         String JavaDoc key1a = "foo1";
92         String JavaDoc key2 = "foo2";
93         String JavaDoc value1 = "blah1";
94         String JavaDoc value1a = "blah1";
95         String JavaDoc value2 = "blah2";
96
97         //basics
98
p = new Param();
99         assertTrue("param obj check 1a.1 failed - p.key!=null", p.key==null);
100         assertTrue("param obj check 1a.2 failed - p.getKey()!=null", p.getKey()==null);
101         assertTrue("param obj check 1b.1 failed - p.value!=null", p.value==null);
102         assertTrue("param obj check 1b.2 failed - p.getvalue()!=null", p.getValue()==null);
103         p = new Param(key1, value1);
104         assertTrue("param obj check 2a.1 failed - p.key!=key", p.key==key1);
105         assertTrue("param obj check 2a.2 failed - p.getKey()!=key", p.getKey()==key1);
106         assertTrue("param obj check 2b.1 failed - p.value!=value", p.value==value1);
107         assertTrue("param obj check 2b.2 failed - p.getvalue()!=value", p.getValue()==value1);
108
109         //equality (shouldn't happen until both key and value match)
110
p2 = new Param(key2, value2);
111         assertTrue("param obj check 3a.1 failed - equality check failed", !(p.equals(p2)));
112         assertTrue("param obj check 3a.2 failed - equality check failed", !(p2.equals(p)));
113         p2.setKey(key1);
114         assertTrue("param obj check 3a.3 failed - equality check failed", !(p.equals(p2)));
115         assertTrue("param obj check 3a.4 failed - equality check failed", !(p2.equals(p)));
116         p2.setKey(key2);
117         p2.setValue(value1);
118         assertTrue("param obj check 3a.5 failed - equality check failed", !(p.equals(p2)));
119         assertTrue("param obj check 3a.6 failed - equality check failed", !(p2.equals(p)));
120         p2.setKey(key1);
121         assertTrue("param obj check 3a.7 failed - equality check failed", (p.equals(p2)));
122         assertTrue("param obj check 3a.8 failed - equality check failed", (p2.equals(p)));
123         p2.setKey(key1a);
124         p2.setValue(value1a);
125         assertTrue("param obj check 3a.9 failed - equality check failed", (p.equals(p2)));
126         assertTrue("param obj check 3a.10 failed - equality check failed", (p2.equals(p)));
127     }
128 }
129
Popular Tags