KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > SchemaTransformTest


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;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import javax.swing.text.BadLocationException JavaDoc;
25 import javax.swing.text.Document JavaDoc;
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 /**
42  *
43  * @author Ayub Khan
44  */

45 public class SchemaTransformTest extends AbstractTestCase {
46     
47     public static final String JavaDoc LINE_RUSSIAN_DOLL_XSD = "resources/line_RussianDoll.xsd";
48     public static final String JavaDoc LINE_VENETIAN_BLIND_XSD = "resources/line_VenetianBlind.xsd";
49     public static final String JavaDoc LINE_SALAMI_SLICE_XSD = "resources/line_SalamiSlice.xsd";
50     public static final String JavaDoc LINE_GARDEN_OF_EDEN_XSD = "resources/line_GardenOfEden.xsd";
51     public static final String JavaDoc LOAN_APP_XSD = "resources/LoanApplication.xsd";
52     public static final String JavaDoc PO_XSD = "resources/po.xsd";
53     public static final String JavaDoc TYPES_XSD = "resources/types.xsd";
54     public static final String JavaDoc RECURSION_PO_XSD = "resources/recursion_po.xsd";
55     public static final String JavaDoc ANNOTATION_XSD = "resources/annotation.xsd";
56     public static final String JavaDoc NEWPO_XSD = "resources/newpo.xsd";
57     public static final String JavaDoc NEWPO1_XSD = "resources/newpo1.xsd";
58     public static final String JavaDoc COURIER_XSD = "resources/courier.xsd";
59     public static final String JavaDoc INCLUDE_XSD = "resources/include.xsd";
60     public static final String JavaDoc IMPORT_XSD = "resources/import.xsd";
61     public static final String JavaDoc ELEMENT_REUSE_XSD = "resources/elementreuse.xsd";
62     public static final String JavaDoc ELEMENT_REUSE1_XSD = "resources/elementreuse1.xsd";
63     public static final String JavaDoc ELEMENT_REUSE2_XSD = "resources/elementreuse2.xsd";
64     public static final String JavaDoc TYPE_REUSE_XSD = "resources/typereuse.xsd";
65     public static final String JavaDoc GLOBAL_ELEMENT = "Line";
66     
67     private Document JavaDoc doc = null;
68     
69     public SchemaTransformTest(String JavaDoc testName) {
70         super(testName, LINE_RUSSIAN_DOLL_XSD, GLOBAL_ELEMENT);
71     }
72     
73     public static Test suite() {
74 // TestSuite suite = new TestSuite(DesignPatternTest.class);
75
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("testDiscardTransform"));
86
suite.addTest(new SchemaTransformTest("testRenameAfterTransform"));
87         //FIXME suite.addTest(new SchemaTransformTest("testNewApproach"));
88
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 JavaDoc 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 JavaDoc ex) {
112             //ex.printStackTrace();
113
assertTrue("Should not be here", false);
114         }
115         validateSchema(axiModel.getSchemaModel());
116         
117 // printDocument();
118
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 JavaDoc ex) {
128             //ex.printStackTrace();
129
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 JavaDoc ex) {
138             //ex.printStackTrace();
139
assertTrue("Should not be here", false);
140         }
141         validateSchema(axiModel.getSchemaModel());
142         
143 // printDocument();
144
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 JavaDoc ex) {
154             //ex.printStackTrace();
155
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 JavaDoc ex) {
164             //ex.printStackTrace();
165
assertTrue("Should not be here", false);
166         }
167         validateSchema(axiModel.getSchemaModel());
168         
169 // printDocument();
170
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 JavaDoc ex) {
180             //ex.printStackTrace();
181
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 JavaDoc ex) {
190             //ex.printStackTrace();
191
assertTrue("Should not be here", false);
192         }
193         validateSchema(axiModel.getSchemaModel());
194         
195 // printDocument();
196
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 JavaDoc ex) {
206 // ex.printStackTrace();
207
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 JavaDoc ex) {
216             //ex.printStackTrace();
217
assertTrue("Should not be here", false);
218         }
219         validateSchema(axiModel.getSchemaModel());
220         
221 // printDocument();
222
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 JavaDoc ex) {
232             //ex.printStackTrace();
233
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         //Transform from Venetian Blind to Russian Doll
240
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 JavaDoc ex) {
247             //ex.printStackTrace();
248
assertTrue("Should not be here", false);
249         }
250         validateSchema(axiModel.getSchemaModel());
251         
252 // printDocument();
253
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         //Transform from Russian Doll to Venetian Blind
261
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 JavaDoc ex) {
268             //ex.printStackTrace();
269
assertTrue("Should not be here", false);
270         }
271         validateSchema(axiModel.getSchemaModel());
272         
273 // printDocument();
274
assertEquals("global complex types",17,getSchemaModel().getSchema().getComplexTypes().size());
275         //FIXME gives 19 instead of 8
276
// assertEquals("global simple types",8,getSchemaModel().getSchema().getSimpleTypes().size());
277
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         //Transform from Venetian Blind to Salami Slice
283
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 JavaDoc ex) {
291             //ex.printStackTrace();
292
assertTrue("Should not be here", false);
293         }
294         validateSchema(axiModel.getSchemaModel());
295         
296 // printDocument();
297
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         //Transform from Salami Slice to Venetian Blind
305
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 JavaDoc ex) {
312             //ex.printStackTrace();
313
assertTrue("Should not be here", false);
314         }
315         
316 // printDocument();
317
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         //Transform from Venetian Blind to Salami Slice
325
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 JavaDoc ex) {
332             //ex.printStackTrace();
333
assertTrue("Should not be here", false);
334         }
335         validateSchema(axiModel.getSchemaModel());
336         
337 // printDocument();
338
assertEquals("global complex types",18,getSchemaModel().getSchema().getComplexTypes().size());
339         //FIXME should be 19 instead of 38
340
// assertEquals("global simple types",19,getSchemaModel().getSchema().getSimpleTypes().size());
341
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         //Transform from Salami Slice to Venetian Blind
347
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 JavaDoc ex) {
354             //ex.printStackTrace();
355
assertTrue("Should not be here", false);
356         }
357         validateSchema(axiModel.getSchemaModel());
358         
359 // printDocument();
360
assertEquals("global complex types",17,getSchemaModel().getSchema().getComplexTypes().size());
361         //FIXME should be 19 instead of 72
362
// assertEquals("global simple types",19,getSchemaModel().getSchema().getSimpleTypes().size());
363
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 JavaDoc ex) {
374             //ex.printStackTrace();
375
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         //Transform from Garden of Eden to Russian Doll
385
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 JavaDoc ex) {
392             //ex.printStackTrace();
393
assertTrue("Should not be here", false);
394         }
395 // printDocument();
396

