1 25 package org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.ejb2view; 26 27 import static org.testng.Assert.assertEquals; 28 import static org.testng.Assert.assertFalse; 29 import static org.testng.Assert.assertTrue; 30 import static org.testng.Assert.fail; 31 32 import java.rmi.RemoteException ; 33 34 import javax.ejb.CreateException ; 35 import javax.ejb.EJBMetaData ; 36 import javax.ejb.RemoveException ; 37 import javax.naming.Context ; 38 import javax.naming.InitialContext ; 39 import javax.naming.NamingException ; 40 41 import org.objectweb.easybeans.log.JLog; 42 import org.objectweb.easybeans.log.JLogFactory; 43 44 49 public abstract class Ejb2Client implements ItfEjb2Client { 50 51 54 private static JLog logger = JLogFactory.getLog(Ejb2Client.class); 55 56 60 public abstract SimpleEjb2Home getBeanHome(); 61 62 66 public abstract String getBeanName(); 67 68 74 public void createWithoutParameters() throws CreateException , RemoteException { 75 SimpleEjb2Home beanHome = getBeanHome(); 76 SimpleEjb2 bean = beanHome.create(); 77 assertEquals(bean.getCode(), SimpleEjb2.DEFAULT_CODE_REMOTE, "The bean was not created with the correct value."); 78 79 } 80 81 87 public void createWithParameters() throws CreateException , RemoteException { 88 SimpleEjb2Home beanHome = getBeanHome(); 89 SimpleEjb2 bean = beanHome.create(DEFAULT_CODE, DEFAULT_NAME); 90 assertEquals(bean.getCode(), DEFAULT_CODE, "The bean was not created with the correct value."); 91 } 92 93 100 public void getBeanByLookup() throws NamingException , CreateException , RemoteException { 101 Context initCtx = new InitialContext (); 103 104 Object result = initCtx.lookup(getBeanName()); 105 106 SimpleEjb2Home beanHomeLookup = (SimpleEjb2Home) javax.rmi.PortableRemoteObject.narrow(result, 107 SimpleEjb2Home.class); 108 109 SimpleEjb2 beanLookup = beanHomeLookup.create(DEFAULT_CODE, DEFAULT_NAME); 110 assertEquals(beanLookup.getCode(), DEFAULT_CODE, "The bean was not created with the correct value."); 111 112 } 113 114 120 public void removeObject() throws RemoteException , RemoveException , CreateException { 121 SimpleEjb2Home beanHome = getBeanHome(); 122 SimpleEjb2 bean = beanHome.create(); 123 beanHome.remove(bean); 124 125 try { 126 bean.toString(); 127 fail("The bean was not discarded"); 128 } catch (Exception e) { 129 logger.debug("The bean threw an expected exception :{0}", e); 130 } 131 } 132 133 138 public void getEJBMetaData() throws RemoteException { 139 SimpleEjb2Home beanHome = getBeanHome(); 140 EJBMetaData data = beanHome.getEJBMetaData(); 141 142 assertFalse(data.isStatelessSession(), 143 "The metadata interface is doing an incorrect value for the isStatelessSession method."); 144 } 145 146 152 public void verifyIdentity() throws CreateException , RemoteException { 153 SimpleEjb2Home beanHome = getBeanHome(); 154 SimpleEjb2 bean1 = beanHome.create(); 155 SimpleEjb2 bean2 = beanHome.create(); 156 157 assertTrue(bean1.isIdentical(bean1), "The bean is not considered identical to itself."); 158 assertFalse(bean1.isIdentical(bean2), "The two different beans are considered identical."); 159 } 160 161 167 public void verifyGetPrimaryKey() throws RemoteException , CreateException { 168 SimpleEjb2Home beanHome = getBeanHome(); 169 SimpleEjb2 bean1 = beanHome.create(); 170 try{ 171 bean1.getPrimaryKey(); 172 fail("The client cannot call the getPrimaryKey method."); 173 }catch (RemoteException e){ 174 logger.debug("The bean threw an expected exception :{0}", e); 175 } 176 } 177 } 178 | Popular Tags |