1 package org.jacorb.test.common; 2 3 23 24 import java.lang.reflect.*; 25 26 import junit.framework.*; 27 import junit.extensions.*; 28 29 36 public class JacORBTestSuite extends TestSuite implements JacORBTest 37 { 38 private TestAnnotations annotations = null; 39 40 private String clientVersion = null; 41 private String serverVersion = null; 42 43 48 public JacORBTestSuite (String name, 49 Class annotatedClass) 50 { 51 super (name); 52 clientVersion = System.getProperty ("jacorb.test.client.version", "cvs"); 53 serverVersion = System.getProperty ("jacorb.test.server.version", "cvs"); 54 if (!clientVersion.equals("cvs") || !serverVersion.equals("cvs")) 55 { 56 annotations = TestAnnotations.forClass (annotatedClass); 57 } 58 } 59 60 65 protected JacORBTestSuite (String name) 66 { 67 super (name); 68 clientVersion = System.getProperty ("jacorb.test.client.version", "cvs"); 69 serverVersion = System.getProperty ("jacorb.test.server.version", "cvs"); 70 if (!clientVersion.equals("cvs") || !serverVersion.equals("cvs")) 71 { 72 annotations = TestAnnotations.forTestSuite (this); 73 } 74 } 75 76 public boolean isApplicableTo (String clientVersion, String serverVersion) 77 { 78 if (annotations == null) 79 return true; 80 else 81 { 82 boolean result = annotations.isApplicableTo (clientVersion, 83 serverVersion); 84 if (!result) System.out.println ("not applicable: " + getName()); 85 return result; 86 } 87 } 88 89 94 public void addTest (Test test) 95 { 96 if (clientVersion == null && serverVersion == null) 97 { 98 super.addTest (test); 99 } 100 else if (test instanceof JacORBTest) 101 { 102 if (((JacORBTest)test).isApplicableTo (clientVersion, 103 serverVersion)) 104 super.addTest (test); 105 } 106 else if (test instanceof TestDecorator) 107 { 108 TestDecorator decorator = (TestDecorator)test; 109 Test t = decorator.getTest(); 110 if (t instanceof JacORBTest) 111 { 112 if (((JacORBTest)t).isApplicableTo (clientVersion, 113 serverVersion)) 114 super.addTest (test); 115 } 116 else 117 super.addTest (test); 118 } 119 else 120 { 121 super.addTest (test); 122 } 123 } 124 125 135 public void addTestSuite (Class c) 136 { 137 if (JacORBTest.class.isAssignableFrom(c)) 138 { 139 TestAnnotationsParser p = TestAnnotationsParser.getInstance(c); 140 TestAnnotations ta = p.getClassAnnotations(); 141 if (ta == null || ta.isApplicableTo (clientVersion, serverVersion)) 142 { 143 TestSuite ts = invokeSuiteMethod (c); 144 super.addTest (ts); 145 } 146 } 147 else 148 { 149 super.addTestSuite(c); 150 } 151 } 152 153 158 private TestSuite invokeSuiteMethod (Class c) 159 { 160 try 161 { 162 Method suiteMethod = c.getDeclaredMethod ("suite", 163 new Class []{}); 164 Object result = suiteMethod.invoke(null, new Object []{}); 165 return (TestSuite)result; 166 } 167 catch (Exception ex) 168 { 169 throw new RuntimeException (ex); 170 } 171 } 172 173 } 174 | Popular Tags |