KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > passivation > test > EntityPassivationUnitTestCase


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.cmp2.passivation.test;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import javax.rmi.PortableRemoteObject JavaDoc;
29
30 import junit.framework.Test;
31
32 import org.jboss.test.JBossTestCase;
33 import org.jboss.test.cmp2.passivation.interfaces.RapidlyPassivatedEntity;
34 import org.jboss.test.cmp2.passivation.interfaces.RapidlyPassivatedEntityHome;
35
36 /**
37  * Tests the integrity of entity beans after they have been through
38  * a passivate/activate cycle.
39  *
40  * It has been designed to expose the bug described at
41  * <a HREF="https://sourceforge.net/tracker/?group_id=22866&atid=376685&func=detail&aid=742197">
42  * Detail:769139 entityCtx.getEJBLocalObject() returns wrong instance</a>
43  * and
44  * <a HREF="https://sourceforge.net/tracker/?func=detail&atid=376685&aid=769139&group_id=22866">
45  * Detail:742197 getEJBLocalObject() bug</a>
46  *
47  */

48 public class EntityPassivationUnitTestCase extends JBossTestCase
49 {
50
51    // Constants -----------------------------------------------------
52
static final int ENTITY_PASSIVATION_TIMEOUT = 15 * 1000;
53    
54    // Attributes ----------------------------------------------------
55
List JavaDoc mEntities = new ArrayList JavaDoc(getBeanCount());
56
57    // Static --------------------------------------------------------
58

59    public static Test suite()
60       throws Exception JavaDoc
61    {
62       return getDeploySetup(EntityPassivationUnitTestCase.class, "cmp2-passivation.jar");
63    }
64
65    // Constructors --------------------------------------------------
66

67    public EntityPassivationUnitTestCase(String JavaDoc name)
68    {
69       super(name);
70    }
71
72
73    // Public --------------------------------------------------------
74

75    /**
76     * Wait for the entities to be passivated and then check their
77     * context's idea of which entity is actually referenced.
78     * via its local object reference.
79     * @throws Exception
80     */

81    public void testPostPassivationLocalEJBIntegrity()
82       throws Exception JavaDoc
83    {
84       log.info("Waiting for entities to passivate");
85       Thread.sleep(ENTITY_PASSIVATION_TIMEOUT);
86       for (Iterator JavaDoc i = mEntities.iterator(); i.hasNext();)
87       {
88          RapidlyPassivatedEntity e = (RapidlyPassivatedEntity)i.next();
89          assertEquals(e.getIdViaEJBLocalObject(), e.getPrimaryKey());
90       }
91    }
92    
93
94    /**
95     * Wait for the entities to be passivated and then check their
96     * context's idea of which entity is actually referenced
97     * via its remote object reference.
98     *
99     * This probably should be run against a collection of
100     * local interfaces in a session bean, rather than
101     * here.
102     *
103     * TODO Place this test in SLSB with a collection of local interfaces.
104     * @throws Exception
105     */

106    public void testPostPassivationRemoteEJBIntegrity()
107       throws Exception JavaDoc
108    {
109       log.info("Waiting for entities to passivate");
110       Thread.sleep(ENTITY_PASSIVATION_TIMEOUT);
111       for (Iterator JavaDoc i = mEntities.iterator(); i.hasNext();)
112       {
113          RapidlyPassivatedEntity e = (RapidlyPassivatedEntity)i.next();
114          assertEquals(e.getIdViaEJBObject(), e.getPrimaryKey());
115       }
116    }
117    
118
119    // Protected --------------------------------------------------------
120

121    /**
122     * Create some entities to test against.
123     * @see junit.framework.TestCase#setUp()
124     */

125    protected void setUp() throws Exception JavaDoc
126    {
127       super.setUp();
128       Object JavaDoc homeObject =
129          getInitialContext().lookup(RapidlyPassivatedEntityHome.JNDI_NAME);
130       RapidlyPassivatedEntityHome home =
131          (RapidlyPassivatedEntityHome) PortableRemoteObject.narrow(
132             homeObject,
133             RapidlyPassivatedEntityHome.class);
134
135       for (int i = 0, n = getBeanCount(); i < n; ++i)
136          mEntities.add(home.create("nothing to see here"));
137
138    }
139 }
140
Popular Tags