KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.*;
23 import org.netbeans.modules.xml.axi.AXIComponent.ComponentType;
24 import org.netbeans.modules.xml.axi.visitor.DeepAXITreeVisitor;
25
26         
27 /**
28  * The test measures the performance by creating an AXI tree for all
29  * elements in the OTA schema. See reverseEngineer().
30  * 1. Run it by making AXIModelBuilder.makeSharable as false.
31  * 2. Run it by making AXIModelBuilder.makeSharable as true.
32  * See the difference in numbers.
33  *
34  *
35  * @author Samaresh (Samaresh.Panda@Sun.Com)
36  */

37 public class AXIModelPerfTest extends AbstractTestCase {
38             
39     public static final String JavaDoc TEST_XSD = "resources/OTA_TravelItinerary.xsd";
40     public static final String JavaDoc CYCLE_XSD = "resources/cycle.xsd";
41         
42     /**
43      * AXIModelPerfTest
44      */

45     public AXIModelPerfTest(String JavaDoc testName) {
46         super(testName, TEST_XSD, null);
47     }
48     
49     public static Test suite() {
50         TestSuite suite = new TestSuite(AXIModelPerfTest.class);
51         
52         return suite;
53     }
54     
55     public void testPerformance() throws Exception JavaDoc {
56         DeepAXITreeVisitor visitor = new DeepAXITreeVisitor();
57         long startTime = System.currentTimeMillis();
58         visitor.visit(getAXIModel().getRoot());
59         long endTime = System.currentTimeMillis();
60         PerfVisitor visitor1 = new PerfVisitor();
61         visitor1.visit(getAXIModel().getRoot());
62         assert(visitor1.getComponentCount() ==
63                getAXIModel().getComponentFactory().getComponentCount());
64         print("Time taken to create AXI model for OTA: " + (endTime - startTime));
65         print(getAXIModel().getComponentFactory().toString());
66     }
67             
68     public void testCyclicSchema() throws Exception JavaDoc {
69         AXIModel cyclicModel = getModel(CYCLE_XSD);
70         DeepAXITreeVisitor visitor = new DeepAXITreeVisitor();
71         long startTime = System.currentTimeMillis();
72         visitor.visit(cyclicModel.getRoot());
73         long endTime = System.currentTimeMillis();
74         print("Time taken to deep visit cyclic schema: " + (endTime - startTime));
75     }
76         
77     private class PerfVisitor extends DeepAXITreeVisitor {
78         long componentCount = 0;
79         public void traverse(AXIDocument document) {
80             document.accept(this);
81         }
82         
83         public long getComponentCount() {
84             return componentCount;
85         }
86
87         protected void visitChildren(AXIComponent component) {
88             componentCount++;
89             ComponentType type = component.getComponentType();
90             AXIComponent original = component.getOriginal();
91             switch(type) {
92                 case PROXY:
93                     assert(component.isShared());
94                     assert(original != component);
95                     if(original.getComponentType() == ComponentType.REFERENCE)
96                         assert(original.isShared());
97                     else
98                         assert(!original.isShared());
99                     //assert(component.getContentModel() != null);
100
break;
101             
102                 case REFERENCE:
103                     assert(component.isShared());
104                     break;
105                 
106                 case SHARED:
107                     assert(!component.isShared());
108                     assert(component.getParent() instanceof AXIDocument);
109                     break;
110                 
111                 case LOCAL:
112                     assert(!component.isShared());
113                     assert(original == component);
114                     break;
115                     
116                 default:
117                     assert(false);
118             }
119             super.visitChildren(component);
120         }
121     }
122     
123 }
124
Popular Tags