1 9 10 package org.netbeans.modules.xml.schema.model; 11 12 import java.util.Collection ; 13 import junit.framework.TestCase; 14 15 19 public class KeyRefTest extends TestCase{ 20 public static final String TEST_XSD = "resources/KeyRef.xsd"; 21 22 23 public KeyRefTest(String testcase) { 24 super(testcase); 25 } 26 27 Schema schema = null; 28 protected void setUp() throws Exception { 29 SchemaModel model = Util.loadSchemaModel(TEST_XSD); 30 schema = model.getSchema(); 31 } 32 33 protected void tearDown() throws Exception { 34 TestCatalogModel.getDefault().clearDocumentPool(); 35 } 36 37 public void testKeyRef(){ 38 Collection <GlobalElement> elements = schema.getElements(); 39 GlobalElement elem = elements.iterator().next(); 40 LocalType localType = elem.getInlineType(); 41 assertTrue("localType instanceof LocalComplexType", 42 localType instanceof LocalComplexType); 43 LocalComplexType lct = (LocalComplexType)localType; 44 ComplexTypeDefinition ctd = lct.getDefinition(); 45 assertTrue("ComplextTypeDefinition instanceof Sequence", 46 ctd instanceof Sequence); 47 Sequence seq = (Sequence)ctd; 48 java.util.List <SequenceDefinition> seqDefs = seq.getContent(); 49 SequenceDefinition seqDef = seqDefs.iterator().next(); 50 assertTrue("SequenceDefinition instanceof LocalElement", 51 seqDef instanceof LocalElement); 52 LocalElement le = (LocalElement)seqDef; 53 Collection <Constraint> constraints = le.getConstraints(); 54 Constraint constraint = constraints.iterator().next(); 55 assertTrue("Constraint instanceof KeyRef", constraint instanceof KeyRef); 56 KeyRef keyRef = (KeyRef)constraint; 57 Constraint key = keyRef.getReferer(); 58 System.out.println("key: " + key.getName()); 59 assertEquals("Referred key", "pNumKey", key.getName()); 60 } 61 } 62 | Popular Tags |