KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SunONEDeploymentConfigurationTest.java
21  * JUnit based test
22  *
23  * Created on March 11, 2004, 12:24 PM
24  */

25
26 package org.netbeans.modules.j2ee.sun.share.configbean;
27
28 import java.io.InputStream JavaDoc;
29 import java.io.OutputStream JavaDoc;
30 import java.io.StringBufferInputStream JavaDoc;
31 import java.io.StringWriter JavaDoc;
32 import java.io.File JavaDoc;
33 import java.io.FileInputStream JavaDoc;
34 import java.io.FileOutputStream JavaDoc;
35 import java.io.ByteArrayInputStream JavaDoc;
36 import java.io.ByteArrayOutputStream JavaDoc;
37 import java.util.ArrayList JavaDoc;
38 import java.util.Collections JavaDoc;
39 import java.util.HashMap JavaDoc;
40 import java.util.Iterator JavaDoc;
41 import java.util.LinkedHashMap JavaDoc;
42 import java.util.List JavaDoc;
43 import java.util.Map JavaDoc;
44 import java.util.Set JavaDoc;
45 import junit.framework.*;
46 import org.netbeans.modules.schema2beans.BaseBean;
47 import org.netbeans.modules.schema2beans.Schema2BeansRuntimeException;
48 import javax.enterprise.deploy.model.DDBean JavaDoc;
49 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
50 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
51 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
52 import javax.enterprise.deploy.spi.DConfigBeanRoot JavaDoc;
53 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
54 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException JavaDoc;
55 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
56 import org.netbeans.modules.j2ee.sun.share.Constants;
57 import org.netbeans.modules.j2ee.sun.share.SunDeploymentManager;
58 import org.netbeans.modules.j2ee.sun.share.plan.DeploymentPlan;
59 import org.netbeans.modules.j2ee.sun.share.plan.FileEntry;
60 import org.netbeans.modules.j2ee.sun.common.dd.webapp.SunWebApp;
61
62 import org.netbeans.modules.j2ee.sun.share.SunDeploymentFactory;
63 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
64 import org.netbeans.modules.j2ee.sun.share.MockDeployableObject;
65 import org.netbeans.modules.j2ee.sun.share.TestConstants;
66 /**
67  *
68  * @author vkraemer
69  */

