use of org.structr.web.entity.dom.Content in project structr by structr.
the class RendererTest method testMarkdownRenderer.
@Test
public void testMarkdownRenderer() {
Content content = null;
try (final Tx tx = app.tx()) {
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));
final Page page1 = Page.createSimplePage(securityContext, "page1");
final Element div = (Element) page1.getElementsByTagName("div").item(0);
content = (Content) div.getFirstChild();
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
logger.warn("", fex);
}
try (final Tx tx = app.tx()) {
// test markdown content
content.setProperty(StructrApp.key(Content.class, "contentType"), "text/markdown");
content.setProperty(StructrApp.key(Content.class, "content"), "# Title\n" + "This is a test\n\n" + "## Another title\n");
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
logger.warn("", fex);
}
RestAssured.basePath = "/";
// test successful basic auth
RestAssured.given().header("X-User", "admin").header("X-Password", "admin").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).expect().statusCode(200).body("html.head.title", Matchers.equalTo("Page1")).body("html.body.h1", Matchers.equalTo("Page1")).body("html.body.div.h1.a", Matchers.equalTo("Title")).body("html.body.div.p", Matchers.equalTo("This is a test")).body("html.body.div.h2.a", Matchers.equalTo("Another title")).when().get("/html/page1");
}
use of org.structr.web.entity.dom.Content 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.web.entity.dom.Content in project structr by structr.
the class UiScriptingTest method testRestQueryRepeater.
@Test
public void testRestQueryRepeater() {
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();
// setup scripting repeater
content.setProperty(StructrApp.key(Content.class, "restQuery"), "/Page/${current.id}");
content.setProperty(StructrApp.key(Content.class, "dataKey"), "test");
content.setProperty(StructrApp.key(Content.class, "content"), "${test.id}");
// 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(uuid)).when().get("/html/test/" + uuid);
}
use of org.structr.web.entity.dom.Content in project structr by structr.
the class DeploymentTest method test24ContentShowConditions.
@Test
public void test24ContentShowConditions() {
// setup
try (final Tx tx = app.tx()) {
final Page page = Page.createNewPage(securityContext, "test24");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test24");
final Body body = createElement(page, html, "body");
final Div div1 = createElement(page, body, "div");
final Content content1 = createContent(page, div1, "${current.type}");
final Content content2 = createContent(page, div1, "${find('User', 'name', '@structr')[0].id}");
final Content content3 = createContent(page, div1, "${find('User', 'name', '@structr')[0].id}");
content1.setProperty(StructrApp.key(DOMNode.class, "showConditions"), "eq(current.type, 'MyTestFolder')");
content2.setProperty(StructrApp.key(DOMNode.class, "showConditions"), "if(equal(extract(first(find('User', 'name' 'structr')), 'name'), '@structr'), true, false)");
// for testing only
content3.setProperty(StructrApp.key(DOMNode.class, "showConditions"), "(((((([]))))))");
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
compare(calculateHash(), true);
}
use of org.structr.web.entity.dom.Content in project structr by structr.
the class DeploymentTest method test19HtmlEntities.
@Test
public void test19HtmlEntities() {
// setup
try (final Tx tx = app.tx()) {
final Page page = Page.createNewPage(securityContext, "test19");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test19");
final Body body = createElement(page, html, "body");
final Div div1 = createElement(page, body, "div");
final Content content = createContent(page, div1, "<b>Test</b>");
content.setProperty(StructrApp.key(Content.class, "contentType"), "text/html");
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
compare(calculateHash(), true, false);
}
Aggregations