KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > model > SchemaComponentTest


1 /*
2  * SchemaComponentTest.java
3  *
4  * Created on November 2, 2005, 2:41 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.xml.schema.model;
11
12 import java.util.Collection JavaDoc;
13 import junit.framework.TestCase;
14 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
15
16 /**
17  *
18  * @author rico
19  */

20 public class SchemaComponentTest extends TestCase{
21     public static final String JavaDoc TEST_XSD = "resources/PurchaseOrder.xsd";
22     public static final String JavaDoc EMPTY_XSD = "resources/Empty.xsd";
23     
24      Schema schema = null;
25     /**
26      * Creates a new instance of SchemaComponentTest
27      */

28     public SchemaComponentTest(String JavaDoc testcase) {
29         super(testcase);
30     }
31     
32    
33     protected void setUp() throws Exception JavaDoc {
34         SchemaModel model = Util.loadSchemaModel(TEST_XSD);
35         schema = model.getSchema();
36     }
37     
38     public void testPosition(){
39         //schema position
40
this.assertEquals("<schema> position ", 40, schema.findPosition());
41         System.out.println("schema position: " + schema.findPosition());
42         
43         //position of first global element
44
Collection JavaDoc<GlobalElement> elements = schema.getElements();
45         GlobalElement element = elements.iterator().next();
46         System.out.println("position of first element: " + element.findPosition());
47         this.assertEquals("<purchaseorder> element position ", 276, element.findPosition());
48         
49          //position of referenced type PurchaseType
50
NamedComponentReference<? extends GlobalType> ref = element.getType();
51         GlobalType type = ref.get();
52         System.out.println("Position of referenced type: " + type.getName() + ": " + type.findPosition());
53         assertEquals("referenced PurchaseType position ", 387, type.findPosition() );
54         
55         //position of sequence under PurchaseType
56
GlobalComplexType gct = (GlobalComplexType)type;
57         ComplexTypeDefinition def = gct.getDefinition();
58         System.out.println("Sequence under PurchaseType position: " + def.findPosition());
59         assertEquals("sequence under PurchaseType position ", 430, def.findPosition() );
60         
61         Collection JavaDoc<GlobalSimpleType> simpleTypes = schema.getSimpleTypes();
62         GlobalSimpleType simpleType = simpleTypes.iterator().next();
63         System.out.println("Position of simple Type: " + simpleType.findPosition());
64         assertEquals("simple type allNNI position ", 865, simpleType.findPosition());
65     }
66     
67 }
68
Popular Tags