1 22 23 package org.jboss.test.hibernate.test; 24 25 import java.util.Date ; 26 import java.util.List ; 27 import java.util.Iterator ; 28 import javax.naming.InitialContext ; 29 30 import org.jboss.test.JBossTestCase; 31 32 import junit.framework.Test; 33 34 40 public class ScopedEarsUnitTestCase extends JBossTestCase 41 { 42 public ScopedEarsUnitTestCase(String name) throws Exception 43 { 44 super(name); 45 } 46 47 50 public static Test suite() throws Exception 51 { 52 return getDeploySetup(ScopedEarsUnitTestCase.class, "hib-ear1.ear,hib-ear2.ear"); 53 } 54 55 public void testEAR1Session() throws Throwable 56 { 57 InitialContext ctx = getInitialContext(); 58 org.jboss.test.hibernate.model.v1.IPersonHome home = 59 (org.jboss.test.hibernate.model.v1.IPersonHome) ctx.lookup("hibernate/ear1/PersonBean"); 60 org.jboss.test.hibernate.model.v1.IPerson bean = null; 61 62 try 63 { 64 bean = home.create(); 65 bean.init(); 66 bean.sessionInit(); 67 68 int initialCount = bean.listPeople().size(); 69 assertTrue("People initialCount == 0 ", initialCount == 0 ); 70 71 org.jboss.test.hibernate.model.v1.Person jimmy = new org.jboss.test.hibernate.model.v1.Person(197); 72 Date bday = new Date (2003, 6, 13); 73 jimmy.setBDay(bday); 74 jimmy.setName("Jimmy Neutron"); 75 jimmy.setAddress("Channel 302, Nicktoons USA"); 76 jimmy.setPay(new Float (123456.789)); 77 bean.storeUser(jimmy); 78 79 List persons = bean.listPeople(); 80 assertNotNull(persons); 81 assertEquals("Incorrect result size", initialCount + 1, persons.size()); 82 83 org.jboss.test.hibernate.model.v1.Person found = null; 84 Iterator itr = persons.iterator(); 85 while (itr.hasNext()) 86 { 87 org.jboss.test.hibernate.model.v1.Person p = 88 (org.jboss.test.hibernate.model.v1.Person) itr.next(); 89 if (p.getName().equals(jimmy.getName())) 90 { 91 found = p; 92 } 93 } 94 assertNotNull("Found Jimmy in list", found); 95 } 96 finally 97 { 98 if (bean != null) 99 { 100 try 101 { 102 bean.remove(); 103 } 104 catch (Throwable t) 105 { 106 } 108 } 109 } 110 } 111 112 public void testEAR2Session() throws Throwable 113 { 114 InitialContext ctx = getInitialContext(); 115 org.jboss.test.hibernate.model.v2.IPersonHome home = 116 (org.jboss.test.hibernate.model.v2.IPersonHome) ctx.lookup("hibernate/ear2/PersonBean"); 117 org.jboss.test.hibernate.model.v2.IPerson bean = null; 118 119 try 120 { 121 bean = home.create(); 122 bean.init(); 123 bean.sessionInit(); 124 125 int initialCount = bean.listPeople().size(); 126 assertTrue("People initialCount == 0 ", initialCount == 0 ); 127 128 org.jboss.test.hibernate.model.v2.Person jimmy = new org.jboss.test.hibernate.model.v2.Person(197); 129 Date bday = new Date (2003, 6, 13); 130 jimmy.setBDay(bday); 131 jimmy.setName("Jimmy Neutron"); 132 jimmy.setAddress("Channel 302, Nicktoons USA"); 133 jimmy.setPay(new Float (123456.789)); 134 bean.storeUser(jimmy); 135 136 List persons = bean.listPeople(); 137 assertNotNull(persons); 138 assertEquals("Incorrect result size", initialCount + 1, persons.size()); 139 140 org.jboss.test.hibernate.model.v2.Person found = null; 141 Iterator itr = persons.iterator(); 142 while (itr.hasNext()) 143 { 144 org.jboss.test.hibernate.model.v2.Person p = 145 (org.jboss.test.hibernate.model.v2.Person) itr.next(); 146 if (p.getName().equals(jimmy.getName())) 147 { 148 found = p; 149 } 150 } 151 assertNotNull("Found Jimmy in list", found); 152 } 153 finally 154 { 155 if (bean != null) 156 { 157 try 158 { 159 bean.remove(); 160 } 161 catch (Throwable t) 162 { 163 } 165 } 166 } 167 } 168 169 } 170 | Popular Tags |