1 19 20 package org.netbeans.modules.xml.axi; 21 22 import javax.swing.text.Document ; 23 import junit.framework.*; 24 import org.netbeans.modules.xml.schema.model.AttributeGroupReference; 25 import org.netbeans.modules.xml.schema.model.Choice; 26 import org.netbeans.modules.xml.schema.model.GlobalAttributeGroup; 27 import org.netbeans.modules.xml.schema.model.GlobalComplexType; 28 import org.netbeans.modules.xml.schema.model.GlobalElement; 29 import org.netbeans.modules.xml.schema.model.LocalAttribute; 30 import org.netbeans.modules.xml.schema.model.LocalComplexType; 31 import org.netbeans.modules.xml.schema.model.LocalElement; 32 import org.netbeans.modules.xml.schema.model.SchemaModel; 33 import org.netbeans.modules.xml.schema.model.SimpleExtension; 34 import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel; 35 36 37 41 public class SchemaGeneratorPerfTest extends AbstractTestCase { 42 43 public static final String TEST_XSD = "resources/OTA_TI_simple.xsd"; public static final String GLOBAL_ELEMENT = "OTA_TravelItineraryRS"; 45 46 private Document doc = null; 47 48 public SchemaGeneratorPerfTest(String testName) { 49 super(testName, TEST_XSD, GLOBAL_ELEMENT); 50 } 51 52 protected void setUp() throws Exception { 53 super.setUp(); 54 } 55 56 public static Test suite() { 57 TestSuite suite = new TestSuite(SchemaGeneratorPerfTest.class); 58 59 return suite; 60 } 61 62 public void testGenerateSchema() throws Exception { 63 generateSchema(); 64 } 65 66 69 public void generateSchema() throws Exception { 70 Element element = globalElement; 71 assertNotNull(element); 72 SchemaModel sm = null; 73 sm = getSchemaModel(); 74 doc = ((AbstractDocumentModel)sm).getBaseDocument(); 75 77 axiModel.startTransaction(); 79 for(Element e:axiModel.getRoot().getElements()) 80 if(e.getName().equals("CancellationStatus")) 81 e.setName(e.getName()+"_"); 82 long startTime = System.currentTimeMillis(); 83 axiModel.endTransaction(); 84 long endTime = System.currentTimeMillis(); 85 print("Time taken to flush: "+(endTime-startTime)+" ms"); 86 94 118 119 axiModel.startTransaction(); 121 for(Element e:axiModel.getRoot().getElements()) { 122 if(e.getName().equals(GLOBAL_ELEMENT)) { 123 for(AXIComponent e2: e.getCompositor().getChildren()) { 124 if(e2 instanceof Element) { 125 if(((Element)e2).getName().equals("Errors")) { 126 AbstractAttribute attr = ((Element)((Element)e2).getChildren().get(0).getChildren().get(0)).getAttributes().get(0); 127 if(attr instanceof Attribute) { 128 ((Attribute)attr).setName("XYZ"); 129 } 130 } 131 } 132 } 133 } 134 } 135 startTime = System.currentTimeMillis(); 136 axiModel.endTransaction(); 137 endTime = System.currentTimeMillis(); 138 print("Time taken to flush: "+(endTime-startTime)+" ms"); 139 140 boolean found = false; 141 for(GlobalElement ge:sm.getSchema().getElements()) { 142 if(ge.getName().startsWith(GLOBAL_ELEMENT)) { 143 LocalComplexType lct = (LocalComplexType) ge.getChildren().get(1); 144 Choice choice = (Choice) lct.getChildren().get(0); 145 LocalElement le = (LocalElement) choice.getChildren().get(1); 146 GlobalComplexType gct = (GlobalComplexType) le.getType().get(); 147 le = (LocalElement) gct.getChildren().get(1).getChildren().get(0); 148 gct = (GlobalComplexType) le.getType().get(); 149 SimpleExtension se = (SimpleExtension) gct.getChildren().get(1).getChildren().get(0); 150 gct = (GlobalComplexType)se.getBase().get(); 151 AttributeGroupReference agr = (AttributeGroupReference)gct.getChildren().get(1).getChildren().get(0).getChildren().get(0); 152 GlobalAttributeGroup gag = agr.getGroup().get(); 153 LocalAttribute la = (LocalAttribute)gag.getChildren().get(1); 154 assertEquals("updated schemamodel", "XYZ", la.getName()); 155 found = true; 156 } 157 } 158 assertTrue("Should have verified updated element", found); 159 validateSchema(axiModel.getSchemaModel()); 160 } 161 162 public void testGenerateSchema2() { 163 assertEquals("global elements",SchemaGeneratorTest.GE_SIZE,getSchemaModel().getSchema().getElements().size()); 164 Element element = axiModel.getComponentFactory().createElement(); 165 element.setName("NewElement"+axiModel.getRoot().getElements().size()); 166 167 axiModel.startTransaction(); 168 try { 169 axiModel.getRoot().addElement(element); 170 } finally { 171 axiModel.endTransaction(); 172 } 173 assertEquals("global elements",SchemaGeneratorTest.GE_SIZE+1,getSchemaModel().getSchema().getElements().size()); 174 175 183 axiModel.startTransaction(); 184 try { 185 axiModel.getRoot().removeElement(element); 186 } finally { 187 axiModel.endTransaction(); 188 } 189 assertEquals("global elements",SchemaGeneratorTest.GE_SIZE,getSchemaModel().getSchema().getElements().size()); 190 validateSchema(axiModel.getSchemaModel()); 191 } 199 200 } 201 | Popular Tags |