1 19 20 package org.netbeans.modules.xml.axi; 21 22 import junit.framework.Test; 23 import junit.framework.TestSuite; 24 import org.netbeans.modules.xml.axi.AXIComponent.ComponentType; 25 import org.netbeans.modules.xml.axi.visitor.DeepAXITreeVisitor; 26 27 34 public class ProxyComponentTest extends AbstractTestCase { 35 public static final String TEST_XSD = "resources/address2.xsd"; 36 37 public ProxyComponentTest(String testName) { 38 super(testName, TEST_XSD, null); 39 } 40 41 public static Test suite() { 42 TestSuite suite = new TestSuite(ProxyComponentTest.class); 43 return suite; 44 } 45 46 public void testProxyComponents() { 47 DeepModelVisitor visitor = new DeepModelVisitor(); 48 getAXIModel().getRoot().accept(visitor); 49 } 50 51 private class DeepModelVisitor extends DeepAXITreeVisitor { 52 private int counter = 0; 53 54 protected void visitChildren(AXIComponent component) { 55 if(component.getComponentType() == ComponentType.PROXY) { 56 proxyIndirection = 0; 59 AXIComponent o = getOriginal(component); 60 assert(proxyIndirectionTest == proxyIndirection); 61 } 62 63 if(component instanceof ContentModel) { 64 ContentModel cm = (ContentModel)component; 65 if(cm.getName().equals("group")) { 66 checkProxyIndirection = true; 67 proxyIndirectionTest = 0; 68 } 69 if(cm.getName().equals("attr-group")) { 70 checkProxyIndirection = true; 71 proxyIndirectionTest = 0; 72 } 73 if(cm.getName().equals("USAddress")) { 74 checkProxyIndirection = true; 75 proxyIndirectionTest = 1; 76 } 77 } 78 79 if(component instanceof Element) { 80 Element e = (Element)component; 81 if(e.getName().equals("address")) { 82 checkProxyIndirection = true; 83 proxyIndirectionTest = 2; 84 } else 85 checkProxyIndirection = false; 86 } 87 super.visitChildren(component); 88 } 89 } 90 91 95 private AXIComponent getOriginal(AXIComponent component) { 96 AXIComponent shared = component.getSharedComponent(); 97 if(shared == null) 98 return component; 99 100 proxyIndirection++; 101 if(shared.getComponentType() != ComponentType.PROXY) { 102 return shared; 103 } 104 105 return getOriginal(shared); 106 } 107 108 private int proxyIndirectionTest = 0; 109 private int proxyIndirection = 0; 110 private boolean checkProxyIndirection = false; 111 } 112 | Popular Tags |