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.util.Collection;
019: import java.util.Collections;
020: import java.util.Map;
021: import java.util.Set;
022: import java.util.HashSet;
023: import java.util.jar.JarFile;
024:
025: import org.apache.geronimo.common.DeploymentException;
026: import org.apache.geronimo.deployment.DeploymentContext;
027: import org.apache.geronimo.deployment.ModuleIDBuilder;
028: import org.apache.geronimo.deployment.NamespaceDrivenBuilder;
029: import org.apache.geronimo.deployment.util.DeploymentUtil;
030: import org.apache.geronimo.gbean.AbstractName;
031: import org.apache.geronimo.gbean.AbstractNameQuery;
032: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
033: import org.apache.geronimo.j2ee.management.impl.J2EEServerImpl;
034: import org.apache.geronimo.kernel.Jsr77Naming;
035: import org.apache.geronimo.kernel.Naming;
036: import org.apache.geronimo.kernel.config.ConfigurationData;
037: import org.apache.geronimo.kernel.mock.MockConfigStore;
038: import org.apache.geronimo.kernel.mock.MockRepository;
039: import org.apache.geronimo.kernel.repository.Artifact;
040: import org.apache.geronimo.kernel.repository.ArtifactManager;
041: import org.apache.geronimo.kernel.repository.ArtifactResolver;
042: import org.apache.geronimo.kernel.repository.DefaultArtifactManager;
043: import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
044: import org.apache.geronimo.kernel.repository.Environment;
045: import org.apache.geronimo.kernel.repository.ImportType;
046: import org.apache.geronimo.kernel.repository.ListableRepository;
047: import org.apache.geronimo.testsupport.TestSupport;
048:
049: /**
050: * Provides support for EAR config builder tests.
051: *
052: * @version $Rev:386276 $ $Date: 2007-08-16 17:52:52 -0700 (Thu, 16 Aug 2007) $
053: */
054: public abstract class EARConfigBuilderTestSupport extends TestSupport {
055: protected static String WEB_NAMESPACE = "foo";
056:
057: protected static JarFile earFile;
058:
059: protected static MockConfigStore configStore = new MockConfigStore();
060:
061: protected static ArtifactManager artifactManager = new DefaultArtifactManager();
062:
063: protected static MockEJBConfigBuilder ejbConfigBuilder = new MockEJBConfigBuilder();
064:
065: protected static MockWARConfigBuilder webConfigBuilder = new MockWARConfigBuilder();
066:
067: protected static MockConnectorConfigBuilder connectorConfigBuilder = new MockConnectorConfigBuilder();
068:
069: protected static ActivationSpecInfoLocator activationSpecInfoLocator = connectorConfigBuilder;
070:
071: protected static ModuleBuilder appClientConfigBuilder = null;
072:
073: protected final static ModuleIDBuilder idBuilder = new ModuleIDBuilder();
074:
075: protected static final NamespaceDrivenBuilder securityBuilder = null;
076:
077: protected static final NamespaceDrivenBuilder serviceBuilder = null;
078:
079: protected static final ModuleBuilderExtension persistenceUnitBuilder = null;
080:
081: protected static final Naming naming = new Jsr77Naming();
082:
083: protected static final AbstractName rootConfig = naming
084: .createRootName(new Artifact("test", "stuff", "", "car"),
085: "test", "test");
086:
087: protected static final AbstractName transactionManagerObjectName = naming
088: .createChildName(rootConfig, "TransactionManager",
089: "TransactionManager");
090:
091: protected static final AbstractName connectionTrackerObjectName = naming
092: .createChildName(rootConfig, "ConnectionTracker",
093: "ConnectionTracker");
094:
095: protected static final AbstractName transactionalTimerObjectName = naming
096: .createChildName(rootConfig,
097: "TransactionalThreaPooledTimer",
098: "ThreadPooledTimer");
099:
100: protected static final AbstractName nonTransactionalTimerObjectName = naming
101: .createChildName(rootConfig,
102: "NonTransactionalThreaPooledTimer",
103: "ThreadPooledTimer");
104:
105: protected static final AbstractName serverName = naming
106: .createChildName(rootConfig, "J2EEServer", "Server");
107:
108: protected static final AbstractName earName = naming
109: .createRootName(new Artifact(
110: "org.apache.geronimo.test.test-ear", "ear", "",
111: "ear"), "test", NameFactory.J2EE_APPLICATION);
112:
113: protected static final AbstractName ejbModuleName = naming
114: .createChildName(earName, "ejb-jar", NameFactory.EJB_MODULE);
115:
116: protected static final AbstractName webModuleName = naming
117: .createChildName(earName, "war", NameFactory.WEB_MODULE);
118:
119: protected static final AbstractName raModuleName = naming
120: .createChildName(earName, "rar",
121: NameFactory.RESOURCE_ADAPTER_MODULE);
122:
123: protected Environment defaultParentId;
124:
125: protected static String contextRoot = "test";
126:
127: protected static final Map portMap = null;
128:
129: protected final AbstractNameQuery transactionManagerAbstractNameQuery = new AbstractNameQuery(
130: transactionManagerObjectName, null);
131:
132: protected final AbstractNameQuery connectionTrackerAbstractNameQuery = new AbstractNameQuery(
133: connectionTrackerObjectName, null);
134:
135: protected final AbstractNameQuery transactionalTimerAbstractNameQuery = new AbstractNameQuery(
136: transactionalTimerObjectName, null);
137:
138: protected final AbstractNameQuery nonTransactionalTimerAbstractNameQuery = new AbstractNameQuery(
139: nonTransactionalTimerObjectName, null);
140:
141: protected final AbstractNameQuery corbaGBeanAbstractNameQuery = new AbstractNameQuery(
142: serverName, null);
143:
144: private ListableRepository repository;
145: protected ArtifactResolver artifactResolver = new DefaultArtifactResolver(
146: artifactManager, Collections.singleton(repository), null);
147: protected Collection<? extends ArtifactResolver> artifactResolvers = Collections
148: .singleton(new DefaultArtifactResolver(artifactManager,
149: repository));
150:
151: protected void setUp() throws Exception {
152: super .setUp();
153: Set<Artifact> repo = new HashSet<Artifact>();
154: repo.add(Artifact
155: .create("org.apache.geronimo.tests/test/1/car"));
156: repository = new MockRepository(repo);
157: defaultParentId = new Environment();
158: defaultParentId.addDependency(new Artifact(
159: "org.apache.geronimo.tests", "test", "1", "car"),
160: ImportType.ALL);
161: }
162:
163: public void testBuildConfiguration() throws Exception {
164: ConfigurationData configurationData = null;
165: DeploymentContext context = null;
166: try {
167: EARConfigBuilder configBuilder = new EARConfigBuilder(
168: defaultParentId,
169: transactionManagerAbstractNameQuery,
170: connectionTrackerAbstractNameQuery,
171: transactionalTimerAbstractNameQuery,
172: nonTransactionalTimerAbstractNameQuery,
173: corbaGBeanAbstractNameQuery, null, Collections
174: .singleton(repository), ejbConfigBuilder,
175: webConfigBuilder, connectorConfigBuilder,
176: activationSpecInfoLocator, appClientConfigBuilder,
177: securityBuilder, serviceBuilder,
178: persistenceUnitBuilder, naming, artifactResolvers);
179:
180: Object plan = configBuilder.getDeploymentPlan(null,
181: earFile, idBuilder);
182: context = configBuilder.buildConfiguration(false,
183: configBuilder.getConfigurationID(plan, earFile,
184: idBuilder), plan, earFile, Collections
185: .singleton(configStore), artifactResolver,
186: configStore);
187: configurationData = getConfigurationData(context);
188: } finally {
189: if (context != null) {
190: context.close();
191: }
192: if (configurationData != null) {
193: DeploymentUtil.recursiveDelete(configurationData
194: .getConfigurationDir());
195: }
196: }
197: }
198:
199: public void testBadEJBJARConfiguration() throws Exception {
200: EARConfigBuilder configBuilder = new EARConfigBuilder(
201: defaultParentId, transactionManagerAbstractNameQuery,
202: connectionTrackerAbstractNameQuery,
203: transactionalTimerAbstractNameQuery,
204: nonTransactionalTimerAbstractNameQuery,
205: corbaGBeanAbstractNameQuery, null, null,
206: ejbConfigBuilder, webConfigBuilder,
207: connectorConfigBuilder, activationSpecInfoLocator,
208: appClientConfigBuilder, securityBuilder,
209: serviceBuilder, persistenceUnitBuilder, naming,
210: artifactResolvers);
211:
212: ConfigurationData configurationData = null;
213: DeploymentContext context = null;
214: try {
215: Object plan = configBuilder
216: .getDeploymentPlan(
217: resolveFile("src/test/resources/plans/test-bad-ejb-jar.xml"),
218: earFile, idBuilder);
219: context = configBuilder.buildConfiguration(false,
220: configBuilder.getConfigurationID(plan, earFile,
221: idBuilder), plan, earFile, Collections
222: .singleton(configStore), artifactResolver,
223: configStore);
224: configurationData = getConfigurationData(context);
225: fail("Should have thrown a DeploymentException");
226: } catch (DeploymentException e) {
227: //we now may get a FileNotFoundException for missing wars.
228: } finally {
229: if (context != null) {
230: context.close();
231: }
232: if (configurationData != null) {
233: DeploymentUtil.recursiveDelete(configurationData
234: .getConfigurationDir());
235: }
236: }
237: }
238:
239: public void testBadWARConfiguration() throws Exception {
240: EARConfigBuilder configBuilder = new EARConfigBuilder(
241: defaultParentId, transactionManagerAbstractNameQuery,
242: connectionTrackerAbstractNameQuery,
243: transactionalTimerAbstractNameQuery,
244: nonTransactionalTimerAbstractNameQuery,
245: corbaGBeanAbstractNameQuery, null, null,
246: ejbConfigBuilder, webConfigBuilder,
247: connectorConfigBuilder, activationSpecInfoLocator,
248: appClientConfigBuilder, securityBuilder,
249: serviceBuilder, persistenceUnitBuilder, naming,
250: artifactResolvers);
251:
252: ConfigurationData configurationData = null;
253: DeploymentContext context = null;
254: try {
255: Object plan = configBuilder
256: .getDeploymentPlan(
257: resolveFile("src/test/resources/plans/test-bad-war.xml"),
258: earFile, idBuilder);
259: context = configBuilder.buildConfiguration(false,
260: configBuilder.getConfigurationID(plan, earFile,
261: idBuilder), plan, earFile, Collections
262: .singleton(configStore), artifactResolver,
263: configStore);
264: configurationData = getConfigurationData(context);
265: fail("Should have thrown a DeploymentException");
266: } catch (DeploymentException e) {
267: //we now may get a FileNotFoundException for missing wars.
268: } finally {
269: if (context != null) {
270: context.close();
271: }
272: if (configurationData != null) {
273: DeploymentUtil.recursiveDelete(configurationData
274: .getConfigurationDir());
275: }
276: }
277: }
278:
279: public void testBadRARConfiguration() throws Exception {
280: EARConfigBuilder configBuilder = new EARConfigBuilder(
281: defaultParentId, transactionManagerAbstractNameQuery,
282: connectionTrackerAbstractNameQuery,
283: transactionalTimerAbstractNameQuery,
284: nonTransactionalTimerAbstractNameQuery,
285: corbaGBeanAbstractNameQuery, null, null,
286: ejbConfigBuilder, webConfigBuilder,
287: connectorConfigBuilder, activationSpecInfoLocator,
288: appClientConfigBuilder, securityBuilder,
289: serviceBuilder, persistenceUnitBuilder, naming,
290: artifactResolvers);
291:
292: ConfigurationData configurationData = null;
293: DeploymentContext context = null;
294: try {
295: Object plan = configBuilder
296: .getDeploymentPlan(
297: resolveFile("src/test/resources/plans/test-bad-rar.xml"),
298: earFile, idBuilder);
299: context = configBuilder.buildConfiguration(false,
300: configBuilder.getConfigurationID(plan, earFile,
301: idBuilder), plan, earFile, Collections
302: .singleton(configStore), artifactResolver,
303: configStore);
304: configurationData = getConfigurationData(context);
305: fail("Should have thrown a DeploymentException");
306: } catch (DeploymentException e) {
307: //we now may get a FileNotFoundException for missing wars.
308: } finally {
309: if (context != null) {
310: context.close();
311: }
312: if (configurationData != null) {
313: DeploymentUtil.recursiveDelete(configurationData
314: .getConfigurationDir());
315: }
316: }
317: }
318:
319: public void testBadCARConfiguration() throws Exception {
320: EARConfigBuilder configBuilder = new EARConfigBuilder(
321: defaultParentId, transactionManagerAbstractNameQuery,
322: connectionTrackerAbstractNameQuery,
323: transactionalTimerAbstractNameQuery,
324: nonTransactionalTimerAbstractNameQuery,
325: corbaGBeanAbstractNameQuery, null, null,
326: ejbConfigBuilder, webConfigBuilder,
327: connectorConfigBuilder, activationSpecInfoLocator,
328: appClientConfigBuilder, securityBuilder,
329: serviceBuilder, persistenceUnitBuilder, naming,
330: artifactResolvers);
331:
332: ConfigurationData configurationData = null;
333: DeploymentContext context = null;
334: try {
335: Object plan = configBuilder
336: .getDeploymentPlan(
337: resolveFile("src/test/resources/plans/test-bad-car.xml"),
338: earFile, idBuilder);
339: context = configBuilder.buildConfiguration(false,
340: configBuilder.getConfigurationID(plan, earFile,
341: idBuilder), plan, earFile, Collections
342: .singleton(configStore), artifactResolver,
343: configStore);
344: configurationData = getConfigurationData(context);
345: fail("Should have thrown a DeploymentException");
346: } catch (DeploymentException e) {
347: //we now may get a FileNotFoundException for missing wars.
348: } finally {
349: if (context != null) {
350: context.close();
351: }
352: if (configurationData != null) {
353: DeploymentUtil.recursiveDelete(configurationData
354: .getConfigurationDir());
355: }
356: }
357: }
358:
359: public void testNoEJBDeployer() throws Exception {
360: EARConfigBuilder configBuilder = new EARConfigBuilder(
361: defaultParentId, transactionManagerAbstractNameQuery,
362: connectionTrackerAbstractNameQuery,
363: transactionalTimerAbstractNameQuery,
364: nonTransactionalTimerAbstractNameQuery,
365: corbaGBeanAbstractNameQuery, null, null, null,
366: webConfigBuilder, connectorConfigBuilder,
367: activationSpecInfoLocator, appClientConfigBuilder,
368: securityBuilder, serviceBuilder,
369: persistenceUnitBuilder, naming, artifactResolvers);
370:
371: ConfigurationData configurationData = null;
372: DeploymentContext context = null;
373: try {
374: Object plan = configBuilder.getDeploymentPlan(null,
375: earFile, idBuilder);
376: context = configBuilder.buildConfiguration(false,
377: configBuilder.getConfigurationID(plan, earFile,
378: idBuilder), plan, earFile, Collections
379: .singleton(configStore), artifactResolver,
380: configStore);
381: configurationData = getConfigurationData(context);
382: fail("Should have thrown a DeploymentException");
383: } catch (DeploymentException e) {
384: // expected
385: } finally {
386: if (context != null) {
387: context.close();
388: }
389: if (configurationData != null) {
390: DeploymentUtil.recursiveDelete(configurationData
391: .getConfigurationDir());
392: }
393: }
394: }
395:
396: public void testNoWARDeployer() throws Exception {
397: EARConfigBuilder configBuilder = new EARConfigBuilder(
398: defaultParentId, transactionManagerAbstractNameQuery,
399: connectionTrackerAbstractNameQuery,
400: transactionalTimerAbstractNameQuery,
401: nonTransactionalTimerAbstractNameQuery,
402: corbaGBeanAbstractNameQuery, null, null,
403: ejbConfigBuilder, null, connectorConfigBuilder,
404: activationSpecInfoLocator, appClientConfigBuilder,
405: securityBuilder, serviceBuilder,
406: persistenceUnitBuilder, naming, artifactResolvers);
407:
408: ConfigurationData configurationData = null;
409: DeploymentContext context = null;
410: try {
411: Object plan = configBuilder.getDeploymentPlan(null,
412: earFile, idBuilder);
413: context = configBuilder.buildConfiguration(false,
414: configBuilder.getConfigurationID(plan, earFile,
415: idBuilder), plan, earFile, Collections
416: .singleton(configStore), artifactResolver,
417: configStore);
418: configurationData = getConfigurationData(context);
419: fail("Should have thrown a DeploymentException");
420: } catch (DeploymentException e) {
421: // expected
422: } finally {
423: if (context != null) {
424: context.close();
425: }
426: if (configurationData != null) {
427: DeploymentUtil.recursiveDelete(configurationData
428: .getConfigurationDir());
429: }
430: }
431: }
432:
433: public void testNoConnectorDeployer() throws Exception {
434: EARConfigBuilder configBuilder = new EARConfigBuilder(
435: defaultParentId, transactionManagerAbstractNameQuery,
436: connectionTrackerAbstractNameQuery,
437: transactionalTimerAbstractNameQuery,
438: nonTransactionalTimerAbstractNameQuery,
439: corbaGBeanAbstractNameQuery, null, null,
440: ejbConfigBuilder, webConfigBuilder, null,
441: activationSpecInfoLocator, appClientConfigBuilder,
442: securityBuilder, serviceBuilder,
443: persistenceUnitBuilder, naming, artifactResolvers);
444:
445: ConfigurationData configurationData = null;
446: DeploymentContext context = null;
447: try {
448: Object plan = configBuilder.getDeploymentPlan(null,
449: earFile, idBuilder);
450: context = configBuilder.buildConfiguration(false,
451: configBuilder.getConfigurationID(plan, earFile,
452: idBuilder), plan, earFile, Collections
453: .singleton(configStore), artifactResolver,
454: configStore);
455: configurationData = getConfigurationData(context);
456: fail("Should have thrown a DeploymentException");
457: } catch (DeploymentException e) {
458: // expected
459: } finally {
460: if (context != null) {
461: context.close();
462: }
463: if (configurationData != null) {
464: DeploymentUtil.recursiveDelete(configurationData
465: .getConfigurationDir());
466: }
467: }
468: }
469:
470: protected ConfigurationData getConfigurationData(
471: DeploymentContext context) throws Exception {
472: // add the a j2ee server so the application context reference can be resolved
473: context.addGBean("geronimo", J2EEServerImpl.GBEAN_INFO);
474:
475: return context.getConfigurationData();
476: }
477:
478: protected static void close(Module module) {
479: if (module != null) {
480: module.close();
481: }
482: }
483:
484: }
|