Search in sources :

Example 6 with Content

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");
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Content(org.structr.web.entity.dom.Content) Element(org.w3c.dom.Element) Page(org.structr.web.entity.dom.Page) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 7 with Content

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);
}
Also used : Div(org.structr.web.entity.html.Div) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Content(org.structr.web.entity.dom.Content) Page(org.structr.web.entity.dom.Page) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 8 with Content

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);
}
Also used : Div(org.structr.web.entity.html.Div) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Content(org.structr.web.entity.dom.Content) Page(org.structr.web.entity.dom.Page) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 9 with Content

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);
}
Also used : Div(org.structr.web.entity.html.Div) Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Content(org.structr.web.entity.dom.Content) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) DOMNode(org.structr.web.entity.dom.DOMNode) Body(org.structr.web.entity.html.Body) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 10 with Content

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);
}
Also used : Div(org.structr.web.entity.html.Div) Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Content(org.structr.web.entity.dom.Content) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Content (org.structr.web.entity.dom.Content)14 Test (org.junit.Test)12 FrameworkException (org.structr.common.error.FrameworkException)12 Tx (org.structr.core.graph.Tx)12 StructrUiTest (org.structr.web.StructrUiTest)12 Page (org.structr.web.entity.dom.Page)12 Div (org.structr.web.entity.html.Div)11 Body (org.structr.web.entity.html.Body)8 Head (org.structr.web.entity.html.Head)8 Html (org.structr.web.entity.html.Html)7 NodeAttribute (org.structr.core.graph.NodeAttribute)3 DOMNode (org.structr.web.entity.dom.DOMNode)3 SecurityContext (org.structr.common.SecurityContext)2 App (org.structr.core.app.App)2 StructrApp (org.structr.core.app.StructrApp)2 Principal (org.structr.core.entity.Principal)2 User (org.structr.web.entity.User)2 Table (org.structr.web.entity.html.Table)2 IOException (java.io.IOException)1 Attribute (org.jsoup.nodes.Attribute)1