result = service.query(query); result = service.query(query);
result = service.query(query);
	public void testTypedVariables() {		ResourceSet result;		String query;		boolean exceptionThrown;		String message;				try {			XPathQueryService service = 				storeXMLStringAndGetQueryService(NUMBERS_XML, numbers);			System.out.println("testTypedVariables 1: ========" );			query = "let $v as element()* := ( <assign/> , <assign/> )\n" 				+ "let $w := <r>{ $v }</r>\n"				+ "let $x as element()* := $w/assign\n"				+ "return $x";			result = service.query(query);							assertEquals( "XQuery: " + query, 2, result.getSize() );			assertEquals( "XQuery: " + query, Node.ELEMENT_NODE, ((XMLResource)result.getResource(0)).getContentAsDOM().getNodeType());			assertEquals( "XQuery: " + query, "assign", ((XMLResource)result.getResource(0)).getContentAsDOM().getNodeName());			System.out.println("testTypedVariables 2: ========" );			query = "let $v as node()* := ()\n" 			+ "return $v";			result = service.query(query);					assertEquals( "XQuery: " + query, 0, result.getSize() );						System.out.println("testTypedVariables 3: ========" );			query = "let $v as item()* := ()\n" 			+ "return $v";			result = service.query(query);					assertEquals( "XQuery: " + query, 0, result.getSize() );						System.out.println("testTypedVariables 4: ========" );			query = "let $v as empty() := ()\n" 			+ "return $v";			result = service.query(query);					assertEquals( "XQuery: " + query, 0, result.getSize() );									System.out.println("testTypedVariables 5: ========" );			query = "let $v as item() := ()\n" 			+ "return $v";						try {				exceptionThrown = false;				result = service.query(query);									} catch (XMLDBException e) {				exceptionThrown = true;				message = e.getMessage();			}			assertTrue("XQuery: " + query, exceptionThrown);						System.out.println("testTypedVariables 6: ========" );			query = "let $v as item()* := ( <a/> , 1 )\n" 				+ "return $v";			result = service.query(query);					assertEquals( "XQuery: " + query, 2, result.getSize() );				assertEquals( "XQuery: " + query, Node.ELEMENT_NODE, ((XMLResource)result.getResource(0)).getContentAsDOM().getNodeType());			assertEquals( "XQuery: " + query, "a", ((XMLResource)result.getResource(0)).getContentAsDOM().getNodeName());						assertEquals( "XQuery: " + query, "1", ((XMLResource)result.getResource(1)).getContent());								System.out.println("testTypedVariables 7: ========" );			query = "let $v as node()* := ( <a/> , 1 )\n" 				+ "return $v";						try {				exceptionThrown = false;				result = service.query(query);					} catch (XMLDBException e) {				exceptionThrown = true;				message = e.getMessage();			}			assertTrue(exceptionThrown);							System.out.println("testTypedVariables 8: ========" );			query = "let $v as item()* := ( <a/> , 1 )\n" 				+ "let $w as element()* := $v\n"				+ "return $w";					try {				exceptionThrown = false;				result = service.query(query);						result = service.query(query);					} catch (XMLDBException e) {				exceptionThrown = true;				message = e.getMessage();			}			assertTrue(exceptionThrown);							System.out.println("testTypedVariables 9: ========" );			query = "declare variable $v as element()* {( <assign/> , <assign/> ) };\n" 				+ "declare variable $w { <r>{ $v }</r> };\n"				+ "declare variable $x as element()* { $w/assign };\n"				+ "$x";			result = service.query(query);							assertEquals( "XQuery: " + query, 2, result.getSize() );			assertEquals( "XQuery: " + query, Node.ELEMENT_NODE, ((XMLResource)result.getResource(0)).getContentAsDOM().getNodeType());			assertEquals( "XQuery: " + query, "assign", ((XMLResource)result.getResource(0)).getContentAsDOM().getNodeName());						System.out.println("testTypedVariables 10: ========" );			query = "declare variable $v as node()* { () };\n" 			+ "$v";			result = service.query(query);					assertEquals( "XQuery: " + query, 0, result.getSize() );						System.out.println("testTypedVariables 11: ========" );			query = "declare variable $v as item()* { () };\n" 			+ "$v";			result = service.query(query);					assertEquals( "XQuery: " + query, 0, result.getSize() );						System.out.println("testTypedVariables 12: ========" );			query = "declare variable $v as empty() { () };\n" 			+ "$v";			result = service.query(query);					assertEquals( "XQuery: " + query, 0, result.getSize() );									System.out.println("testTypedVariables 13: ========" );			query = "declare variable $v as item() { () };\n" 			+ "$v";						try {				exceptionThrown = false;				result = service.query(query);									} catch (XMLDBException e) {				exceptionThrown = true;				message = e.getMessage();			}			assertTrue("XQuery: " + query, exceptionThrown);						System.out.println("testTypedVariables 14: ========" );			query = "declare variable $v as item()* { ( <a/> , 1 ) }; \n" 				+ "$v";			result = service.query(query);					assertEquals( "XQuery: " + query, 2, result.getSize() );				assertEquals( "XQuery: " + query, Node.ELEMENT_NODE, ((XMLResource)result.getResource(0)).getContentAsDOM().getNodeType());			assertEquals( "XQuery: " + query, "a", ((XMLResource)result.getResource(0)).getContentAsDOM().getNodeName());						assertEquals( "XQuery: " + query, "1", ((XMLResource)result.getResource(1)).getContent());								System.out.println("testTypedVariables 15: ========" );			query = "declare variable $v as node()* { ( <a/> , 1 ) };\n" 				+ "$v";						try {				exceptionThrown = false;				result = service.query(query);					} catch (XMLDBException e) {				exceptionThrown = true;				message = e.getMessage();			}			assertTrue(exceptionThrown);							System.out.println("testTypedVariables 16: ========" );			query = "declare variable $v as item()* { ( <a/> , 1 ) };\n" 				+ "declare variable $w as element()* { $v };\n"				+ "$w";					try {				exceptionThrown = false;				result = service.query(query);						result = service.query(query);					} catch (XMLDBException e) {				exceptionThrown = true;				message = e.getMessage();			}			assertTrue(exceptionThrown);						System.out.println("testTypedVariables 15: ========" );			query = "let $v as document-node() :=  doc(\"" + "/db/test/" + NUMBERS_XML + "\") \n" 				+ "return $v";			result = service.query(query);					assertEquals( "XQuery: " + query, 1, result.getSize() );				//TODO : no way to test the node type ?			//assertEquals( "XQuery: " + query, Node.DOCUMENT_NODE, ((XMLResource)result.getResource(0)));			assertEquals( "XQuery: " + query, "test", ((XMLResource)result.getResource(0)).getContentAsDOM().getNodeName());									} catch (XMLDBException e) {			System.out.println("testTypedVariables : XMLDBException: "+e);			fail(e.getMessage());		}	}	