001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.j2ee.deployment;
017:
018: import java.net.URI;
019:
020: import javax.management.ObjectName;
021: import javax.naming.Reference;
022:
023: import junit.framework.TestCase;
024: import org.apache.geronimo.common.DeploymentException;
025: import org.apache.geronimo.gbean.AbstractName;
026: import org.apache.geronimo.gbean.AbstractNameQuery;
027: import org.apache.geronimo.gbean.GBeanData;
028: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
029: import org.apache.geronimo.kernel.Jsr77Naming;
030: import org.apache.geronimo.kernel.Naming;
031: import org.apache.geronimo.kernel.config.Configuration;
032: import org.apache.geronimo.kernel.repository.Artifact;
033:
034: /**
035: * @version $Rev:385692 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
036: */
037: public class EJBRefContextTest extends TestCase {
038: private final String coffee = "some/path/coffee.jar";
039: private final String language = "some/where/language.jar";
040: private final String car = "foo/bar/car.jar";
041:
042: private AbstractName coffee_peaberry;
043: private AbstractName coffee_java;
044:
045: private AbstractName language_lisp;
046: private AbstractName language_java;
047:
048: private AbstractName car_enzo;
049:
050: private Configuration configuration;
051:
052: public void testNothing() throws Exception {
053: }
054:
055: // public void xtestSimpleRefs() throws Exception {
056: // assertReferenceEqual(coffee_peaberry, refContext.getEJBRemoteRef(null, configuration, "peaberry", null, coffee, null, null, true, null, null));
057: // assertReferenceEqual(coffee_peaberry, refContext.getEJBLocalRef(null, configuration, "peaberry", null, coffee, null, null, true, null, null));
058: // }
059: //
060: // public void xtestAmbiguousRefs() throws Exception {
061: // assertReferenceEqual(coffee_java, refContext.getEJBRemoteRef(null, configuration, "java", null, coffee, null, null, true, null, null));
062: // assertReferenceEqual(coffee_java, refContext.getEJBLocalRef(null, configuration, "java", null, coffee, null, null, true, null, null));
063: // assertReferenceEqual(language_java, refContext.getEJBRemoteRef(null, configuration, "java", null, language, null, null, true, null, null));
064: // assertReferenceEqual(language_java, refContext.getEJBLocalRef(null, configuration, "java", null, language, null, null, true, null, null));
065: //
066: // try {
067: // refContext.getEJBRemoteRef(null, configuration, "java", null, car, null, null, true, null, null);
068: // fail("should have thrown an AmbiguousEJBRefException");
069: // } catch (UnresolvedReferenceException e) {
070: // // good
071: // }
072: // try {
073: // refContext.getEJBLocalRef(null, configuration, "java", null, car, null, null, true, null, null);
074: // fail("should have thrown an AmbiguousEJBRefException");
075: // } catch (UnresolvedReferenceException e) {
076: // // good
077: // }
078: // }
079: //
080: // public void xtestRelativeRefs() throws Exception {
081: // assertReferenceEqual(car_enzo, refContext.getEJBRemoteRef(null, configuration, "enzo", "../../foo/bar/car.jar", coffee, null, null, true, null, null));
082: // assertReferenceEqual(car_enzo, refContext.getEJBLocalRef(null, configuration, "enzo", "../../foo/bar/car.jar", coffee, null, null, true, null, null));
083: // assertReferenceEqual(car_enzo, refContext.getEJBRemoteRef(null, configuration, "enzo", "./../funk/../../foo/bar/car.jar", coffee, null, null, true, null, null));
084: // assertReferenceEqual(car_enzo, refContext.getEJBLocalRef(null, configuration, "enzo", "./../funk/../../foo/bar/car.jar", coffee, null, null, true, null, null));
085: // assertReferenceEqual(coffee_java, refContext.getEJBRemoteRef(null, configuration, "java", "./coffee.jar", coffee, null, null, true, null, null));
086: // assertReferenceEqual(coffee_java, refContext.getEJBLocalRef(null, configuration, "java", "./coffee.jar", coffee, null, null, true, null, null));
087: // assertReferenceEqual(coffee_java, refContext.getEJBRemoteRef(null, configuration, "java", "coffee.jar", coffee, null, null, true, null, null));
088: // assertReferenceEqual(coffee_java, refContext.getEJBLocalRef(null, configuration, "java", "coffee.jar", coffee, null, null, true, null, null));
089: //
090: // try {
091: // refContext.getEJBRemoteRef(null, configuration, "blah", "not_exist.jar", coffee, null, null, true, null, null);
092: // fail("should have thrown an UnknownEJBRefException");
093: // } catch (UnresolvedReferenceException e) {
094: // // good
095: // }
096: //
097: // try {
098: // refContext.getEJBLocalRef(null, configuration, "blah", "not_exist.jar", coffee, null, null, true, null, null);
099: // 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 {
161: super .setUp();
162:
163: Naming naming = new Jsr77Naming();
164: AbstractName applicationName = naming.createRootName(
165: new Artifact("test", "stuff", "", "ear"), "app",
166: NameFactory.J2EE_APPLICATION);
167:
168: AbstractName coffeeName = naming.createChildName(
169: applicationName, coffee, NameFactory.EJB_MODULE);
170: coffee_peaberry = naming.createChildName(coffeeName,
171: "peaberry", NameFactory.STATELESS_SESSION_BEAN);
172: coffee_java = naming.createChildName(coffeeName, "java",
173: NameFactory.STATELESS_SESSION_BEAN);
174:
175: AbstractName languageName = naming.createChildName(
176: applicationName, language, NameFactory.EJB_MODULE);
177: language_lisp = naming.createChildName(languageName, "lisp",
178: NameFactory.STATELESS_SESSION_BEAN);
179: language_java = naming.createChildName(languageName, "java",
180: NameFactory.STATELESS_SESSION_BEAN);
181:
182: AbstractName carName = naming.createChildName(applicationName,
183: car, NameFactory.EJB_MODULE);
184: AbstractName car_gt = naming.createChildName(carName, "gt",
185: NameFactory.STATELESS_SESSION_BEAN);
186: car_enzo = naming.createChildName(carName, "enzo",
187: NameFactory.STATELESS_SESSION_BEAN);
188:
189: // configuration = null;
190: // configuration.addGBean(new GBeanData(coffee_peaberry, null));
191: // configuration.addGBean(new GBeanData(coffee_java, null));
192: //
193: // configuration.addGBean(new GBeanData(language_lisp, null));
194: // configuration.addGBean(new GBeanData(language_java, null));
195: //
196: // configuration.addGBean(new GBeanData(car_gt, null));
197: // configuration.addGBean(new GBeanData(car_enzo, null));
198: }
199:
200: // private void addEJBRemote(URI modulePath, String name, ObjectName objectName, boolean isSession, String home, String remote ) throws MalformedObjectNameException {
201: // GBeanData gBeanData = new GBeanData(objectName, null);
202: // configuration.addGBean(gBeanData);
203: // }
204: //
205: // private void addEJBLocal(URI modulePath, String name, String containerID, boolean isSession, String home, String remote ) throws MalformedObjectNameException {
206: // ObjectName objectName = new ObjectName(containerID);
207: // GBeanData gBeanData = new GBeanData(objectName, null);
208: // configuration.addGBean(gBeanData);
209: // }
210:
211: private void assertReferenceEqual(AbstractName expected,
212: Reference reference) {
213: FakeReference fakeReference = (FakeReference) reference;
214: String containerId = null;
215: if (fakeReference != null) {
216: containerId = fakeReference.containerId;
217: }
218: assertEquals(expected.toURI().toString(), containerId);
219: }
220:
221: // private void assertReferenceEqual(String expected, Reference reference) {
222: // FakeReference fakeReference = (FakeReference) reference;
223: // String containerId = null;
224: // if (fakeReference != null) {
225: // containerId = fakeReference.containerId;
226: // }
227: // assertEquals(expected, containerId);
228: // }
229:
230: private class FakeReference extends Reference {
231: private String containerId;
232:
233: public FakeReference(String containerId) {
234: super (null);
235: this .containerId = containerId;
236: }
237: }
238:
239: private static class MockActivationSpecInfoLocator implements
240: ActivationSpecInfoLocator {
241: public Reference createResourceRef(
242: AbstractNameQuery containerId, Class iface,
243: Configuration configuration) {
244: return null;
245: }
246:
247: public Reference createAdminObjectRef(
248: AbstractNameQuery containerId, Class iface,
249: Configuration configuration) {
250: return null;
251: }
252:
253: public ObjectName locateResourceName(ObjectName query) {
254: return null;
255: }
256:
257: public GBeanData locateActivationSpecInfo(
258: AbstractNameQuery nameQuery,
259: String messageListenerInterface,
260: Configuration configuration) {
261: return null;
262: }
263:
264: public GBeanData locateResourceAdapterGBeanData(
265: GBeanData resourceAdapterModuleData) {
266: return null;
267: }
268:
269: public GBeanData locateAdminObjectInfo(
270: GBeanData resourceAdapterModuleData,
271: String adminObjectInterfaceName) {
272: return null;
273: }
274:
275: public GBeanData locateConnectionFactoryInfo(
276: GBeanData resourceAdapterModuleData,
277: String connectionFactoryInterfaceName) {
278: return null;
279: }
280: }
281:
282: }
|