KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > cmrtransaction > test > CMRTransactionUnitTestCase


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.cmrtransaction.test;
23
24 import javax.naming.InitialContext JavaDoc;
25 import javax.rmi.PortableRemoteObject JavaDoc;
26
27 import junit.framework.Test;
28 import org.jboss.test.JBossTestCase;
29 import org.jboss.test.cmp2.cmrtransaction.interfaces.TreeFacadeHome;
30 import org.jboss.test.cmp2.cmrtransaction.interfaces.TreeFacade;
31
32 /**
33  * @author B Stansberry brian_stansberry@wanconcepts.com
34  */

35 public class CMRTransactionUnitTestCase extends JBossTestCase
36 {
37     // ------------------------------------------------------------- Constants
38

39     // ------------------------------------------------------- Instance Fields
40

41     // ---------------------------------------------------------- Constructors
42

43     public CMRTransactionUnitTestCase(String JavaDoc name)
44     {
45         super(name);
46     }
47
48     // -------------------------------------------------------- Public Methods
49

50     public void testCMRTransaction() throws Exception JavaDoc
51     {
52
53         InitialContext JavaDoc ctx = getInitialContext();
54         Object JavaDoc obj = ctx.lookup("cmrTransactionTest/TreeFacadeRemote");
55         TreeFacadeHome home = (TreeFacadeHome)
56                 PortableRemoteObject.narrow(obj, TreeFacadeHome.class);
57         TreeFacade facade = home.create();
58         facade.setup();
59         facade.createNodes();
60
61         int waitTime = 0;
62
63         CMRTransactionThread rearrange = new CMRTransactionThread(facade);
64         rearrange.start();
65         rearrange.join();
66
67         if (rearrange.exception != null)
68         {
69             fail(rearrange.exception.getMessage());
70         }
71
72         assertTrue(rearrange.finished);
73     }
74
75     // -------------------------------------------------------- Static Methods
76

77     public static Test suite() throws Exception JavaDoc
78     {
79         return getDeploySetup(CMRTransactionUnitTestCase.class, "cmp2-cmrtransaction.jar");
80     }
81
82     // --------------------------------------------------------- Inner Classes
83

84     class CMRTransactionThread extends Thread JavaDoc
85     {
86         boolean finished = false;
87         Exception JavaDoc exception = null;
88         TreeFacade treeFacade = null;
89
90         CMRTransactionThread(TreeFacade facade)
91         {
92             treeFacade = facade;
93         }
94
95         public void run()
96         {
97             try
98             {
99                 treeFacade.rearrangeNodes();
100             }
101             catch (Exception JavaDoc e)
102             {
103                 exception = e;
104             }
105             finally
106             {
107                 finished = true;
108             }
109         }
110     }
111
112 }
113
Popular Tags