1 21 22 package org.jacorb.test.notification.common; 23 24 import java.lang.reflect.Constructor ; 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 ; 32 import org.omg.CORBA.ORB ; 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 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 ()); 60 } 61 62 public final void setUp() throws Exception 63 { 64 super.setUp(); 65 66 setUpTest(); 67 } 68 69 protected void setUpTest() throws Exception 70 { 71 } 73 74 public static Test suite(Class clazz) throws Exception 75 { 76 return suite("TestSuite defined in Class " + clazz.getName(), clazz); 77 } 78 79 public static Test suite(String suiteName, Class clazz) throws Exception 80 { 81 return suite(suiteName, clazz, "test"); 82 } 83 84 public static Test suite(String suiteName, Class clazz, String testMethodPrefix) 85 throws Exception 86 { 87 if (!NotifyServerTestCase.class.isAssignableFrom(clazz)) 88 { 89 throw new IllegalArgumentException ("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 [] _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 clazz, 104 String [] testMethods) throws Exception 105 { 106 Constructor _ctor = clazz.getConstructor(new Class [] { String .class, 107 NotifyServerTestSetup.class }); 108 109 for (int x = 0; x < testMethods.length; ++x) 110 { 111 suite.addTest((Test) _ctor.newInstance(new Object [] { testMethods[x], setup })); 112 } 113 } 114 115 public ORB getClientORB() 116 { 117 return setup.getClientOrb(); 118 } 119 120 public Filter createFilter() throws Exception 121 { 122 return getDefaultChannel().default_filter_factory().create_filter("EXTENDED_TCL"); 123 } 124 } 125 | Popular Tags |