1 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 37 public class AXIModelPerfTest extends AbstractTestCase { 38 39 public static final String TEST_XSD = "resources/OTA_TravelItinerary.xsd"; 40 public static final String CYCLE_XSD = "resources/cycle.xsd"; 41 42 45 public AXIModelPerfTest(String 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 { 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 { 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 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 |