Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 276134 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/xml/xpath2/processor/test/AbstractPsychoPathTest.java (-5 / +183 lines)
Lines 7-27 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
 *     Jin Mingjan - bug 262765 -  extractXPathExpression and getExpectedResults
11
 *     Mukul Gandhi - bug 273760 - wrong namespace for functions and data types
12
 *     Mukul Gandhi - bug 276134 - improvements to schema aware primitive type support
13
 *                                  for attribute/element nodes  
10
 *******************************************************************************/
14
 *******************************************************************************/
11
package org.eclipse.wst.xml.xpath2.processor.test;
15
package org.eclipse.wst.xml.xpath2.processor.test;
12
16
17
18
13
import java.io.*;
19
import java.io.*;
14
import java.net.URL;
20
import java.net.URL;
15
21
import java.util.HashMap;
22
import java.util.Iterator;
23
import java.util.regex.Matcher;
24
import java.util.regex.Pattern;
25
26
import javax.xml.XMLConstants;
27
import javax.xml.transform.stream.StreamSource;
28
import javax.xml.validation.Schema;
29
import javax.xml.validation.SchemaFactory;
30
31
import org.apache.xerces.impl.xs.SchemaGrammar;
32
import org.apache.xerces.jaxp.validation.XSGrammarPoolContainer;
33
import org.apache.xerces.xni.grammars.Grammar;
34
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
35
import org.apache.xerces.xni.grammars.XMLGrammarPool;
36
import org.apache.xerces.xni.grammars.XSGrammar;
16
import org.apache.xerces.xs.ElementPSVI;
37
import org.apache.xerces.xs.ElementPSVI;
17
import org.apache.xerces.xs.XSModel;
38
import org.apache.xerces.xs.XSModel;
18
import org.eclipse.core.runtime.Platform;
39
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.wst.xml.xpath2.processor.*;
40
import org.eclipse.wst.xml.xpath2.processor.*;
20
import org.eclipse.wst.xml.xpath2.processor.ast.*;
41
import org.eclipse.wst.xml.xpath2.processor.ast.*;
21
import org.eclipse.wst.xml.xpath2.processor.function.*;
42
import org.eclipse.wst.xml.xpath2.processor.function.*;
22
import org.eclipse.wst.xml.xpath2.processor.internal.function.XDTCtrLibrary;
43
import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType;
44
import org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType;
45
import org.eclipse.wst.xml.xpath2.processor.internal.types.QName;
23
import org.osgi.framework.Bundle;
46
import org.osgi.framework.Bundle;
24
import org.w3c.dom.Document;
47
import org.w3c.dom.Document;
48
import org.xml.sax.SAXException;
25
49
26
import junit.framework.TestCase;
50
import junit.framework.TestCase;
27
51
Lines 29-34 Link Here
29
53
30
	protected Document domDoc = null;
54
	protected Document domDoc = null;
31
	protected Bundle bundle = null;
55
	protected Bundle bundle = null;
56
	
57
	private static final String INPUT_CONTEXT = "input-context";
58
	private static final String INPUT_CONTEXT1 = "input-context1";
59
	private static final String INPUT_CONTEXT2 = "input-context2";
60
//	private static final String S_COMMENT1 = "(:";
61
	private static final String S_COMMENT2 = ":)";
62
	private static final String DECLARE_NAMESPACE = "declare namespace";
63
	private static final String DECLARE_VARIABLE = "declare variable";
64
	private static final String REGEX_DN = "declare namespace\\s+(\\w[-_\\w]*)\\s*=\\s*['\"]([^;]*)['\"];";
65
	private static HashMap<String, String> namespaceMap = new HashMap<String, String>(3);
66
	private static HashMap<String, String> inputMap = new HashMap<String, String>(3);
32
67
33
	@Override
68
	@Override
34
	protected void setUp() throws Exception {
69
	protected void setUp() throws Exception {
Lines 44-49 Link Here
44
		domloader.set_validating(false);
79
		domloader.set_validating(false);
45
		domDoc = domloader.load(is);
80
		domDoc = domloader.load(is);
46
	}
81
	}
82
	
83
	protected void loadDOMDocument(URL fileURL, URL schemaURL) throws IOException,
84
	        DOMLoaderException, SAXException {
85
      InputStream is = fileURL.openStream();
86
      InputStream schemaIs = schemaURL.openStream();
87
      Schema jaxpSchema = getSchema(schemaIs);
88
      DOMLoader domloader = new XercesLoader(jaxpSchema);
89
      domloader.set_validating(false);
90
      domDoc = domloader.load(is);
91
    }
92
	
93
	private Schema getSchema(InputStream schemaIs) throws SAXException {
94
		SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
95
        Schema schema = sf.newSchema(new StreamSource(schemaIs));
96
        return schema;
97
	}
47
98
48
	@Override
99
	@Override
