KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > tools > DDBeanRootTest


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
18 package org.apache.geronimo.deployment.tools;
19
20 import java.net.URL JavaDoc;
21 import java.util.Arrays JavaDoc;
22 import java.util.Enumeration JavaDoc;
23 import java.io.FileNotFoundException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import javax.enterprise.deploy.model.DDBean JavaDoc;
26 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
27 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
28 import javax.enterprise.deploy.model.exceptions.DDBeanCreateException;
29 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
30
31 import junit.framework.TestCase;
32
33 /**
34  *
35  *
36  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
37  */

38 public class DDBeanRootTest extends TestCase {
39     private DDBeanRoot JavaDoc root;
40     private ClassLoader JavaDoc classLoader;
41
42     public void testRoot() throws Exception JavaDoc {
43         DeployableObject JavaDoc deployable = new MockDeployable();
44         URL JavaDoc descriptor = classLoader.getResource("descriptors/app-client1.xml");
45         root = new DDBeanRootImpl(deployable, descriptor);
46         assertEquals("1.4", root.getDDBeanRootVersion());
47         assertEquals(deployable, root.getDeployableObject());
48         assertEquals(ModuleType.CAR, root.getType());
49         assertEquals("/", root.getXpath());
50         assertNull(root.getText("foo"));
51         assertTrue(Arrays.equals(new String JavaDoc[] {"Test DD for app-client1"}, root.getText("application-client/description")));
52         assertTrue(Arrays.equals(new String JavaDoc[] {"http://localhost"}, root.getText("application-client/env-entry/env-entry-value")));
53         assertTrue(Arrays.equals(new String JavaDoc[] {"url/test1", "url/test2"}, root.getText("application-client/env-entry/env-entry-name")));
54
55         DDBean JavaDoc description = root.getChildBean("application-client/description")[0];
56         assertEquals("Test DD for app-client1", description.getText());
57         assertEquals("application-client/description", description.getXpath());
58         assertEquals(description, description.getChildBean("/application-client/description")[0]);
59     }
60
61     protected void setUp() throws Exception JavaDoc {
62         classLoader = Thread.currentThread().getContextClassLoader();
63     }
64
65     private class MockDeployable implements DeployableObject JavaDoc {
66         public Enumeration JavaDoc entries() {
67             fail();
68             throw new AssertionError JavaDoc();
69         }
70
71         public DDBean JavaDoc[] getChildBean(String JavaDoc xpath) {
72             fail();
73             throw new AssertionError JavaDoc();
74         }
75
76         public Class JavaDoc getClassFromScope(String JavaDoc className) {
77             fail();
78             throw new AssertionError JavaDoc();
79         }
80
81         public DDBeanRoot JavaDoc getDDBeanRoot() {
82             fail();
83             throw new AssertionError JavaDoc();
84         }
85
86         public DDBeanRoot JavaDoc getDDBeanRoot(String JavaDoc filename) throws FileNotFoundException JavaDoc, DDBeanCreateException {
87             fail();
88             throw new AssertionError JavaDoc();
89         }
90
91         public InputStream JavaDoc getEntry(String JavaDoc name) {
92             fail();
93             throw new AssertionError JavaDoc();
94         }
95
96         public String JavaDoc getModuleDTDVersion() {
97             fail();
98             throw new AssertionError JavaDoc();
99         }
100
101         public String JavaDoc[] getText(String JavaDoc xpath) {
102             fail();
103             throw new AssertionError JavaDoc();
104         }
105
106         public ModuleType JavaDoc getType() {
107             return ModuleType.CAR;
108         }
109     }
110 }
111
Popular Tags