01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.tomcat.deployment;
17:
18: import java.io.File;
19: import java.net.URL;
20: import java.util.Collections;
21:
22: import junit.framework.TestCase;
23: import org.apache.geronimo.deployment.xbeans.ArtifactType;
24: import org.apache.geronimo.deployment.xbeans.EnvironmentType;
25: import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
26: import org.apache.geronimo.deployment.service.GBeanBuilder;
27: import org.apache.geronimo.gbean.AbstractName;
28: import org.apache.geronimo.gbean.AbstractNameQuery;
29: import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
30: import org.apache.geronimo.j2ee.deployment.NamingBuilderCollection;
31: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
32: import org.apache.geronimo.kernel.Jsr77Naming;
33: import org.apache.geronimo.kernel.Naming;
34: import org.apache.geronimo.kernel.repository.Artifact;
35: import org.apache.geronimo.kernel.repository.Environment;
36: import org.apache.geronimo.xbeans.geronimo.naming.GerResourceRefType;
37: import org.apache.geronimo.xbeans.geronimo.web.GerWebAppDocument;
38: import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType;
39: import org.apache.geronimo.xbeans.geronimo.web.tomcat.TomcatWebAppType;
40: import org.apache.geronimo.security.deployment.GeronimoSecurityBuilderImpl;
41:
42: /**
43: */
44: public class PlanParsingTest extends TestCase {
45: private ClassLoader classLoader = this .getClass().getClassLoader();
46:
47: private Naming naming = new Jsr77Naming();
48: private Artifact baseId = new Artifact("test", "base", "1", "car");
49: private AbstractName baseRootName = naming.createRootName(baseId,
50: "root", NameFactory.SERVICE_MODULE);
51: private AbstractNameQuery tomcatContainerObjectName = new AbstractNameQuery(
52: naming.createChildName(baseRootName, "TomcatContainer",
53: NameFactory.GERONIMO_SERVICE));
54: private WebServiceBuilder webServiceBuilder = null;
55: private Environment defaultEnvironment = new Environment();
56: private TomcatModuleBuilder builder;
57:
58: protected void setUp() throws Exception {
59: builder = new TomcatModuleBuilder(defaultEnvironment,
60: tomcatContainerObjectName, Collections
61: .singleton(webServiceBuilder),
62: Collections.singleton(new GeronimoSecurityBuilderImpl(
63: null)), Collections.singleton(new GBeanBuilder(
64: null, null)), new NamingBuilderCollection(null,
65: null), Collections.EMPTY_LIST, null,
66: new MockResourceEnvironmentSetter(), null);
67: builder.doStart();
68: }
69:
70: protected void tearDown() throws Exception {
71: builder.doStop();
72: }
73:
74: public void testResourceRef() throws Exception {
75: URL resourceURL = classLoader.getResource("plans/plan1.xml");
76: File resourcePlan = new File(resourceURL.getFile());
77: assertTrue(resourcePlan.exists());
78: TomcatWebAppType tomcatWebApp = builder.getTomcatWebApp(
79: resourcePlan, null, true, null, null);
80: assertEquals(1, tomcatWebApp.getResourceRefArray().length);
81: }
82:
83: public void testConstructPlan() throws Exception {
84: GerWebAppDocument tomcatWebAppDoc = GerWebAppDocument.Factory
85: .newInstance();
86: GerWebAppType tomcatWebAppType = tomcatWebAppDoc.addNewWebApp();
87: EnvironmentType environmentType = tomcatWebAppType
88: .addNewEnvironment();
89: ArtifactType artifactType = environmentType.addNewModuleId();
90: artifactType.setArtifactId("foo");
91:
92: GerResourceRefType ref = tomcatWebAppType.addNewResourceRef();
93: ref.setRefName("ref");
94: ref.setResourceLink("target");
95:
96: XmlBeansUtil.validateDD(tomcatWebAppType);
97: }
98:
99: }
|