KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cache > test > aop > MBeanUnitTestCase


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.cache.test.aop;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26 import org.jboss.test.JBossTestCase;
27 import org.jboss.test.cache.bean.TreeCacheAopMBeanTester;
28 import org.jboss.test.cache.bean.TreeCacheAopMBeanTesterHome;
29
30 import javax.naming.Context JavaDoc;
31 import javax.naming.InitialContext JavaDoc;
32 import javax.rmi.PortableRemoteObject JavaDoc;
33 import javax.transaction.UserTransaction JavaDoc;
34 import java.util.Properties JavaDoc;
35
36 /**
37  * Tests transactional access to a local TreeCache MBean service.
38  *
39  * @version $Revision: 37406 $
40  */

41 public class MBeanUnitTestCase extends JBossTestCase
42 {
43    TreeCacheAopMBeanTesterHome cache_home;
44    TreeCacheAopMBeanTester cache1 = null, cache2 = null;
45    Properties JavaDoc p_ = new Properties JavaDoc();
46
47
48    public MBeanUnitTestCase(String JavaDoc name)
49    {
50       super(name);
51    }
52
53    public void setUp() throws Exception JavaDoc
54    {
55       super.setUp();
56         mySetup();
57    }
58
59    public void tearDown() throws Exception JavaDoc
60    {
61       if (cache2 != null)
62          cache2.remove(); // calls stop()
63
if (cache1 != null)
64          cache1.remove();
65    }
66
67    public void mySetup() throws Exception JavaDoc
68    {
69       Object JavaDoc obj;
70
71       p_.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
72       p_.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
73       p_.put(Context.PROVIDER_URL, "localhost:1099");
74       obj = new InitialContext JavaDoc(p_).lookup(TreeCacheAopMBeanTesterHome.JNDI_NAME);
75       cache_home = (TreeCacheAopMBeanTesterHome) PortableRemoteObject.narrow(obj, TreeCacheAopMBeanTesterHome.class);
76    }
77
78
79    public void testSetup()
80    {
81       assertNotNull("TreeCacheAopTesterHome ", cache_home);
82    }
83
84    public void testPutObjectTx()
85    {
86       UserTransaction JavaDoc tx = null;
87
88       try {
89          tx = (UserTransaction JavaDoc) new InitialContext JavaDoc(p_).lookup("UserTransaction");
90          assertNotNull("UserTransaction should not be null ", tx);
91          // Note that to set tree cache properties, you can do it here
92
// or go to transient-cache-service.xml.
93
cache1 = cache_home.create();
94
95 // tx.begin();
96
log("Create person ...");
97          cache1.createPerson("/aop/person", "Benito", 38);
98 // tx.commit();
99

100 // tx.begin();
101
log("check equalityu ...");
102          assertEquals(38, cache1.getAge("/aop/person"));
103 // tx.commit();
104

105       } catch (Throwable JavaDoc t) {
106          fail(t.toString());
107          try {
108             tx.rollback();
109          } catch (Throwable JavaDoc t2) {
110             ;
111          }
112          fail(t.toString());
113       }
114    }
115
116
117    void _sleep(long timeout)
118    {
119       try {
120          Thread.sleep(timeout);
121       } catch (InterruptedException JavaDoc e) {
122       }
123    }
124
125    void log(String JavaDoc msg)
126    {
127       getLog().info("-- [" + Thread.currentThread() + "]: " + msg);
128    }
129
130
131    public static Test suite() throws Exception JavaDoc
132    {
133 // return getDeploySetup(MBeanUnitTestCase.class, "cachetest.sar");
134
// Deploy the package recursively. The jar contains ejb and the sar file contains
135
// tree cache MBean service
136
return getDeploySetup(getDeploySetup(MBeanUnitTestCase.class, "cachetest.jar"),
137             "cacheAoptest.sar");
138 // return new TestSuite(MBeanUnitTestCase.class);
139
}
140
141    public static void main(String JavaDoc[] args) throws Exception JavaDoc
142    {
143       junit.textui.TestRunner.run(suite());
144    }
145
146
147 }
148
Popular Tags