70 public class SunONEDeploymentConfigurationTest extends TestCase {
71     
72     public void testRemove() {
73         WebAppRoot war = null;
74         try {
75             war = (WebAppRoot) dc2.getDConfigBeanRoot(waddbean);
76             assertNotNull(war);
77             dc2.removeDConfigBean(war);
78             //war = (WebAppRoot) dc2.getDConfigBeanRoot(waddbean);
79
dc2.removeDConfigBean(war);
80             fail("I should not be here");
81         }
82         catch (BeanNotFoundException JavaDoc bnfe) {
83             assertTrue(bnfe.getMessage().startsWith("No match for"));
84         }
85         catch (ConfigurationException JavaDoc ce) {
86             ce.printStackTrace();
87         }
88     }
89         
90     
91     public void testDirectoryDeploySupport() {
92             WebAppRoot war = null;
93             try {
94                 war = (WebAppRoot) warDC.getDConfigBeanRoot(waddbean);
95                 assertNotNull(war);
96                 war.setContextRoot("myTestCR");
97                 java.io.File JavaDoc f = new java.io.File JavaDoc("sun-web.xml");
98                 f.createNewFile();
99                 warDC.extractFileFromPlanForModule(f, warDC.getDeployableObject()); // DeployableObject mod)
100
war.setContextRoot("anotherCR");
101                 warDC.addFileToPlanForModule(f, warDC.getDeployableObject());
102                 assertEquals(war.getContextRoot(), "myTestCR");
103             }
104             catch (java.io.IOException JavaDoc ioe) {
105                 ioe.printStackTrace();
106                 fail("got an ioe");
107             }
108             catch (java.beans.PropertyVetoException JavaDoc pve) {
109                 pve.printStackTrace();
110                 fail("got a pve");
111             }
112             catch (ConfigurationException JavaDoc ce) {
113                 ce.printStackTrace();
114                 fail("go a ce");
115             }
116     }
117     
118     public void testContextRootStuff() {
119             WebAppRoot war = null;
120             try {
121                 war = (WebAppRoot) warDC.getDConfigBeanRoot(waddbean);
122                 assertNotNull(war);
123                 war.setContextRoot("testContextRootValue");
124                 assertEquals(war.getContextRoot(), warDC.getContextRoot());
125                 warDC.setContextRoot("newContextRoot");
126                 assertEquals(war.getContextRoot(), warDC.getContextRoot());
127             }
128             catch (java.beans.PropertyVetoException JavaDoc pve) {
129                 pve.printStackTrace();
130                 fail("got a pve");
131             }
132             catch (ConfigurationException JavaDoc ce) {
133                 ce.printStackTrace();
134                 fail("got a ce");
135             }
136     }
137         
138         
139     public void testSaveRestore() {
140         try {
141             java.io.ByteArrayOutputStream JavaDoc baos =
142                 new java.io.ByteArrayOutputStream JavaDoc();
143             //warDC.save(baos);
144
//assertEquals("<sun-web-app></sun-web-app>",baos.toString());
145
/*MockDDBeanRoot waddbean = new MockDDBeanRoot();
146             /*waddbean.setXpath("/web-app");
147             waddbean.setRoot(waddbean);*/

148             WebAppRoot war = null;
149             war = (WebAppRoot) warDC.getDConfigBeanRoot(waddbean);
150             assertNotNull(war);
151             war.setContextRoot("testContextRootValue");
152             baos = new java.io.ByteArrayOutputStream JavaDoc();
153             warDC.save(baos);
154             assertTrue(baos.toString().indexOf("testContextRootValue") > 0);
155             war.setContextRoot("ContextRootValueTest");
156             warDC.restore(new java.io.ByteArrayInputStream JavaDoc(baos.toByteArray()));
157             assertEquals(war.getContextRoot(), "testContextRootValue");
158             //assertFalse(baos.toString()
159
}
160         catch (java.beans.PropertyVetoException JavaDoc pve) {
161             fail("setter got veto'ed");
162         }
163         catch (ConfigurationException JavaDoc ce) {
164             ce.printStackTrace();
165             fail("check on this");
166         }
167     }
168     
169     public void testCreate() {
170         assertNotNull(warDC);
171     }
172     
173     public SunONEDeploymentConfigurationTest(java.lang.String JavaDoc testName) {
174         super(testName);
175     }
176     
177     static SunDeploymentFactory DF = new SunDeploymentFactory();
178     static DeploymentManager DM = null;
179     static SunONEDeploymentConfiguration warDC = null;
180     static DConfigBeanRoot JavaDoc WAR = null;
181     static MockDDBeanRoot waddbean = null;
182     static DeploymentConfiguration JavaDoc dc2 = null;
183     static {
184         try {
185             DM = DF.getDisconnectedDeploymentManager("deployer:Sun:AppServer::localhost:4848");
186             MockDeployableObject dObj = new MockDeployableObject();
187             waddbean = new MockDDBeanRoot();
188             waddbean.setXpath("/web-app");
189             dObj.setDDBeanRoot(waddbean);
190             waddbean.setRoot(waddbean);
191             warDC = (SunONEDeploymentConfiguration) DM.createConfiguration(dObj);
192             dc2 = DM.createConfiguration(dObj);
193 // WAR = DC.getDConfigBeanRoot(new MockDDBeanRoot());
194
}
195         catch (Throwable JavaDoc t) {
196             fail(t.getMessage());
197         }
198     }
199
200
201     
202 }
203
Popular Tags