use of org.structr.core.graph.Tx in project structr by structr.
the class SimpleTest method test01DOMChildren.
@Test
public void test01DOMChildren() {
final String pageName = "page-01";
final String pageTitle = "Page Title";
try (final Tx tx = app.tx()) {
Page page = Page.createNewPage(securityContext, pageName);
if (page != null) {
DOMElement html = (DOMElement) page.createElement("html");
DOMElement head = (DOMElement) page.createElement("head");
DOMElement title = (DOMElement) page.createElement("title");
Text titleText = page.createTextNode(pageTitle);
for (AbstractRelationship r : page.getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("PAGE", r.getRelType().name());
}
html.appendChild(head);
for (AbstractRelationship r : head.getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("CONTAINS", r.getRelType().name());
}
head.appendChild(title);
title.appendChild(titleText);
for (AbstractRelationship r : ((DOMNode) titleText).getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("CONTAINS", r.getRelType().name());
}
}
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.graph.Tx in project structr by structr.
the class SimpleTest method testPagePath.
@Test
public void testPagePath() {
final String pageName = "page-01";
try (final Tx tx = app.tx()) {
Page page = Page.createNewPage(securityContext, pageName);
assertTrue(page != null);
assertTrue(page instanceof Page);
DOMElement html = (DOMElement) page.createElement("html");
DOMElement head = (DOMElement) page.createElement("head");
DOMElement body = (DOMElement) page.createElement("body");
DOMElement title = (DOMElement) page.createElement("title");
DOMElement div = (DOMElement) page.createElement("div");
DOMElement div_2 = (DOMElement) page.createElement("div");
DOMElement div_3 = (DOMElement) page.createElement("div");
DOMElement h1 = (DOMElement) page.createElement("h1");
DOMElement h1_2 = (DOMElement) page.createElement("h1");
try {
// 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);
title.appendChild(page.createTextNode("Test Page"));
// add DIVs to BODY
body.appendChild(div);
body.appendChild(div_2);
body.appendChild(div_3);
// add H1 elements to DIV
div_3.appendChild(h1);
div_3.appendChild(h1_2);
h1.appendChild(page.createTextNode("Page Title"));
} catch (DOMException dex) {
throw new FrameworkException(422, dex.getMessage());
}
assertEquals(html.getPositionPath(), "/0");
assertEquals(head.getPositionPath(), "/0/0");
assertEquals(title.getPositionPath(), "/0/0/0");
assertEquals(body.getPositionPath(), "/0/1");
assertEquals(div.getPositionPath(), "/0/1/0");
assertEquals(div_2.getPositionPath(), "/0/1/1");
assertEquals(div_3.getPositionPath(), "/0/1/2");
assertEquals(h1.getPositionPath(), "/0/1/2/0");
assertEquals(h1_2.getPositionPath(), "/0/1/2/1");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception");
}
}
use of org.structr.core.graph.Tx in project structr by structr.
the class SimpleTest method testHttpResponseHeaders.
@Test
public void testHttpResponseHeaders() {
try (final Tx tx = app.tx()) {
Page.createSimplePage(securityContext, "test");
app.create(User.class, new NodeAttribute<>(StructrApp.key(User.class, "name"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "isAdmin"), true));
tx.success();
} catch (FrameworkException fex) {
fail("Unepxected exception.");
}
RestAssured.given().header("X-User", "admin").header("X-Password", "admin").filter(ResponseLoggingFilter.logResponseTo(System.out)).expect().response().contentType("text/html").header("Expires", "Thu, 01 Jan 1970 00:00:00 GMT").header("X-Structr-Edition", "Community").header("Cache-Control", "private, max-age=0, s-maxage=0, no-cache, no-store, must-revalidate").header("Pragma", "no-cache, no-store").header("Content-Type", "text/html;charset=utf-8").header("Strict-Transport-Security", "max-age=60").header("X-Content-Type-Options", "nosniff").header("X-Frame-Options", "SAMEORIGIN").header("X-XSS-Protection", "1;mode=block").header("Vary", "Accept-Encoding, User-Agent").header("Content-Length", "133").header("Server", "Jetty(9.4.8.v20171121)").statusCode(200).when().get("http://127.0.0.1:8875/test");
}
use of org.structr.core.graph.Tx in project structr by structr.
the class UiScriptingTest method testRestQueryWithRemoteAttributeRepeater.
@Test
public void testRestQueryWithRemoteAttributeRepeater() {
String uuid = null;
try (final Tx tx = app.tx()) {
final Page page = Page.createSimplePage(securityContext, "test");
final Div div = (Div) page.getElementsByTagName("div").item(0);
final Content content = (Content) div.getFirstChild();
// Create second div without children
Div div2 = (Div) div.cloneNode(false);
div.getUuid();
// setup scripting repeater to repeat over (non-existing) children of second div
content.setProperty(StructrApp.key(Content.class, "restQuery"), "/Div/" + div2.getUuid() + "/children");
content.setProperty(StructrApp.key(Content.class, "dataKey"), "test");
content.setProperty(StructrApp.key(Content.class, "content"), "foo${test}");
// store UUID for later use
uuid = page.getUuid();
// create admin user
createTestNode(User.class, new NodeAttribute<>(StructrApp.key(User.class, "name"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "isAdmin"), true));
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception.");
}
RestAssured.basePath = "/";
// test successful basic auth
RestAssured.given().headers("X-User", "admin", "X-Password", "admin").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("html.head.title", Matchers.equalTo("Test")).body("html.body.h1", Matchers.equalTo("Test")).body("html.body.div", Matchers.equalTo("")).when().get("/html/test/" + uuid);
}
use of org.structr.core.graph.Tx in project structr by structr.
the class UiScriptingTest method testMultiRequestParameters.
@Test
public void testMultiRequestParameters() {
try (final Tx tx = app.tx()) {
Page page = (Page) app.create(Page.class, new NodeAttribute(Page.name, "test"), new NodeAttribute(Page.visibleToPublicUsers, true));
Template template = (Template) app.create(Template.class, new NodeAttribute(Page.visibleToPublicUsers, true));
template.setContent("${each(request.param, print(data))}");
page.appendChild(template);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
RestAssured.given().filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body(equalTo("abc")).when().get("http://localhost:8875/test?param=a¶m=b¶m=c");
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
}
Aggregations