1 22 43 package org.jboss.test.hibernate.test; 44 45 import org.jboss.test.JBossTestCase; 46 import org.jboss.test.hibernate.model.User; 47 import org.jboss.test.hibernate.model.Name; 48 import org.jboss.test.hibernate.ejb.interfaces.ProfileService; 49 import org.jboss.test.hibernate.ejb.interfaces.ProfileServiceHome; 50 import org.jboss.test.hibernate.ejb.interfaces.ProfileServiceUtil; 51 52 import java.util.GregorianCalendar ; 53 import java.util.List ; 54 import java.util.Iterator ; 55 56 import junit.framework.Test; 57 58 63 public class HibernateIntgUnitTestCase extends JBossTestCase 64 { 65 public HibernateIntgUnitTestCase(String name) throws Exception 66 { 67 super(name); 68 } 69 70 72 public static Test suite() throws Exception 73 { 74 return getDeploySetup(HibernateIntgUnitTestCase.class, "hib-test.ear"); 75 } 76 77 public void testRedeployment() throws Throwable 78 { 79 Throwable initialThrowable = null; 80 81 try 83 { 84 ProfileServiceHome home = ProfileServiceUtil.getHome(); 85 ProfileService service = null; 86 try 87 { 88 service = home.create(); 89 90 User user = new User(); 91 user.setEmail("nobody@nowhere.com"); 92 user.setName( new Name() ); 93 user.getName().setFirstName("John"); 94 user.getName().setInitial( new Character ('Q') ); 95 user.getName().setLastName("Public"); 96 user.setPassword("password"); 97 user.setTimeOfCreation( new GregorianCalendar () ); 98 user.setHandle("myHandle"); 99 100 Long savedUserId = service.storeUser( user ).getId(); 101 getLog().info("User created with id = " + savedUserId ); 102 103 List users = service.listUsers(); 109 assertNotNull( users ); 110 assertEquals( "Incorrect result size", 1, users.size() ); 111 } 112 finally 113 { 114 if ( service != null ) 115 { 116 try 117 { 118 service.remove(); 119 } 120 catch( Throwable t ) 121 { 122 } 123 } 124 } 125 } 126 catch( Throwable t ) 127 { 128 initialThrowable = t; 131 } 132 133 delegate.redeploy( "hib-test.ear" ); 135 136 ProfileServiceHome home = ProfileServiceUtil.getHome(); 138 ProfileService service = null; 139 try 140 { 141 service = home.create(); 142 143 User user = new User(); 144 user.setEmail("nobody@nowhere.com"); 145 user.setName( new Name() ); 146 user.getName().setFirstName("John"); 147 user.getName().setInitial( new Character ('Q') ); 148 user.getName().setLastName("Public"); 149 user.setPassword("password"); 150 user.setTimeOfCreation( new GregorianCalendar () ); 151 user.setHandle("myHandle"); 152 153 Long savedUserId = service.storeUser( user ).getId(); 154 getLog().info("User created with id = " + savedUserId ); 155 156 List users = service.listUsers(); 157 assertNotNull( users ); 158 assertEquals( "Incorrect result size", 1, users.size() ); 159 } 160 catch( Throwable t ) 161 { 162 if ( initialThrowable == null ) 166 { 167 fail( "Getting new exceptions after redeploy [" + t + "]" ); 168 } 169 170 if ( !t.getClass().getName().equals( initialThrowable.getClass().getName() ) ) 171 { 172 fail( "After redploy failing for different cause [" + t + "]" ); 173 } 174 } 175 finally 176 { 177 if ( service != null ) 178 { 179 try 180 { 181 service.remove(); 182 } 183 catch( Throwable t ) 184 { 185 } 186 } 187 } 188 189 } 190 191 public void testCurrentSession() throws Throwable { 192 193 ProfileServiceHome home = ProfileServiceUtil.getHome(); 194 ProfileService service = null; 195 196 try 197 { 198 service = home.create(); 199 200 User user = new User(); 201 user.setEmail("nobody@nowhere.com"); 202 user.setName( new Name() ); 203 user.getName().setFirstName("John"); 204 user.getName().setInitial( new Character ('Q') ); 205 user.getName().setLastName("Public"); 206 user.setPassword("password"); 207 user.setTimeOfCreation( new GregorianCalendar () ); 208 user.setHandle("myHandle"); 209 210 Long savedUserId = service.storeUser( user ).getId(); 211 getLog().info("User created with id = " + savedUserId ); 212 213 List users = service.listUsers(); 214 assertNotNull( users ); 215 assertEquals( "Incorrect result size", 1, users.size() ); 216 217 Long userId = ( ( User ) users.get( 0 ) ).getId(); 218 assertEquals( "Saved used not returned", savedUserId, userId ); 219 220 user = service.loadUser( savedUserId ); 221 assertNotNull( user ); 222 } 223 finally 224 { 225 if ( service != null ) 226 { 227 try 228 { 229 service.remove(); 230 } 231 catch( Throwable t ) 232 { 233 } 235 } 236 } 237 } 238 239 } 240 | Popular Tags |