1 22 package org.jboss.test.bmp.test; 23 24 import java.util.Iterator ; 25 26 import javax.naming.InitialContext ; 27 28 import junit.framework.Test; 29 30 import org.jboss.test.JBossTestCase; 31 import org.jboss.test.bmp.interfaces.BMPHelperSession; 32 import org.jboss.test.bmp.interfaces.BMPHelperSessionHome; 33 import org.jboss.test.bmp.interfaces.SimpleBMP; 34 import org.jboss.test.bmp.interfaces.SimpleBMPHome; 35 36 public class SmallCacheBmpUnitTestCase 37 extends JBossTestCase 38 { 39 public SmallCacheBmpUnitTestCase(String name) 40 { 41 super(name); 42 } 43 44 public void testBMP() throws Exception 45 { 46 BMPHelperSessionHome sessionHome = (BMPHelperSessionHome)new InitialContext ().lookup ("bmp.BMPHelperSession"); 47 BMPHelperSession session = sessionHome.create (); 48 49 getLog().debug ("looking up table:"); 50 boolean exists = session.existsSimpleBeanTable (); 51 if (exists) 52 { 53 getLog().debug ("table exists."); 54 getLog().debug ("delete it..."); 55 session.dropSimpleBeanTable(); 56 getLog().debug ("done."); 57 } 58 59 getLog().debug ("table does not exist."); 60 getLog().debug ("create it..."); 61 session.createSimpleBeanTable(); 62 try 63 { 64 getLog().debug ("done."); 65 66 getLog().debug ("start playing with bmp beans."); 67 SimpleBMPHome home = (SimpleBMPHome)new InitialContext ().lookup ("bmp.SmallCacheBMP"); 68 SimpleBMP[] beans = new SimpleBMP[10]; 69 for (int i = 0; i < 10; ++i) 70 { 71 getLog().debug ("create bean " + i); 72 beans[i] = home.create (i, "Bean " + i); 73 getLog().debug ("getName (): "+ beans[i].getName ()); 74 } 75 76 Thread.sleep(10000); 77 78 for (int i = 0; i < 10; ++i) 79 assertEquals(beans[i].getPrimaryKey(), beans[i].getIdViaEJBObject()); 80 81 getLog().debug ("removing all beans:"); 82 Iterator it = home.findAll ().iterator (); 83 while (it.hasNext ()) 84 ((SimpleBMP)it.next ()).remove (); 85 } 86 finally 87 { 88 getLog().debug ("table exists."); 89 getLog().debug ("delete it..."); 90 session.dropSimpleBeanTable(); 91 getLog().debug ("done."); 92 } 93 } 94 95 public static Test suite() throws Exception 96 { 97 return getDeploySetup(SmallCacheBmpUnitTestCase.class, "bmp.jar"); 98 } 99 } 100 | Popular Tags |