KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestWebAppDelegatorBaseBean


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 /*
21  * TestWebAppDelegatorBaseBean - test the basic features.
22  *
23  * The following test assumes that we know the content of the
24  * graph as we get elements, add and change them. Therefore, the TestWebAppDelegatorBaseBean.xml
25  * file and this java test should be kept in sync.
26  *
27  * Test the following:
28  *
29  * single String: get/set/remove/set/get
30  * boolean (from true): get/set true/get/set false/get/set true/get
31  * boolean (from false): get/set false/get/set true/get/set false/get
32  * String[]: get/set (null & !null)/add/remove
33  * Bean: remove/set(null)/create bean and graph of beans/set/add
34  *
35  */

36
37 import java.io.*;
38 import java.util.*;
39 import org.w3c.dom.*;
40
41 import webapp.*;
42
43
44 public class TestWebAppDelegatorBaseBean extends BaseTest {
45     public static void main(String JavaDoc[] argv) {
46         TestWebAppDelegatorBaseBean o = new TestWebAppDelegatorBaseBean();
47         if (argv.length > 0)
48             o.setDocumentDir(argv[0]);
49         try {
50             o.run();
51         } catch (Exception JavaDoc e) {
52             e.printStackTrace();
53             System.exit(1);
54         }
55         System.exit(0);
56     }
57     
58     public void run() throws Exception JavaDoc {
59         WebAppDelegator webApp;
60
61         this.readDocument();
62
63         out("creating the bean graph");
64         webApp = WebAppDelegator.createGraph(doc);
65
66         // Check that we can read the graph and it is complete
67
out("bean graph created");
68         webApp.write(out);
69
70         out("making some minor changes");
71         webApp.setDescription(0, "Changed the description");
72         webApp.getFilter(0).setFilterClass("foo");
73         webApp.write(out);
74
75         out("set some goodnesses");
76         SecurityConstraintType sc = new SecurityConstraintType();
77         webApp.addSecurityConstraint(sc);
78         sc.setAuthConstraint(new AuthConstraintType());
79         sc.getAuthConstraint().addGoodPresidentCandidate(true);
80         sc.getAuthConstraint().addGoodPresidentCandidate(false);
81         boolean firstCandiateGoodness = sc.getAuthConstraint().isGoodPresidentCandidate(0);
82         check(firstCandiateGoodness == true, "firstCandiateGoodness is good");
83         boolean[] allCandidateGoodnesses = sc.getAuthConstraint().getGoodPresidentCandidate();
84         check(allCandidateGoodnesses.length == 2, "2 candidates goodness");
85         check(allCandidateGoodnesses[0] == true, "candidate 0 is good");
86         check(allCandidateGoodnesses[1] == false, "candidate 1 is not good");
87         webApp.write(out);
88
89         try {
90             webApp.validate();
91             check(false, "Failed to get validate exception");
92         } catch (org.netbeans.modules.schema2beans.ValidateException e) {
93             check(true, "Got good validate exception: "+e.getMessage());
94         }
95         webApp.setVersion("2.4");
96         try {
97             webApp.validate();
98             check(false, "Failed to get validate exception");
99         } catch (org.netbeans.modules.schema2beans.ValidateException e) {
100             check(true, "Got good validate exception: "+e.getMessage());
101         }
102         sc.addWebResourceCollection(new WebResourceCollectionType());
103         try {
104             webApp.validate();
105             check(false, "Failed to get validate exception");
106         } catch (org.netbeans.modules.schema2beans.ValidateException e) {
107             check(true, "Got good validate exception: "+e.getMessage());
108         }
109         sc.getWebResourceCollection(0).setWebResourceName("blue");
110         try {
111             webApp.validate();
112             check(false, "Failed to get validate exception");
113         } catch (org.netbeans.modules.schema2beans.ValidateException e) {
114             check(true, "Got good validate exception: "+e.getMessage());
115         }
116         sc.getWebResourceCollection(0).addUrlPattern("*.html");
117         webApp.write(out);
118         webApp.validate();
119
120         out("Add some descriptions with xml:lang attributes.");
121         webApp.setDescriptionXmlLang(0, "en");
122         webApp.addDescription("Das ist mein App.");
123         webApp.setDescriptionXmlLang(1, "de");
124         webApp.validate();
125         webApp.write(out);
126
127         out("Test multiple things");
128         check("thing1".equals(webApp.getThing().getFilterName()), "thing1");
129         check("thing2".equals(webApp.getThing2().getFilterName()), "thing2");
130         check("thing3".equals(webApp.getThing3().getFilterName()), "thing3");
131
132         webApp._setSchemaLocation("http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd");
133         webApp.write(out);
134     }
135 }
136
Popular Tags