397         //TODO - validation fails due to ambigous schema po.xsd
398
// validateSchema(axiModel.getSchemaModel());
399

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         //Transform from Russian Doll to Garden Of Eden
409
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 JavaDoc ex) {
416             //ex.printStackTrace();
417
assertTrue("Should not be here", false);
418         }
419         
420 // printDocument();
421
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         //Transform from Venetian Blind to Salami Slice
429
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 JavaDoc ex) {
436             //ex.printStackTrace();
437
assertTrue("Should not be here", false);
438         }
439         //TODO - validation fails due to ambigous schema po.xsd
440
// validateSchema(axiModel.getSchemaModel());
441

442 // printDocument();
443
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         //Transform from Salami Slice to Garden of Eden
451
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 JavaDoc ex) {
458             //ex.printStackTrace();
459
assertTrue("Should not be here", false);
460         }
461         //TODO - validation fails due to ambigous schema po.xsd
462
// validateSchema(axiModel.getSchemaModel());
463

464 // printDocument();
465
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         //Transform from Venetian Blind to Venetian Blind
473
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 JavaDoc ex) {
480             //ex.printStackTrace();
481
assertTrue("Should not be here", false);
482         }
483         //TODO - validation fails due to ambigous schema po.xsd
484
// validateSchema(axiModel.getSchemaModel());
485

486 // printDocument();
487
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         //Transform from Venetian Blind to Garden of Eden
495
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 JavaDoc ex) {
502             //ex.printStackTrace();
503
assertTrue("Should not be here", false);
504         }
505         //TODO - validation fails due to ambigous schema po.xsd
506
// validateSchema(axiModel.getSchemaModel());
507

508 // printDocument();
509
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 JavaDoc ex) {
522             //ex.printStackTrace();
523
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 JavaDoc ex) {
532             //ex.printStackTrace();
533
assertTrue("Should not be here", false);
534         }
535         validateSchema(axiModel.getSchemaModel());
536         
537 // printDocument();
538
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 JavaDoc ex) {
548             //ex.printStackTrace();
549
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 JavaDoc ex) {
558             //ex.printStackTrace();
559
assertTrue("Should not be here", false);
560         }
561         validateSchema(axiModel.getSchemaModel());
562         
563 // printDocument();
564
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 JavaDoc ex) {
574             //ex.printStackTrace();
575
assertTrue("Should not be here", false);
576         }
577         assertPurchaseOrder();
578         
579         //save document contents
580
Document JavaDoc doc = AbstractDocumentModel.class.cast(getSchemaModel()).getBaseDocument();
581         String JavaDoc savedDoc = null;
582         try {
583             savedDoc = doc.getText(0, doc.getLength());
584         } catch (BadLocationException JavaDoc ex) {
585 // ex.printStackTrace();
586
}
587         try {
588             SchemaGeneratorFactory.getDefault().transformSchema(
589                     axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL);
590         } catch (IOException JavaDoc ex) {
591             //ex.printStackTrace();
592
assertTrue("Should not be here", false);
593         }
594         validateSchema(axiModel.getSchemaModel());
595         
596 // printDocument();
597
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 // axiModel.startTransaction();
609
getSchemaModel().sync();
610 // axiModel.endTransaction();
611
// printDocument();
612
axiModel.sync();
613             String JavaDoc newDoc = doc.getText(0, doc.getLength());
614             assertEquals("newDoc is not same as saveDoc", newDoc, savedDoc);
615         } catch (BadLocationException JavaDoc ex) {
616 // ex.printStackTrace();
617
fail("failed");
618         } catch (IOException JavaDoc ex) {
619 // ex.printStackTrace();
620
fail("failed");
621         }
622 // printDocument();
623
// assertPurchaseOrder();
624

