KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.jar.JarFile JavaDoc;
23
24 import org.apache.geronimo.common.DeploymentException;
25 import org.apache.geronimo.deployment.DeploymentContext;
26 import org.apache.geronimo.deployment.ModuleIDBuilder;
27 import org.apache.geronimo.deployment.NamespaceDrivenBuilder;
28 import org.apache.geronimo.deployment.util.DeploymentUtil;
29 import org.apache.geronimo.gbean.AbstractName;
30 import org.apache.geronimo.gbean.AbstractNameQuery;
31 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
32 import org.apache.geronimo.j2ee.management.impl.J2EEServerImpl;
33 import org.apache.geronimo.kernel.Jsr77Naming;
34 import org.apache.geronimo.kernel.Naming;
35 import org.apache.geronimo.kernel.config.ConfigurationData;
36 import org.apache.geronimo.kernel.repository.Artifact;
37 import org.apache.geronimo.kernel.repository.ArtifactManager;
38 import org.apache.geronimo.kernel.repository.ArtifactResolver;
39 import org.apache.geronimo.kernel.repository.DefaultArtifactManager;
40 import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
41 import org.apache.geronimo.kernel.repository.Environment;
42 import org.apache.geronimo.kernel.repository.ImportType;
43 import org.apache.geronimo.testsupport.TestSupport;
44
45 /**
46  * Provides support for EAR config builder tests.
47  *
48  * @version $Rev:386276 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
49  */

