Search in sources :

Example 6 with FrameworkException

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

the class DeploymentTest method test11TemplateInTbody.

@Test
public void test11TemplateInTbody() {
    // setup
    try (final Tx tx = app.tx()) {
        // create first page
        final Page page1 = Page.createNewPage(securityContext, "test11");
        final Html html1 = createElement(page1, page1, "html");
        final Head head1 = createElement(page1, html1, "head");
        createElement(page1, head1, "title", "test11_1");
        final Body body1 = createElement(page1, html1, "body");
        final Table table = createElement(page1, body1, "table");
        final Tbody tbody = createElement(page1, table, "tbody");
        final Template template1 = createTemplate(page1, tbody, "<tr><td>${user.name}</td></tr>");
        final PropertyMap template1Properties = new PropertyMap();
        template1Properties.put(StructrApp.key(DOMNode.class, "functionQuery"), "find('User')");
        template1Properties.put(StructrApp.key(DOMNode.class, "dataKey"), "user");
        template1.setProperties(template1.getSecurityContext(), template1Properties);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true);
}
Also used : Head(org.structr.web.entity.html.Head) Table(org.structr.web.entity.html.Table) PropertyMap(org.structr.core.property.PropertyMap) 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) Tbody(org.structr.web.entity.html.Tbody) DOMNode(org.structr.web.entity.dom.DOMNode) Body(org.structr.web.entity.html.Body) Template(org.structr.web.entity.dom.Template) MailTemplate(org.structr.core.entity.MailTemplate) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 7 with FrameworkException

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

the class DeploymentTest method test10SharedComponent.

@Test
public void test10SharedComponent() {
    // setup
    try (final Tx tx = app.tx()) {
        // create first page
        final Page page1 = Page.createNewPage(securityContext, "test10_1");
        final Html html1 = createElement(page1, page1, "html");
        final Head head1 = createElement(page1, html1, "head");
        createElement(page1, head1, "title", "test10_1");
        final Body body1 = createElement(page1, html1, "body");
        final Div div1 = createElement(page1, body1, "div");
        createElement(page1, div1, "div", "test1");
        createElement(page1, div1, "div", "test1");
        final Div component = createComponent(div1);
        // create second page
        final Page page2 = Page.createNewPage(securityContext, "test10_2");
        final Html html2 = createElement(page2, page2, "html");
        final Head head2 = createElement(page2, html2, "head");
        createElement(page2, head2, "title", "test10_2");
        final Body body2 = createElement(page2, html2, "body");
        final Div div2 = createElement(page2, body2, "div");
        // re-use template from above
        cloneComponent(component, div2);
        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) 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)

Example 8 with FrameworkException

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

the class DeploymentTest method test36BuiltInTypesWithProperties.

@Test
public void test36BuiltInTypesWithProperties() {
    // setup schema
    try (final Tx tx = app.tx()) {
        final JsonSchema schema = StructrSchema.createFromDatabase(app);
        Assert.assertNotNull("StructrSchema must return a valid schema object", schema);
        final JsonType pageType = schema.getType("Page");
        final JsonType fileType = schema.getType("File");
        Assert.assertNotNull("Type Page must exist in every schema", pageType);
        Assert.assertNotNull("Type File must exist in every schema", fileType);
        pageType.addIntegerProperty("displayPosition");
        pageType.addStringProperty("icon");
        fileType.addIntegerProperty("test1");
        fileType.addStringProperty("test2");
        // install schema
        StructrSchema.replaceDatabaseSchema(app, schema);
        tx.success();
    } catch (FrameworkException | URISyntaxException fex) {
        fail("Unexpected exception.");
    }
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createSimplePage(securityContext, "page1");
        page.setProperty(StructrApp.key(Page.class, "displayPosition"), 12);
        page.setProperty(StructrApp.key(Page.class, "icon"), "icon");
        final Folder folder = app.create(Folder.class, "files");
        folder.setProperty(StructrApp.key(Folder.class, "includeInFrontendExport"), true);
        // create test file with custom attributes
        app.create(File.class, new NodeAttribute<>(StructrApp.key(File.class, "name"), "test.txt"), new NodeAttribute<>(StructrApp.key(File.class, "parent"), folder), new NodeAttribute<>(StructrApp.key(File.class, "contentType"), "text/plain"), new NodeAttribute<>(StructrApp.key(File.class, "test1"), 123), new NodeAttribute<>(StructrApp.key(File.class, "test2"), "testString"));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    compare(calculateHash(), true);
}
Also used : JsonType(org.structr.schema.json.JsonType) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) JsonSchema(org.structr.schema.json.JsonSchema) Page(org.structr.web.entity.dom.Page) URISyntaxException(java.net.URISyntaxException) Folder(org.structr.web.entity.Folder) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 9 with FrameworkException

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

