KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > event > TestDefaultEventBroker


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: TestDefaultEventBroker.java,v 1.2 2004/02/01 05:16:33 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.event;
21
22 import java.util.*;
23
24 import junit.framework.*;
25 import org.apache.log4j.*;
26
27 import org.enhydra.barracuda.plankton.data.*;
28 import org.enhydra.barracuda.testbed.*;
29
30 //csc_121302.1 - created
31
/**
32  * Unit tests for DefaultEventBroker (make sure we can register and look up ids/events
33  * correctly
34  */

35 public class TestDefaultEventBroker extends DefaultTestCase {
36     //common vars (customize for every test class)
37
private static String JavaDoc testClass = TestDefaultEventBroker.class.getName();
38     private static Logger logger = Logger.getLogger("test."+testClass);
39
40     //variables
41

42     //-------------------- Basics --------------------------------
43
/**
44      * Public Constructor
45      */

46     public TestDefaultEventBroker(String JavaDoc name) {
47         super(name);
48     }
49     
50     /**
51      * Every test class should have a main method so it can be run
52      * directly (when debugging tests you often will not want to run
53      * the whole suite)
54      *
55      * @param args defined in test.util.TestUtil
56      */

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

73     /**
74      * Simple test to verify that the component renders as expected
75      */

76     public void testListeners() throws InvalidClassException {
77         if (logger.isInfoEnabled()) logger.info("testing event broker listeners");
78
79         //create the event broker
80
DefaultEventBroker eb = new DefaultEventBroker(null, ".event");
81         List lAliases = null;
82         String JavaDoc id = null;
83         String JavaDoc result = null;
84         
85         //create some aliases
86
String JavaDoc classes[] = new String JavaDoc[] {
87             "foo.blah.event.Test",
88             "foo.blah.event.Blarney",
89             "foo.blah.event2.Test"
90         };
91         for (int i=0; i<classes.length; i++) {
92             eb.addAliases(classes[i], eb.getAliases(classes[i]), eb.eventXref);
93         }
94
95         //now see what we have
96
/*
97         System.out.println ("");
98         System.out.println ("Check @ point 1:");
99         CollectionsUtil.printStackTrace(eb.eventXref, System.out);
100 */

101
102         //now see if we get matches
103
id = "Blarney";
104         result = eb.matchEventClass(id);
105         assertTrue("failed to find id:"+id+", got:"+result, classes[1].equals(result));
106         id = "event2.Test";
107         result = eb.matchEventClass(id);
108         assertTrue("failed to find id:"+id+", got:"+result, classes[2].equals(result));
109         id = "Test";
110         try {
111             result = eb.matchEventClass(id);
112             fail("failed to throw exception on id:"+id+", got:"+result);
113         } catch (InvalidClassException e) {
114             //noop - this is what we expected
115
}
116         id = "BLARNEY"; //test upper case
117
result = eb.matchEventClass(id);
118         assertTrue("failed to find id:"+id+", got:"+result, classes[1].equals(result));
119         id = "blarney"; //test lower case
120
result = eb.matchEventClass(id);
121         assertTrue("failed to find id:"+id+", got:"+result, classes[1].equals(result));
122         id = "fOo.BlAh.EvEnT.bLaRnEy"; //test mixed case
123
result = eb.matchEventClass(id);
124         assertTrue("failed to find id:"+id+", got:"+result, classes[1].equals(result));
125     }
126 }
127
Popular Tags