|
Lines 7-19
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* David Carver (STAR) - initial API and implementation |
9 |
* David Carver (STAR) - initial API and implementation |
| 10 |
* Mukul Gandhi - bug 273719 - String-Length with Element Arg |
10 |
* Mukul Gandhi - bug 273719 - improvements to fn:string-length function |
| 11 |
* Mukul Gandhi - bug 273795 - improvements to substring function |
11 |
* Mukul Gandhi - bug 273795 - improvements to fn:substring function |
|
|
12 |
* Mukul Gandhi - bug 274471 - improvements to fn:string function |
| 13 |
* Mukul Gandhi - bug 274719 - implementation of equality of xs:anyURI values |
| 14 |
* Mukul Gandhi - bug 274725 - implementation of fn:base-uri function |
| 15 |
* Mukul Gandhi - bug 274731 - implementation of fn:document-uri function |
| 16 |
* Mukul Gandhi - bug 274784 - improvements to xs:boolean data type |
| 17 |
* Mukul Gandhi - bug 274792 - improvements to xs:date data type |
| 18 |
* Mukul Gandhi - bug 274805 - improvements to xs:integer data type |
| 19 |
* Mukul Gandhi - bug 274952 - implementation of xs:long data type |
| 20 |
* Mukul Gandhi - bug 275105 - implementation of xs:int data type |
| 21 |
* Mukul Gandhi - bug 276134 - improvements to schema aware primitive type support |
| 22 |
* for attribute/element nodes |
| 12 |
*******************************************************************************/ |
23 |
*******************************************************************************/ |
| 13 |
package org.eclipse.wst.xml.xpath2.processor.test; |
24 |
package org.eclipse.wst.xml.xpath2.processor.test; |
| 14 |
|
25 |
|
| 15 |
import java.net.URL; |
26 |
import java.net.URL; |
| 16 |
|
27 |
|
|
|
28 |
import javax.xml.parsers.DocumentBuilder; |
| 29 |
import javax.xml.parsers.DocumentBuilderFactory; |
| 30 |
|
| 17 |
import org.apache.xerces.xs.XSModel; |
31 |
import org.apache.xerces.xs.XSModel; |
| 18 |
import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator; |
32 |
import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator; |
| 19 |
import org.eclipse.wst.xml.xpath2.processor.DynamicContext; |
33 |
import org.eclipse.wst.xml.xpath2.processor.DynamicContext; |
|
Lines 94-98
Link Here
|
| 94 |
|
108 |
|
| 95 |
assertEquals("true", actual); |
109 |
assertEquals("true", actual); |
| 96 |
} |
110 |
} |
|
|
111 |
|
| 112 |
public void testStringFunctionBug274471() throws Exception { |
| 113 |
// Bug 274471 |
| 114 |
URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 115 |
loadDOMDocument(fileURL); |
| 116 |
|
| 117 |
// Get XML Schema Information for the Document |
| 118 |
XSModel schema = getGrammar(); |
| 119 |
|
| 120 |
DynamicContext dc = setupDynamicContext(schema); |
| 121 |
|
| 122 |
String xpath = "x/string() = 'unhappy'"; |
| 123 |
XPath path = compileXPath(dc, xpath); |
| 124 |
|
| 125 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 126 |
ResultSequence rs = eval.evaluate(path); |
| 127 |
|
| 128 |
XSBoolean result = (XSBoolean) rs.first(); |
| 129 |
|
| 130 |
String actual = result.string_value(); |
| 131 |
|
| 132 |
assertEquals("true", actual); |
| 133 |
} |
| 134 |
|
| 135 |
public void testStringLengthFunctionBug274471() throws Exception { |
| 136 |
// Bug 274471. string-length() with arity 0 |
| 137 |
URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 138 |
loadDOMDocument(fileURL); |
| 139 |
|
| 140 |
// Get XML Schema Information for the Document |
| 141 |
XSModel schema = getGrammar(); |
| 142 |
|
| 143 |
DynamicContext dc = setupDynamicContext(schema); |
| 144 |
|
| 145 |
String xpath = "x/string-length() = 7"; |
| 146 |
XPath path = compileXPath(dc, xpath); |
| 147 |
|
| 148 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 149 |
ResultSequence rs = eval.evaluate(path); |
| 150 |
|
| 151 |
XSBoolean result = (XSBoolean) rs.first(); |
| 152 |
|
| 153 |
String actual = result.string_value(); |
| 154 |
|
| 155 |
assertEquals("true", actual); |
| 156 |
} |
| 157 |
|
| 158 |
public void testNormalizeSpaceFunctionBug274471() throws Exception { |
| 159 |
// Bug 274471. normalize-space() with arity 0 |
| 160 |
URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 161 |
loadDOMDocument(fileURL); |
| 162 |
|
| 163 |
// Get XML Schema Information for the Document |
| 164 |
XSModel schema = getGrammar(); |
| 165 |
|
| 166 |
DynamicContext dc = setupDynamicContext(schema); |
| 167 |
|
| 168 |
String xpath = "x/normalize-space() = 'unhappy'"; |
| 169 |
XPath path = compileXPath(dc, xpath); |
| 170 |
|
| 171 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 172 |
ResultSequence rs = eval.evaluate(path); |
| 173 |
|
| 174 |
XSBoolean result = (XSBoolean) rs.first(); |
| 175 |
|
| 176 |
String actual = result.string_value(); |
| 177 |
|
| 178 |
assertEquals("true", actual); |
| 179 |
} |
| 180 |
|
| 181 |
public void testAnyUriEqualityBug() throws Exception { |
| 182 |
// Bug 274719 |
| 183 |
// reusing the XML document from another bug |
| 184 |
URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 185 |
loadDOMDocument(fileURL); |
| 186 |
|
| 187 |
// Get XML Schema Information for the Document |
| 188 |
XSModel schema = getGrammar(); |
| 189 |
|
| 190 |
DynamicContext dc = setupDynamicContext(schema); |
| 191 |
|
| 192 |
String xpath = "xs:anyURI('abc') eq xs:anyURI('abc')"; |
| 193 |
XPath path = compileXPath(dc, xpath); |
| 194 |
|
| 195 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 196 |
ResultSequence rs = eval.evaluate(path); |
| 197 |
|
| 198 |
XSBoolean result = (XSBoolean) rs.first(); |
| 199 |
|
| 200 |
String actual = result.string_value(); |
| 201 |
|
| 202 |
assertEquals("true", actual); |
| 203 |
} |
| 204 |
|
| 205 |
public void testBaseUriBug() throws Exception { |
| 206 |
// Bug 274725 |
| 207 |
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 208 |
DocumentBuilder docBuilder = dbf.newDocumentBuilder(); |
| 209 |
|
| 210 |
// for testing this bug, we read the XML document from the web. |
| 211 |
// this ensures, that base-uri property of DOM is not null. |
| 212 |
domDoc = docBuilder.parse("http://www.w3schools.com/xml/note.xml"); |
| 213 |
|
| 214 |
// we pass XSModel as null for this test case. Otherwise, we would |
| 215 |
// get an exception. |
| 216 |
DynamicContext dc = setupDynamicContext(null); |
| 217 |
|
| 218 |
String xpath = "base-uri(note) eq xs:anyURI('http://www.w3schools.com/xml/note.xml')"; |
| 219 |
|
| 220 |
// please note: The below XPath would also work, with base-uri using arity 0. |
| 221 |
//String xpath = "note/base-uri() eq xs:anyURI('http://www.w3schools.com/xml/note.xml')"; |
| 222 |
|
| 223 |
XPath path = compileXPath(dc, xpath); |
| 224 |
|
| 225 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 226 |
ResultSequence rs = eval.evaluate(path); |
| 227 |
|
| 228 |
XSBoolean result = (XSBoolean) rs.first(); |
| 229 |
|
| 230 |
String actual = result.string_value(); |
| 231 |
|
| 232 |
assertEquals("true", actual); |
| 233 |
} |
| 234 |
|
| 235 |
public void testDocumentUriBug() throws Exception { |
| 236 |
// Bug 274731 |
| 237 |
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 238 |
DocumentBuilder docBuilder = dbf.newDocumentBuilder(); |
| 239 |
|
| 240 |
domDoc = docBuilder.parse("http://www.w3schools.com/xml/note.xml"); |
| 241 |
|
| 242 |
DynamicContext dc = setupDynamicContext(null); |
| 243 |
|
| 244 |
String xpath = "document-uri(/) eq xs:anyURI('http://www.w3schools.com/xml/note.xml')"; |
| 245 |
|
| 246 |
XPath path = compileXPath(dc, xpath); |
| 247 |
|
| 248 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 249 |
ResultSequence rs = eval.evaluate(path); |
| 250 |
|
| 251 |
XSBoolean result = (XSBoolean) rs.first(); |
| 252 |
|
| 253 |
String actual = "false"; |
| 254 |
|
| 255 |
if (result != null) { |
| 256 |
actual = result.string_value(); |
| 257 |
} |
| 258 |
|
| 259 |
assertEquals("true", actual); |
| 260 |
} |
| 261 |
|
| 262 |
public void testBooleanTypeBug() throws Exception { |
| 263 |
// Bug 274784 |
| 264 |
// reusing the XML document from another bug |
| 265 |
URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml"); |
| 266 |
loadDOMDocument(fileURL); |
| 267 |
|
| 268 |
// Get XML Schema Information for the Document |
| 269 |
XSModel schema = getGrammar(); |
| 270 |
|
| 271 |
DynamicContext dc = setupDynamicContext(schema); |
| 272 |
|
| 273 |
String xpath = "xs:boolean('1') eq xs:boolean('true')"; |
| 274 |
XPath path = compileXPath(dc, xpath); |
| 275 |
|
| 276 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 277 |
ResultSequence rs = eval.evaluate(path); |
| 278 |
|
| 279 |
XSBoolean result = (XSBoolean) rs.first(); |
| 280 |
|
| 281 |
String actual = result.string_value(); |
| 282 |
|
| 283 |
assertEquals("true", actual); |
| 284 |
} |
| 285 |
|
| 286 |
public void testDateConstructorBug() throws Exception { |
| 287 |
// Bug 274792 |
| 288 |
URL fileURL = bundle.getEntry("/bugTestFiles/bug274792.xml"); |
| 289 |
loadDOMDocument(fileURL); |
| 290 |
|
| 291 |
// Get XML Schema Information for the Document |
| 292 |
XSModel schema = getGrammar(); |
| 293 |
|
| 294 |
DynamicContext dc = setupDynamicContext(schema); |
| 295 |
|
| 296 |
String xpath = "xs:date('2009-01-01') eq xs:date('2009-01-01')"; |
| 297 |
XPath path = compileXPath(dc, xpath); |
| 298 |
|
| 299 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 300 |
ResultSequence rs = eval.evaluate(path); |
| 301 |
|
| 302 |
XSBoolean result = (XSBoolean) rs.first(); |
| 303 |
|
| 304 |
String actual = result.string_value(); |
| 305 |
|
| 306 |
assertEquals("true", actual); |
| 307 |
} |
| 308 |
|
| 309 |
public void testIntegerDataTypeBug() throws Exception { |
| 310 |
// Bug 274805 |
| 311 |
URL fileURL = bundle.getEntry("/bugTestFiles/bug274805.xml"); |
| 312 |
loadDOMDocument(fileURL); |
| 313 |
|
| 314 |
// Get XML Schema Information for the Document |
| 315 |
XSModel schema = getGrammar(); |
| 316 |
|
| 317 |
DynamicContext dc = setupDynamicContext(schema); |
| 318 |
|
| 319 |
// xs:integer by definition is from -INF to +INF |
| 320 |
String xpath = "xs:integer(x) gt 100"; |
| 321 |
XPath path = compileXPath(dc, xpath); |
| 322 |
|
| 323 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 324 |
ResultSequence rs = eval.evaluate(path); |
| 325 |
|
| 326 |
XSBoolean result = (XSBoolean) rs.first(); |
| 327 |
|
| 328 |
String actual = result.string_value(); |
| 329 |
|
| 330 |
assertEquals("true", actual); |
| 331 |
} |
| 332 |
|
| 333 |
public void testLongDataType() throws Exception { |
| 334 |
// Bug 274952 |
| 335 |
URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 336 |
loadDOMDocument(fileURL); |
| 337 |
|
| 338 |
// Get XML Schema Information for the Document |
| 339 |
XSModel schema = getGrammar(); |
| 340 |
|
| 341 |
DynamicContext dc = setupDynamicContext(schema); |
| 342 |
|
| 343 |
// long min value is -9223372036854775808 |
| 344 |
// and max value can be 9223372036854775807 |
| 345 |
String xpath = "xs:long('9223372036854775807') gt 0"; |
| 346 |
XPath path = compileXPath(dc, xpath); |
| 347 |
|
| 348 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 349 |
ResultSequence rs = eval.evaluate(path); |
| 350 |
|
| 351 |
XSBoolean result = (XSBoolean) rs.first(); |
| 352 |
|
| 353 |
String actual = result.string_value(); |
| 354 |
|
| 355 |
assertEquals("true", actual); |
| 356 |
} |
| 357 |
|
| 358 |
public void testIntDataType() throws Exception { |
| 359 |
// Bug 275105 |
| 360 |
URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 361 |
loadDOMDocument(fileURL); |
| 362 |
|
| 363 |
// Get XML Schema Information for the Document |
| 364 |
XSModel schema = getGrammar(); |
| 365 |
|
| 366 |
DynamicContext dc = setupDynamicContext(schema); |
| 367 |
|
| 368 |
// int min value is -2147483648 |
| 369 |
// and max value can be 2147483647 |
| 370 |
String xpath = "xs:int('2147483647') gt 0"; |
| 371 |
XPath path = compileXPath(dc, xpath); |
| 372 |
|
| 373 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 374 |
ResultSequence rs = eval.evaluate(path); |
| 375 |
|
| 376 |
XSBoolean result = (XSBoolean) rs.first(); |
| 377 |
|
| 378 |
String actual = result.string_value(); |
| 379 |
|
| 380 |
assertEquals("true", actual); |
| 381 |
} |
| 382 |
|
| 383 |
public void testSchemaAwarenessForAttributes() throws Exception { |
| 384 |
// Bug 276134 |
| 385 |
URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml"); |
| 386 |
URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd"); |
| 387 |
|
| 388 |
loadDOMDocument(fileURL, schemaURL); |
| 389 |
|
| 390 |
// Get XSModel object for the Schema |
| 391 |
XSModel schema = getGrammar(); |
| 392 |
|
| 393 |
DynamicContext dc = setupDynamicContext(schema); |
| 394 |
|
| 395 |
String xpath = "person/@dob eq xs:date('2006-12-10')"; |
| 396 |
XPath path = compileXPath(dc, xpath); |
| 397 |
|
| 398 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 399 |
ResultSequence rs = eval.evaluate(path); |
| 400 |
|
| 401 |
XSBoolean result = (XSBoolean) rs.first(); |
| 402 |
|
| 403 |
String actual = result.string_value(); |
| 404 |
|
| 405 |
assertEquals("true", actual); |
| 406 |
} |
| 407 |
|
| 408 |
public void testSchemaAwarenessForElements() throws Exception { |
| 409 |
// Bug 276134 |
| 410 |
URL fileURL = bundle.getEntry("/bugTestFiles/bug276134_2.xml"); |
| 411 |
URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134_2.xsd"); |
| 412 |
|
| 413 |
loadDOMDocument(fileURL, schemaURL); |
| 414 |
|
| 415 |
// Get XSModel object for the Schema |
| 416 |
XSModel schema = getGrammar(); |
| 417 |
|
| 418 |
DynamicContext dc = setupDynamicContext(schema); |
| 419 |
|
| 420 |
String xpath = "person/dob eq xs:date('2006-12-10')"; |
| 421 |
XPath path = compileXPath(dc, xpath); |
| 422 |
|
| 423 |
Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 424 |
ResultSequence rs = eval.evaluate(path); |
| 425 |
|
| 426 |
XSBoolean result = (XSBoolean) rs.first(); |
| 427 |
|
| 428 |
String actual = result.string_value(); |
| 429 |
|
| 430 |
assertEquals("true", actual); |
| 431 |
} |
| 97 |
|
432 |
|
| 98 |
} |
433 |
} |