KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > sync > SyncPerfTest


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.sync;
21
22 import junit.framework.*;
23 import org.netbeans.modules.xml.axi.AXIModel;
24 import org.netbeans.modules.xml.axi.visitor.DeepAXITreeVisitor;
25 import org.netbeans.modules.xml.schema.model.GlobalElement;
26 import org.netbeans.modules.xml.schema.model.SchemaModel;
27
28         
29 /**
30  * The unit test covers various use cases of sync on Element
31  * and ElementRef.
32  *
33  * @author Samaresh (Samaresh.Panda@Sun.Com)
34  */

35 public class SyncPerfTest extends AbstractSyncTestCase {
36                 
37     public static final String JavaDoc OTA_XSD = "resources/OTA_TravelItinerary.xsd";
38     public static final String JavaDoc HL7_XSD = "resources/hl7/fields.xsd";
39     
40     /**
41      * SyncElementTest
42      */

43     public SyncPerfTest(String JavaDoc testName) {
44         super(testName, HL7_XSD, null);
45     }
46         
47     public static Test suite() {
48         TestSuite suite = new TestSuite(SyncPerfTest.class);
49         return suite;
50     }
51
52     public void testHealthcareSchemaSyncPerformance() {
53         doRun(getSchemaModel(), getAXIModel(), false);
54         //doRun(getSchemaModel(), getAXIModel(), true);
55
}
56     
57 // public void testOTASyncPerformance() throws Exception {
58
// AXIModel hlModel = getModel(OTA_XSD);
59
// doRun(hlModel.getSchemaModel(), hlModel, false);
60
// doRun(hlModel.getSchemaModel(), hlModel, true);
61
// }
62

63     private void doRun(SchemaModel sModel, AXIModel aModel, boolean worstCase) {
64         if(worstCase) {
65             DeepAXITreeVisitor visitor = new DeepAXITreeVisitor();
66             visitor.visit(aModel.getRoot());
67         }
68         int schemaChildCount = sModel.getSchema().getChildren().size();
69         int axiChildCount = aModel.getRoot().getChildren().size();
70         try {
71             getSchemaModel().startTransaction();
72             GlobalElement ge = getSchemaModel().getFactory().createGlobalElement();
73             ge.setName("NewGlobalElement");
74             getSchemaModel().getSchema().addElement(ge);
75             getSchemaModel().endTransaction();
76             long startTime = System.currentTimeMillis();
77             getAXIModel().sync();
78             long endTime = System.currentTimeMillis();
79             print("Time taken to sync: " +
80                     (endTime - startTime));
81         } catch(Exception JavaDoc ex) {
82             ex.printStackTrace();
83         }
84         assert(schemaChildCount+1 == sModel.getSchema().getChildren().size());
85         assert(axiChildCount+1 == aModel.getRoot().getChildren().size());
86     }
87 }
88
Popular Tags