the class DeploymentTest method test34WidgetWithTemplate.

@Test
public void test34WidgetWithTemplate() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page testPage = Page.createNewPage(securityContext, "WidgetTestPage");
        final Html html = createElement(testPage, testPage, "html");
        final Head head = createElement(testPage, html, "head");
        final Body body = createElement(testPage, html, "body");
        final Div div = createElement(testPage, body, "div");
        final Div div2 = createElement(testPage, body, "div");
        div.setProperty(AbstractNode.name, "WidgetTestPage-Div");
        div2.setProperty(AbstractNode.name, "WidgetTestPage-Div2");
        Widget widgetToImport = app.create(Widget.class, new NodeAttribute<>(StructrApp.key(Widget.class, "name"), "TestWidget"), new NodeAttribute<>(StructrApp.key(Widget.class, "source"), "<!-- @structr:content(text/html) --><structr:template>${{Structr.print(\"<div>Test</div>\");}}</structr:template>"), new NodeAttribute<>(StructrApp.key(Widget.class, "configuration"), "{\"processDeploymentInfo\": true}"), new NodeAttribute<>(StructrApp.key(Widget.class, "visibleToPublicUsers"), true), new NodeAttribute<>(StructrApp.key(Widget.class, "visibleToAuthenticatedUsers"), true));
        Importer importer = new Importer(securityContext, widgetToImport.getProperty(new StringProperty("source")), null, null, true, true);
        importer.setIsDeployment(true);
        importer.setCommentHandler(new DeploymentCommentHandler());
        importer.parse(true);
        DOMNode template = importer.createComponentChildNodes(div, testPage);
        div.appendChild(template);
        makePublic(testPage, html, head, body, div, div2, template);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // test
    try (final Tx tx = app.tx()) {
        Div div = (Div) app.nodeQuery().andName("WidgetTestPage-Div").getFirst();
        assertEquals(1, div.treeGetChildCount());
        Object obj = div.treeGetFirstChild();
        assertTrue(Template.class.isAssignableFrom(obj.getClass()));
        Template template = (Template) obj;
        assertEquals("${{Structr.print(\"<div>Test</div>\");}}", template.getTextContent());
        assertEquals("text/html", template.getContentType());
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Widget(org.structr.web.entity.Widget) Html(org.structr.web.entity.html.Html) StringProperty(org.structr.core.property.StringProperty) Page(org.structr.web.entity.dom.Page) Template(org.structr.web.entity.dom.Template) MailTemplate(org.structr.core.entity.MailTemplate) Div(org.structr.web.entity.html.Div) DeploymentCommentHandler(org.structr.web.maintenance.deploy.DeploymentCommentHandler) GraphObject(org.structr.core.GraphObject) DOMNode(org.structr.web.entity.dom.DOMNode) Body(org.structr.web.entity.html.Body) Importer(org.structr.web.importer.Importer) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 10 with FrameworkException

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

the class DeploymentTest method test04ContentTypes.

@Test
public void test04ContentTypes() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test04");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test04");
        createElement(page, head, "link");
        createElement(page, head, "link");
        createComment(page, head, "commentöäüÖÄÜß+#");
        final Link link3 = createElement(page, head, "link");
        final PropertyMap link3Properties = new PropertyMap();
        link3Properties.put(StructrApp.key(Link.class, "_html_href"), "/");
        link3Properties.put(StructrApp.key(Link.class, "_html_media"), "screen");
        link3Properties.put(StructrApp.key(Link.class, "_html_type"), "stylesheet");
        link3.setProperties(link3.getSecurityContext(), link3Properties);
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        createElement(page, div1, "h1", "private");
        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) PropertyMap(org.structr.core.property.PropertyMap) 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) Body(org.structr.web.entity.html.Body) Link(org.structr.web.entity.html.Link) 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