1 19 20 package org.netbeans.modules.xml.xam.dom; 21 22 import junit.framework.*; 23 import org.netbeans.modules.xml.xam.TestComponent2; 24 import org.netbeans.modules.xml.xam.TestModel2; 25 import org.netbeans.modules.xml.xam.Util; 26 27 31 public class ReadOnlyAccessTest extends TestCase { 32 33 public ReadOnlyAccessTest(String testName) { 34 super(testName); 35 } 36 37 protected void setUp() throws Exception { 38 } 39 40 protected void tearDown() throws Exception { 41 } 42 43 public static Test suite() { 44 return new TestSuite(ReadOnlyAccessTest.class); 45 } 46 47 public void testFindPosition() throws Exception { 48 TestModel2 model = Util.loadModel("resources/test1.xml"); 49 assertEquals(40, model.getRootComponent().findPosition()); 50 assertEquals(4, model.getRootComponent().getChildren().size()); 51 TestComponent2 component = model.getRootComponent().getChildren().get(0); 52 assertEquals("a", component.getPeer().getLocalName()); 53 assertEquals(141, component.findPosition()); 54 } 55 56 public void testFindPositionWithPrefix() throws Exception { 57 TestModel2 model = Util.loadModel("resources/test1.xml"); 58 TestComponent2.B b = model.getRootComponent().getChildren(TestComponent2.B.class).get(0); 59 TestComponent2.Aa aa = b.getChildren(TestComponent2.Aa.class).get(0); 60 assertEquals(218, aa.findPosition()); 61 } 62 63 public void testFindPositionWithElementTagInAttr() throws Exception { 64 TestModel2 model = Util.loadModel("resources/test1.xml"); 65 TestComponent2.C c = model.getRootComponent().getChildren(TestComponent2.C.class).get(0); 66 assertEquals(261, c.findPosition()); 67 } 68 69 public void testFindElement() throws Exception { 70 TestModel2 model = Util.loadModel("resources/test1.xml"); 71 TestComponent2 component = model.getRootComponent().getChildren().get(0); 72 assertEquals(component, model.findComponent(141)); 73 assertEquals(component, model.findComponent(155)); 74 assertEquals(component, model.findComponent(171)); 75 } 76 77 public void testFindElementWithPrefix() throws Exception { 78 TestModel2 model = Util.loadModel("resources/test1.xml"); 79 TestComponent2.B b = model.getRootComponent().getChildren(TestComponent2.B.class).get(0); 80 TestComponent2.Aa aa = b.getChildren(TestComponent2.Aa.class).get(0); 81 assertEquals(aa, model.findComponent(218)); 82 assertEquals(aa, model.findComponent(230)); 83 assertEquals(aa, model.findComponent(244)); 84 } 85 86 public void testFindElementWithTagInAttr() throws Exception { 87 TestModel2 model = Util.loadModel("resources/test1.xml"); 88 TestComponent2.C c = model.getRootComponent().getChildren(TestComponent2.C.class).get(0); 89 assertEquals(c, model.findComponent(261)); 90 assertEquals(c, model.findComponent(265)); 91 assertEquals(c, model.findComponent(277)); 92 } 93 94 public void testFindElementGivenTextPosition() throws Exception { 95 TestModel2 model = Util.loadModel("resources/test1.xml"); 96 TestComponent2 root = model.getRootComponent(); 97 TestComponent2.B b = root.getChildren(TestComponent2.B.class).get(0); 98 assertEquals(b, model.findComponent(211)); 99 assertEquals(root, model.findComponent(260)); 100 assertEquals(root, model.findComponent(279)); 101 } 102 103 public void testGetXmlFragment() throws Exception { 104 TestModel2 model = Util.loadModel("resources/test1.xml"); 105 TestComponent2 root = model.getRootComponent(); 106 TestComponent2.B b = model.getRootComponent().getChildren(TestComponent2.B.class).get(0); 107 String result = b.getXmlFragment(); 108 assertTrue(result.startsWith(" <!-- comment -->")); 109 assertTrue(result.indexOf("value=\"c\"/>") > 0); 110 } 111 112 } 113 | Popular Tags |