KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > dom > ReadOnlyAccessTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /**
28  *
29  * @author nn136682
30  */

31 public class ReadOnlyAccessTest extends TestCase {
32     
33     public ReadOnlyAccessTest(String JavaDoc testName) {
34         super(testName);
35     }
36
37     protected void setUp() throws Exception JavaDoc {
38     }
39
40     protected void tearDown() throws Exception JavaDoc {
41     }
42
43     public static Test suite() {
44         return new TestSuite(ReadOnlyAccessTest.class);
45     }
46
47     public void testFindPosition() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc result = b.getXmlFragment();
108         assertTrue(result.startsWith(" <!-- comment -->"));
109         assertTrue(result.indexOf("value=\"c\"/>") > 0);
110     }
111
112 }
113
Popular Tags