KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > SchemaGeneratorPerf2Test


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 package org.netbeans.modules.xml.axi;
21
22 import javax.swing.text.Document JavaDoc;
23 import junit.framework.*;
24 import org.netbeans.modules.xml.schema.model.LocalElement;
25 import org.netbeans.modules.xml.schema.model.SchemaModel;
26 import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel;
27
28
29 /**
30  *
31  * @author Ayub Khan
32  */

33 public class SchemaGeneratorPerf2Test extends AbstractTestCase {
34     
35     public static final String JavaDoc TEST_XSD = "resources/LoanApplication.xsd";
36     public static final String JavaDoc GLOBAL_ELEMENT = "autoLoanApplication";
37     
38     private Document JavaDoc doc = null;
39     
40     public SchemaGeneratorPerf2Test(String JavaDoc testName) {
41         super(testName, TEST_XSD, GLOBAL_ELEMENT);
42     }
43     
44     protected void setUp() throws Exception JavaDoc {
45         super.setUp();
46     }
47     
48     public static Test suite() {
49         TestSuite suite = new TestSuite(SchemaGeneratorPerf2Test.class);
50         
51         return suite;
52     }
53     
54     public void testGenerateSchema() throws Exception JavaDoc {
55         Element element = globalElement;
56         assertNotNull(element);
57         SchemaModel sm = null;
58         sm = getSchemaModel();
59         doc = ((AbstractDocumentModel)sm).getBaseDocument();
60         //global element name change
61
axiModel.startTransaction();
62         for(Element e:axiModel.getRoot().getElements())
63             if(e.getName().equals(GLOBAL_ELEMENT))
64                 e.setName(e.getName()+"_");
65         long startTime = System.currentTimeMillis();
66         axiModel.endTransaction();
67         long endTime = System.currentTimeMillis();
68         print("Time taken to flush: "+(endTime-startTime)+" ms");
69         validateSchema(axiModel.getSchemaModel());
70     }
71     
72     public void testGenerateSchema2() {
73         assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size());
74         Element element = axiModel.getComponentFactory().createElement();
75         element.setName("MyElement");
76         
77         axiModel.startTransaction();
78         try {
79             for(Element e:axiModel.getRoot().getElements())
80                 if(e.getName().equals(GLOBAL_ELEMENT+"_"))
81                     e.getCompositor().addElement(element);
82         } finally {
83             axiModel.endTransaction();
84         }
85         assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size());
86         assertEquals("global elements","MyElement",((LocalElement)getSchemaModel().getSchema().getElements().iterator().next().//autoLoanApp
87
getChildren().get(1).//complexType
88
getChildren().get(0).//sequence
89
getChildren().get(7)).getName());//NewElement
90
validateSchema(axiModel.getSchemaModel());
91 // try {
92
// SchemaModel sm = getSchemaModel();
93
// doc = ((AbstractDocumentModel)sm).getBaseDocument();
94
// print("doc: "+doc.getText(0, doc.getLength()));
95
// } catch (BadLocationException ex) {
96
// ex.printStackTrace();
97
// }
98

99         axiModel.startTransaction();
100         try {
101             for(Element e:axiModel.getRoot().getElements())
102                 if(e.getName().equals(GLOBAL_ELEMENT+"_"))
103                     e.getCompositor().removeElement(element);
104         } finally {
105             axiModel.endTransaction();
106         }
107         assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size());
108         validateSchema(axiModel.getSchemaModel());
109 // try {
110
// SchemaModel sm = getSchemaModel();
111
// doc = ((AbstractDocumentModel)sm).getBaseDocument();
112
// print("doc: "+doc.getText(0, doc.getLength()));
113
// } catch (BadLocationException ex) {
114
// ex.printStackTrace();
115
// }
116
}
117     
118     public void testDeleteExistingGlobalElement() {
119         assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size());
120         Element element = axiModel.getComponentFactory().createElement();
121         element.setName("NewElement"+axiModel.getRoot().getElements().size());
122         //global element name change
123
axiModel.startTransaction();
124         try {
125             for(Element e:axiModel.getRoot().getElements())
126                 if(e.getName().equals(GLOBAL_ELEMENT+"_"))
127                     axiModel.getRoot().removeElement(e);
128         } finally {
129             axiModel.endTransaction();
130         }
131         assertEquals("global elements",0,getSchemaModel().getSchema().getElements().size());
132         validateSchema(axiModel.getSchemaModel());
133 // try {
134
// SchemaModel sm = getSchemaModel();
135
// doc = ((AbstractDocumentModel)sm).getBaseDocument();
136
// print("doc: "+doc.getText(0, doc.getLength()));
137
// } catch (BadLocationException ex) {
138
// ex.printStackTrace();
139
// }
140
}
141 }
142
Popular Tags