" <?echo \"A processing instruction\"?>\n" +
" <para>Another <b>paragraph</b>.</para>\n" +
"</test>";
public void testNodeStorage() throws Exception {
BrokerPool pool = BrokerPool.getInstance();
DBBroker broker = null;
try {
broker = pool.get(pool.getSecurityManager().getSystemSubject());
XQuery xquery = broker.getXQueryService();
assertNotNull(xquery);
// test element ids
Sequence seq = xquery.execute("doc('/db/test/test_string.xml')/test/para",
null, AccessContext.TEST);
assertEquals(3, seq.getItemCount());
NodeProxy comment = (NodeProxy) seq.itemAt(0);
assertEquals(comment.getNodeId().toString(), "1.1");
comment = (NodeProxy) seq.itemAt(1);
assertEquals(comment.getNodeId().toString(), "1.3");
comment = (NodeProxy) seq.itemAt(2);
assertEquals(comment.getNodeId().toString(), "1.5");
seq = xquery.execute("doc('/db/test/test_string.xml')/test//a",
null, AccessContext.TEST);
assertEquals(1, seq.getItemCount());
NodeProxy a = (NodeProxy) seq.itemAt(0);
assertEquals("1.3.2", a.getNodeId().toString());
// test attribute id
seq = xquery.execute("doc('/db/test/test_string.xml')/test//a/@href",
null, AccessContext.TEST);
assertEquals(1, seq.getItemCount());
NodeProxy href = (NodeProxy) seq.itemAt(0);
System.out.println(StorageAddress.toString(href.getInternalAddress()));
assertEquals("1.3.2.1", href.getNodeId().toString());
// test Attr deserialization
Attr attr = (Attr) href.getNode();
System.out.println(StorageAddress.toString(((StoredNode)attr).getInternalAddress()));
// test Attr fields
assertEquals(attr.getNodeName(), "href");
assertEquals(attr.getName(), "href");
assertEquals(attr.getValue(), "#");
// test DOMFile.getNodeValue()
assertEquals(href.getStringValue(), "#");
// test text node
seq = xquery.execute("doc('/db/test/test_string.xml')/test//b/text()",
null, AccessContext.TEST);
assertEquals(1, seq.getItemCount());
NodeProxy text = (NodeProxy) seq.itemAt(0);
assertEquals("1.5.2.1", text.getNodeId().toString());
// test DOMFile.getNodeValue()
assertEquals(text.getStringValue(), "paragraph");
// test Text deserialization
Text node = (Text) text.getNode();
assertEquals(node.getNodeValue(), "paragraph");
assertEquals(node.getData(), "paragraph");
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
pool.release(broker);
}
}