KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > WebAppRootTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * WebAppRootTest.java
21  * JUnit based test
22  *
23  * Created on February 23, 2004, 5:22 PM
24  */

25
26 package org.netbeans.modules.j2ee.sun.share.configbean;
27
28 import junit.framework.*;
29 import org.netbeans.modules.j2ee.sun.share.SunDeploymentFactory;
30 import org.netbeans.modules.j2ee.sun.share.MockDeployableObject;
31 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
32 import org.netbeans.modules.j2ee.sun.share.SunDeploymentManager;
33 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
34 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration;
35 import javax.enterprise.deploy.spi.DConfigBeanRoot JavaDoc;
36 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
37
38 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
39
40 /**
41  *
42  * @author vkraemer
43  */

44 public class WebAppRootTest extends TestCase {
45     
46     // requires a fix to Base.constructFileName...
47
//
48
/*public void testGetXPaths() {
49         doTestGetXPaths("");
50     }*/

51
52     public void testGetXPathsAbsolutely() {
53         doTestGetXPaths("/web-app/");
54     }
55     
56     private void doTestGetXPaths(String JavaDoc prefix) {
57         MockDDBeanRoot waddbean = new MockDDBeanRoot();
58         waddbean.setXpath("/web-app");
59         waddbean.setRoot(waddbean);
60         WebAppRoot war = null;
61         try {
62             war = (WebAppRoot) DC.getDConfigBeanRoot(waddbean);
63             assertNotNull(war);
64         }
65         catch (ConfigurationException JavaDoc ce) {
66             fail("this should not fail");
67         }
68         String JavaDoc[] xpaths = war.getXpaths();
69         assertNotNull(xpaths);
70         assertEquals(6, xpaths.length);
71         for (int i = 0; i < xpaths.length; i++) {
72             MockDDBean mddb = new MockDDBean();
73             mddb.setXpath(prefix+xpaths[i]);
74             mddb.setRoot(waddbean);
75             DConfigBean JavaDoc dcb = null;
76             try {
77                 dcb = war.getDConfigBean(mddb);
78                 assertNotNull("got null dcb for xpath: "+xpaths[i],dcb);
79                 if (null != dcb)
80                     try {
81                         war.removeDConfigBean(dcb);
82                     }
83                     catch (javax.enterprise.deploy.spi.exceptions.BeanNotFoundException JavaDoc bnfe) {
84                         fail("got a bean not found, I should not!");
85                     }
86             }
87             catch (ConfigurationException JavaDoc ce) {
88                 ce.printStackTrace();
89                 fail("got a ce for xpath: "+xpaths[i]);
90             }
91             try {
92                 war.removeDConfigBean(dcb);
93                 fail("I should not be able to find the dcb... I had removed it");
94             }
95             catch (javax.enterprise.deploy.spi.exceptions.BeanNotFoundException JavaDoc bnfe) {
96                 assertTrue(bnfe.getMessage(),bnfe.getMessage().startsWith("No match for bean"));
97             }
98         }
99     }
100
101     
102     
103     public void testProperCreate() {
104         MockDDBeanRoot waddbean = new MockDDBeanRoot();
105         WebAppRoot war = null;
106         try {
107             war = (WebAppRoot) DC.getDConfigBeanRoot(null);
108             fail(war.toString());
109         }
110         catch (ConfigurationException JavaDoc ce) {
111             assertEquals("DDBean cannot be null.",ce.getMessage());
112         }
113         try {
114             war = (WebAppRoot) DC.getDConfigBeanRoot(waddbean);
115             fail(war.toString());
116         }
117         catch (ConfigurationException JavaDoc ce) {
118             assertEquals("DDBean cannot have a null Xpath.",ce.getMessage());
119         }
120         waddbean.setXpath("/web-app");
121         waddbean.setRoot(waddbean);
122         try {
123             war = (WebAppRoot) DC.getDConfigBeanRoot(waddbean);
124             assertTrue(war.isValid());
125         }
126         catch (ConfigurationException JavaDoc ce) {
127             fail("I should not fail here");
128         }
129     }
130     
131     static SunDeploymentFactory DF = new SunDeploymentFactory();
132     static DeploymentManager JavaDoc DM = null;
133     static DeploymentConfiguration JavaDoc DC = null;
134     static DConfigBeanRoot JavaDoc WAR = null;
135     static {
136         try {
137             DM = DF.getDisconnectedDeploymentManager("deployer:Sun:AppServer::localhost:4848");
138             DC = DM.createConfiguration(new MockDeployableObject());
139 // WAR = DC.getDConfigBeanRoot(new MockDDBeanRoot());
140
}
141         catch (Throwable JavaDoc t) {
142             fail(t.getMessage());
143         }
144     }
145
146     public WebAppRootTest(java.lang.String JavaDoc testName) {
147         super(testName);
148     }
149     
150 }
151     
152
Popular Tags