KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > j2ee > deployment > EJBRefContextTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.j2ee.deployment;
18
19 import java.net.URI JavaDoc;
20
21 import javax.management.ObjectName JavaDoc;
22 import javax.naming.Reference JavaDoc;
23
24 import junit.framework.TestCase;
25 import org.apache.geronimo.common.DeploymentException;
26 import org.apache.geronimo.gbean.AbstractName;
27 import org.apache.geronimo.gbean.AbstractNameQuery;
28 import org.apache.geronimo.gbean.GBeanData;
29 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
30 import org.apache.geronimo.kernel.Jsr77Naming;
31 import org.apache.geronimo.kernel.Naming;
32 import org.apache.geronimo.kernel.config.Configuration;
33 import org.apache.geronimo.kernel.repository.Artifact;
34
35 /**
36  * @version $Rev:385692 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
37  */

38 public class EJBRefContextTest extends TestCase {
39     private final String JavaDoc coffee = "some/path/coffee.jar";
40     private final String JavaDoc language = "some/where/language.jar";
41     private final String JavaDoc car = "foo/bar/car.jar";
42
43     private AbstractName coffee_peaberry;
44     private AbstractName coffee_java;
45
46     private AbstractName language_lisp;
47     private AbstractName language_java;
48
49     private AbstractName car_enzo;
50
51     private Configuration configuration;
52
53     public void testNothing() throws Exception JavaDoc {}
54
55 // public void xtestSimpleRefs() throws Exception {
56
// assertReferenceEqual(coffee_peaberry, refContext.getEJBRemoteRef(null, configuration, "peaberry", null, coffee, null, null, true, null, null));
57
// assertReferenceEqual(coffee_peaberry, refContext.getEJBLocalRef(null, configuration, "peaberry", null, coffee, null, null, true, null, null));
58
// }
59
//
60
// public void xtestAmbiguousRefs() throws Exception {
61
// assertReferenceEqual(coffee_java, refContext.getEJBRemoteRef(null, configuration, "java", null, coffee, null, null, true, null, null));
62
// assertReferenceEqual(coffee_java, refContext.getEJBLocalRef(null, configuration, "java", null, coffee, null, null, true, null, null));
63
// assertReferenceEqual(language_java, refContext.getEJBRemoteRef(null, configuration, "java", null, language, null, null, true, null, null));
64
// assertReferenceEqual(language_java, refContext.getEJBLocalRef(null, configuration, "java", null, language, null, null, true, null, null));
65
//
66
// try {
67
// refContext.getEJBRemoteRef(null, configuration, "java", null, car, null, null, true, null, null);
68
// fail("should have thrown an AmbiguousEJBRefException");
69
// } catch (UnresolvedReferenceException e) {
70
// // good
71
// }
72
// try {
73
// refContext.getEJBLocalRef(null, configuration, "java", null, car, null, null, true, null, null);
74
// fail("should have thrown an AmbiguousEJBRefException");
75
// } catch (UnresolvedReferenceException e) {
76
// // good
77
// }
78
// }
79
//
80
// public void xtestRelativeRefs() throws Exception {
81
// assertReferenceEqual(car_enzo, refContext.getEJBRemoteRef(null, configuration, "enzo", "../../foo/bar/car.jar", coffee, null, null, true, null, null));
82
// assertReferenceEqual(car_enzo, refContext.getEJBLocalRef(null, configuration, "enzo", "../../foo/bar/car.jar", coffee, null, null, true, null, null));
83
// assertReferenceEqual(car_enzo, refContext.getEJBRemoteRef(null, configuration, "enzo", "./../funk/../../foo/bar/car.jar", coffee, null, null, true, null, null));
84
// assertReferenceEqual(car_enzo, refContext.getEJBLocalRef(null, configuration, "enzo", "./../funk/../../foo/bar/car.jar", coffee, null, null, true, null, null));
85
// assertReferenceEqual(coffee_java, refContext.getEJBRemoteRef(null, configuration, "java", "./coffee.jar", coffee, null, null, true, null, null));
86
// assertReferenceEqual(coffee_java, refContext.getEJBLocalRef(null, configuration, "java", "./coffee.jar", coffee, null, null, true, null, null));
87
// assertReferenceEqual(coffee_java, refContext.getEJBRemoteRef(null, configuration, "java", "coffee.jar", coffee, null, null, true, null, null));
88
// assertReferenceEqual(coffee_java, refContext.getEJBLocalRef(null, configuration, "java", "coffee.jar", coffee, null, null, true, null, null));
89
//
90
// try {
91
// refContext.getEJBRemoteRef(null, configuration, "blah", "not_exist.jar", coffee, null, null, true, null, null);
92
// fail("should have thrown an UnknownEJBRefException");
93
// } catch (UnresolvedReferenceException e) {
94
// // good
95
// }
96
//
97
// try {
98
// refContext.getEJBLocalRef(null, configuration, "blah", "not_exist.jar", coffee, null, null, true, null, null);
99
// fail("should have thrown an UnknownEJBRefException");
100
// } catch (UnresolvedReferenceException e) {
101
// // good
102
// }
103
//
104
// try {
105
// refContext.getEJBRemoteRef(null, configuration, "blah", "coffee.jar", coffee, null, null, true, null, null);
106
// fail("should have thrown an UnknownEJBRefException");
107
// } catch (UnresolvedReferenceException e) {
108
// // good
109
// }
110
//
111
// try {
112
// refContext.getEJBLocalRef(null, configuration, "blah", "coffee.jar", coffee, null, null, true, null, null);
113
// fail("should have thrown an UnknownEJBRefException");
114
// } catch (UnresolvedReferenceException e) {
115
// // good
116
// }
117
//
118
// try {
119
// refContext.getEJBRemoteRef(null, configuration, "enzo", "../../../../foo/bar/car.jar",coffee, null, null, true, null, null);
120
// fail("should have thrown an UnknownEJBRefException");
121
// } catch (UnresolvedReferenceException e) {
122
// // good
123
// }
124
// try {
125
// refContext.getEJBLocalRef(null, configuration, "enzo", "../../../../foo/bar/car.jar",coffee, null, null, true, null, null);
126
// fail("should have thrown an UnknownEJBRefException");
127
// } catch (UnresolvedReferenceException e) {
128
// // good
129
// }
130
// }
131
//
132
// public void xtestBasicImplicitRefs() throws Exception {
133
// assertReferenceEqual(language_lisp, refContext.getEJBRemoteRef(null, configuration, "blah", null, coffee, null, null, true, "LispHome", "LispRemote"));
134
// assertReferenceEqual(language_lisp, refContext.getEJBLocalRef(null, configuration, "blah", null, coffee, null, null, true, "LispLocalHome", "LispLocal"));
135
// }
136
//
137
// public void xtestInModuleImplicitRefs() throws Exception {
138
// assertReferenceEqual(coffee_java, refContext.getEJBLocalRef(null, configuration, "blah", null, coffee, null, null, true, "LocalHome", "Local"));
139
// assertReferenceEqual(car_enzo, refContext.getEJBLocalRef(null, configuration, "blah", null, car, null, null, true, "LocalHome", "Local"));
140
// }
141
//
142
// public void xtestAmbiguousModuleImplicitRefs() throws Exception {
143
// try {
144
// refContext.getEJBLocalRef(null, configuration, "blah", null, language, null, null, true, "LocalHome", "Local");
145
// fail("should have thrown an UnresolvedEJBRefException");
146
// } catch (UnresolvedEJBRefException e) {
147
// // good
148
// }
149
// }
150
//
151
// public void xtestNoMatchImplicitRefs() throws Exception {
152
// try {
153
// refContext.getEJBLocalRef(null, configuration, "blah", null, language, null, null, true, "foo", "bar");
154
// fail("should have thrown an UnresolvedEJBRefException");
155
// } catch (UnresolvedEJBRefException e) {
156
// // good
157
// }
158
// }
159
//
160
protected void setUp() throws Exception JavaDoc {
161         super.setUp();
162
163         Naming naming = new Jsr77Naming();
164         AbstractName applicationName = naming.createRootName(new Artifact("test", "stuff", "", "ear"), "app", NameFactory.J2EE_APPLICATION) ;
165
166
167         AbstractName coffeeName = naming.createChildName(applicationName, coffee, NameFactory.EJB_MODULE);
168         coffee_peaberry = naming.createChildName(coffeeName, "peaberry", NameFactory.STATELESS_SESSION_BEAN);
169         coffee_java = naming.createChildName(coffeeName, "java", NameFactory.STATELESS_SESSION_BEAN);
170
171         AbstractName languageName = naming.createChildName(applicationName, language, NameFactory.EJB_MODULE);
172         language_lisp = naming.createChildName(languageName, "lisp", NameFactory.STATELESS_SESSION_BEAN);
173         language_java = naming.createChildName(languageName, "java", NameFactory.STATELESS_SESSION_BEAN);
174
175         AbstractName carName = naming.createChildName(applicationName, car, NameFactory.EJB_MODULE);
176         AbstractName car_gt = naming.createChildName(carName, "gt", NameFactory.STATELESS_SESSION_BEAN);
177         car_enzo = naming.createChildName(carName, "enzo", NameFactory.STATELESS_SESSION_BEAN);
178
179 // configuration = null;
180
// configuration.addGBean(new GBeanData(coffee_peaberry, null));
181
// configuration.addGBean(new GBeanData(coffee_java, null));
182
//
183
// configuration.addGBean(new GBeanData(language_lisp, null));
184
// configuration.addGBean(new GBeanData(language_java, null));
185
//
186
// configuration.addGBean(new GBeanData(car_gt, null));
187
// configuration.addGBean(new GBeanData(car_enzo, null));
188
}
189
190 // private void addEJBRemote(URI modulePath, String name, ObjectName objectName, boolean isSession, String home, String remote ) throws MalformedObjectNameException {
191
// GBeanData gBeanData = new GBeanData(objectName, null);
192
// configuration.addGBean(gBeanData);
193
// }
194
//
195
// private void addEJBLocal(URI modulePath, String name, String containerID, boolean isSession, String home, String remote ) throws MalformedObjectNameException {
196
// ObjectName objectName = new ObjectName(containerID);
197
// GBeanData gBeanData = new GBeanData(objectName, null);
198
// configuration.addGBean(gBeanData);
199
// }
200

201     private void assertReferenceEqual(AbstractName expected, Reference JavaDoc reference) {
202         FakeReference fakeReference = (FakeReference) reference;
203         String JavaDoc containerId = null;
204         if (fakeReference != null) {
205             containerId = fakeReference.containerId;
206         }
207         assertEquals(expected.toURI().toString(), containerId);
208     }
209 // private void assertReferenceEqual(String expected, Reference reference) {
210
// FakeReference fakeReference = (FakeReference) reference;
211
// String containerId = null;
212
// if (fakeReference != null) {
213
// containerId = fakeReference.containerId;
214
// }
215
// assertEquals(expected, containerId);
216
// }
217

218     private class FakeReference extends Reference JavaDoc {
219         private String JavaDoc containerId;
220
221         public FakeReference(String JavaDoc containerId) {
222             super(null);
223             this.containerId = containerId;
224         }
225     }
226
227     private static class MockActivationSpecInfoLocator implements ActivationSpecInfoLocator {
228         public Reference JavaDoc createResourceRef(AbstractNameQuery containerId, Class JavaDoc iface, Configuration configuration) {
229             return null;
230         }
231
232         public Reference JavaDoc createAdminObjectRef(AbstractNameQuery containerId, Class JavaDoc iface, Configuration configuration) {
233             return null;
234         }
235
236         public ObjectName JavaDoc locateResourceName(ObjectName JavaDoc query) {
237             return null;
238         }
239
240         public GBeanData locateActivationSpecInfo(AbstractNameQuery nameQuery, String JavaDoc messageListenerInterface, Configuration configuration) {
241             return null;
242         }
243
244         public GBeanData locateResourceAdapterGBeanData(GBeanData resourceAdapterModuleData) {
245             return null;
246         }
247
248         public GBeanData locateAdminObjectInfo(GBeanData resourceAdapterModuleData, String JavaDoc adminObjectInterfaceName) {
249             return null;
250         }
251
252         public GBeanData locateConnectionFactoryInfo(GBeanData resourceAdapterModuleData, String JavaDoc connectionFactoryInterfaceName) {
253             return null;
254         }
255     }
256
257 }
258
Popular Tags