49
	protected void tearDown() throws Exception {
100
	protected void tearDown() throws Exception {
Lines 56-70 Link Here
56
		XSModel schema = rootPSVI.getSchemaInformation();
107
		XSModel schema = rootPSVI.getSchemaInformation();
57
		return schema;
108
		return schema;
58
	}
109
	}
110
	
111
	protected XSModel getGrammar(URL schemaURL) 
112
	                          throws IOException, SAXException {
113
		InputStream schemaIs = schemaURL.openStream();
114
		SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
115
        Schema schema = sf.newSchema(new StreamSource(schemaIs));
116
        XSGrammarPoolContainer poolContainer = (XSGrammarPoolContainer) schema;
117
        XMLGrammarPool pool = poolContainer.getGrammarPool();
118
        Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
119
        
120
        XSGrammar[] xsGrammars = new XSGrammar[grammars.length];
121
        System.arraycopy(grammars, 0, xsGrammars, 0, grammars.length);
122
        
123
        return xsGrammars[0].toXSModel(xsGrammars);
124
	}
59
125
60
	protected DynamicContext setupDynamicContext(XSModel schema) {
126
	protected DynamicContext setupDynamicContext(XSModel schema) {
61
		DynamicContext dc = new DefaultDynamicContext(schema, domDoc);
127
		DynamicContext dc = new DefaultDynamicContext(schema, domDoc);
62
		dc.add_namespace("xsd", "http://www.w3.org/2001/XMLSchema");
128
		dc.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");
63
		dc.add_namespace("xdt", "http://www.w3.org/2004/10/xpath-datatypes");
129
		dc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
64
130
65
		dc.add_function_library(new FnFunctionLibrary());
131
		dc.add_function_library(new FnFunctionLibrary());
66
		dc.add_function_library(new XSCtrLibrary());
132
		dc.add_function_library(new XSCtrLibrary());
67
		dc.add_function_library(new XDTCtrLibrary());
68
		return dc;
133
		return dc;
69
	}
134
	}
70
135
Lines 77-81 Link Here
77
		name_check.check(path);
142
		name_check.check(path);
78
		return path;
143
		return path;
79
	}
144
	}
145
	
146
	protected String getExpectedResult(String xqFile){
147
		String resultFile = xqFile;
148
		//
149
		if (resultFile.length()<10) {   //<9 enough? like XPST0001
150
			return resultFile;
151
		}
152
		String content="";
153
		//
154
		InputStream isrf;
155
		try {
156
			isrf = bundle.getEntry(resultFile).openStream();
157
			BufferedReader rfreader = new BufferedReader(new InputStreamReader(isrf));
158
			//XXX:assume char buffer 2048 is long enough;1024 maybe enough
159
	        //Exception: Axes085, NodeTest003/04/05,... 
160
			int bufferLength = 2048;
161
			if ((resultFile.indexOf("Axes085") != -1)
162
					|| (resultFile.indexOf("NodeTest003") != -1)
163
					|| (resultFile.indexOf("NodeTest004") != -1)
164
					|| (resultFile.indexOf("NodeTest005") != -1)) {
165
				bufferLength = 40000;
166
			}else if(resultFile.indexOf("ForExpr013") != -1) {
167
				bufferLength = 433500;
168
			}else if(resultFile.indexOf("ForExpr016") != -1
169
					|| (resultFile.indexOf("ReturnExpr011") != -1)
170
					|| (resultFile.indexOf("sgml-queries-results-q1") != -1)
171
					|| (resultFile.indexOf("sgml-queries-results-q2") != -1)) {
172
				bufferLength = 10240;
173
			}
174
			char[] cbuf = new char[bufferLength];
175
			int nByte = rfreader.read(cbuf);
176
	        assertTrue(resultFile,nByte<bufferLength);//assert nice buffer length
177
	        
178
	        content = new String(cbuf).trim();
179
	        rfreader.close();
180
	        isrf.close();
181
			
182
		} catch (IOException e) {
183
//			e.printStackTrace();
184
			content = "XPST0003";
185
		}
186
		return content;
187
	}
188
	
