KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > completion > BasicCompletionTest


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 package org.netbeans.modules.xml.schema.completion;
20
21 import java.util.List JavaDoc;
22 import junit.framework.*;
23 import javax.swing.text.Document JavaDoc;
24 import org.openide.filesystems.FileObject;
25
26 /**
27  *
28  * @author Samaresh
29  */

30 public class BasicCompletionTest extends AbstractTestCase {
31     
32     static final String JavaDoc PO_INSTANCE_DOCUMENT = "resources/PO.xml";
33     static final String JavaDoc TEST_INSTANCE_DOCUMENT = "resources/Test.xml";
34     
35     public BasicCompletionTest(String JavaDoc testName) {
36         super(testName);
37     }
38     
39     public static Test suite() {
40         TestSuite suite = new TestSuite(BasicCompletionTest.class);
41         return suite;
42     }
43
44     /**
45      * Queries elements.
46      */

47     public void testPurchaseOrder() throws Exception JavaDoc {
48         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
49         buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //offset=39
50
buffer.append("<po:purchaseOrder xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); //offset=72
51
buffer.append(" xmlns:po=\"http://xml.netbeans.org/schema/PO\"\n"); //offset=47
52
buffer.append(" xsi:schemaLocation=\"http://xml.netbeans.org/schema/PO PO.xsd\">\n"); //offset=65
53
buffer.append(" <\n");
54         buffer.append("</po:purchaseOrder>\n");
55         setupCompletion(PO_INSTANCE_DOCUMENT, buffer);
56         List JavaDoc<CompletionResultItem> items = query(227);
57         String JavaDoc[] expectedResult = {"po:shipTo", "po:billTo", "po:comment", "po:items"};
58         assertResult(items, expectedResult);
59     }
60     
61     /**
62      * Queries an empty tag.
63      */

64     public void testEmptyTag() throws Exception JavaDoc {
65         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
66         buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //offset=39
67
buffer.append("<A:rootA3 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); //offset=64
68
buffer.append(" xmlns:A=\"http://xml.netbeans.org/schema/TNSA\"\n"); //offset=48
69
buffer.append(" xsi:schemaLocation=\"http://xml.netbeans.org/schema/TNSA A.xsd\">\n");
70         buffer.append(" <A31 />\n");
71         buffer.append("</A:rootA3>\n");
72         setupCompletion(TEST_INSTANCE_DOCUMENT, buffer);
73         List JavaDoc<CompletionResultItem> items = query(226);
74         String JavaDoc[] expectedResult = {"attrA31", "attrA32"};
75         assertResult(items, expectedResult);
76     }
77     
78     public void testWildcard1() throws Exception JavaDoc {
79         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
80         buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //offset=39
81
buffer.append("<A:rootA1 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); //offset=64
82
buffer.append(" xmlns:A=\"http://xml.netbeans.org/schema/TNSA\"\n"); //offset=48
83
buffer.append(" xsi:schemaLocation=\"http://xml.netbeans.org/schema/TNSA A.xsd\">\n");
84         buffer.append(" <\n");
85         buffer.append("</A:rootA1>\n");
86         setupCompletion(TEST_INSTANCE_DOCUMENT, buffer);
87         List JavaDoc<CompletionResultItem> items = query(222);
88         String JavaDoc[] expectedResult = {"A:rootA1", "A:rootA2", "A:rootA3", "A:A11", "A:A12"};
89         assertResult(items, expectedResult);
90     }
91     
92     public void testWildcard2() throws Exception JavaDoc {
93         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
94         buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //offset=39
95
buffer.append("<A:rootA1 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); //offset=64
96
buffer.append(" xmlns:A=\"http://xml.netbeans.org/schema/TNSA\"\n"); //offset=48
97
buffer.append(" xsi:schemaLocation=\"http://xml.netbeans.org/schema/TNSA A.xsd\n");
98         buffer.append(" http://xml.netbeans.org/schema/TNSB B.xsd\">\n");
99         buffer.append(" <\n");
100         buffer.append("</A:rootA1>\n");
101         setupCompletion(TEST_INSTANCE_DOCUMENT, buffer);
102         List JavaDoc<CompletionResultItem> items = query(265);
103         String JavaDoc[] expectedResult = {"ns1:rootB1", "ns1:rootB2", "A:rootA1", "A:rootA2",
104         "A:rootA3", "A:A11", "A:A12"};
105         assertResult(items, expectedResult);
106     }
107     
108     public void testWildcard3() throws Exception JavaDoc {
109         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
110         buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //offset=39
111
buffer.append("<A:rootA1 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); //offset=64
112
buffer.append(" xmlns:A=\"http://xml.netbeans.org/schema/TNSA\"\n"); //offset=48
113
buffer.append(" xmlns:B=\"http://xml.netbeans.org/schema/TNSB\"\n"); //offset=48
114
buffer.append(" xmlns:C=\"http://xml.netbeans.org/schema/TNSC\"\n"); //offset=48
115
buffer.append(" xsi:schemaLocation=\"http://xml.netbeans.org/schema/TNSA A.xsd\n"); //offset=64
116
buffer.append(" http://xml.netbeans.org/schema/TNSB B.xsd\n"); //offset=44
117
buffer.append(" http://xml.netbeans.org/schema/TNSC C.xsd\">\n"); //offset=46
118
buffer.append(" <\n"); //offset=04
119
buffer.append("</A:rootA1>\n");
120         setupCompletion(TEST_INSTANCE_DOCUMENT, buffer);
121         List JavaDoc<CompletionResultItem> items = query(405);
122         String JavaDoc[] expectedResult = {"C:rootC1", "C:rootC1","B:rootB1", "B:rootB2",
123         "A:rootA1", "A:rootA2", "A:rootA3", "A:A11", "A:A12"};
124         assertResult(items, expectedResult);
125     }
126     
127     public void testWildcard4() throws Exception JavaDoc {
128         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
129         buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //offset=39
130
buffer.append("<A:rootA2 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); //offset=64
131
buffer.append(" xmlns:A=\"http://xml.netbeans.org/schema/TNSA\"\n"); //offset=48
132
buffer.append(" xmlns:B=\"http://xml.netbeans.org/schema/TNSB\"\n"); //offset=48
133
buffer.append(" xmlns:C=\"http://xml.netbeans.org/schema/TNSC\"\n"); //offset=48
134
buffer.append(" xsi:schemaLocation=\"http://xml.netbeans.org/schema/TNSA A.xsd\n"); //offset=64
135
buffer.append(" http://xml.netbeans.org/schema/TNSB B.xsd\n"); //offset=44
136
buffer.append(" http://xml.netbeans.org/schema/TNSC C.xsd\">\n"); //offset=46
137
buffer.append(" <\n"); //offset=04
138
buffer.append("</A:rootA2>\n");
139         setupCompletion(TEST_INSTANCE_DOCUMENT, buffer);
140         List JavaDoc<CompletionResultItem> items = query(405);
141         String JavaDoc[] expectedResult = {"C:rootC1", "C:rootC1","B:rootB1", "B:rootB2", "A:rootA1",
142             "A:rootA2", "A:rootA3", "A:rootA3", "A:A21", "A:A22"};
143         assertResult(items, expectedResult);
144     }
145 }
146
Popular Tags