public void testVariableReplacement() {
final Date now = new Date();
Page page = null;
DOMNode html = null;
DOMNode head = null;
DOMNode body = null;
DOMNode title = null;
DOMNode h1 = null;
DOMNode div1 = null;
DOMNode p1 = null;
DOMNode div2 = null;
DOMNode p2 = null;
DOMNode div3 = null;
DOMNode p3 = null;
DOMNode a = null;
DOMNode div4 = null;
DOMNode p4 = null;
try (final Tx tx = app.tx()) {
page = Page.createNewPage(securityContext, "testpage");
assertTrue(page != null);
assertTrue(page instanceof Page);
html = (DOMNode) page.createElement("html");
head = (DOMNode) page.createElement("head");
body = (DOMNode) page.createElement("body");
title = (DOMNode) page.createElement("title");
h1 = (DOMNode) page.createElement("h1");
div1 = (DOMNode) page.createElement("div");
p1 = (DOMNode) page.createElement("p");
div2 = (DOMNode) page.createElement("div");
p2 = (DOMNode) page.createElement("p");
div3 = (DOMNode) page.createElement("div");
p3 = (DOMNode) page.createElement("p");
a = (DOMNode) page.createElement("a");
div4 = (DOMNode) page.createElement("div");
p4 = (DOMNode) page.createElement("p");
// add HTML element to page
page.appendChild(html);
// add HEAD and BODY elements to HTML
html.appendChild(head);
html.appendChild(body);
// add TITLE element to HEAD
head.appendChild(title);
// add H1 element to BODY
body.appendChild(h1);
// add DIV element 1 to BODY
body.appendChild(div1);
div1.appendChild(p1);
// add DIV element 2 to DIV
div1.appendChild(div2);
div2.appendChild(p2);
// add DIV element 3 to DIV
div2.appendChild(div3);
div3.appendChild(p3);
// add link to p3
p3.appendChild(a);
a.setProperty(LinkSource.linkable, page);
body.appendChild(div4);
div4.appendChild(p4);
p4.setProperty(DOMElement.restQuery, "/divs");
p4.setProperty(DOMElement.dataKey, "div");
NodeList paragraphs = page.getElementsByTagName("p");
assertEquals(p1, paragraphs.item(0));
assertEquals(p2, paragraphs.item(1));
assertEquals(p3, paragraphs.item(2));