625         try {
626             SchemaGeneratorFactory.getDefault().transformSchema(
627                     axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL);
628         } catch (IOException JavaDoc ex) {
629             ex.printStackTrace();
630             assertTrue("Should not be here", false);
631         }
632         validateSchema(axiModel.getSchemaModel());
633         
634 // printDocument();
635
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 JavaDoc ex) {
646             //ex.printStackTrace();
647
assertTrue("Should not be here", false);
648         }
649 // printDocument();
650
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 JavaDoc ex) {
657             //ex.printStackTrace();
658
assertTrue("Should not be here", false);
659         }
660         validateSchema(axiModel.getSchemaModel());
661         
662 // printDocument();
663
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 JavaDoc 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         //since CompositorProxy extends Compositor, so use Compositor
695
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 JavaDoc ex) {
705             //ex.printStackTrace();
706
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         //save document contents
716
Document JavaDoc doc = AbstractDocumentModel.class.cast(getSchemaModel()).getBaseDocument();
717         String JavaDoc savedDoc = null;
718         try {
719             savedDoc = doc.getText(0, doc.getLength());
720         } catch (BadLocationException JavaDoc ex) {
721 // ex.printStackTrace();
722
}
723         try {
724             SchemaGeneratorFactory.getDefault().transformSchema(
725                     axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL);
726         } catch (IOException JavaDoc ex) {
727             //ex.printStackTrace();
728
assertTrue("Should not be here", false);
729         }
730         validateSchema(axiModel.getSchemaModel());
731         
732 // printDocument();
733
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 JavaDoc ex) {
751             //ex.printStackTrace();
752
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 // printDocument();
769
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 JavaDoc ex) {
782             //ex.printStackTrace();
783
assertTrue("Should not be here", false);
784         }
785         try {
786             SchemaGeneratorFactory.getDefault().transformSchema(
787                     axiModel.getSchemaModel(), SchemaGenerator.Pattern.RUSSIAN_DOLL);
788         } catch (IOException JavaDoc ex) {
789             //ex.printStackTrace();
790
assertTrue("Should not be here", false);
791         }
792 // printDocument();
793
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 JavaDoc ex) {
800             //ex.printStackTrace();
801
assertTrue("Should not be here", false);
802         }
803         validateSchema(axiModel.getSchemaModel());
804         
805 // printDocument();
806
assertEquals("global complex types",3,getSchemaModel().getSchema().getComplexTypes().size());
807 // assertEquals("global simple types",2,getSchemaModel().getSchema().getSimpleTypes().size());
808
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 JavaDoc ex) {
816             ex.printStackTrace();
817             assertTrue("Should not be here", false);
818         }
819 // printDocument();
820
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 JavaDoc ex) {
830             //ex.printStackTrace();
831
assertTrue("Should not be here", false);
832         }
833 // printDocument();
834
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 JavaDoc ex) {
847             //ex.printStackTrace();
848
assertTrue("Should not be here", false);
849         }
850 // printDocument();
851
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 JavaDoc ex) {
861             //ex.printStackTrace();
862
assertTrue("Should not be here", false);
863         }
864 // printDocument();
865
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 JavaDoc ex) {
876             //ex.printStackTrace();
877
assertTrue("Should not be here", false);
878         }
879 // printDocument();
880
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 JavaDoc ex) {
893             //ex.printStackTrace();
894
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         //Transform from Garden of Eden to Russian Doll
901
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 JavaDoc ex) {
908             //ex.printStackTrace();
909
assertTrue("Should not be here", false);
910         }
911 // printDocument();
912

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 JavaDoc ex) {
926             //ex.printStackTrace();
927
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         //Transform from Garden of Eden to Russian Doll
934
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 JavaDoc ex) {
941             //ex.printStackTrace();
942
assertTrue("Should not be here", false);
943         }
944 // printDocument();
945

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 JavaDoc 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 JavaDoc 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 JavaDoc ex) {
970             //ex.printStackTrace();
971
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         //Transform from Garden of Eden to Russian Doll
978
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 JavaDoc ex) {
985             //ex.printStackTrace();
986
assertTrue("Should not be here", false);
987         }
988 // printDocument();
989

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 JavaDoc ex) {
1003            //ex.printStackTrace();
1004
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        //Transform from Garden of Eden to Russian Doll
1011
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 JavaDoc ex) {
1018            //ex.printStackTrace();
1019
assertTrue("Should not be here", false);
1020        }
1021// printDocument();
1022

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 JavaDoc 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 JavaDoc 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 JavaDoc ex) {
1048            //ex.printStackTrace();
1049
assertTrue("Should not be here", false);
1050        }
1051    }
1052    
1053}
1054
Popular Tags