1 19 package org.netbeans.modules.xml.axi; 20 21 import junit.framework.Test; 22 import junit.framework.TestSuite; 23 import org.netbeans.modules.xml.axi.AXIComponent.ComponentType; 24 import org.netbeans.modules.xml.axi.visitor.DeepAXITreeVisitor; 25 26 32 public class ContentModelTest extends AbstractTestCase { 33 public static final String TEST_XSD = "resources/po.xsd"; 34 35 public ContentModelTest(String testName) { 36 super(testName, TEST_XSD, null); 37 } 38 39 public static Test suite() { 40 TestSuite suite = new TestSuite(ContentModelTest.class); 41 return suite; 42 } 43 44 public void testContentModels() { 45 axiModel = getAXIModel(); 46 47 DeepAXITreeVisitor visitor = new DeepAXITreeVisitor(); 49 axiModel.getRoot().accept(visitor); 50 51 ContentModelVisitor cmv = new ContentModelVisitor(); 53 cmv.checkContentModels(getAXIModel()); 54 } 55 56 private class ContentModelVisitor extends DeepAXITreeVisitor { 57 private int refCount = 0; 58 private ContentModel contentModel; 59 private AXIModel axiModel; 60 61 public void checkContentModels(AXIModel model) { 62 axiModel = getAXIModel(); 63 for(ContentModel cm : model.getRoot().getContentModels()) { 64 assert(axiModel == cm.getModel()); 66 67 contentModel = cm; 68 print("checking ContentModel: " + 69 cm.getName() + " Type: " + cm.getType() + "....."); 70 if(cm.getRefSet() == null) 71 continue; 72 73 refCount = cm.getRefSet().size(); 74 cm.accept(this); 75 } 76 } 77 78 protected void visitChildren(AXIComponent component) { 79 if(component instanceof ContentModel) { 80 super.visitChildren(component); 81 return; 82 } 83 print("Component: " + component + " type: " + component.getComponentType()); 84 assert(component.getRefSet().size() == refCount); 85 for(AXIComponent ref : component.getRefSet()) { 86 AXIComponent original = ref.getSharedComponent(); 87 assert(original == component); 88 } 89 super.visitChildren(component); 90 } 91 } 92 } 93 | Popular Tags |