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.web.deployment;
017:
018: import java.net.URL;
019: import java.util.Arrays;
020:
021: import javax.enterprise.deploy.model.DDBean;
022: import javax.enterprise.deploy.model.DDBeanRoot;
023: import javax.enterprise.deploy.spi.DeploymentConfiguration;
024:
025: import junit.framework.TestCase;
026: import org.apache.geronimo.deployment.tools.loader.WebDeployable;
027:
028: /**
029: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
030: */
031: public class WebAppDConfigTest extends TestCase {
032: private DeploymentConfiguration config;
033: private WebDeployable deployable;
034: private DDBeanRoot ddBeanRoot;
035: private WebAppDConfigRoot configRoot;
036:
037: public void testWebAppRoot() throws Exception {
038: assertNotNull(configRoot);
039: assertTrue(Arrays.equals(new String[] { "web-app" }, configRoot
040: .getXpaths()));
041: assertNotNull(configRoot.getDConfigBean(ddBeanRoot
042: .getChildBean("web-app")[0]));
043: assertNull(configRoot.getDConfigBean(ddBeanRoot
044: .getChildBean("web-app/description")[0]));
045: }
046:
047: public void testWebApp() throws Exception {
048: DDBean ddBean = ddBeanRoot.getChildBean("web-app")[0];
049: WebAppDConfigBean webApp = (WebAppDConfigBean) configRoot
050: .getDConfigBean(ddBean);
051: assertNotNull(webApp);
052: /*
053: String[] xpaths = webApp.getXpaths();
054: assertTrue(Arrays.equals(
055: new String[]{
056: "ejb-ref",
057: "ejb-local-ref",
058: "message-destination-ref",
059: "resource-env-ref",
060: "resource-ref",
061: },
062: xpaths)
063: );
064: */
065: }
066:
067: /*
068: public void testEJBRef() throws Exception {
069: DDBean ddBean = ddBeanRoot.getChildBean("web-app")[0];
070: WebAppDConfigBean webApp = (WebAppDConfigBean) configRoot.getDConfigBean(ddBean);
071: DDBean[] ddBeans = ddBean.getChildBean(webApp.getXpaths()[0]);
072: assertEquals(2, ddBeans.length);
073: assertEquals("fake-ejb-ref", ddBeans[0].getChildBean("ejb-ref-name")[0].getText());
074: assertEquals("another-ejb-ref", ddBeans[1].getChildBean("ejb-ref-name")[0].getText());
075:
076: EJBRefDConfigBean ejbRef0 = (EJBRefDConfigBean) webApp.getDConfigBean(ddBeans[0]);
077: EJBRefDConfigBean ejbRef1 = (EJBRefDConfigBean) webApp.getDConfigBean(ddBeans[1]);
078: assertNotNull(ejbRef0);
079: assertEquals(ddBeans[0], ejbRef0.getDDBean());
080: assertNotNull(ejbRef1);
081: assertEquals(ddBeans[1], ejbRef1.getDDBean());
082: assertTrue(ejbRef0 != ejbRef1);
083: }
084: */
085:
086: /*
087: public void testEJBLocalRef() throws Exception {
088: DDBean ddBean = ddBeanRoot.getChildBean("web-app")[0];
089: WebAppDConfigBean webApp = (WebAppDConfigBean) configRoot.getDConfigBean(ddBean);
090: DDBean[] ddBeans = ddBean.getChildBean(webApp.getXpaths()[1]);
091: assertEquals(2, ddBeans.length);
092: assertEquals("fake-ejb-local-ref", ddBeans[0].getChildBean("ejb-ref-name")[0].getText());
093: assertEquals("another-ejb-local-ref", ddBeans[1].getChildBean("ejb-ref-name")[0].getText());
094:
095: EJBLocalRefDConfigBean ejbRef0 = (EJBLocalRefDConfigBean) webApp.getDConfigBean(ddBeans[0]);
096: EJBLocalRefDConfigBean ejbRef1 = (EJBLocalRefDConfigBean) webApp.getDConfigBean(ddBeans[1]);
097: assertNotNull(ejbRef0);
098: assertEquals(ddBeans[0], ejbRef0.getDDBean());
099: assertNotNull(ejbRef1);
100: assertEquals(ddBeans[1], ejbRef1.getDDBean());
101: assertTrue(ejbRef0 != ejbRef1);
102: }
103: */
104:
105: protected void setUp() throws Exception {
106: super .setUp();
107: ClassLoader classLoader = Thread.currentThread()
108: .getContextClassLoader();
109: URL warDir = classLoader.getResource("deployables/war1/");
110: deployable = new WebDeployable(warDir);
111: config = new WARConfiguration(deployable);
112:
113: ddBeanRoot = deployable.getDDBeanRoot();
114: configRoot = (WebAppDConfigRoot) config
115: .getDConfigBeanRoot(ddBeanRoot);
116: }
117:
118: protected void tearDown() throws Exception {
119: super.tearDown();
120: }
121: }
|