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.deployment.tools;
017:
018: import java.net.URL;
019: import java.util.Arrays;
020: import java.util.Enumeration;
021: import java.io.FileNotFoundException;
022: import java.io.InputStream;
023: import javax.enterprise.deploy.model.DDBean;
024: import javax.enterprise.deploy.model.DDBeanRoot;
025: import javax.enterprise.deploy.model.DeployableObject;
026: import javax.enterprise.deploy.model.exceptions.DDBeanCreateException;
027: import javax.enterprise.deploy.shared.ModuleType;
028:
029: import junit.framework.TestCase;
030:
031: /**
032: *
033: *
034: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
035: */
036: public class DDBeanRootTest extends TestCase {
037: private DDBeanRoot root;
038: private ClassLoader classLoader;
039:
040: public void testRoot() throws Exception {
041: DeployableObject deployable = new MockDeployable();
042: URL descriptor = classLoader
043: .getResource("descriptors/app-client1.xml");
044: root = new DDBeanRootImpl(deployable, descriptor);
045: assertEquals("1.4", root.getDDBeanRootVersion());
046: assertEquals(deployable, root.getDeployableObject());
047: assertEquals(ModuleType.CAR, root.getType());
048: assertEquals("/", root.getXpath());
049: assertNull(root.getText("foo"));
050: assertTrue(Arrays.equals(
051: new String[] { "Test DD for app-client1" }, root
052: .getText("application-client/description")));
053: assertTrue(Arrays
054: .equals(
055: new String[] { "http://localhost" },
056: root
057: .getText("application-client/env-entry/env-entry-value")));
058: assertTrue(Arrays
059: .equals(
060: new String[] { "url/test1", "url/test2" },
061: root
062: .getText("application-client/env-entry/env-entry-name")));
063:
064: DDBean description = root
065: .getChildBean("application-client/description")[0];
066: assertEquals("Test DD for app-client1", description.getText());
067: assertEquals("application-client/description", description
068: .getXpath());
069: assertEquals(description, description
070: .getChildBean("/application-client/description")[0]);
071: }
072:
073: protected void setUp() throws Exception {
074: classLoader = Thread.currentThread().getContextClassLoader();
075: }
076:
077: private class MockDeployable implements DeployableObject {
078: public Enumeration entries() {
079: fail();
080: throw new AssertionError();
081: }
082:
083: public DDBean[] getChildBean(String xpath) {
084: fail();
085: throw new AssertionError();
086: }
087:
088: public Class getClassFromScope(String className) {
089: fail();
090: throw new AssertionError();
091: }
092:
093: public DDBeanRoot getDDBeanRoot() {
094: fail();
095: throw new AssertionError();
096: }
097:
098: public DDBeanRoot getDDBeanRoot(String filename)
099: throws FileNotFoundException, DDBeanCreateException {
100: fail();
101: throw new AssertionError();
102: }
103:
104: public InputStream getEntry(String name) {
105: fail();
106: throw new AssertionError();
107: }
108:
109: public String getModuleDTDVersion() {
110: fail();
111: throw new AssertionError();
112: }
113:
114: public String[] getText(String xpath) {
115: fail();
116: throw new AssertionError();
117: }
118:
119: public ModuleType getType() {
120: return ModuleType.CAR;
121: }
122: }
123: }
|