KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > bmp > test > SmallCacheBmpUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.bmp.test;
23
24 import java.util.Iterator JavaDoc;
25
26 import javax.naming.InitialContext JavaDoc;
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 JavaDoc name)
40     {
41         super(name);
42     }
43
44     public void testBMP() throws Exception JavaDoc
45    {
46       BMPHelperSessionHome sessionHome = (BMPHelperSessionHome)new InitialContext JavaDoc ().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 JavaDoc ().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 JavaDoc 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 JavaDoc
96    {
97       return getDeploySetup(SmallCacheBmpUnitTestCase.class, "bmp.jar");
98    }
99 }
100
Popular Tags