1 19 20 package org.netbeans.modules.xml.axi; 21 22 import junit.framework.*; 23 import org.netbeans.modules.xml.axi.AXIComponent.ComponentType; 24 import org.netbeans.modules.xml.axi.visitor.DeepAXITreeVisitor; 25 import org.openide.filesystems.FileObject; 26 27 28 38 public class AXIModelExTest extends AXIModelTest { 39 40 public static final String TEST_XSD = "resources/multifilePO.xsd"; 41 42 private static String PO_TNS = "http://xml.netbeans.org/examples/targetNS/PO"; 43 private static String ITEMS_TNS = "http://xml.netbeans.org/examples/targetNS/Items"; 44 private static String ADDR_TNS = "http://xml.netbeans.org/examples/targetNS/Address"; 45 private AXIModel aModelPO; 46 47 50 public AXIModelExTest(String testName) { 51 super(testName, TEST_XSD, GLOBAL_ELEMENT); 52 } 53 54 public static Test suite() { 55 TestSuite suite = new TestSuite(AXIModelExTest.class); 56 return suite; 57 } 58 59 public void testModel() { 60 aModelPO = getAXIModel(); 61 assertEquals(getAXIModel().getRoot().getTargetNamespace(), PO_TNS); 62 CheckTargetNamespaceVisitor visitor = new CheckTargetNamespaceVisitor(); 63 visitor.checkNamespace(getAXIModel().getRoot()); 64 } 65 66 private class CheckTargetNamespaceVisitor extends DeepAXITreeVisitor { 67 68 public void checkNamespace(AXIDocument document) { 69 document.accept(this); 70 } 71 72 protected void visitChildren(AXIComponent component) { 73 String ns = component.getTargetNamespace(); 74 75 if( !ns.equals(PO_TNS) && 77 !ns.equals(ADDR_TNS) && 78 !ns.equals(ITEMS_TNS)) { 79 assert(false); 80 } 81 82 if(component.getTargetNamespace().equals(PO_TNS)) { 85 assert(aModelPO == component.getModel()); 86 } 87 88 if(component.getComponentType() == ComponentType.REFERENCE) { 90 for(AXIComponent c: component.getChildren()) { 91 assert(c.getComponentType() == ComponentType.PROXY); 92 } 93 } 94 95 if(!component.getTargetNamespace().equals(PO_TNS)) { 98 doValidate(component, component.getOriginal().getModel()); 99 } 100 101 super.visitChildren(component); 102 } 103 104 private void doValidate(AXIComponent component, AXIModel otherModel) { 105 assert(component.getComponentType() == ComponentType.PROXY); 107 assert(component.getModel() == aModelPO); 108 assert(component.isReadOnly()); 109 110 AXIComponent original = component.getOriginal(); 113 assert(otherModel != aModelPO); 114 assert(otherModel == original.getModel()); 115 116 FileObject fPO = (FileObject)aModelPO.getModelSource(). 119 getLookup().lookup(FileObject.class); 120 FileObject otherFO = (FileObject)otherModel.getModelSource(). 121 getLookup().lookup(FileObject.class); 122 assert(fPO != null); 123 assert(otherFO != null); 124 assert(fPO != otherFO); 125 } 126 } 127 128 } 129 | Popular Tags |