1 25 package org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.ejb2view; 26 27 import static org.testng.Assert.fail; 28 import static org.testng.Assert.assertTrue; 29 30 import java.rmi.RemoteException ; 31 32 import javax.ejb.CreateException ; 33 import javax.ejb.EJB ; 34 import javax.ejb.EJBException ; 35 import javax.ejb.Remote ; 36 import javax.ejb.Stateless ; 37 import javax.ejb.TransactionAttribute ; 38 import javax.ejb.TransactionAttributeType ; 39 import javax.ejb.TransactionRequiredLocalException ; 40 import javax.transaction.TransactionRequiredException ; 41 42 48 @Stateless 49 @Remote (ItfCMTEjb2ViewClient.class) 50 public class SLSBCMTEjb2ViewClient implements ItfCMTEjb2ViewClient { 51 52 55 @EJB 56 private CMTEjb2ViewHome beanHome; 57 58 61 @EJB 62 private CMTEjb2ViewLocalHome beanLocalHome; 63 64 70 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 71 public void testRemoteMandatoryException() throws RemoteException , CreateException { 72 CMTEjb2View bean = beanHome.create(); 73 try { 74 bean.attributeMandatory(); 75 fail("The container did not throw an exception after a mandatory method had been " 76 + "called without a transaction context."); 77 } catch (Exception e) { 78 if (!(e instanceof TransactionRequiredException )) { 79 fail("The bean has 2.1 remote client view and did not receive the correct exception after a mandatory " 80 + "method had been called without a transaction context. The excepted exception expected was " 81 + "TransactionRequiredException, but the exception received was " + e.getClass().getName()); 82 } 83 } 84 } 85 86 91 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 92 public void testLocalMandatoryException() throws CreateException { 93 CMTEjb2LocalView bean = beanLocalHome.create(); 94 try { 95 bean.attributeMandatoryLocal(); 96 fail("The container did not throw an exception after a mandatory method had been called " 97 + "without a transaction context."); 98 } catch (Exception e) { 99 if (!(e instanceof TransactionRequiredLocalException )) { 100 fail("The bean has 2.1 local client view and did not receive the correct exception after a mandatory " 101 + "method had been called without a transaction context. The excepted exception expected was " 102 + "TransactionRequiredLocalException, but the exception received was " + e.getClass().getName()); 103 } 104 } 105 } 106 107 113 @TransactionAttribute (TransactionAttributeType.REQUIRED) 114 public void testRemoteNeverException() throws RemoteException , CreateException { 115 CMTEjb2View bean = beanHome.create(); 116 try { 117 bean.attributeNever(); 118 fail("The container did not throw an exception after a never method had been called " 119 + "with a transaction context."); 120 } catch (Exception e) { 121 if (!(e instanceof RemoteException )) { 122 fail("The bean has 2.1 remote client view and did not receive the correct exception after " 123 + "a never method had been called with a transaction context. The excepted exception expected " 124 + "was RemoteException, but the exception received was " + e.getClass().getName()); 125 } 126 } 127 } 128 129 134 @TransactionAttribute (TransactionAttributeType.REQUIRED) 135 public void testLocalNeverException() throws CreateException { 136 CMTEjb2LocalView bean = beanLocalHome.create(); 137 try { 138 bean.attributeNeverLocal(); 139 fail("The container did not throw an exception after a never method had been called " 140 + "with a transaction context."); 141 } catch (Exception e) { 142 if (!(e instanceof EJBException )) { 143 fail("The bean has 2.1 local client view and did not receive the correct exception after a never method " 144 + "had been called with a transaction context. The excepted exception expected was EJBException, " 145 + "but the exception received was " + e.getClass().getName()); 146 } 147 } 148 } 149 150 155 public void testIdentity() throws RemoteException , CreateException { 156 CMTEjb2View bean1 = beanHome.create(); 157 CMTEjb2View bean2 = beanHome.create(); 158 159 assertTrue(bean1.isIdentical(bean1), "The isIdentical method is not working for stateless beans"); 160 assertTrue(bean1.isIdentical(bean2), "The isIdentical method is not working for stateless beans"); 161 } 162 } 163 | Popular Tags |