Search in sources :

Example 11 with Div

use of org.structr.web.entity.html.Div in project structr by structr.

the class DeploymentTest method test20ExportOwnership.

@Test
public void test20ExportOwnership() {
    Principal user1 = null;
    Principal user2 = null;
    try (final Tx tx = app.tx()) {
        user1 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
        user2 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
        tx.success();
    } catch (FrameworkException ex) {
        fail("Unexpected exception.");
    }
    Assert.assertNotNull("User was not created, test cannot continue", user1);
    Assert.assertNotNull("User was not created, test cannot continue", user2);
    // setup
    final SecurityContext context1 = SecurityContext.getInstance(user1, AccessMode.Backend);
    final App app1 = StructrApp.getInstance(context1);
    try (final Tx tx = app1.tx()) {
        final Page page = Page.createNewPage(context1, "test20");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test20");
        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");
        // set owner to different user
        div1.setProperty(AbstractNode.owner, user2);
        content.setProperty(AbstractNode.owner, user2);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true, false);
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) NodeAttribute(org.structr.core.graph.NodeAttribute) Head(org.structr.web.entity.html.Head) User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Div(org.structr.web.entity.html.Div) Content(org.structr.web.entity.dom.Content) SecurityContext(org.structr.common.SecurityContext) Body(org.structr.web.entity.html.Body) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 12 with Div

use of org.structr.web.entity.html.Div in project structr by structr.

the class DiffTest method testTreeRemovalFix.

@Test
public void testTreeRemovalFix() {
    final String comment = "<!-- comment --->";
    testDiff("<html><head><title>Title</title></head><body><div>" + comment + "<div>" + comment + "<div>test</div>" + comment + "<div></div></div></body></html>", (String from) -> {
        String modified = from;
        modified = modified.replace(comment, "");
        return modified;
    });
    // test result on the node level
    try (final Tx tx = app.tx()) {
        final Page page = app.nodeQuery(Page.class).andName("test").getFirst();
        assertNotNull(page);
        final NodeList nodes = page.getElementsByTagName("div");
        final List<Div> divs = collectNodes(nodes, Div.class);
        assertEquals("Wrong number of divs returned from node query", 4, divs.size());
        // check first div, should have no siblings and one child
        final Div firstDiv = divs.get(0);
        assertEquals("Wrong number of children", 1, firstDiv.getChildRelationships().size());
        assertNull("Node should not have siblings", firstDiv.getNextSibling());
        // check second div, should have no siblings and two children
        final Div secondDiv = divs.get(1);
        assertEquals("Wrong number of children", 2, secondDiv.getChildRelationships().size());
        assertNull("Node should not have siblings", secondDiv.getNextSibling());
        // check third div, should have one sibling and one #text child
        final Div thirdDiv = divs.get(2);
        assertEquals("Wrong number of children", 1, thirdDiv.getChildRelationships().size());
        assertNotNull("Node should have one sibling", thirdDiv.getNextSibling());
        // check fourth div, should have no siblings and no children
        final Div fourthDiv = divs.get(3);
        assertEquals("Wrong number of children", 0, fourthDiv.getChildRelationships().size());
        assertNull("Node should not have siblings", fourthDiv.getNextSibling());
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
}
Also used : Div(org.structr.web.entity.html.Div) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NodeList(org.w3c.dom.NodeList) Page(org.structr.web.entity.dom.Page) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 13 with Div

use of org.structr.web.entity.html.Div in project structr by structr.

the class CustomHtmlAttributeTest method testCustomHtmlAttribute.

@Test
public void testCustomHtmlAttribute() {
    try (final Tx tx = app.tx()) {
        // create a page
        final Page newPage = Page.createNewPage(securityContext, "customAttributeTestPage");
        final Html html = createElement(newPage, newPage, "html");
        final Head head = createElement(newPage, html, "head");
        final Title title = createElement(newPage, head, "title", "Test Page for custom html attributes");
        final Body body = createElement(newPage, html, "body");
        final Div div1 = createElement(newPage, body, "div", "DIV with old-style data attribute");
        div1.setProperty(new GenericProperty<String>("data-test-attribute-old-style"), "old-style data attribute");
        final Div div2 = createElement(newPage, body, "div", "DIV with new-style custom html attribute");
        div2.setProperty(new GenericProperty<String>("_custom_html_test-attribute-new-style"), "new-style custom attribute");
        final Div div3 = createElement(newPage, body, "div", "DIV with data-attribute as new-style custom html attribute");
        div3.setProperty(new GenericProperty<String>("_custom_html_data-test-attribute-new-style"), "new-style custom data-attribute");
        final RenderContext renderContext = new RenderContext(securityContext);
        newPage.render(renderContext, 0);
        final String renderedHtml = StringUtils.join(renderContext.getBuffer().getQueue(), "");
        final String expectedHtml = "<!DOCTYPE html>\n" + "<html>\n" + "	<head>\n" + "		<title>Test Page for custom html attributes</title>\n" + "	</head>\n" + "	<body>\n" + "		<div data-test-attribute-old-style=\"old-style data attribute\">DIV with old-style data attribute</div>\n" + "		<div test-attribute-new-style=\"new-style custom attribute\">DIV with new-style custom html attribute</div>\n" + "		<div data-test-attribute-new-style=\"new-style custom data-attribute\">DIV with data-attribute as new-style custom html attribute</div>\n" + "	</body>\n" + "</html>";
        Assert.assertEquals(expectedHtml, renderedHtml);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
}
Also used : Div(org.structr.web.entity.html.Div) RenderContext(org.structr.web.common.RenderContext) Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Html(org.structr.web.entity.html.Html) Title(org.structr.web.entity.html.Title) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 14 with Div

use of org.structr.web.entity.html.Div 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 15 with Div

use of org.structr.web.entity.html.Div 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)

Aggregations

Test (org.junit.Test)28 FrameworkException (org.structr.common.error.FrameworkException)28 Tx (org.structr.core.graph.Tx)28 StructrUiTest (org.structr.web.StructrUiTest)28 Page (org.structr.web.entity.dom.Page)28 Div (org.structr.web.entity.html.Div)28 Body (org.structr.web.entity.html.Body)22 Head (org.structr.web.entity.html.Head)22 Html (org.structr.web.entity.html.Html)22 Content (org.structr.web.entity.dom.Content)11 MailTemplate (org.structr.core.entity.MailTemplate)7 Template (org.structr.web.entity.dom.Template)7 DOMNode (org.structr.web.entity.dom.DOMNode)6 PropertyMap (org.structr.core.property.PropertyMap)5 GraphObject (org.structr.core.GraphObject)3 Principal (org.structr.core.entity.Principal)3 NodeAttribute (org.structr.core.graph.NodeAttribute)3 User (org.structr.web.entity.User)3 Table (org.structr.web.entity.html.Table)3 SecurityContext (org.structr.common.SecurityContext)2