50 public abstract class EARConfigBuilderTestSupport
51     extends TestSupport
52 {
53     protected static String JavaDoc WEB_NAMESPACE = "foo";
54     
55     protected static JarFile JavaDoc earFile;
56     
57     protected static MockConfigStore configStore = new MockConfigStore();
58     
59     protected static ArtifactManager artifactManager = new DefaultArtifactManager();
60     
61     protected static ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager, Collections.EMPTY_SET, null);
62     
63     protected static MockEJBConfigBuilder ejbConfigBuilder = new MockEJBConfigBuilder();
64     
65     protected static MockWARConfigBuilder webConfigBuilder = new MockWARConfigBuilder();
66     
67     protected static MockConnectorConfigBuilder connectorConfigBuilder = new MockConnectorConfigBuilder();
68     
69     protected static ActivationSpecInfoLocator activationSpecInfoLocator = connectorConfigBuilder;
70     
71     protected static ModuleBuilder appClientConfigBuilder = null;
72     
73     protected final static ModuleIDBuilder idBuilder = new ModuleIDBuilder();
74     
75     protected static final NamespaceDrivenBuilder securityBuilder = null;
76     
77     protected static final NamespaceDrivenBuilder serviceBuilder = null;
78
79     protected static final Naming naming = new Jsr77Naming();
80
81     protected static final AbstractName rootConfig = naming.createRootName(new Artifact("test", "stuff", "", "car"), "test", "test") ;
82     
83     protected static final AbstractName transactionManagerObjectName = naming.createChildName(rootConfig, "TransactionManager", "TransactionManager");
84     
85     protected static final AbstractName connectionTrackerObjectName = naming.createChildName(rootConfig, "ConnectionTracker", "ConnectionTracker");
86     
87     protected static final AbstractName transactionalTimerObjectName = naming.createChildName(rootConfig, "TransactionalThreaPooledTimer", "ThreadPooledTimer");
88     
89     protected static final AbstractName nonTransactionalTimerObjectName = naming.createChildName(rootConfig, "NonTransactionalThreaPooledTimer", "ThreadPooledTimer");
90     
91     protected static final AbstractName serverName = naming.createChildName(rootConfig, "J2EEServer", "Server");
92     
93     protected static final AbstractName earName = naming.createRootName(new Artifact("org.apache.geronimo.test.test-ear", "ear", "", "ear"), "test", NameFactory.J2EE_APPLICATION);
94     
95     protected static final AbstractName ejbModuleName = naming.createChildName(earName, "ejb-jar", NameFactory.EJB_MODULE);
96     
97     protected static final AbstractName webModuleName = naming.createChildName(earName, "war", NameFactory.WEB_MODULE);
98     
99     protected static final AbstractName raModuleName = naming.createChildName(earName, "rar", NameFactory.RESOURCE_ADAPTER_MODULE);
100
101     protected Environment defaultParentId;
102     
103     protected static String JavaDoc contextRoot = "test";
104     
105     protected static final Map JavaDoc portMap = null;
106     
107     protected final AbstractNameQuery transactionManagerAbstractNameQuery = new AbstractNameQuery(transactionManagerObjectName, null);
108     
109     protected final AbstractNameQuery connectionTrackerAbstractNameQuery = new AbstractNameQuery(connectionTrackerObjectName, null);
110     
111     protected final AbstractNameQuery transactionalTimerAbstractNameQuery = new AbstractNameQuery(transactionalTimerObjectName, null);
112     
113     protected final AbstractNameQuery nonTransactionalTimerAbstractNameQuery = new AbstractNameQuery(nonTransactionalTimerObjectName, null);
114     
115     protected final AbstractNameQuery corbaGBeanAbstractNameQuery = new AbstractNameQuery(serverName, null);
116
117     protected void setUp() throws Exception JavaDoc {
118         super.setUp();
119         
120         defaultParentId = new Environment();
121         defaultParentId.addDependency(new Artifact("org.apache.geronimo.tests", "test", "1", "car"), ImportType.ALL);
122     }
123
124     public void testBuildConfiguration() throws Exception JavaDoc {
125         ConfigurationData configurationData = null;
126         DeploymentContext context = null;
127         try {
128             EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId,
129                     transactionManagerAbstractNameQuery,
130                     connectionTrackerAbstractNameQuery,
131                     transactionalTimerAbstractNameQuery,
132                     nonTransactionalTimerAbstractNameQuery,
133                     corbaGBeanAbstractNameQuery,
134                     null,
135                     null,
136                     ejbConfigBuilder,
137                     webConfigBuilder,
138                     connectorConfigBuilder,
139                     activationSpecInfoLocator,
140                     appClientConfigBuilder,
141                     securityBuilder,
142                     serviceBuilder,
143                     naming);
144
145             Object JavaDoc plan = configBuilder.getDeploymentPlan(null, earFile, idBuilder);
146             context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore);
147             configurationData = getConfigurationData(context);
148         } finally {
149             if (context != null) {
150                 context.close();
151             }
152             if (configurationData != null) {
153                 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir());
154             }
155         }
156     }
157
158     public void testBadEJBJARConfiguration() throws Exception JavaDoc {
159         EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId,
160                 transactionManagerAbstractNameQuery,
161                 connectionTrackerAbstractNameQuery,
162                 transactionalTimerAbstractNameQuery,
163                 nonTransactionalTimerAbstractNameQuery,
164                 corbaGBeanAbstractNameQuery,
165                 null,
166                 null,
167                 ejbConfigBuilder,
168                 webConfigBuilder,
169                 connectorConfigBuilder,
170                 activationSpecInfoLocator,
171                 appClientConfigBuilder,
172                 securityBuilder,
173                 serviceBuilder,
174                 naming);
175
176         ConfigurationData configurationData = null;
177         DeploymentContext context = null;
178         try {
179             Object JavaDoc plan = configBuilder.getDeploymentPlan(resolveFile("src/test/resources/plans/test-bad-ejb-jar.xml"), earFile, idBuilder);
180             context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore);
181             configurationData = getConfigurationData(context);
182             fail("Should have thrown a DeploymentException");
183         } catch (DeploymentException e) {
184             if (e.getCause() instanceof IOException JavaDoc) {
185                 fail("Should not be complaining about bad vendor DD for invalid module entry");
186             }
187         } finally {
188             if (context != null) {
189                 context.close();
190             }
191             if (configurationData != null) {
192                 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir());
193             }
194         }
195     }
196
197     public void testBadWARConfiguration() throws Exception JavaDoc {
198         EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId,
199                 transactionManagerAbstractNameQuery,
200                 connectionTrackerAbstractNameQuery,
201                 transactionalTimerAbstractNameQuery,
202                 nonTransactionalTimerAbstractNameQuery,
203                 corbaGBeanAbstractNameQuery,
204                 null,
205                 null,
206                 ejbConfigBuilder,
207                 webConfigBuilder,
208                 connectorConfigBuilder,
209                 activationSpecInfoLocator,
210                 appClientConfigBuilder,
211                 securityBuilder,
212                 serviceBuilder,
213                 naming);
214
215         ConfigurationData configurationData = null;
216         DeploymentContext context = null;
217         try {
218             Object JavaDoc plan = configBuilder.getDeploymentPlan(resolveFile("src/test/resources/plans/test-bad-war.xml"), earFile, idBuilder);
219             context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore);
220             configurationData = getConfigurationData(context);
221             fail("Should have thrown a DeploymentException");
222         } catch (DeploymentException e) {
223             if (e.getCause() instanceof IOException JavaDoc) {
224                 fail("Should not be complaining about bad vendor DD for invalid module entry");
225             }
226         } finally {
227             if (context != null) {
228                 context.close();
229             }
230             if (configurationData != null) {
231                 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir());
232             }
233         }
234     }
235
236     public void testBadRARConfiguration() throws Exception JavaDoc {
237         EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId,
238                 transactionManagerAbstractNameQuery,
239                 connectionTrackerAbstractNameQuery,
240                 transactionalTimerAbstractNameQuery,
241                 nonTransactionalTimerAbstractNameQuery,
242                 corbaGBeanAbstractNameQuery,
243                 null,
244                 null,
245                 ejbConfigBuilder,
246                 webConfigBuilder,
247                 connectorConfigBuilder,
248                 activationSpecInfoLocator,
249                 appClientConfigBuilder,
250                 securityBuilder,
251                 serviceBuilder,
252                 naming);
253
254         ConfigurationData configurationData = null;
255         DeploymentContext context = null;
256         try {
257             Object JavaDoc plan = configBuilder.getDeploymentPlan(resolveFile("src/test/resources/plans/test-bad-rar.xml"), earFile, idBuilder);
258             context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore);
259             configurationData = getConfigurationData(context);
260             fail("Should have thrown a DeploymentException");
261         } catch (DeploymentException e) {
262             if (e.getCause() instanceof IOException JavaDoc) {
263                 fail("Should not be complaining about bad vendor DD for invalid module entry");
264             }
265         } finally {
266             if (context != null) {
267                 context.close();
268             }
269             if (configurationData != null) {
270                 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir());
271             }
272         }
273     }
274
275     public void testBadCARConfiguration() throws Exception JavaDoc {
276         EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId,
277                 transactionManagerAbstractNameQuery,
278                 connectionTrackerAbstractNameQuery,
279                 transactionalTimerAbstractNameQuery,
280                 nonTransactionalTimerAbstractNameQuery,
281                 corbaGBeanAbstractNameQuery,
282                 null,
283                 null,
284                 ejbConfigBuilder,
285                 webConfigBuilder,
286                 connectorConfigBuilder,
287                 activationSpecInfoLocator,
288                 appClientConfigBuilder,
289                 securityBuilder,
290                 serviceBuilder,
291                 naming);
292
293         ConfigurationData configurationData = null;
294         DeploymentContext context = null;
295         try {
296             Object JavaDoc plan = configBuilder.getDeploymentPlan(resolveFile("src/test/resources/plans/test-bad-car.xml"), earFile, idBuilder);
297             context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore);
298             configurationData = getConfigurationData(context);
299             fail("Should have thrown a DeploymentException");
300         } catch (DeploymentException e) {
301             if (e.getCause() instanceof IOException JavaDoc) {
302                 fail("Should not be complaining about bad vendor DD for invalid module entry");
303             }
304         } finally {
305             if (context != null) {
306                 context.close();
307             }
308             if (configurationData != null) {
309                 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir());
310             }
311         }
312     }
313
314     public void testNoEJBDeployer() throws Exception JavaDoc {
315         EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId,
316                 transactionManagerAbstractNameQuery,
317                 connectionTrackerAbstractNameQuery,
318                 transactionalTimerAbstractNameQuery,
319                 nonTransactionalTimerAbstractNameQuery,
320                 corbaGBeanAbstractNameQuery,
321                 null,
322                 null,
323                 null,
324                 webConfigBuilder,
325                 connectorConfigBuilder,
326                 activationSpecInfoLocator,
327                 appClientConfigBuilder,
328                 securityBuilder,
329                 serviceBuilder,
330                 naming);
331
332
333         ConfigurationData configurationData = null;
334         DeploymentContext context = null;
335         try {
336             Object JavaDoc plan = configBuilder.getDeploymentPlan(null, earFile, idBuilder);
337             context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore);
338             configurationData = getConfigurationData(context);
339             fail("Should have thrown a DeploymentException");
340         } catch (DeploymentException e) {
341             // expected
342
} finally {
343             if (context != null) {
344                 context.close();
345             }
346             if (configurationData != null) {
347                 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir());
348             }
349         }
350     }
351
352     public void testNoWARDeployer() throws Exception JavaDoc {
353         EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId,
354                 transactionManagerAbstractNameQuery,
355                 connectionTrackerAbstractNameQuery,
356                 transactionalTimerAbstractNameQuery,
357                 nonTransactionalTimerAbstractNameQuery,
358                 corbaGBeanAbstractNameQuery,
359                 null,
360                 null,
361                 ejbConfigBuilder,
362                 null,
363                 connectorConfigBuilder,
364                 activationSpecInfoLocator,
365                 appClientConfigBuilder,
366                 securityBuilder,
367                 serviceBuilder,
368                 naming);
369
370         ConfigurationData configurationData = null;
371         DeploymentContext context = null;
372         try {
373             Object JavaDoc plan = configBuilder.getDeploymentPlan(null, earFile, idBuilder);
374             context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore);
375             configurationData = getConfigurationData(context);
376             fail("Should have thrown a DeploymentException");
377         } catch (DeploymentException e) {
378             // expected
379
} finally {
380             if (context != null) {
381                 context.close();
382             }
383             if (configurationData != null) {
384                 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir());
385             }
386         }
387     }
388
389     public void testNoConnectorDeployer() throws Exception JavaDoc {
390         EARConfigBuilder configBuilder = new EARConfigBuilder(defaultParentId,
391                 transactionManagerAbstractNameQuery,
392                 connectionTrackerAbstractNameQuery,
393                 transactionalTimerAbstractNameQuery,
394                 nonTransactionalTimerAbstractNameQuery,
395                 corbaGBeanAbstractNameQuery,
396                 null,
397                 null,
398                 ejbConfigBuilder,
399                 webConfigBuilder,
400                 null,
401                 activationSpecInfoLocator,
402                 appClientConfigBuilder,
403                 securityBuilder,
404                 serviceBuilder,
405                 naming);
406
407         ConfigurationData configurationData = null;
408         DeploymentContext context = null;
409         try {
410             Object JavaDoc plan = configBuilder.getDeploymentPlan(null, earFile, idBuilder);
411             context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, earFile, idBuilder), plan, earFile, Collections.singleton(configStore), artifactResolver, configStore);
412             configurationData = getConfigurationData(context);
413             fail("Should have thrown a DeploymentException");
414         } catch (DeploymentException e) {
415             // expected
416
} finally {
417             if (context != null) {
418                 context.close();
419             }
420             if (configurationData != null) {
421                 DeploymentUtil.recursiveDelete(configurationData.getConfigurationDir());
422             }
423         }
424     }
425
426     protected ConfigurationData getConfigurationData(DeploymentContext context) throws Exception JavaDoc {
427         // add the a j2ee server so the application context reference can be resolved
428
context.addGBean("geronimo", J2EEServerImpl.GBEAN_INFO);
429
430         return context.getConfigurationData();
431     }
432
433     protected static void close(Module module) {
434         if (module != null) {
435             module.close();
436         }
437     }
438 }
439
Popular Tags