1 19 20 package org.netbeans.modules.xml.axi; 21 22 import java.io.IOException ; 23 import java.util.Iterator ; 24 import javax.swing.text.BadLocationException ; 25 import javax.swing.text.Document ; 26 import junit.framework.*; 27 import org.netbeans.modules.xml.axi.impl.AttributeImpl; 28 import org.netbeans.modules.xml.axi.impl.AttributeProxy; 29 import org.netbeans.modules.xml.schema.model.Choice; 30 import org.netbeans.modules.xml.schema.model.ComplexExtension; 31 import org.netbeans.modules.xml.schema.model.ComplexTypeDefinition; 32 import org.netbeans.modules.xml.schema.model.GlobalAttributeGroup; 33 import org.netbeans.modules.xml.schema.model.GlobalComplexType; 34 import org.netbeans.modules.xml.schema.model.GlobalElement; 35 import org.netbeans.modules.xml.schema.model.LocalAttribute; 36 import org.netbeans.modules.xml.schema.model.SchemaModel; 37 import org.netbeans.modules.xml.schema.model.Sequence; 38 import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel; 39 40 41 45 public class SchemaTransformTest extends AbstractTestCase { 46 47 public static final String LINE_RUSSIAN_DOLL_XSD = "resources/line_RussianDoll.xsd"; 48 public static final String LINE_VENETIAN_BLIND_XSD = "resources/line_VenetianBlind.xsd"; 49 public static final String LINE_SALAMI_SLICE_XSD = "resources/line_SalamiSlice.xsd"; 50 public static final String LINE_GARDEN_OF_EDEN_XSD = "resources/line_GardenOfEden.xsd"; 51 public static final String LOAN_APP_XSD = "resources/LoanApplication.xsd"; 52 public static final String PO_XSD = "resources/po.xsd"; 53 public static final String TYPES_XSD = "resources/types.xsd"; 54 public static final String RECURSION_PO_XSD = "resources/recursion_po.xsd"; 55 public static final String ANNOTATION_XSD = "resources/annotation.xsd"; 56 public static final String NEWPO_XSD = "resources/newpo.xsd"; 57 public static final String NEWPO1_XSD = "resources/newpo1.xsd"; 58 public static final String COURIER_XSD = "resources/courier.xsd"; 59 public static final String INCLUDE_XSD = "resources/include.xsd"; 60 public static final String IMPORT_XSD = "resources/import.xsd"; 61 public static final String ELEMENT_REUSE_XSD = "resources/elementreuse.xsd"; 62 public static final String ELEMENT_REUSE1_XSD = "resources/elementreuse1.xsd"; 63 public static final String ELEMENT_REUSE2_XSD = "resources/elementreuse2.xsd"; 64 public static final String TYPE_REUSE_XSD = "resources/typereuse.xsd"; 65 public static final String GLOBAL_ELEMENT = "Line"; 66 67 private Document doc = null; 68 69 public SchemaTransformTest(String testName) { 70 super(testName, LINE_RUSSIAN_DOLL_XSD, GLOBAL_ELEMENT); 71 } 72 73 public static Test suite() { 74 TestSuite suite = new TestSuite(); 76 suite.addTest(new SchemaTransformTest("testFindUsageVisitor")); 77 suite.addTest(new SchemaTransformTest("testLineGardenOfEden")); 78 suite.addTest(new SchemaTransformTest("testLineSalamiSlice")); 79 suite.addTest(new SchemaTransformTest("testLineVenetianBlind")); 80 suite.addTest(new SchemaTransformTest("testLineRussianDoll")); 81 suite.addTest(new SchemaTransformTest("testTypes")); 82 suite.addTest(new SchemaTransformTest("testLoanApp")); 83 suite.addTest(new SchemaTransformTest("testAnnotation")); 84 suite.addTest(new SchemaTransformTest("testPurchaseOrder")); 85 suite.addTest(new SchemaTransformTest("testRenameAfterTransform")); 87 suite.addTest(new SchemaTransformTest("testMultiSchemaInclude")); 89 suite.addTest(new SchemaTransformTest("testMultiSchemaImport")); 90 suite.addTest(new SchemaTransformTest("testGlobalElementReuse")); 91 suite.addTest(new SchemaTransformTest("testGlobalElementReuse1")); 92 suite.addTest(new SchemaTransformTest("testGlobalElementReuse2")); 93 suite.addTest(new SchemaTransformTest("testContentModelReuse")); 94 return suite; 95 } 96 97 public void testFindUsageVisitor() { 98 print("testFindUsageVisitor"); 99 try { 100 loadModel(RECURSION_PO_XSD); 101 } catch (Exception ex) { 102 ex.printStackTrace(); 103 assertTrue("Should not be here", false); 104 } 105 assertEquals("global complex types",2,getSchemaModel().getSchema().getComplexTypes().size()); 106 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 107 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 108 try { 109 SchemaGeneratorFactory.getDefault().transformSchema( 110 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 111 } catch (IOException ex) { 112 assertTrue("Should not be here", false); 114 } 115 validateSchema(axiModel.getSchemaModel()); 116 117 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 119 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 120 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 121 } 122 123 public void testLineGardenOfEden() { 124 print("testLineGardenOfEden"); 125 try { 126 loadModel(LINE_RUSSIAN_DOLL_XSD); 127 } catch (Exception ex) { 128 assertTrue("Should not be here", false); 130 } 131 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 132 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 133 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 134 try { 135 SchemaGeneratorFactory.getDefault().transformSchema( 136 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 137 } catch (IOException ex) { 138 assertTrue("Should not be here", false); 140 } 141 validateSchema(axiModel.getSchemaModel()); 142 143 assertEquals("global complex types",3,getSchemaModel().getSchema().getComplexTypes().size()); 145 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 146 assertEquals("global elements",3,getSchemaModel().getSchema().getElements().size()); 147 } 148 149 public void testLineSalamiSlice() { 150 print("testLineSalamiSlice"); 151 try { 152 loadModel(LINE_GARDEN_OF_EDEN_XSD); 153 } catch (Exception ex) { 154 assertTrue("Should not be here", false); 156 } 157 assertEquals("global complex types",2,getSchemaModel().getSchema().getComplexTypes().size()); 158 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 159 assertEquals("global elements",3,getSchemaModel().getSchema().getElements().size()); 160 try { 161 SchemaGeneratorFactory.getDefault().transformSchema( 162 axiModel.getSchemaModel(), SchemaGenerator.Pattern.SALAMI_SLICE); 163 } catch (IOException ex) { 164 assertTrue("Should not be here", false); 166 } 167 validateSchema(axiModel.getSchemaModel()); 168 169 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 171 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 172 assertEquals("global elements",3,getSchemaModel().getSchema().getElements().size()); 173 } 174 175 public void testLineVenetianBlind() { 176 print("testLineVenetianBlind"); 177 try { 178 loadModel(LINE_SALAMI_SLICE_XSD); 179 } catch (Exception ex) { 180 assertTrue("Should not be here", false); 182 } 183 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 184 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 185 assertEquals("global elements",3,getSchemaModel().getSchema().getElements().size()); 186 try { 187 SchemaGeneratorFactory.getDefault().transformSchema( 188 axiModel.getSchemaModel(), SchemaGenerator.Pattern.VENITIAN_BLIND); 189 } catch (IOException ex) { 190 assertTrue("Should not be here", false); 192 } 193 validateSchema(axiModel.getSchemaModel()); 194 195 assertEquals("global complex types",2,getSchemaModel().getSchema().getComplexTypes().size()); 197 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 198 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 199 } 200 201 public void testLineRussianDoll() { 202 print("testLineRussianDoll"); 203 try { 204 loadModel(LINE_VENETIAN_BLIND_XSD); 205 } catch (Exception ex) { 206 assertTrue("Should not be here", false); 208 } 209 assertEquals("global complex types",1,getSchemaModel().getSchema().getComplexTypes().size()); 210 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 211 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 212 try { 213 SchemaGeneratorFactory.getDefault().transformSchema( 214 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 215 } catch (IOException ex) { 216 assertTrue("Should not be here", false); 218 } 219 validateSchema(axiModel.getSchemaModel()); 220 221 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 223 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 224 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 225 } 226 227 public void testLoanApp() { 228 print("testLoanApp"); 229 try { 230 loadModel(LOAN_APP_XSD); 231 } catch (Exception ex) { 232 assertTrue("Should not be here", false); 234 } 235 assertEquals("global complex types",7,getSchemaModel().getSchema().getComplexTypes().size()); 236 assertEquals("global simple types",2,getSchemaModel().getSchema().getSimpleTypes().size()); 237 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 238 239 try { 241 long start = System.currentTimeMillis(); 242 SchemaGeneratorFactory.getDefault().transformSchema( 243 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 244 long end = System.currentTimeMillis(); 245 print("Time taken to transform from VB to RD: "+(end-start)+"ms"); 246 } catch (IOException ex) { 247 assertTrue("Should not be here", false); 249 } 250 validateSchema(axiModel.getSchemaModel()); 251 252 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 254 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 255 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 256 257 assertEquals("AXI content models",0,axiModel.getRoot().getContentModels().size()); 258 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 259 260 try { 262 long start = System.currentTimeMillis(); 263 SchemaGeneratorFactory.getDefault().transformSchema( 264 axiModel.getSchemaModel(), SchemaGenerator.Pattern.VENITIAN_BLIND); 265 long end = System.currentTimeMillis(); 266 print("Time taken to transform from RD to VB: "+(end-start)+"ms"); 267 } catch (IOException ex) { 268 assertTrue("Should not be here", false); 270 } 271 validateSchema(axiModel.getSchemaModel()); 272 273 assertEquals("global complex types",17,getSchemaModel().getSchema().getComplexTypes().size()); 275 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 278 279 assertEquals("AXI content models",17,axiModel.getRoot().getContentModels().size()); 280 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 281 282 try { 284 long start = System.currentTimeMillis(); 285 286 SchemaGeneratorFactory.getDefault().transformSchema( 287 axiModel.getSchemaModel(), SchemaGenerator.Pattern.SALAMI_SLICE); 288 long end = System.currentTimeMillis(); 289 print("Time taken to transform from VB to SS: "+(end-start)+"ms"); 290 } catch (IOException ex) { 291 assertTrue("Should not be here", false); 293 } 294 validateSchema(axiModel.getSchemaModel()); 295 296 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 298 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 299 assertEquals("global elements",58,getSchemaModel().getSchema().getElements().size()); 300 301 assertEquals("AXI content models",0,axiModel.getRoot().getContentModels().size()); 302 assertEquals("AXI global elements",58,axiModel.getRoot().getElements().size()); 303 304 try { 306 long start = System.currentTimeMillis(); 307 SchemaGeneratorFactory.getDefault().transformSchema( 308 axiModel.getSchemaModel(), SchemaGenerator.Pattern.VENITIAN_BLIND); 309 long end = System.currentTimeMillis(); 310 print("Time taken to transform from SS to VB: "+(end-start)+"ms"); 311 } catch (IOException ex) { 312 assertTrue("Should not be here", false); 314 } 315 316 assertEquals("global complex types",17,getSchemaModel().getSchema().getComplexTypes().size()); 318 assertEquals("global simple types",19,getSchemaModel().getSchema().getSimpleTypes().size()); 319 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 320 321 assertEquals("AXI content models",17,axiModel.getRoot().getContentModels().size()); 322 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 323 324 try { 326 long start = System.currentTimeMillis(); 327 SchemaGeneratorFactory.getDefault().transformSchema( 328 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 329 long end = System.currentTimeMillis(); 330 print("Time taken to transform from VB to GE: "+(end-start)+"ms"); 331 } catch (IOException ex) { 332 assertTrue("Should not be here", false); 334 } 335 validateSchema(axiModel.getSchemaModel()); 336 337 assertEquals("global complex types",18,getSchemaModel().getSchema().getComplexTypes().size()); 339 assertEquals("global elements",58,getSchemaModel().getSchema().getElements().size()); 342 343 assertEquals("AXI content models",18,axiModel.getRoot().getContentModels().size()); 344 assertEquals("AXI global elements",58,axiModel.getRoot().getElements().size()); 345 346 try { 348 long start = System.currentTimeMillis(); 349 SchemaGeneratorFactory.getDefault().transformSchema( 350 axiModel.getSchemaModel(), SchemaGenerator.Pattern.VENITIAN_BLIND); 351 long end = System.currentTimeMillis(); 352 print("Time taken to transform from GE to VB: "+(end-start)+"ms"); 353 } catch (IOException ex) { 354 assertTrue("Should not be here", false); 356 } 357 validateSchema(axiModel.getSchemaModel()); 358 359 assertEquals("global complex types",17,getSchemaModel().getSchema().getComplexTypes().size()); 361 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 364 365 assertEquals("AXI content models",17,axiModel.getRoot().getContentModels().size()); 366 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 367 } 368 369 public void testPurchaseOrder() { 370 print("testPurchaseOrder"); 371 try { 372 loadModel("resources/po.xsd"); 373 } catch (Exception ex) { 374 assertTrue("Should not be here", false); 376 } 377 assertEquals("global complex types",7,getSchemaModel().getSchema().getComplexTypes().size()); 378 assertEquals("global attribute groups",2,getSchemaModel().getSchema().getAttributeGroups().size()); 379 assertEquals("global groups",2,getSchemaModel().getSchema().getGroups().size()); 380 assertEquals("global attributes",1,getSchemaModel().getSchema().getAttributes().size()); 381 assertEquals("global simple types",2,getSchemaModel().getSchema().getSimpleTypes().size()); 382 assertEquals("global elements",2,getSchemaModel().getSchema().getElements().size()); 383 384 try { 386 long start = System.currentTimeMillis(); 387 SchemaGeneratorFactory.getDefault().transformSchema( 388 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 389 long end = System.currentTimeMillis(); 390 print("Time taken to transform from GE to RD: "+(end-start)+"ms"); 391 } catch (IOException ex) { 392 assertTrue("Should not be here", false); 394 } 395 397 400 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 401 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 402 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 403 404 assertEquals("AXI content models",0,axiModel.getRoot().getContentModels().size()); 405 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 406 407 408 try { 410 long start = System.currentTimeMillis(); 411 SchemaGeneratorFactory.getDefault().transformSchema( 412 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 413 long end = System.currentTimeMillis(); 414 print("Time taken to transform from RD to GE: "+(end-start)+"ms"); 415 } catch (IOException ex) { 416 assertTrue("Should not be here", false); 418 } 419 420 assertEquals("global complex types",7,getSchemaModel().getSchema().getComplexTypes().size()); 422 assertEquals("global simple types",2,getSchemaModel().getSchema().getSimpleTypes().size()); 423 assertEquals("global elements",18,getSchemaModel().getSchema().getElements().size()); 424 425 assertEquals("AXI content models",7,axiModel.getRoot().getContentModels().size()); 426 assertEquals("AXI global elements",18,axiModel.getRoot().getElements().size()); 427 428 try { 430 long start = System.currentTimeMillis(); 431 SchemaGeneratorFactory.getDefault().transformSchema( 432 axiModel.getSchemaModel(), SchemaGenerator.Pattern.SALAMI_SLICE); 433 long end = System.currentTimeMillis(); 434 print("Time taken to transform from GE to SS: "+(end-start)+"ms"); 435 } catch (IOException ex) { 436 assertTrue("Should not be here", false); 438 } 439 442 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 444 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 445 assertEquals("global elements",18,getSchemaModel().getSchema().getElements().size()); 446 447 assertEquals("AXI content models",0,axiModel.getRoot().getContentModels().size()); 448 assertEquals("AXI global elements",18,axiModel.getRoot().getElements().size()); 449 450 try { 452 long start = System.currentTimeMillis(); 453 SchemaGeneratorFactory.getDefault().transformSchema( 454 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 455 long end = System.currentTimeMillis(); 456 print("Time taken to transform from SS to GE: "+(end-start)+"ms"); 457 } catch (IOException ex) { 458 assertTrue("Should not be here", false); 460 } 461 464 assertEquals("global complex types",7,getSchemaModel().getSchema().getComplexTypes().size()); 466 assertEquals("global simple types",2,getSchemaModel().getSchema().getSimpleTypes().size()); 467 assertEquals("global elements",18,getSchemaModel().getSchema().getElements().size()); 468 469 assertEquals("AXI content models",7,axiModel.getRoot().getContentModels().size()); 470 assertEquals("AXI global elements",18,axiModel.getRoot().getElements().size()); 471 472 try { 474 long start = System.currentTimeMillis(); 475 SchemaGeneratorFactory.getDefault().transformSchema( 476 axiModel.getSchemaModel(), SchemaGenerator.Pattern.VENITIAN_BLIND); 477 long end = System.currentTimeMillis(); 478 print("Time taken to transform from GE to VB: "+(end-start)+"ms"); 479 } catch (IOException ex) { 480 assertTrue("Should not be here", false); 482 } 483 486 assertEquals("global complex types",6,getSchemaModel().getSchema().getComplexTypes().size()); 488 assertEquals("global simple types",2,getSchemaModel().getSchema().getSimpleTypes().size()); 489 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 490 491 assertEquals("AXI content models",6,axiModel.getRoot().getContentModels().size()); 492 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 493 494 try { 496 long start = System.currentTimeMillis(); 497 SchemaGeneratorFactory.getDefault().transformSchema( 498 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 499 long end = System.currentTimeMillis(); 500 print("Time taken to transform from VB to GE: "+(end-start)+"ms"); 501 } catch (IOException ex) { 502 assertTrue("Should not be here", false); 504 } 505 508 assertEquals("global complex types",7,getSchemaModel().getSchema().getComplexTypes().size()); 510 assertEquals("global simple types",2,getSchemaModel().getSchema().getSimpleTypes().size()); 511 assertEquals("global elements",18,getSchemaModel().getSchema().getElements().size()); 512 513 assertEquals("AXI content models",7,axiModel.getRoot().getContentModels().size()); 514 assertEquals("AXI global elements",18,axiModel.getRoot().getElements().size()); 515 } 516 517 public void testTypes() { 518 print("testLineGardenOfEden"); 519 try { 520 loadModel(TYPES_XSD); 521 } catch (Exception ex) { 522 assertTrue("Should not be here", false); 524 } 525 assertEquals("global complex types",3,getSchemaModel().getSchema().getComplexTypes().size()); 526 assertEquals("global simple types",7,getSchemaModel().getSchema().getSimpleTypes().size()); 527 assertEquals("global elements",3,getSchemaModel().getSchema().getElements().size()); 528 try { 529 SchemaGeneratorFactory.getDefault().transformSchema( 530 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 531 } catch (IOException ex) { 532 assertTrue("Should not be here", false); 534 } 535 validateSchema(axiModel.getSchemaModel()); 536 537 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 539 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 540 assertEquals("global elements",2,getSchemaModel().getSchema().getElements().size()); 541 } 542 543 public void testAnnotation() { 544 print("testAnnotation"); 545 try { 546 loadModel(ANNOTATION_XSD); 547 } catch (Exception ex) { 548 assertTrue("Should not be here", false); 550 } 551 assertEquals("global complex types",1,getSchemaModel().getSchema().getComplexTypes().size()); 552 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 553 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 554 try { 555 SchemaGeneratorFactory.getDefault().transformSchema( 556 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 557 } catch (IOException ex) { 558 assertTrue("Should not be here", false); 560 } 561 validateSchema(axiModel.getSchemaModel()); 562 563 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 565 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 566 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 567 } 568 569 public void testDiscardTransform() { 570 print("testDiscardTransform"); 571 try { 572 loadModel(NEWPO1_XSD); 573 } catch (Exception ex) { 574 assertTrue("Should not be here", false); 576 } 577 assertPurchaseOrder(); 578 579 Document doc = AbstractDocumentModel.class.cast(getSchemaModel()).getBaseDocument(); 581 String savedDoc = null; 582 try { 583 savedDoc = doc.getText(0, doc.getLength()); 584 } catch (BadLocationException ex) { 585 } 587 try { 588 SchemaGeneratorFactory.getDefault().transformSchema( 589 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 590 } catch (IOException ex) { 591 assertTrue("Should not be here", false); 593 } 594 validateSchema(axiModel.getSchemaModel()); 595 596 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 598 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 599 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 600 601 assertEquals("AXI content models",0,axiModel.getRoot().getContentModels().size()); 602 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 603 604 assertTrue(savedDoc != null); 605 try { 606 doc.remove(0, doc.getLength()); 607 doc.insertString(0, savedDoc, null); 608 getSchemaModel().sync(); 610 axiModel.sync(); 613 String newDoc = doc.getText(0, doc.getLength()); 614 assertEquals("newDoc is not same as saveDoc", newDoc, savedDoc); 615 } catch (BadLocationException ex) { 616 fail("failed"); 618 } catch (IOException ex) { 619 fail("failed"); 621 } 622 625 try { 626 SchemaGeneratorFactory.getDefault().transformSchema( 627 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 628 } catch (IOException ex) { 629 ex.printStackTrace(); 630 assertTrue("Should not be here", false); 631 } 632 validateSchema(axiModel.getSchemaModel()); 633 634 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 636 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 637 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 638 639 assertEquals("AXI content models",0,axiModel.getRoot().getContentModels().size()); 640 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 641 642 try { 643 SchemaGeneratorFactory.getDefault().transformSchema( 644 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 645 } catch (IOException ex) { 646 assertTrue("Should not be here", false); 648 } 649 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 651 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 652 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 653 try { 654 SchemaGeneratorFactory.getDefault().transformSchema( 655 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 656 } catch (IOException ex) { 657 assertTrue("Should not be here", false); 659 } 660 validateSchema(axiModel.getSchemaModel()); 661 662 assertEquals("global complex types",3,getSchemaModel().getSchema().getComplexTypes().size()); 664 assertEquals("global simple types",2,getSchemaModel().getSchema().getSimpleTypes().size()); 665 assertEquals("global elements",6,getSchemaModel().getSchema().getElements().size()); 666 } 667 668 private void assertPurchaseOrder() { 669 assertEquals("global complex types",3,getSchemaModel().getSchema().getComplexTypes().size()); 670 assertEquals("global simple types",1,getSchemaModel().getSchema().getSimpleTypes().size()); 671 assertEquals("global elements",2,getSchemaModel().getSchema().getElements().size()); 672 673 Iterator itge = getSchemaModel().getSchema().getElements().iterator(); 674 GlobalElement po1 = (GlobalElement)itge.next(); 675 if(!po1.getName().equals("purchaseOrder")) 676 po1 = (GlobalElement) itge.next(); 677 GlobalComplexType poType = (GlobalComplexType) po1.getType().get(); 678 ComplexTypeDefinition ctd = poType.getDefinition(); 679 ComplexExtension ce = (ComplexExtension) ctd.getChildren().get(0); 680 GlobalComplexType poTypeBase = ((GlobalComplexType) ce.getBase().get()); 681 GlobalAttributeGroup ag = poTypeBase.getAttributeGroupReferences(). 682 iterator().next().getGroup().get(); 683 684 assertEquals("po's child compositor proxy",1, ce.getChildren(Choice.class).size()); 685 assertEquals("po's child compositor proxy",1, poTypeBase.getChildren(Sequence.class).size()); 686 assertEquals("po's attribute proxy",3, ag.getChildren(LocalAttribute.class).size()); 687 688 assertEquals("AXI content models",5,axiModel.getRoot().getContentModels().size()); 689 assertEquals("AXI global elements",2,axiModel.getRoot().getElements().size()); 690 691 Element po = (Element)axiModel.getRoot().getElements().get(0); 692 if(!po.getName().equals("purchaseOrder")) 693 po = (Element)axiModel.getRoot().getElements().get(1); 694 assertEquals("po's child compositor proxy",2, po.getChildren(Compositor.class).size()); 696 assertEquals("po's attribute proxy",3, po.getChildren(AttributeProxy.class).size()); 697 assertEquals("po's attribute",0, po.getChildren(AttributeImpl.class).size()); 698 } 699 700 public void testRenameAfterTransform() { 701 print("testRenameAfterTransform"); 702 try { 703 loadModel(COURIER_XSD); 704 } catch (Exception ex) { 705 assertTrue("Should not be here", false); 707 } 708 assertEquals("global complex types",1,getSchemaModel().getSchema().getComplexTypes().size()); 709 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 710 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 711 712 assertEquals("AXI content models",1,axiModel.getRoot().getContentModels().size()); 713 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 714 715 Document doc = AbstractDocumentModel.class.cast(getSchemaModel()).getBaseDocument(); 717 String savedDoc = null; 718 try { 719 savedDoc = doc.getText(0, doc.getLength()); 720 } catch (BadLocationException ex) { 721 } 723 try { 724 SchemaGeneratorFactory.getDefault().transformSchema( 725 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 726 } catch (IOException ex) { 727 assertTrue("Should not be here", false); 729 } 730 validateSchema(axiModel.getSchemaModel()); 731 732 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 734 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 735 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 736 737 assertEquals("AXI content models",0,axiModel.getRoot().getContentModels().size()); 738 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 739 740 Attribute first = 741 (Attribute) axiModel.getRoot().getElements().get(0). 742 getChildElements().get(0).getAttributes().get(0); 743 axiModel.startTransaction(); 744 first.setName("first2"); 745 axiModel.endTransaction(); 746 747 try { 748 SchemaGeneratorFactory.getDefault().transformSchema( 749 axiModel.getSchemaModel(), SchemaGenerator.Pattern.VENITIAN_BLIND); 750 } catch (IOException ex) { 751 assertTrue("Should not be here", false); 753 } 754 validateSchema(axiModel.getSchemaModel()); 755 756 Attribute first2 = 757 (Attribute) axiModel.getRoot().getContentModels().get(0). 758 getAttributes().get(0); 759 axiModel.startTransaction(); 760 first2.setName("first3"); 761 axiModel.endTransaction(); 762 763 Attribute first3 = 764 (Attribute) axiModel.getRoot().getElements().get(0). 765 getChildElements().get(0).getAttributes().get(0); 766 assertEquals("attr after rename", "first3", first3.getName()); 767 768 assertEquals("global complex types",1,getSchemaModel().getSchema().getComplexTypes().size()); 770 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 771 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 772 773 assertEquals("AXI content models",1,axiModel.getRoot().getContentModels().size()); 774 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 775 } 776 777 public void testNewApproach() { 778 print("testLineGardenOfEden"); 779 try { 780 loadModel(NEWPO_XSD); 781 } catch (Exception ex) { 782 assertTrue("Should not be here", false); 784 } 785 try { 786 SchemaGeneratorFactory.getDefault().transformSchema( 787 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 788 } catch (IOException ex) { 789 assertTrue("Should not be here", false); 791 } 792 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 794 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 795 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 796 try { 797 SchemaGeneratorFactory.getDefault().transformSchema( 798 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 799 } catch (IOException ex) { 800 assertTrue("Should not be here", false); 802 } 803 validateSchema(axiModel.getSchemaModel()); 804 805 assertEquals("global complex types",3,getSchemaModel().getSchema().getComplexTypes().size()); 807 assertEquals("global elements",13,getSchemaModel().getSchema().getElements().size()); 809 } 810 811 public void testMultiSchemaInclude() { 812 print("testMultiSchemaInclude"); 813 try { 814 loadModel(INCLUDE_XSD); 815 } catch (Exception ex) { 816 ex.printStackTrace(); 817 assertTrue("Should not be here", false); 818 } 819 assertEquals("global complex types",1,getSchemaModel().getSchema().getComplexTypes().size()); 821 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 822 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 823 824 assertEquals("AXI content models",1,axiModel.getRoot().getContentModels().size()); 825 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 826 try { 827 SchemaGeneratorFactory.getDefault().transformSchema( 828 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 829 } catch (IOException ex) { 830 assertTrue("Should not be here", false); 832 } 833 assertEquals("global complex types",1,getSchemaModel().getSchema().getComplexTypes().size()); 835 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 836 assertEquals("global elements",3,getSchemaModel().getSchema().getElements().size()); 837 838 assertEquals("AXI content models",1,axiModel.getRoot().getContentModels().size()); 839 assertEquals("AXI global elements",3,axiModel.getRoot().getElements().size()); 840 } 841 842 public void testMultiSchemaImport() { 843 print("testMultiSchemaInclude"); 844 try { 845 loadModel(IMPORT_XSD); 846 } catch (Exception ex) { 847 assertTrue("Should not be here", false); 849 } 850 assertEquals("global complex types",1,getSchemaModel().getSchema().getComplexTypes().size()); 852 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 853 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 854 855 assertEquals("AXI content models",1,axiModel.getRoot().getContentModels().size()); 856 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 857 try { 858 SchemaGeneratorFactory.getDefault().transformSchema( 859 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 860 } catch (IOException ex) { 861 assertTrue("Should not be here", false); 863 } 864 assertEquals("global complex types",1,getSchemaModel().getSchema().getComplexTypes().size()); 866 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 867 assertEquals("global elements",3,getSchemaModel().getSchema().getElements().size()); 868 869 assertEquals("AXI content models",1,axiModel.getRoot().getContentModels().size()); 870 assertEquals("AXI global elements",3,axiModel.getRoot().getElements().size()); 871 872 try { 873 SchemaGeneratorFactory.getDefault().transformSchema( 874 axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL); 875 } catch (IOException ex) { 876 assertTrue("Should not be here", false); 878 } 879 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 881 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 882 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 883 884 assertEquals("AXI content models",0,axiModel.getRoot().getContentModels().size()); 885 assertEquals("AXI global elements",1,axiModel.getRoot().getElements().size()); 886 } 887 888 public void testGlobalElementReuse() { 889 print("testGlobalElementReuse"); 890 try { 891 loadModel(ELEMENT_REUSE_XSD); 892 } catch (Exception ex) { 893 assertTrue("Should not be here", false); 895 } 896 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 897 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 898 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 899 900 try { 902 long start = System.currentTimeMillis(); 903 SchemaGeneratorFactory.getDefault().transformSchema( 904 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 905 long end = System.currentTimeMillis(); 906 print("Time taken to transform from GE to RD: "+(end-start)+"ms"); 907 } catch (IOException ex) { 908 assertTrue("Should not be here", false); 910 } 911 913 assertEquals("global complex types",4,getSchemaModel().getSchema().getComplexTypes().size()); 914 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 915 assertEquals("global elements",5,getSchemaModel().getSchema().getElements().size()); 916 917 assertEquals("AXI content models",4,axiModel.getRoot().getContentModels().size()); 918 assertEquals("AXI global elements",5,axiModel.getRoot().getElements().size()); 919 } 920 921 public void testGlobalElementReuse1() { 922 print("testGlobalElementReuse1"); 923 try { 924 loadModel(ELEMENT_REUSE1_XSD); 925 } catch (Exception ex) { 926 assertTrue("Should not be here", false); 928 } 929 assertEquals("global complex types",0,getSchemaModel().getSchema().getComplexTypes().size()); 930 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 931 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 932 933 try { 935 long start = System.currentTimeMillis(); 936 SchemaGeneratorFactory.getDefault().transformSchema( 937 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 938 long end = System.currentTimeMillis(); 939 print("Time taken to transform from GE to RD: "+(end-start)+"ms"); 940 } catch (IOException ex) { 941 assertTrue("Should not be here", false); 943 } 944 946 assertEquals("global complex types",3,getSchemaModel().getSchema().getComplexTypes().size()); 947 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 948 assertEquals("global elements",4,getSchemaModel().getSchema().getElements().size()); 949 950 assertEquals("AXI content models",3,axiModel.getRoot().getContentModels().size()); 951 assertEquals("AXI global elements",4,axiModel.getRoot().getElements().size()); 952 953 Iterator it = getSchemaModel().getSchema().getElements().iterator(); 954 assertEquals("global elements","newElement",((GlobalElement)it.next()).getName()); 955 assertEquals("global elements","newElement1",((GlobalElement)it.next()).getName()); 956 assertEquals("global elements","newElement2",((GlobalElement)it.next()).getName()); 957 assertEquals("global elements","newElement3",((GlobalElement)it.next()).getName()); 958 959 Iterator it2 = getSchemaModel().getSchema().getComplexTypes().iterator(); 960 assertEquals("global elements","newElementType",((GlobalComplexType)it2.next()).getName()); 961 assertEquals("global elements","newElementType1",((GlobalComplexType)it2.next()).getName()); 962 assertEquals("global elements","newElementType2",((GlobalComplexType)it2.next()).getName()); 963 } 964 965 public void testGlobalElementReuse2() { 966 print("testGlobalElementReuse2"); 967 try { 968 loadModel(ELEMENT_REUSE2_XSD); 969 } catch (Exception ex) { 970 assertTrue("Should not be here", false); 972 } 973 assertEquals("global complex types",1,getSchemaModel().getSchema().getComplexTypes().size()); 974 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 975 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 976 977 try { 979 long start = System.currentTimeMillis(); 980 SchemaGeneratorFactory.getDefault().transformSchema( 981 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 982 long end = System.currentTimeMillis(); 983 print("Time taken to transform from GE to RD: "+(end-start)+"ms"); 984 } catch (IOException ex) { 985 assertTrue("Should not be here", false); 987 } 988 990 assertEquals("global complex types",2,getSchemaModel().getSchema().getComplexTypes().size()); 991 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 992 assertEquals("global elements",3,getSchemaModel().getSchema().getElements().size()); 993 994 assertEquals("AXI content models",2,axiModel.getRoot().getContentModels().size()); 995 assertEquals("AXI global elements",3,axiModel.getRoot().getElements().size()); 996 } 997 998 public void testContentModelReuse() { 999 print("testContentModelReuse"); 1000 try { 1001 loadModel(TYPE_REUSE_XSD); 1002 } catch (Exception ex) { 1003 assertTrue("Should not be here", false); 1005 } 1006 assertEquals("global complex types",1,getSchemaModel().getSchema().getComplexTypes().size()); 1007 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 1008 assertEquals("global elements",1,getSchemaModel().getSchema().getElements().size()); 1009 1010 try { 1012 long start = System.currentTimeMillis(); 1013 SchemaGeneratorFactory.getDefault().transformSchema( 1014 axiModel.getSchemaModel(), SchemaGenerator.Pattern.GARDEN_OF_EDEN); 1015 long end = System.currentTimeMillis(); 1016 print("Time taken to transform from GE to RD: "+(end-start)+"ms"); 1017 } catch (IOException ex) { 1018 assertTrue("Should not be here", false); 1020 } 1021 1023 assertEquals("global complex types",2,getSchemaModel().getSchema().getComplexTypes().size()); 1024 assertEquals("global simple types",0,getSchemaModel().getSchema().getSimpleTypes().size()); 1025 assertEquals("global elements",5,getSchemaModel().getSchema().getElements().size()); 1026 1027 assertEquals("AXI content models",2,axiModel.getRoot().getContentModels().size()); 1028 assertEquals("AXI global elements",5,axiModel.getRoot().getElements().size()); 1029 1030 Iterator it = getSchemaModel().getSchema().getElements().iterator(); 1031 assertEquals("global elements","test",((GlobalElement)it.next()).getName()); 1032 assertEquals("global elements","street",((GlobalElement)it.next()).getName()); 1033 assertEquals("global elements","name",((GlobalElement)it.next()).getName()); 1034 assertEquals("global elements","city",((GlobalElement)it.next()).getName()); 1035 assertEquals("global elements","state",((GlobalElement)it.next()).getName()); 1036 1037 Iterator it2 = getSchemaModel().getSchema().getComplexTypes().iterator(); 1038 assertEquals("global elements","testType",((GlobalComplexType)it2.next()).getName()); 1039 assertEquals("global elements","nameType",((GlobalComplexType)it2.next()).getName()); 1040 } 1041 1042 private void printDocument() { 1043 try { 1044 SchemaModel sm = getSchemaModel(); 1045 doc = ((AbstractDocumentModel)sm).getBaseDocument(); 1046 System.out.println("doc: "+doc.getText(0, doc.getLength())); 1047 } catch (BadLocationException ex) { 1048 assertTrue("Should not be here", false); 1050 } 1051 } 1052 1053} 1054 | Popular Tags |