KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestObjectRepositoryAssembler.java,v 1.8 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 TestObjectRepositoryAssembler extends DefaultTestCase {
44     //common vars (customize for every test class)
45
private static String JavaDoc testClass = TestObjectRepositoryAssembler.class.getName();
46     private static Logger logger = Logger.getLogger("test."+testClass);
47
48     //variables
49

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

54     public TestObjectRepositoryAssembler(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 testAssembler() {
85         if (logger.isInfoEnabled()) logger.info("testing assembler");
86
87         //get the initial values
88
/*
89         String INIT_TEST_STRING = ObjectRepositoryAssembler.TEST_STRING;
90         int INIT_TEST_INT = ObjectRepositoryAssembler.TEST_INT;
91         short INIT_TEST_SHORT = ObjectRepositoryAssembler.TEST_SHORT;
92         long INIT_TEST_LONG = ObjectRepositoryAssembler.TEST_LONG;
93         double INIT_TEST_DOUBLE = ObjectRepositoryAssembler.TEST_DOUBLE;
94         float INIT_TEST_FLOAT = ObjectRepositoryAssembler.TEST_FLOAT;
95         boolean INIT_TEST_BOOLEAN = ObjectRepositoryAssembler.TEST_BOOLEAN;
96         Integer INIT_TEST_INT2 = ObjectRepositoryAssembler.TEST_INT2;
97         Short INIT_TEST_SHORT2 = ObjectRepositoryAssembler.TEST_SHORT2;
98         Long INIT_TEST_LONG2 = ObjectRepositoryAssembler.TEST_LONG2;
99         Double INIT_TEST_DOUBLE2 = ObjectRepositoryAssembler.TEST_DOUBLE2;
100         Float INIT_TEST_FLOAT2 = ObjectRepositoryAssembler.TEST_FLOAT2;
101         Boolean INIT_TEST_BOOLEAN2 = ObjectRepositoryAssembler.TEST_BOOLEAN2;
102 */

103         //assemble into the default ObjectRepository
104
new ObjectRepositoryAssembler().assemble("../WEB-INF/object-repository.xml");
105
106         //now make sure the values got changed
107
assertTrue("Failed to set TEST_CLASS", ObjectRepositoryAssembler.TEST_CLASS.equals(Param.class));
108         assertTrue("Failed to set TEST_STRING", ObjectRepositoryAssembler.TEST_STRING.equals("foo"));
109         assertTrue("Failed to set TEST_INT", ObjectRepositoryAssembler.TEST_INT==99);
110         assertTrue("Failed to set TEST_SHORT", ObjectRepositoryAssembler.TEST_SHORT==((short) 99));
111         assertTrue("Failed to set TEST_LONG", ObjectRepositoryAssembler.TEST_LONG==((long) 99));
112         assertTrue("Failed to set TEST_DOUBLE", ObjectRepositoryAssembler.TEST_DOUBLE==((double) 99));
113         assertTrue("Failed to set TEST_FLOAT", ObjectRepositoryAssembler.TEST_FLOAT==((float) 99));
114         assertTrue("Failed to set TEST_BOOLEAN", ObjectRepositoryAssembler.TEST_BOOLEAN==true);
115         assertEquals("Failed to set TEST_INT2", ObjectRepositoryAssembler.TEST_INT2, new Integer JavaDoc(99));
116         assertEquals("Failed to set TEST_SHORT2", ObjectRepositoryAssembler.TEST_SHORT2, new Short JavaDoc((short) 99));
117         assertEquals("Failed to set TEST_LONG2", ObjectRepositoryAssembler.TEST_LONG2, new Long JavaDoc(99));
118         assertEquals("Failed to set TEST_DOUBLE2", ObjectRepositoryAssembler.TEST_DOUBLE2, new Double JavaDoc(99));
119         assertEquals("Failed to set TEST_FLOAT2", ObjectRepositoryAssembler.TEST_FLOAT2, new Float JavaDoc(99));
120         assertEquals("Failed to set TEST_BOOLEAN2", ObjectRepositoryAssembler.TEST_BOOLEAN2, Boolean.TRUE);
121         assertTrue("Failed to set TEST_STRING2", ObjectRepositoryAssembler.TEST_STRING2.equals("foo"));
122         assertTrue("Failed to set TEST_STRING3", ObjectRepositoryAssembler.TEST_STRING3.equals("jujubean"));
123
124         ObjectRepository or = ObjectRepository.getGlobalRepository();
125         assertEquals("Failed to set TEST_KEY1", or.getState("TEST_KEY1").toString(), "my very elderly mother just sent us nine pizzas");
126         assertEquals("Failed to set TEST_KEY2", or.getState("TEST_KEY2").toString(), "sometimes you feel like a nut, sometimes you don't");
127         assertEquals("Failed to set TEST_KEY3", or.getState("TEST_KEY3"), or.getState("TEST_KEY2").toString());
128         assertEquals("Failed to set TEST_KEY4", or.getState("TEST_KEY4"), ObjectRepositoryAssembler.class);
129         assertTrue("Failed to set TEST_KEY5", or.getState("TEST_KEY5")!=null);
130
131         //todo: we really ought to be testing the other aspects of this class as well (instantiating
132
//an object, invoking methods on it, and placing it in the object repository)
133

134
135     }
136 }
137
Popular Tags