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 javax.ejb.CreateException ; 33 import javax.ejb.EJBException ; 34 import javax.ejb.RemoveException ; 35 import javax.naming.Context ; 36 import javax.naming.InitialContext ; 37 import javax.naming.NamingException ; 38 39 import org.objectweb.easybeans.log.JLog; 40 import org.objectweb.easybeans.log.JLogFactory; 41 42 48 public abstract class Ejb2LocalClient implements ItfEjb2LocalClient { 49 50 53 private static JLog logger = JLogFactory.getLog(Ejb2Client.class); 54 55 59 public abstract SimpleEjb2LocalHome getBeanHome(); 60 61 65 public abstract String getBeanName(); 66 67 72 public void createWithIntParameter() throws CreateException { 73 SimpleEjb2LocalHome beanHome = getBeanHome(); 74 SimpleEjb2Local bean = beanHome.create(DEFAULT_CODE); 75 assertEquals(bean.getNameLocal(), SimpleEjb2Local.DEFAULT_NAME_LOCAL, "The bean was not created with the correct value."); 76 77 } 78 79 84 public void createWithStrParameter() throws CreateException { 85 SimpleEjb2LocalHome beanHome = getBeanHome(); 86 SimpleEjb2Local bean = beanHome.create(DEFAULT_NAME); 87 assertEquals(bean.getCodeLocal(), DEFAULT_CODE, "The bean was not created with the correct value."); 88 } 89 90 96 public void getBeanByLookup() throws NamingException , CreateException { 97 Context initCtx = new InitialContext (); 99 100 Object result = initCtx.lookup(getBeanName()); 101 102 SimpleEjb2LocalHome beanHomeLookup = (SimpleEjb2LocalHome) javax.rmi.PortableRemoteObject.narrow(result, 103 SimpleEjb2LocalHome.class); 104 105 SimpleEjb2Local beanLookup = beanHomeLookup.create(DEFAULT_NAME); 106 assertEquals(beanLookup.getCodeLocal(), DEFAULT_CODE, "The bean was not created with the correct value."); 107 108 } 109 110 115 public void removeObject() throws RemoveException , CreateException { 116 SimpleEjb2LocalHome beanHome = getBeanHome(); 117 SimpleEjb2Local bean = beanHome.create(DEFAULT_CODE); 118 beanHome.remove(bean); 119 120 try { 121 bean.toString(); 122 fail("The bean was not discarded"); 123 } catch (Exception e) { 124 logger.debug("The bean threw an expected exception :{0}", e); 125 } 126 } 127 128 133 public void verifyIdentity() throws CreateException { 134 SimpleEjb2LocalHome beanHome = getBeanHome(); 135 SimpleEjb2Local bean1 = beanHome.create(DEFAULT_NAME); 136 SimpleEjb2Local bean2 = beanHome.create(DEFAULT_NAME); 137 138 assertTrue(bean1.isIdentical(bean1), "The bean is not considered identical to itself."); 139 assertFalse(bean1.isIdentical(bean2), "The two different beans are considered identical."); 140 } 141 142 147 public void verifyGetPrimaryKey() throws CreateException { 148 SimpleEjb2LocalHome beanHome = getBeanHome(); 149 SimpleEjb2Local bean1 = beanHome.create(DEFAULT_NAME); 150 try{ 151 bean1.getPrimaryKey(); 152 fail("The client cannot call the getPrimaryKey method."); 153 }catch(EJBException e){ 154 logger.debug("The bean threw an expected exception :{0}", e); 155 } 156 } 157 } 158 | Popular Tags |