1 22 package org.jboss.test.txpropiiop.test; 23 24 import java.rmi.RemoteException ; 25 import java.util.Properties ; 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 28 import javax.rmi.PortableRemoteObject ; 29 30 import junit.framework.Test; 31 import org.jboss.iiop.CorbaORB; 32 import org.jboss.test.JBossIIOPTestCase; 33 import org.jboss.test.txpropiiop.interfaces.a.SessionA; 34 import org.jboss.test.txpropiiop.interfaces.a.SessionAHome; 35 import org.jboss.test.txpropiiop.interfaces.b.SessionB; 36 import org.jboss.test.txpropiiop.interfaces.b.SessionBHome; 37 import org.jboss.tm.iiop.TxClientInterceptor; 38 import org.omg.CORBA.ORB ; 39 import org.omg.CosTransactions.PropagationContext; 40 import org.omg.CosTransactions.TransIdentity; 41 import org.omg.CosTransactions.otid_t; 42 43 49 public class TxPropIIOPUnitTestCase extends JBossIIOPTestCase 50 { 51 private static SessionA sessionA; 52 private static SessionB sessionB; 53 54 public TxPropIIOPUnitTestCase(String name) throws Exception 55 { 56 super(name); 57 } 58 59 public static Test suite() throws Exception 60 { 61 return getDeploySetup(TxPropIIOPUnitTestCase.class, "txpropiiopB.jar"); 62 } 63 64 protected void setUp() throws Exception 65 { 66 log.debug("====== Starting test " + getName()); 67 77 } 78 79 protected void tearDown() throws Exception 80 { 81 log.debug("====== Ended test " + getName()); 82 90 } 91 92 99 100 public void testTxToNotSupported() throws Exception 101 { 102 setTransaction(); 103 try 104 { 105 String hello = "Hello"; 106 String result = getSessionB().testNotSupported(hello); 107 validate(hello, result); 108 } 109 finally 110 { 111 unsetTransaction(); 112 } 113 } 114 115 public void testTxToRequired() throws Exception 116 { 117 setTransaction(); 118 try 119 { 120 String hello = "Hello"; 121 String result = getSessionB().testRequired(hello); 122 fail("Expected remote exception"); 123 } 124 catch (RemoteException expected) 125 { 126 } 127 finally 128 { 129 unsetTransaction(); 130 } 131 } 132 133 public void testTxToRequiresNew() throws Exception 134 { 135 setTransaction(); 136 try 137 { 138 String hello = "Hello"; 139 String result = getSessionB().testRequiresNew(hello); 140 validate(hello, result); 141 } 142 finally 143 { 144 unsetTransaction(); 145 } 146 } 147 148 public void testTxToSupports() throws Exception 149 { 150 setTransaction(); 151 try 152 { 153 String hello = "Hello"; 154 String result = getSessionB().testSupports(hello); 155 fail("Expected remote exception"); 156 } 157 catch (RemoteException expected) 158 { 159 } 160 finally 161 { 162 unsetTransaction(); 163 } 164 } 165 166 public void testTxToMandatory() throws Exception 167 { 168 setTransaction(); 169 try 170 { 171 String hello = "Hello"; 172 String result = getSessionB().testMandatory(hello); 173 fail("Expected remote exception"); 174 } 175 catch (RemoteException expected) 176 { 177 } 178 finally 179 { 180 unsetTransaction(); 181 } 182 } 183 184 public void testTxToNever() throws Exception 185 { 186 setTransaction(); 187 try 188 { 189 String hello = "Hello"; 190 String result = getSessionB().testNever(hello); 191 fail("Expected remote exception"); 192 } 193 catch (RemoteException expected) 194 { 195 } 196 finally 197 { 198 unsetTransaction(); 199 } 200 } 201 202 public void testNoTxToNotSupported() throws Exception 203 { 204 String hello = "Hello"; 205 String result = getSessionB().testNotSupported(hello); 206 validate(hello, result); 207 } 208 209 public void testNoTxToRequired() throws Exception 210 { 211 String hello = "Hello"; 212 String result = getSessionB().testNotSupported(hello); 213 validate(hello, result); 214 } 215 216 public void testNoTxToRequiresNew() throws Exception 217 { 218 String hello = "Hello"; 219 String result = getSessionB().testNotSupported(hello); 220 validate(hello, result); 221 } 222 223 public void testNoTxToSupports() throws Exception 224 { 225 String hello = "Hello"; 226 String result = getSessionB().testNotSupported(hello); 227 validate(hello, result); 228 } 229 230 public void testNoTxToMandatory() throws Exception 231 { 232 try 233 { 234 String hello = "Hello"; 235 String result = getSessionB().testMandatory(hello); 236 fail("Expected remote exception"); 237 } 238 catch (RemoteException expected) 239 { 240 } 241 } 242 243 public void testNoTxToNever() throws Exception 244 { 245 String hello = "Hello"; 246 String result = getSessionB().testNotSupported(hello); 247 validate(hello, result); 248 } 249 250 private static void validate(String hello, String result) throws Exception 251 { 252 if (hello == result) 253 fail("Should be pass by value"); 254 assertEquals(hello, result); 255 } 256 257 private SessionA getSessionA() throws Exception 258 { 259 if (sessionA == null) 260 { 261 SessionAHome home = (SessionAHome) lookup("SessionA", SessionAHome.class); 262 sessionA = home.create(); 263 } 264 return sessionA; 265 } 266 267 private SessionB getSessionB() throws Exception 268 { 269 if (sessionB == null) 270 { 271 SessionBHome home = (SessionBHome) lookup("SessionB", SessionBHome.class); 272 sessionB = home.create(); 273 } 274 return sessionB; 275 } 276 277 protected void setTransaction() throws Exception 278 { 279 PropagationContext pc = new PropagationContext(); 280 pc.parents = new TransIdentity[0]; 281 pc.current = new TransIdentity(); 282 pc.current.otid = new otid_t(); 283 pc.current.otid.formatID = 666; 284 pc.current.otid.bqual_length = 1; 285 pc.current.otid.tid = new byte[] { (byte) 1 }; 286 pc.implementation_specific_data = getORB().create_any(); 287 pc.implementation_specific_data.insert_long(1); 288 TxClientInterceptor.setOutgoingPropagationContext(pc); 289 } 290 291 protected void unsetTransaction() 292 { 293 TxClientInterceptor.unsetOutgoingPropagationContext(); 294 } 295 296 private static ORB getORB() throws Exception 297 { 298 return CorbaORB.getInstance(); 299 } 300 301 private Object lookup(String name, Class clazz) throws Exception 302 { 303 Context ctx = getInitialContext(); 304 Object obj = ctx.lookup(name); 305 Object result = PortableRemoteObject.narrow(obj, clazz); 306 return result; 307 } 308 } 309 | Popular Tags |