KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > entity > test > UnsetEntityContextUnitTestCase


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.entity.test;
23
24 import junit.framework.Test;
25
26 import org.jboss.test.JBossTestCase;
27 import org.jboss.test.entity.interfaces.UnsetEntityContext;
28 import org.jboss.test.entity.interfaces.UnsetEntityContextHome;
29
30 /**
31  * Test that unsetEntityContext is called.
32  *
33  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
34  * @version $Revision: 38303 $
35  */

36 public class UnsetEntityContextUnitTestCase extends JBossTestCase
37 {
38    public UnsetEntityContextUnitTestCase(String JavaDoc name)
39    {
40       super(name);
41    }
42
43    public static Test suite()
44       throws Exception JavaDoc
45    {
46       return getDeploySetup(UnsetEntityContextUnitTestCase.class, "jboss-test-unsetentitycontext.jar");
47    }
48    
49    /**
50     * In this test, pooling is disabled (MaximumSize==0) so every business
51     * call to the home interface should create a new instance, use it
52     * but then throw it away rather than put it back in the pool.
53     * At this point we check whether unsetEntityContext() gets called.
54     * @throws Exception
55     */

56    public void testUnsetEntityContextCalled() throws Exception JavaDoc
57    {
58       UnsetEntityContextHome home = (UnsetEntityContextHome)super.getInitialContext().lookup("UnsetEntityContext");
59       
60       // after this call the counter should be 1
61
home.clearUnsetEntityContextCallCounter();
62       
63       // after this call the counter should be 2
64
assertEquals("UnsetEntityContextCallCount", 1, home.getUnsetEntityContextCallCounter());
65       
66       // after this call the counter should be 3
67
assertEquals("UnsetEntityContextCallCount", 2, home.getUnsetEntityContextCallCounter());
68       
69       // after this call the counter should be 4
70
assertEquals("UnsetEntityContextCallCount", 3, home.getUnsetEntityContextCallCounter());
71    }
72
73    /**
74     * A test to see what happens when remove() is called on an
75     * entity bean instance. I would expect it is returned to the
76     * pool, and as a result thrown away (since pooling is disabled
77     * for this test), but it seems not?
78     * @throws Exception
79     */

80    public void testBeanReturnedToPool() throws Exception JavaDoc
81    {
82       UnsetEntityContextHome home = (UnsetEntityContextHome)super.getInitialContext().lookup("UnsetEntityContext");
83       
84       // after this call the counter should be 1
85
home.clearUnsetEntityContextCallCounter();
86       
87       // after this call the counter should be 2
88
assertEquals("UnsetEntityContextCallCount", 1, home.getUnsetEntityContextCallCounter());
89       
90       UnsetEntityContext bean = home.create("TestBean");
91       // after this call the counter should be 3 (the bean should be returned to the pool?)
92
bean.remove();
93       
94       // after this call the counter should be 4
95
// TODO - this assertion fails!
96
// assertEquals("UnsetEntityContextCallCount", 3, home.getUnsetEntityContextCallCounter());
97
}
98 }
99
Popular Tags