1 22 package org.jboss.ejb3.test.longlived.unit; 23 24 import org.jboss.ejb3.test.longlived.Customer; 25 import org.jboss.ejb3.test.longlived.ShoppingCart; 26 import org.jboss.ejb3.test.longlived.StatelessRemote; 27 import org.jboss.test.JBossTestCase; 28 import junit.framework.Test; 29 30 36 37 public class EntityUnitTestCase 38 extends JBossTestCase 39 { 40 org.jboss.logging.Logger log = getLog(); 41 42 static boolean deployed = false; 43 static int test = 0; 44 45 public EntityUnitTestCase(String name) 46 { 47 48 super(name); 49 50 } 51 52 public void testWithFlushMode() throws Exception 53 { 54 ShoppingCart test = (ShoppingCart) this.getInitialContext().lookup("ShoppingCartBean/remote"); 55 StatelessRemote remote = (StatelessRemote) this.getInitialContext().lookup("StatelessSessionBean/remote"); 56 Customer c; 57 long id; 58 59 60 id = test.createCustomer(); 61 c = remote.find(id); 62 assertEquals("William", c.getName()); 63 c = test.find(id); 64 assertEquals("William", c.getName()); 65 test.never(); 66 c = remote.find(id); 67 assertEquals("William", c.getName()); 68 69 test.checkout(); 70 c = remote.find(id); 71 assertEquals("Bob", c.getName()); 72 73 75 test = (ShoppingCart) this.getInitialContext().lookup("ShoppingCartBean/remote"); 76 77 78 id = test.createCustomer(); 79 c = remote.find(id); 80 assertEquals("William", c.getName()); 81 c = test.find(id); 82 assertEquals("William", c.getName()); 83 test.update(); 84 c = remote.find(id); 85 assertEquals("Bill", c.getName()); 86 c = test.find(id); 87 assertEquals("Bill", c.getName()); 88 test.update2(); 89 c = remote.find(id); 90 assertEquals("Billy", c.getName()); 91 c = test.find(id); 92 assertEquals("Billy", c.getName()); 93 test.update3(); 94 c = remote.find(id); 95 assertEquals("Bill Jr.", c.getName()); 96 c = test.find(id); 97 assertEquals("Bill Jr.", c.getName()); 98 test.checkout(); 99 } 100 101 public void testLongLivedSession() throws Exception 102 { 103 ShoppingCart test = (ShoppingCart) this.getInitialContext().lookup("ShoppingCartBean/remote"); 104 StatelessRemote remote = (StatelessRemote) this.getInitialContext().lookup("StatelessSessionBean/remote"); 105 Customer c; 106 107 long id = test.createCustomer(); 108 c = remote.find(id); 109 assertEquals("William", c.getName()); 110 c = test.find(id); 111 assertEquals("William", c.getName()); 112 test.update(); 113 c = remote.find(id); 114 assertEquals("Bill", c.getName()); 115 c = test.find(id); 116 assertEquals("Bill", c.getName()); 117 test.update2(); 118 c = remote.find(id); 119 assertEquals("Billy", c.getName()); 120 c = test.find(id); 121 assertEquals("Billy", c.getName()); 122 test.update3(); 123 c = remote.find(id); 124 assertEquals("Bill Jr.", c.getName()); 125 c = test.find(id); 126 assertEquals("Bill Jr.", c.getName()); 127 test.setContainedCustomer(); 128 Thread.sleep(6000); assertTrue(remote.isPassivated()); 130 test.checkContainedCustomer(); 131 test.findAndUpdateStateless(); 132 test.updateContained(); 133 remote.clearDestroyed(); 134 assertTrue(test.isContainedActivated()); 135 test.checkout(); 136 assertTrue(remote.isDestroyed()); 137 } 138 139 public void testHibernateLongLivedSession() throws Exception 140 { 141 ShoppingCart test = (ShoppingCart) this.getInitialContext().lookup("HibernateShoppingCart"); 142 StatelessRemote remote = (StatelessRemote) this.getInitialContext().lookup("StatelessSessionBean/remote"); 143 Customer c; 144 145 long id = test.createCustomer(); 146 c = remote.find(id); 147 assertEquals("William", c.getName()); 148 c = test.find(id); 149 assertEquals("William", c.getName()); 150 test.update(); 151 c = remote.find(id); 152 assertEquals("Bill", c.getName()); 153 c = test.find(id); 154 assertEquals("Bill", c.getName()); 155 test.update2(); 156 c = remote.find(id); 157 assertEquals("Billy", c.getName()); 158 c = test.find(id); 159 assertEquals("Billy", c.getName()); 160 test.update3(); 161 c = remote.find(id); 162 assertEquals("Bill Jr.", c.getName()); 163 c = test.find(id); 164 assertEquals("Bill Jr.", c.getName()); 165 test.checkout(); 166 } 167 168 public void testHibernateWithFlushMode() throws Exception 169 { 170 ShoppingCart test = (ShoppingCart) this.getInitialContext().lookup("HibernateShoppingCart"); 171 StatelessRemote remote = (StatelessRemote) this.getInitialContext().lookup("StatelessSessionBean/remote"); 172 Customer c; 173 long id; 174 175 176 id = test.createCustomer(); 177 c = remote.find(id); 178 assertEquals("William", c.getName()); 179 c = test.find(id); 180 assertEquals("William", c.getName()); 181 test.never(); 182 c = remote.find(id); 183 assertEquals("William", c.getName()); 184 185 test.checkout(); 186 c = remote.find(id); 187 assertEquals("Bob", c.getName()); 188 189 191 test = (ShoppingCart) this.getInitialContext().lookup("HibernateShoppingCart"); 192 193 194 id = test.createCustomer(); 195 c = remote.find(id); 196 assertEquals("William", c.getName()); 197 c = test.find(id); 198 assertEquals("William", c.getName()); 199 test.update(); 200 c = remote.find(id); 201 assertEquals("Bill", c.getName()); 202 c = test.find(id); 203 assertEquals("Bill", c.getName()); 204 test.update2(); 205 c = remote.find(id); 206 assertEquals("Billy", c.getName()); 207 c = test.find(id); 208 assertEquals("Billy", c.getName()); 209 test.update3(); 210 c = remote.find(id); 211 assertEquals("Bill Jr.", c.getName()); 212 c = test.find(id); 213 assertEquals("Bill Jr.", c.getName()); 214 test.checkout(); 215 } 216 217 public static Test suite() throws Exception 218 { 219 return getDeploySetup(EntityUnitTestCase.class, "longlived-test.jar"); 220 } 221 222 } 223 | Popular Tags |