KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > NotificationTestCaseSetup


1 package org.jacorb.test.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2003 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import java.util.Properties JavaDoc;
25
26 import junit.extensions.TestSetup;
27 import junit.framework.Test;
28
29 import org.apache.avalon.framework.configuration.Configuration;
30 import org.jacorb.notification.AbstractChannelFactory;
31 import org.jacorb.notification.container.PicoContainerFactory;
32 import org.omg.CORBA.ORB JavaDoc;
33 import org.omg.PortableServer.POA JavaDoc;
34 import org.omg.PortableServer.POAHelper JavaDoc;
35 import org.picocontainer.MutablePicoContainer;
36
37 /**
38  * @author Alphonse Bendt
39  */

40
41 public class NotificationTestCaseSetup extends TestSetup
42 {
43     private MutablePicoContainer container_;
44
45     private Thread JavaDoc orbThread_;
46
47     private NotificationTestUtils testUtils_;
48
49     private AbstractChannelFactory eventChannelFactory_;
50
51     private ORB JavaDoc clientORB_;
52
53     private ORB JavaDoc orb_;
54
55     // //////////////////////////////////////
56

57     public NotificationTestCaseSetup(Test suite) throws Exception JavaDoc
58     {
59         super(suite);
60     }
61
62     // //////////////////////////////////////
63

64     public NotificationTestUtils getTestUtils()
65     {
66         return testUtils_;
67     }
68
69     public void setUp() throws Exception JavaDoc
70     {
71         super.setUp();
72
73         orb_ = ORB.init(new String JavaDoc[0], null);
74         POAHelper.narrow(orb_.resolve_initial_references("RootPOA")).the_POAManager().activate();
75
76         container_ = PicoContainerFactory.createRootContainer((org.jacorb.orb.ORB) orb_);
77
78         testUtils_ = new NotificationTestUtils(getORB());
79
80         orbThread_ = new Thread JavaDoc(new Runnable JavaDoc()
81         {
82             public void run()
83             {
84                 getORB().run();
85             }
86         });
87
88         orbThread_.setDaemon(true);
89
90         orbThread_.start();
91
92         clientORB_ = ORB.init(new String JavaDoc[] {}, null);
93         POAHelper.narrow(clientORB_.resolve_initial_references("RootPOA")).the_POAManager()
94                 .activate();
95
96         Thread JavaDoc clientOrbThread = new Thread JavaDoc(new Runnable JavaDoc()
97         {
98             public void run()
99             {
100                 getClientORB().run();
101             }
102         }, "JUnit-Client-ORB-Runner");
103
104         clientOrbThread.setDaemon(true);
105
106         clientOrbThread.start();
107     }
108
109     public void tearDown() throws Exception JavaDoc
110     {
111         if (eventChannelFactory_ != null)
112         {
113             eventChannelFactory_.dispose();
114         }
115
116         container_.dispose();
117
118         orb_.shutdown(true);
119
120         clientORB_.shutdown(true);
121
122         super.tearDown();
123     }
124
125     public ORB JavaDoc getClientORB()
126     {
127         return clientORB_;
128     }
129
130     public AbstractChannelFactory getFactoryServant() throws Exception JavaDoc
131     {
132         if (eventChannelFactory_ == null)
133         {
134             eventChannelFactory_ = AbstractChannelFactory.newFactory(new Properties JavaDoc());
135         }
136
137         return eventChannelFactory_;
138     }
139
140     public ORB JavaDoc getORB()
141     {
142         return (ORB JavaDoc) container_.getComponentInstanceOfType(ORB JavaDoc.class);
143     }
144
145     public POA JavaDoc getPOA()
146     {
147         return (POA JavaDoc) container_.getComponentInstanceOfType(POA JavaDoc.class);
148     }
149
150     public MutablePicoContainer getPicoContainer()
151     {
152         return container_;
153     }
154
155     public Configuration getConfiguration()
156     {
157         return (Configuration) container_.getComponentInstanceOfType(Configuration.class);
158     }
159 }
Popular Tags