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.connector.deployment;
017:
018: import java.io.File;
019: import java.util.Collections;
020: import java.util.Map;
021: import java.util.HashMap;
022: import java.util.Collection;
023:
024: import junit.framework.TestCase;
025: import org.apache.geronimo.common.DeploymentException;
026: import org.apache.geronimo.connector.AdminObjectWrapperGBean;
027: import org.apache.geronimo.gbean.AbstractName;
028: import org.apache.geronimo.gbean.GBeanData;
029: import org.apache.geronimo.gbean.AbstractNameQuery;
030: import org.apache.geronimo.j2ee.deployment.ConnectorModule;
031: import org.apache.geronimo.j2ee.deployment.EARContext;
032: import org.apache.geronimo.j2ee.deployment.Module;
033: import org.apache.geronimo.j2ee.deployment.NamingBuilder;
034: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
035: import org.apache.geronimo.kernel.Jsr77Naming;
036: import org.apache.geronimo.kernel.Naming;
037: import org.apache.geronimo.kernel.config.Configuration;
038: import org.apache.geronimo.kernel.config.ConfigurationData;
039: import org.apache.geronimo.kernel.config.ConfigurationManager;
040: import org.apache.geronimo.kernel.config.ConfigurationModuleType;
041: import org.apache.geronimo.kernel.config.ConfigurationResolver;
042: import org.apache.geronimo.kernel.config.ConfigurationStore;
043: import org.apache.geronimo.kernel.config.LifecycleException;
044: import org.apache.geronimo.kernel.config.LifecycleMonitor;
045: import org.apache.geronimo.kernel.config.LifecycleResults;
046: import org.apache.geronimo.kernel.config.NoSuchConfigException;
047: import org.apache.geronimo.kernel.config.NoSuchStoreException;
048: import org.apache.geronimo.kernel.mock.MockConfigurationManager;
049: import org.apache.geronimo.kernel.repository.Artifact;
050: import org.apache.geronimo.kernel.repository.ArtifactResolver;
051: import org.apache.geronimo.kernel.repository.Environment;
052: import org.apache.geronimo.kernel.repository.Version;
053: import org.apache.geronimo.kernel.repository.Repository;
054: import org.apache.geronimo.schema.SchemaConversionUtils;
055: import org.apache.xmlbeans.XmlCursor;
056: import org.apache.xmlbeans.XmlException;
057: import org.apache.xmlbeans.XmlObject;
058:
059: /**
060: * @version $Rev:390932 $ $Date: 2008-02-12 09:24:48 -0800 (Tue, 12 Feb 2008) $
061: */
062: public class MessageDestinationTest extends TestCase {
063:
064: private static final Naming naming = new Jsr77Naming();
065: Configuration configuration;
066: AbstractName baseName;
067: AdminObjectRefBuilder adminObjectRefBuilder = new AdminObjectRefBuilder(
068: null, new String[] { SchemaConversionUtils.J2EE_NAMESPACE });
069: Module module;
070:
071: Map componentContext = new HashMap();
072:
073: protected void setUp() throws Exception {
074: super .setUp();
075: Artifact id = new Artifact("test", "test", "", "car");
076: module = new ConnectorModule(false, new AbstractName(id,
077: Collections.singletonMap("name", "test")), null, null,
078: "foo", null, null, null, null);
079: ConfigurationManager configurationManager = new MockConfigurationManager();
080: EARContext earContext = new EARContext(new File("foo"), null,
081: new Environment(
082: new Artifact("foo", "bar", "1.0", "car")),
083: ConfigurationModuleType.EAR, naming,
084: configurationManager, (Collection) null, null, null,
085: null, null, null, null, null);
086: module.setEarContext(earContext);
087: module.setRootEarContext(earContext);
088: configuration = earContext.getConfiguration();
089: baseName = naming.createRootName(configuration.getId(),
090: "testRoot", NameFactory.RESOURCE_ADAPTER_MODULE);
091: }
092:
093: private static final String SPECDD1 = "<tmp xmlns=\"http://java.sun.com/xml/ns/j2ee\">"
094: + "<message-destination><message-destination-name>d1</message-destination-name></message-destination>"
095: + "<message-destination><message-destination-name>d2</message-destination-name></message-destination>"
096: + "<message-destination-ref>"
097: + " <message-destination-ref-name>n1</message-destination-ref-name>"
098: + " <message-destination-type>java.lang.Object</message-destination-type>"
099: + " <message-destination-usage>Consumes</message-destination-usage>"
100: + " <message-destination-link>d1</message-destination-link>"
101: + "</message-destination-ref>"
102: + "<message-destination-ref>"
103: + " <message-destination-ref-name>n2</message-destination-ref-name>"
104: + " <message-destination-type>java.lang.Object</message-destination-type>"
105: + " <message-destination-usage>Consumes</message-destination-usage>"
106: + " <message-destination-link>d2</message-destination-link>"
107: + "</message-destination-ref>" + "</tmp>";
108:
109: private static final String PLAN1 = "<tmp xmlns=\"http://geronimo.apache.org/xml/ns/naming-1.2\">"
110: + "<message-destination>"
111: + " <message-destination-name>d1</message-destination-name>"
112: + " <admin-object-link>l1</admin-object-link>"
113: + "</message-destination>"
114: + "<message-destination>"
115: + " <message-destination-name>d2</message-destination-name>"
116: + " <admin-object-link>l2</admin-object-link>"
117: + "</message-destination>" + "</tmp>";
118:
119: public void testMessageDestinations() throws Exception {
120: XmlObject specDD = parse(SPECDD1);
121: XmlObject plan = parse(PLAN1);
122: adminObjectRefBuilder.initContext(specDD, plan, module);
123: AbstractName n1 = naming.createChildName(baseName, "l1",
124: NameFactory.JCA_ADMIN_OBJECT);
125: AbstractName n2 = naming.createChildName(baseName, "l2",
126: NameFactory.JCA_ADMIN_OBJECT);
127: configuration.addGBean(new GBeanData(n1,
128: AdminObjectWrapperGBean.GBEAN_INFO));
129: configuration.addGBean(new GBeanData(n2,
130: AdminObjectWrapperGBean.GBEAN_INFO));
131: adminObjectRefBuilder.buildNaming(specDD, plan, module,
132: componentContext);
133: assertEquals(2, NamingBuilder.JNDI_KEY.get(componentContext)
134: .size());
135: }
136:
137: private static final String PLAN2 = "<tmp xmlns=\"http://geronimo.apache.org/xml/ns/naming-1.2\">"
138: + "<message-destination>"
139: + " <message-destination-name>d1</message-destination-name>"
140: + " <admin-object-module>testRoot</admin-object-module>"
141: + " <admin-object-link>l1</admin-object-link>"
142: + "</message-destination>"
143: + "<message-destination>"
144: + " <message-destination-name>d2</message-destination-name>"
145: + " <admin-object-module>testRoot</admin-object-module>"
146: + " <admin-object-link>l2</admin-object-link>"
147: + "</message-destination>" + "</tmp>";
148:
149: public void testMessageDestinationsWithModule() throws Exception {
150: XmlObject specDD = parse(SPECDD1);
151: XmlObject plan = parse(PLAN2);
152: adminObjectRefBuilder.initContext(specDD, plan, module);
153: AbstractName n1 = naming.createChildName(baseName, "l1",
154: NameFactory.JCA_ADMIN_OBJECT);
155: AbstractName n2 = naming.createChildName(baseName, "l2",
156: NameFactory.JCA_ADMIN_OBJECT);
157: configuration.addGBean(new GBeanData(n1,
158: AdminObjectWrapperGBean.GBEAN_INFO));
159: configuration.addGBean(new GBeanData(n2,
160: AdminObjectWrapperGBean.GBEAN_INFO));
161: adminObjectRefBuilder.buildNaming(specDD, plan, module,
162: componentContext);
163: assertEquals(2, NamingBuilder.JNDI_KEY.get(componentContext)
164: .size());
165: }
166:
167: private static final String SPECDD2 = "<tmp xmlns=\"http://java.sun.com/xml/ns/j2ee\">"
168: + "</tmp>";
169:
170: public void testMessageDestinationsMatch() throws Exception {
171: XmlObject specDD = parse(SPECDD2);
172: XmlObject plan = parse(PLAN1);
173: try {
174: adminObjectRefBuilder.initContext(specDD, plan, module);
175: fail("tried to register a GerMessageDestination witout a MessageDestination and it succeeded");
176: } catch (DeploymentException e) {
177:
178: }
179: }
180:
181: private XmlObject parse(String xmlString) throws XmlException {
182: XmlObject xmlObject = XmlObject.Factory.parse(xmlString);
183: XmlCursor xmlCursor = xmlObject.newCursor();
184: try {
185: xmlCursor.toFirstChild();
186: return xmlCursor.getObject();
187: } finally {
188: xmlCursor.dispose();
189: }
190: }
191:
192: }
|