KickJava   Java API By Example, From Geeks To Geeks.

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


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

34 public class SchemaTransformPerfTest extends AbstractTestCase {
35     
36 // public static final String OTA_SIMPLE_XSD = "resources/OTA_TravelItinerary.xsd";
37
public static final String JavaDoc OTA_SIMPLE_XSD = "resources/OTA_TI_simple.xsd";
38     public static final String JavaDoc GLOBAL_ELEMENT = "Line";
39     
40     private Document JavaDoc doc = null;
41     
42     public SchemaTransformPerfTest(String JavaDoc testName) {
43         super(testName, OTA_SIMPLE_XSD, GLOBAL_ELEMENT);
44     }
45     
46     public static Test suite() {
47 // TestSuite suite = new TestSuite(DesignPatternTest.class);
48
TestSuite suite = new TestSuite();
49 // suite.addTest(new SchemaTransformPerfTest("testTransformPerf"));
50
return suite;
51     }
52     
53     public void testTransformPerf() {
54         print("testTransformPerf");
55         try {
56             loadModel(OTA_SIMPLE_XSD);
57         } catch (Exception JavaDoc ex) {
58             //ex.printStackTrace();
59
assertTrue("Should not be here", false);
60         }
61         
62         assertEquals("global complex types",3,getSchemaModel().getSchema().getComplexTypes().size());
63         assertEquals("global attribute groups",2,getSchemaModel().getSchema().getAttributeGroups().size());
64         assertEquals("global groups",0,getSchemaModel().getSchema().getGroups().size());
65         assertEquals("global attributes",0,getSchemaModel().getSchema().getAttributes().size());
66         assertEquals("global simple types",3,getSchemaModel().getSchema().getSimpleTypes().size());
67         assertEquals("global elements",3,getSchemaModel().getSchema().getElements().size());
68         
69         //Transform from Venetian Blind to Russian Doll
70
try {
71             long start = System.currentTimeMillis();
72             SchemaGeneratorFactory.getDefault().transformSchema(
73                     axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL);
74             long end = System.currentTimeMillis();
75             print("Time taken to transform from VB to RD: "+(end-start)+"ms");
76         } catch (IOException JavaDoc ex) {
77             //ex.printStackTrace();
78
assertTrue("Should not be here", false);
79         }
80         
81 // printDocument();
82
assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size());
83         assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size());
84         assertEquals("global elements",2,getSchemaModel().getSchema().getElements().size());
85         
86         //Transform from Russian Doll to Venetian Blind
87
try {
88             long start = System.currentTimeMillis();
89             SchemaGeneratorFactory.getDefault().transformSchema(
90                     axiModel.getSchemaModel(), SchemaGenerator.Pattern.VENITIAN_BLIND);
91             long end = System.currentTimeMillis();
92             print("Time taken to transform from RD to VB: "+(end-start)+"ms");
93         } catch (IOException JavaDoc ex) {
94             //ex.printStackTrace();
95
assertTrue("Should not be here", false);
96         }
97         
98 // printDocument();
99
assertEquals("global complex types",2,getSchemaModel().getSchema().getComplexTypes().size());
100         assertEquals("global simple types",5,getSchemaModel().getSchema().getSimpleTypes().size());
101         assertEquals("global elements",2,getSchemaModel().getSchema().getElements().size());
102         
103         //Transform from Venetian Blind to Salami Slice
104
try {
105             long start = System.currentTimeMillis();
106             SchemaGeneratorFactory.getDefault().transformSchema(
107                     axiModel.getSchemaModel(), SchemaGenerator.Pattern.SALAMI_SLICE);
108             long end = System.currentTimeMillis();
109             print("Time taken to transform from VB to SS: "+(end-start)+"ms");
110         } catch (IOException JavaDoc ex) {
111             //ex.printStackTrace();
112
assertTrue("Should not be here", false);
113         }
114         
115 // printDocument();
116
assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size());
117         assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size());
118         assertEquals("global elements",9,getSchemaModel().getSchema().getElements().size());
119         
120         //Transform from Salami Slice to Venetian Blind
121
try {
122             long start = System.currentTimeMillis();
123             SchemaGeneratorFactory.getDefault().transformSchema(
124                     axiModel.getSchemaModel(), SchemaGenerator.Pattern.VENITIAN_BLIND);
125             long end = System.currentTimeMillis();
126             print("Time taken to transform from SS to VB: "+(end-start)+"ms");
127         } catch (IOException JavaDoc ex) {
128             //ex.printStackTrace();
129
assertTrue("Should not be here", false);
130         }
131         
132 // printDocument();
133
assertEquals("global complex types",2,getSchemaModel().getSchema().getComplexTypes().size());
134         assertEquals("global simple types",5,getSchemaModel().getSchema().getSimpleTypes().size());
135         assertEquals("global elements",2,getSchemaModel().getSchema().getElements().size());
136         
137         
138         //Transform from Venetian Blind to Salami Slice
139
try {
140             long start = System.currentTimeMillis();
141             SchemaGeneratorFactory.getDefault().transformSchema(
142                     axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN);
143             long end = System.currentTimeMillis();
144             print("Time taken to transform from VB to GE: "+(end-start)+"ms");
145         } catch (IOException JavaDoc ex) {
146             //ex.printStackTrace();
147
assertTrue("Should not be here", false);
148         }
149         
150 // printDocument();
151
assertEquals("global complex types",2,getSchemaModel().getSchema().getComplexTypes().size());
152         assertEquals("global simple types",5,getSchemaModel().getSchema().getSimpleTypes().size());
153         assertEquals("global elements",9,getSchemaModel().getSchema().getElements().size());
154         
155         //Transform from Salami Slice to Venetian Blind
156
try {
157             long start = System.currentTimeMillis();
158             SchemaGeneratorFactory.getDefault().transformSchema(
159                     axiModel.getSchemaModel(), SchemaGenerator.Pattern.VENITIAN_BLIND);
160             long end = System.currentTimeMillis();
161             print("Time taken to transform from GE to VB: "+(end-start)+"ms");
162         } catch (IOException JavaDoc ex) {
163             //ex.printStackTrace();
164
assertTrue("Should not be here", false);
165         }
166         
167 // printDocument();
168
assertEquals("global complex types",2,getSchemaModel().getSchema().getComplexTypes().size());
169         assertEquals("global simple types",5,getSchemaModel().getSchema().getSimpleTypes().size());
170         assertEquals("global elements",2,getSchemaModel().getSchema().getElements().size());
171     }
172     
173     private void printDocument() {
174         try {
175             SchemaModel sm = getSchemaModel();
176             doc = ((AbstractDocumentModel)sm).getBaseDocument();
177             print("doc: "+doc.getText(0, doc.getLength()));
178         } catch (BadLocationException JavaDoc ex) {
179             //ex.printStackTrace();
180
assertTrue("Should not be here", false);
181         }
182     }
183     
184 }
185
Popular Tags