Search in sources :

Example 61 with Tx

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

Example 62 with Tx

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

Example 63 with Tx

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

Example 64 with Tx

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);
}
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 65 with Tx

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&param=b&param=c");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Page(org.structr.web.entity.dom.Page) Template(org.structr.web.entity.dom.Template) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Tx (org.structr.core.graph.Tx)892 FrameworkException (org.structr.common.error.FrameworkException)684 Test (org.junit.Test)461 App (org.structr.core.app.App)201 StructrApp (org.structr.core.app.StructrApp)201 StructrUiTest (org.structr.web.StructrUiTest)139 NodeInterface (org.structr.core.graph.NodeInterface)117 StructrTest (org.structr.common.StructrTest)108 IOException (java.io.IOException)105 PropertyMap (org.structr.core.property.PropertyMap)102 LinkedList (java.util.LinkedList)99 TestOne (org.structr.core.entity.TestOne)98 File (org.structr.web.entity.File)83 Page (org.structr.web.entity.dom.Page)71 Principal (org.structr.core.entity.Principal)65 Folder (org.structr.web.entity.Folder)65 PropertyKey (org.structr.core.property.PropertyKey)62 NodeAttribute (org.structr.core.graph.NodeAttribute)57 SchemaNode (org.structr.core.entity.SchemaNode)45 AbstractFile (org.structr.web.entity.AbstractFile)44