KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > tomcat > deployment > PlanParsingTest


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.tomcat.deployment;
18
19 import java.io.File JavaDoc;
20 import java.net.URL JavaDoc;
21 import java.util.Collections JavaDoc;
22
23 import junit.framework.TestCase;
24 import org.apache.geronimo.deployment.xbeans.ArtifactType;
25 import org.apache.geronimo.deployment.xbeans.EnvironmentType;
26 import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
27 import org.apache.geronimo.deployment.service.GBeanBuilder;
28 import org.apache.geronimo.gbean.AbstractName;
29 import org.apache.geronimo.gbean.AbstractNameQuery;
30 import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
31 import org.apache.geronimo.j2ee.deployment.NamingBuilderCollection;
32 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
33 import org.apache.geronimo.kernel.Jsr77Naming;
34 import org.apache.geronimo.kernel.Naming;
35 import org.apache.geronimo.kernel.repository.Artifact;
36 import org.apache.geronimo.kernel.repository.Environment;
37 import org.apache.geronimo.xbeans.geronimo.naming.GerResourceRefType;
38 import org.apache.geronimo.xbeans.geronimo.web.GerWebAppDocument;
39 import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType;
40 import org.apache.geronimo.xbeans.geronimo.web.tomcat.TomcatWebAppType;
41 import org.apache.geronimo.security.deployment.GeronimoSecurityBuilderImpl;
42 import org.apache.geronimo.naming.deployment.ResourceEnvironmentSetter;
43 import org.apache.geronimo.naming.deployment.ResourceEnvironmentBuilder;
44 import org.apache.xmlbeans.XmlObject;
45
46 /**
47  */

48 public class PlanParsingTest extends TestCase {
49     private ClassLoader JavaDoc classLoader = this.getClass().getClassLoader();
50
51     private Naming naming = new Jsr77Naming();
52     private Artifact baseId = new Artifact("test", "base", "1", "car");
53     private AbstractName baseRootName = naming.createRootName(baseId, "root", NameFactory.SERVICE_MODULE);
54     private AbstractNameQuery tomcatContainerObjectName = new AbstractNameQuery(naming.createChildName(baseRootName, "TomcatContainer", NameFactory.GERONIMO_SERVICE));
55     private WebServiceBuilder webServiceBuilder = null;
56     private Environment defaultEnvironment = new Environment();
57     private TomcatModuleBuilder builder;
58
59     protected void setUp() throws Exception JavaDoc {
60         builder = new TomcatModuleBuilder(defaultEnvironment, tomcatContainerObjectName, Collections.singleton(webServiceBuilder), Collections.singleton(new GeronimoSecurityBuilderImpl()), Collections.singleton(new GBeanBuilder(null, null)), new NamingBuilderCollection(null, null), new MockResourceEnvironmentSetter(), null);
61     }
62
63     public void testResourceRef() throws Exception JavaDoc {
64         URL JavaDoc resourceURL = classLoader.getResource("plans/plan1.xml");
65         File JavaDoc resourcePlan = new File JavaDoc(resourceURL.getFile());
66         assertTrue(resourcePlan.exists());
67         TomcatWebAppType tomcatWebApp = builder.getTomcatWebApp(resourcePlan, null, true, null, null);
68         assertEquals(1, tomcatWebApp.getResourceRefArray().length);
69     }
70
71     public void testConstructPlan() throws Exception JavaDoc {
72         GerWebAppDocument tomcatWebAppDoc = GerWebAppDocument.Factory.newInstance();
73         GerWebAppType tomcatWebAppType = tomcatWebAppDoc.addNewWebApp();
74         EnvironmentType environmentType = tomcatWebAppType.addNewEnvironment();
75         ArtifactType artifactType = environmentType.addNewModuleId();
76         artifactType.setArtifactId("foo");
77
78         GerResourceRefType ref = tomcatWebAppType.addNewResourceRef();
79         ref.setRefName("ref");
80         ref.setResourceLink("target");
81
82         XmlBeansUtil.validateDD(tomcatWebAppType);
83     }
84
85 }
86
Popular Tags