Search in sources :

Example 56 with FrameworkException

use of org.structr.common.error.FrameworkException in project structr by structr.

the class SimpleTest method test001EMailAddressConstraint.

@Test
public void test001EMailAddressConstraint() {
    final PropertyKey<String> eMail = StructrApp.key(User.class, "eMail");
    try (final Tx tx = app.tx()) {
        app.create(User.class, new NodeAttribute(User.name, "TestUser1"), new NodeAttribute(eMail, "user@structr.test"));
        app.create(User.class, new NodeAttribute(User.name, "TestUser2"), new NodeAttribute(eMail, "user@structr.test"));
        tx.success();
        fail("Expected exception to be thrown.");
    } catch (FrameworkException fex) {
        assertEquals("Invalid error code", 422, fex.getStatus());
    }
    check();
    try (final Tx tx = app.tx()) {
        app.create(User.class, new NodeAttribute(User.name, "TestUser1"), new NodeAttribute(eMail, "user@structr.test"));
        app.create(User.class, new NodeAttribute(User.name, "TestUser2"), new NodeAttribute(eMail, "User@Structr.test"));
        tx.success();
        fail("Expected exception to be thrown.");
    } catch (FrameworkException fex) {
        assertEquals("Invalid error code", 422, fex.getStatus());
    }
    check();
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 57 with FrameworkException

use of org.structr.common.error.FrameworkException in project structr by structr.

the class SimpleTest method testIncreasePageVersion.

@Test
public void testIncreasePageVersion() {
    Page page = null;
    try (final Tx tx = app.tx()) {
        page = Page.createSimplePage(securityContext, "test");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unepxected exception.");
    }
    try (final Tx tx = app.tx()) {
        assertEquals("Page version is not increased on modification", 0, page.getVersion());
        final Element div = page.createElement("div");
        // add new element
        page.getElementsByTagName("div").item(0).appendChild(div);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unepxected exception.");
    }
    try (final Tx tx = app.tx()) {
        assertEquals("Page version is not increased on modification", 3, page.getVersion());
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unepxected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DOMElement(org.structr.web.entity.dom.DOMElement) Element(org.w3c.dom.Element) Page(org.structr.web.entity.dom.Page) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 58 with FrameworkException

use of org.structr.common.error.FrameworkException 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 59 with FrameworkException

use of org.structr.common.error.FrameworkException 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 60 with FrameworkException

use of org.structr.common.error.FrameworkException 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)

Aggregations

FrameworkException (org.structr.common.error.FrameworkException)892 Tx (org.structr.core.graph.Tx)673 Test (org.junit.Test)450 App (org.structr.core.app.App)175 StructrApp (org.structr.core.app.StructrApp)174 StructrUiTest (org.structr.web.StructrUiTest)134 NodeInterface (org.structr.core.graph.NodeInterface)121 StructrTest (org.structr.common.StructrTest)118 PropertyKey (org.structr.core.property.PropertyKey)109 PropertyMap (org.structr.core.property.PropertyMap)105 IOException (java.io.IOException)96 GraphObject (org.structr.core.GraphObject)93 TestOne (org.structr.core.entity.TestOne)92 File (org.structr.web.entity.File)85 SecurityContext (org.structr.common.SecurityContext)78 Principal (org.structr.core.entity.Principal)69 Page (org.structr.web.entity.dom.Page)69 LinkedList (java.util.LinkedList)62 Folder (org.structr.web.entity.Folder)60 NodeAttribute (org.structr.core.graph.NodeAttribute)56