|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2001, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2001, 2008 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 23-28
Link Here
|
| 23 |
import org.w3c.dom.Element; |
23 |
import org.w3c.dom.Element; |
| 24 |
|
24 |
|
| 25 |
import com.ibm.wsdl.Constants; |
25 |
import com.ibm.wsdl.Constants; |
|
|
26 |
import com.ibm.wsdl.extensions.schema.SchemaConstants; |
| 26 |
|
27 |
|
| 27 |
/** |
28 |
/** |
| 28 |
* Tests for org.eclipse.wst.wsdl.validation.internal.wsdl11.xsd.InlineSchemaGenerator. |
29 |
* Tests for org.eclipse.wst.wsdl.validation.internal.wsdl11.xsd.InlineSchemaGenerator. |
|
Lines 92-108
Link Here
|
| 92 |
public void testGetNSResolver() |
93 |
public void testGetNSResolver() |
| 93 |
{ |
94 |
{ |
| 94 |
Document doc = new DocumentImpl(); |
95 |
Document doc = new DocumentImpl(); |
| 95 |
Element rootElem = doc.createElementNS(Constants.NS_URI_XSD_2001, "schema"); |
96 |
Element rootElem = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "schema"); |
| 96 |
|
97 |
|
| 97 |
// Check that the resolver is empty. |
98 |
// Check that the resolver is empty. |
| 98 |
Hashtable resolver = generator.getNSResolver(rootElem); |
99 |
Hashtable resolver = generator.getNSResolver(rootElem); |
| 99 |
assertTrue("The resolver is not empty.", resolver.isEmpty()); |
100 |
assertTrue("The resolver is not empty.", resolver.isEmpty()); |
| 100 |
|
101 |
|
| 101 |
// Check the resolver contains one value. |
102 |
// Check the resolver contains one value. |
| 102 |
rootElem.setAttribute("xmlns", Constants.NS_URI_XSD_2001); |
103 |
rootElem.setAttribute("xmlns", SchemaConstants.NS_URI_XSD_2001); |
| 103 |
resolver = generator.getNSResolver(rootElem); |
104 |
resolver = generator.getNSResolver(rootElem); |
| 104 |
assertTrue("The resolver does not contain the empty namespace.", resolver.containsKey("")); |
105 |
assertTrue("The resolver does not contain the empty namespace.", resolver.containsKey("")); |
| 105 |
assertEquals("The resolver does not contain the correct value for the empty namespace.", Constants.NS_URI_XSD_2001, resolver.get("")); |
106 |
assertEquals("The resolver does not contain the correct value for the empty namespace.", SchemaConstants.NS_URI_XSD_2001, resolver.get("")); |
| 106 |
|
107 |
|
| 107 |
// Check the resolver contains two values. |
108 |
// Check the resolver contains two values. |
| 108 |
rootElem.setAttribute("xmlns:other", "http://othernamespace"); |
109 |
rootElem.setAttribute("xmlns:other", "http://othernamespace"); |
|
Lines 112-118
Link Here
|
| 112 |
|
113 |
|
| 113 |
// Check the resolver still contains the empty namespace. |
114 |
// Check the resolver still contains the empty namespace. |
| 114 |
assertTrue("The resolver does not contain the empty namespace after adding a second namespace.", resolver.containsKey("")); |
115 |
assertTrue("The resolver does not contain the empty namespace after adding a second namespace.", resolver.containsKey("")); |
| 115 |
assertEquals("The resolver does not contain the correct value for the empty namespace after adding a second namespace.", Constants.NS_URI_XSD_2001, resolver.get("")); |
116 |
assertEquals("The resolver does not contain the correct value for the empty namespace after adding a second namespace.", SchemaConstants.NS_URI_XSD_2001, resolver.get("")); |
| 116 |
|
117 |
|
| 117 |
// Check the resolver doesn't contain non-xmlns attribute value. |
118 |
// Check the resolver doesn't contain non-xmlns attribute value. |
| 118 |
rootElem.setAttribute("type:other2", "other2:type"); |
119 |
rootElem.setAttribute("type:other2", "other2:type"); |
|
Lines 127-134
Link Here
|
| 127 |
{ |
128 |
{ |
| 128 |
// Check document that contains no required namespaces and no prefix. |
129 |
// Check document that contains no required namespaces and no prefix. |
| 129 |
Document doc = new DocumentImpl(); |
130 |
Document doc = new DocumentImpl(); |
| 130 |
Element rootElem = doc.createElementNS(Constants.NS_URI_XSD_2001, "schema"); |
131 |
Element rootElem = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "schema"); |
| 131 |
rootElem.setAttribute("xmlns",Constants.NS_URI_XSD_2001); |
132 |
rootElem.setAttribute("xmlns",SchemaConstants.NS_URI_XSD_2001); |
| 132 |
//doc.appendChild(rootElem); |
133 |
//doc.appendChild(rootElem); |
| 133 |
|
134 |
|
| 134 |
List reqNSs = generator.getNamespacePrefixes(rootElem); |
135 |
List reqNSs = generator.getNamespacePrefixes(rootElem); |
|
Lines 136-159
Link Here
|
| 136 |
assertEquals("The required namespace list does not contain one empty string.", "", reqNSs.get(0)); |
137 |
assertEquals("The required namespace list does not contain one empty string.", "", reqNSs.get(0)); |
| 137 |
|
138 |
|
| 138 |
// Check document that contains no required namespaces and the xsd prefix. |
139 |
// Check document that contains no required namespaces and the xsd prefix. |
| 139 |
Element rootElem2 = doc.createElementNS(Constants.NS_URI_XSD_2001, "xsd:schema"); |
140 |
Element rootElem2 = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "xsd:schema"); |
| 140 |
rootElem2.setAttribute("xmlns:xsd",Constants.NS_URI_XSD_2001); |
141 |
rootElem2.setAttribute("xmlns:xsd",SchemaConstants.NS_URI_XSD_2001); |
| 141 |
List reqNSs2 = generator.getNamespacePrefixes(rootElem2); |
142 |
List reqNSs2 = generator.getNamespacePrefixes(rootElem2); |
| 142 |
assertEquals("The required namespace list does not contain the one string 'xsd'.", 1, reqNSs2.size()); |
143 |
assertEquals("The required namespace list does not contain the one string 'xsd'.", 1, reqNSs2.size()); |
| 143 |
assertEquals("The required namespace list does not contain the one string 'xsd'.", "xsd", reqNSs2.get(0)); |
144 |
assertEquals("The required namespace list does not contain the one string 'xsd'.", "xsd", reqNSs2.get(0)); |
| 144 |
|
145 |
|
| 145 |
// Check document that contains an element with a required namespace. |
146 |
// Check document that contains an element with a required namespace. |
| 146 |
Element rootElem4 = doc.createElementNS(Constants.NS_URI_XSD_2001, "xsd:schema"); |
147 |
Element rootElem4 = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "xsd:schema"); |
| 147 |
rootElem2.setAttribute("xmlns:xsd",Constants.NS_URI_XSD_2001); |
148 |
rootElem2.setAttribute("xmlns:xsd",SchemaConstants.NS_URI_XSD_2001); |
| 148 |
Element diffNSElem = doc.createElementNS("http://othernamespace", "other:element"); |
149 |
Element diffNSElem = doc.createElementNS("http://othernamespace", "other:element"); |
| 149 |
rootElem4.appendChild(diffNSElem); |
150 |
rootElem4.appendChild(diffNSElem); |
| 150 |
List reqNSs4 = generator.getNamespacePrefixes(rootElem4); |
151 |
List reqNSs4 = generator.getNamespacePrefixes(rootElem4); |
| 151 |
assertTrue("The required namespace list does not contain the prefix 'other' when the namespace is specified for an element.", reqNSs4.contains("other")); |
152 |
assertTrue("The required namespace list does not contain the prefix 'other' when the namespace is specified for an element.", reqNSs4.contains("other")); |
| 152 |
|
153 |
|
| 153 |
// Check document that contains a type with a required namespace. |
154 |
// Check document that contains a type with a required namespace. |
| 154 |
Element rootElem5 = doc.createElementNS(Constants.NS_URI_XSD_2001, "xsd:schema"); |
155 |
Element rootElem5 = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "xsd:schema"); |
| 155 |
rootElem5.setAttribute("xmlns:xsd",Constants.NS_URI_XSD_2001); |
156 |
rootElem5.setAttribute("xmlns:xsd",SchemaConstants.NS_URI_XSD_2001); |
| 156 |
Element otherElem = doc.createElementNS(Constants.NS_URI_XSD_2001, "xsd:element"); |
157 |
Element otherElem = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "xsd:element"); |
| 157 |
otherElem.setAttribute("type", "other:type"); |
158 |
otherElem.setAttribute("type", "other:type"); |
| 158 |
rootElem5.appendChild(otherElem); |
159 |
rootElem5.appendChild(otherElem); |
| 159 |
List reqNSs5 = generator.getNamespacePrefixes(rootElem5); |
160 |
List reqNSs5 = generator.getNamespacePrefixes(rootElem5); |
|
Lines 161-169
Link Here
|
| 161 |
|
162 |
|
| 162 |
// Check document that contains an import. Import elements should be ignored. |
163 |
// Check document that contains an import. Import elements should be ignored. |
| 163 |
// This is a contrived example as it contains a type attribute for the import element. |
164 |
// This is a contrived example as it contains a type attribute for the import element. |
| 164 |
Element rootElem6 = doc.createElementNS(Constants.NS_URI_XSD_2001, "xsd:schema"); |
165 |
Element rootElem6 = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "xsd:schema"); |
| 165 |
rootElem6.setAttribute("xmlns:xsd",Constants.NS_URI_XSD_2001); |
166 |
rootElem6.setAttribute("xmlns:xsd",SchemaConstants.NS_URI_XSD_2001); |
| 166 |
Element importElem = doc.createElementNS(Constants.NS_URI_XSD_2001, "xsd:import"); |
167 |
Element importElem = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "xsd:import"); |
| 167 |
importElem.setAttribute("type", "other:type"); |
168 |
importElem.setAttribute("type", "other:type"); |
| 168 |
rootElem6.appendChild(importElem); |
169 |
rootElem6.appendChild(importElem); |
| 169 |
List reqNSs6 = generator.getNamespacePrefixes(rootElem6); |
170 |
List reqNSs6 = generator.getNamespacePrefixes(rootElem6); |
|
Lines 172-180
Link Here
|
| 172 |
|
173 |
|
| 173 |
// Check document that contains an include. Include elements should be ignored. |
174 |
// Check document that contains an include. Include elements should be ignored. |
| 174 |
// This is a contrived example as it contains a type attribute for the include element. |
175 |
// This is a contrived example as it contains a type attribute for the include element. |
| 175 |
Element rootElem7 = doc.createElementNS(Constants.NS_URI_XSD_2001, "xsd:schema"); |
176 |
Element rootElem7 = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "xsd:schema"); |
| 176 |
rootElem7.setAttribute("xmlns:xsd",Constants.NS_URI_XSD_2001); |
177 |
rootElem7.setAttribute("xmlns:xsd",SchemaConstants.NS_URI_XSD_2001); |
| 177 |
Element includeElem = doc.createElementNS(Constants.NS_URI_XSD_2001, "xsd:include"); |
178 |
Element includeElem = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "xsd:include"); |
| 178 |
includeElem.setAttribute("type", "other:type"); |
179 |
includeElem.setAttribute("type", "other:type"); |
| 179 |
rootElem7.appendChild(includeElem); |
180 |
rootElem7.appendChild(includeElem); |
| 180 |
List reqNSs7 = generator.getNamespacePrefixes(rootElem6); |
181 |
List reqNSs7 = generator.getNamespacePrefixes(rootElem6); |
|
Lines 182-190
Link Here
|
| 182 |
assertEquals("The required namespace list does not contain the one string 'xsd' when an import element is used.", "xsd", reqNSs7.get(0)); |
183 |
assertEquals("The required namespace list does not contain the one string 'xsd' when an import element is used.", "xsd", reqNSs7.get(0)); |
| 183 |
|
184 |
|
| 184 |
// Check document that contains attribute with a required namespace. |
185 |
// Check document that contains attribute with a required namespace. |
| 185 |
Element rootElem3 = doc.createElementNS(Constants.NS_URI_XSD_2001, "xsd:schema"); |
186 |
Element rootElem3 = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "xsd:schema"); |
| 186 |
rootElem3.setAttribute("xmlns:xsd",Constants.NS_URI_XSD_2001); |
187 |
rootElem3.setAttribute("xmlns:xsd",SchemaConstants.NS_URI_XSD_2001); |
| 187 |
Element wsdlAttElem = doc.createElementNS(Constants.NS_URI_XSD_2001, "xsd:element"); |
188 |
Element wsdlAttElem = doc.createElementNS(SchemaConstants.NS_URI_XSD_2001, "xsd:element"); |
| 188 |
wsdlAttElem.setAttributeNS(Constants.NS_URI_WSDL, "wsdl:arrayType", "sometype[]"); |
189 |
wsdlAttElem.setAttributeNS(Constants.NS_URI_WSDL, "wsdl:arrayType", "sometype[]"); |
| 189 |
rootElem3.appendChild(wsdlAttElem); |
190 |
rootElem3.appendChild(wsdlAttElem); |
| 190 |
List reqNSs3 = generator.getNamespacePrefixes(rootElem3); |
191 |
List reqNSs3 = generator.getNamespacePrefixes(rootElem3); |