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.LocalElement; 25 import org.netbeans.modules.xml.schema.model.SchemaModel; 26 import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel; 27 28 29 33 public class SchemaGeneratorPerf2Test extends AbstractTestCase { 34 35 public static final String TEST_XSD = "resources/LoanApplication.xsd"; 36 public static final String GLOBAL_ELEMENT = "autoLoanApplication"; 37 38 private Document doc = null; 39 40 public SchemaGeneratorPerf2Test(String testName) { 41 super(testName, TEST_XSD, GLOBAL_ELEMENT); 42 } 43 44 protected void setUp() throws Exception { 45 super.setUp(); 46 } 47 48 public static Test suite() { 49 TestSuite suite = new TestSuite(SchemaGeneratorPerf2Test.class); 50 51 return suite; 52 } 53 54 public void testGenerateSchema() throws Exception { 55 Element element = globalElement; 56 assertNotNull(element); 57 SchemaModel sm = null; 58 sm = getSchemaModel(); 59 doc = ((AbstractDocumentModel)sm).getBaseDocument(); 60 axiModel.startTransaction(); 62 for(Element e:axiModel.getRoot().getElements()) 63 if(e.getName().equals(GLOBAL_ELEMENT)) 64 e.setName(e.getName()+"_"); 65 long startTime = System.currentTimeMillis(); 66 axiModel.endTransaction(); 67 long endTime = System.currentTimeMillis(); 68 print("Time taken to flush: "+(endTime-startTime)+" ms"); 69 validateSchema(axiModel.getSchemaModel()); 70 } 71 72 public void testGenerateSchema2() { 73 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 74 Element element = axiModel.getComponentFactory().createElement(); 75 element.setName("MyElement"); 76 77 axiModel.startTransaction(); 78 try { 79 for(Element e:axiModel.getRoot().getElements()) 80 if(e.getName().equals(GLOBAL_ELEMENT+"_")) 81 e.getCompositor().addElement(element); 82 } finally { 83 axiModel.endTransaction(); 84 } 85 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 86 assertEquals("global elements","MyElement",((LocalElement)getSchemaModel().getSchema().getElements().iterator().next(). getChildren().get(1). getChildren().get(0). getChildren().get(7)).getName()); validateSchema(axiModel.getSchemaModel()); 91 99 axiModel.startTransaction(); 100 try { 101 for(Element e:axiModel.getRoot().getElements()) 102 if(e.getName().equals(GLOBAL_ELEMENT+"_")) 103 e.getCompositor().removeElement(element); 104 } finally { 105 axiModel.endTransaction(); 106 } 107 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 108 validateSchema(axiModel.getSchemaModel()); 109 } 117 118 public void testDeleteExistingGlobalElement() { 119 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 120 Element element = axiModel.getComponentFactory().createElement(); 121 element.setName("NewElement"+axiModel.getRoot().getElements().size()); 122 axiModel.startTransaction(); 124 try { 125 for(Element e:axiModel.getRoot().getElements()) 126 if(e.getName().equals(GLOBAL_ELEMENT+"_")) 127 axiModel.getRoot().removeElement(e); 128 } finally { 129 axiModel.endTransaction(); 130 } 131 assertEquals("global elements",0,getSchemaModel().getSchema().getElements().size()); 132 validateSchema(axiModel.getSchemaModel()); 133 } 141 } 142 | Popular Tags |