189
	public String extractXPathExpression(String xqFile, String inputFile) {
190
		// get the xpath2 expr from xq file, first
191
        char[] cbuf = new char[2048];//
192
        String content = null;
193
        String xpath2Expr = null;
194
		
195
		try {
196
			InputStream isxq =  bundle.getEntry(xqFile).openStream();
197
	        BufferedReader xqreader = new BufferedReader(new InputStreamReader(isxq));
198
	        int nByte = xqreader.read(cbuf);
199
	        assertTrue(xqFile,nByte<2048);
200
	        content = new String(cbuf).trim();
201
	        //
202
			if (content.indexOf(INPUT_CONTEXT) != -1
203
					&& content.indexOf(INPUT_CONTEXT1) == -1
204
					&& content.indexOf(INPUT_CONTEXT2) == -1) {
205
				inputMap.put(INPUT_CONTEXT, inputFile);
206
			} else if (content.indexOf(INPUT_CONTEXT1) == -1) {
207
				inputMap.put(INPUT_CONTEXT1, inputFile);
208
			} else if (content.indexOf(INPUT_CONTEXT2) != -1) {
209
				inputMap.put(INPUT_CONTEXT2, inputFile);
210
			}
211
	        //	        
212
	        if (content.indexOf(DECLARE_NAMESPACE)!=-1) {
213
	        	setupNamespace(content);
214
	        }
215
	        //
216
	        assertTrue(content.lastIndexOf(S_COMMENT2)!=-1);//assert to get
217
	        xpath2Expr = content.substring(content.lastIndexOf(S_COMMENT2)+2).trim(); 
218
	        
219
	        xqreader.close();
220
	        isxq.close();
221
		} catch (IOException e) {
222
			// TODO Auto-generated catch block
223
			e.printStackTrace();
224
		}
225
		return xpath2Expr;
226
	}
227
	
228
	protected void setupNamespace(String content) {
229
		Pattern p = Pattern.compile(REGEX_DN);
230
		Matcher m = p.matcher(content);
231
		while (m.find()) {
232
			assertTrue(m.groupCount()==2);//
233
			namespaceMap.put(m.group(1), m.group(2));
234
		}
235
		
236
	}
237
	
238
	protected DynamicContext setupVariables(DynamicContext dc) {
239
		dc.add_variable(new QName("x"));
240
		dc.add_variable(new QName("var"));
241
		ElementType elementType = new ElementType(domDoc.getDocumentElement(), 0);;
242
		dc.set_variable(new QName("input-context1"), elementType);
243
		
244
		return dc;
245
	}
246
247
	protected String buildResultString(ResultSequence rs) {
248
		String actual = new String();
249
		Iterator<AnyType> iterator = rs.iterator();
250
		while (iterator.hasNext()) {
251
			AnyType anyType = iterator.next();
252
			actual = actual + anyType.string_value() + " ";
253
		}
254
	
255
		return actual.trim();
256
	}
257
	
80
258
81
}
259
}
(-)src/org/eclipse/wst/xml/xpath2/processor/test/TestBugs.java (-2 / +338 lines)
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(schemaURL);
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
	
409
	public void testSchemaAwarenessForElements() throws Exception {
410
		// Bug 276134
411
		URL fileURL = bundle.getEntry("/bugTestFiles/bug276134_2.xml");
412
		URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134_2.xsd");
413
414
		loadDOMDocument(fileURL, schemaURL);
415
		
416
		// Get XSModel object for the Schema
417
		XSModel schema = getGrammar(schemaURL);
418
419
		DynamicContext dc = setupDynamicContext(schema);
420
		
421
		String xpath = "person/dob eq xs:date('2006-12-10')";
422
		XPath path = compileXPath(dc, xpath);
423
424
		Evaluator eval = new DefaultEvaluator(dc, domDoc);
425
		ResultSequence rs = eval.evaluate(path);
426
427
		XSBoolean result = (XSBoolean) rs.first();
428
429
		String actual = result.string_value();
430
431
		assertEquals("true", actual);
432
	}
97
433
98
}
434
}
(-)bugTestFiles/bug276134_2.xml (+6 lines)
Added Link Here
1
<person>
2
  <id>100</id>
3
  <fname>Mukul</fname>
4
  <lname>Gandhi</lname>
5
  <dob>2006-12-10</dob>
6
</person>
(-)bugTestFiles/bug276134.xsd (+14 lines)
Added Link Here
1
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
2
 
3
  <xs:element name="person">
4
   <xs:complexType>
5
    <xs:sequence>
6
     <xs:element name="fname" type = "xs:string" />
7
     <xs:element name="lname" type = "xs:string" />
8
    </xs:sequence>
9
    <xs:attribute name="id" type="xs:integer" />
10
    <xs:attribute name="dob" type="xs:date" />
11
   </xs:complexType>
12
  </xs:element>
13
 
14
</xs:schema>
(-)bugTestFiles/bug276134.xml (+4 lines)
Added Link Here
1
<person id="100" dob="2006-12-10">
2
  <fname>Mukul</fname>
3
  <lname>Gandhi</lname>
4
</person>
(-)bugTestFiles/bug276134_2.xsd (+14 lines)
Added Link Here
1
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
2
 
3
  <xs:element name="person">
4
   <xs:complexType>
5
    <xs:sequence>
6
     <xs:element name="id" type = "xs:integer" />
7
     <xs:element name="fname" type = "xs:string" />
8
     <xs:element name="lname" type = "xs:string" />
9
     <xs:element name="dob" type = "xs:date" />
10
    </xs:sequence>
11
   </xs:complexType>
12
  </xs:element>
13
 
14
</xs:schema>

Return to bug 276134