KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > common > NotifyServerTestCase


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21
22 package org.jacorb.test.notification.common;
23
24 import java.lang.reflect.Constructor JavaDoc;
25
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.jacorb.test.common.ClientServerTestCase;
30 import org.jacorb.test.common.TestUtils;
31 import org.omg.CORBA.IntHolder JavaDoc;
32 import org.omg.CORBA.ORB JavaDoc;
33 import org.omg.CosNotification.Property;
34 import org.omg.CosNotification.UnsupportedAdmin;
35 import org.omg.CosNotification.UnsupportedQoS;
36 import org.omg.CosNotifyChannelAdmin.EventChannel;
37 import org.omg.CosNotifyChannelAdmin.EventChannelFactory;
38 import org.omg.CosNotifyChannelAdmin.EventChannelFactoryHelper;
39 import org.omg.CosNotifyFilter.Filter;
40
41 public abstract class NotifyServerTestCase extends ClientServerTestCase
42 {
43     public NotifyServerTestCase(String JavaDoc name, NotifyServerTestSetup setup)
44     {
45         super(name, setup);
46     }
47
48     public final EventChannelFactory getEventChannelFactory()
49     {
50         EventChannelFactory channelFactory = EventChannelFactoryHelper.narrow(setup
51                 .getServerObject());
52
53         return channelFactory;
54     }
55
56     public EventChannel getDefaultChannel() throws UnsupportedAdmin, UnsupportedQoS
57     {
58         return getEventChannelFactory().create_channel(new Property[0], new Property[0],
59                 new IntHolder JavaDoc());
60     }
61
62     public final void setUp() throws Exception JavaDoc
63     {
64         super.setUp();
65
66         setUpTest();
67     }
68
69     protected void setUpTest() throws Exception JavaDoc
70     {
71         // no op
72
}
73
74     public static Test suite(Class JavaDoc clazz) throws Exception JavaDoc
75     {
76         return suite("TestSuite defined in Class " + clazz.getName(), clazz);
77     }
78
79     public static Test suite(String JavaDoc suiteName, Class JavaDoc clazz) throws Exception JavaDoc
80     {
81         return suite(suiteName, clazz, "test");
82     }
83
84     public static Test suite(String JavaDoc suiteName, Class JavaDoc clazz, String JavaDoc testMethodPrefix)
85             throws Exception JavaDoc
86     {
87         if (!NotifyServerTestCase.class.isAssignableFrom(clazz))
88         {
89             throw new IllegalArgumentException JavaDoc("Class " + clazz + " is not derived from " + NotifyServerTestCase.class.getName());
90         }
91         
92         TestSuite _suite = new TestSuite(suiteName);
93
94         NotifyServerTestSetup _setup = new NotifyServerTestSetup(_suite);
95
96         String JavaDoc[] _methodNames = TestUtils.getTestMethods(clazz, testMethodPrefix);
97
98         addToSuite(_suite, _setup, clazz, _methodNames);
99
100         return _setup;
101     }
102
103     private static void addToSuite(TestSuite suite, NotifyServerTestSetup setup, Class JavaDoc clazz,
104             String JavaDoc[] testMethods) throws Exception JavaDoc
105     {
106         Constructor JavaDoc _ctor = clazz.getConstructor(new Class JavaDoc[] { String JavaDoc.class,
107                 NotifyServerTestSetup.class });
108
109         for (int x = 0; x < testMethods.length; ++x)
110         {
111             suite.addTest((Test) _ctor.newInstance(new Object JavaDoc[] { testMethods[x], setup }));
112         }
113     }
114
115     public ORB JavaDoc getClientORB()
116     {
117         return setup.getClientOrb();
118     }
119     
120     public Filter createFilter() throws Exception JavaDoc
121     {
122         return getDefaultChannel().default_filter_factory().create_filter("EXTENDED_TCL");
123     }
124 }
125
Popular Tags