Search in sources :

Example 1 with FrameworkException

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

the class DeploymentTest method test18NonNamedNonSharedTemplateWithChildren.

@Test
public void test18NonNamedNonSharedTemplateWithChildren() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test18");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test18");
        final Body body = createElement(page, html, "body");
        final Template template = createTemplate(page, body, "${render(children)}");
        final Template sharedTemplate = createComponent(template);
        // remove original template from page
        app.delete(template);
        createElement(page, sharedTemplate, "div");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true, false);
}
Also used : 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) Template(org.structr.web.entity.dom.Template) MailTemplate(org.structr.core.entity.MailTemplate) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 2 with FrameworkException

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

the class DeploymentTest method test31RoundtripWithEmptyContentElements.

@Test
public void test31RoundtripWithEmptyContentElements() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test31");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test31");
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        final Div div2 = createElement(page, div1, "div", "");
        final Table table1 = createElement(page, div2, "table");
        final Thead thead = createElement(page, table1, "thead");
        final Tbody tbody = createElement(page, table1, "tbody");
        final Tr tr1 = createElement(page, thead, "tr");
        final Tr tr2 = createElement(page, tbody, "tr");
        final Td td11 = createElement(page, tr1, "td");
        final Content c1 = createContent(page, td11, "");
        final Td td12 = createElement(page, tr1, "td", "content12");
        final P p1 = createElement(page, td12, "p", "");
        final Ul ul = createElement(page, p1, "ul");
        final Li li = createElement(page, ul, "li", "");
        final Td td21 = createElement(page, tr2, "td", "content21");
        final Td td22 = createElement(page, tr2, "td", "content22");
        final Select select = createElement(page, td11, "select");
        final Option option1 = createElement(page, select, "option", "");
        final Option option2 = createElement(page, select, "option", "value2");
        final Content c2 = createContent(page, div2, "");
        final Table table2 = createElement(page, div2, "table");
        // include visibility flags
        page.setProperty(AbstractNode.visibleToAuthenticatedUsers, true);
        c1.setProperty(AbstractNode.visibleToAuthenticatedUsers, true);
        c2.setProperty(AbstractNode.visibleToAuthenticatedUsers, true);
        // modify visibility to produce two consecutive deployment instruction comments
        td12.setProperty(AbstractNode.visibleToPublicUsers, true);
        table2.setProperty(AbstractNode.visibleToPublicUsers, true);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    compare(calculateHash(), true);
}
Also used : Head(org.structr.web.entity.html.Head) Table(org.structr.web.entity.html.Table) Tx(org.structr.core.graph.Tx) Thead(org.structr.web.entity.html.Thead) 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) Td(org.structr.web.entity.html.Td) P(org.structr.web.entity.html.P) Content(org.structr.web.entity.dom.Content) Ul(org.structr.web.entity.html.Ul) Select(org.structr.web.entity.html.Select) Option(org.structr.web.entity.html.Option) Tbody(org.structr.web.entity.html.Tbody) Body(org.structr.web.entity.html.Body) Li(org.structr.web.entity.html.Li) Tr(org.structr.web.entity.html.Tr) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 3 with FrameworkException

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

the class DeploymentTest method test28MailTemplates.

@Test
public void test28MailTemplates() {
    // setup
    try (final Tx tx = app.tx()) {
        app.create(MailTemplate.class, new NodeAttribute<>(StructrApp.key(MailTemplate.class, "name"), "template1"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "locale"), "de_DE"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "text"), "text1"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "visibleToPublicUsers"), true));
        app.create(MailTemplate.class, new NodeAttribute<>(StructrApp.key(MailTemplate.class, "name"), "template2"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "locale"), "en"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "text"), "text2"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "visibleToAuthenticatedUsers"), true));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // test
    doImportExportRoundtrip(true);
    // check
    try (final Tx tx = app.tx()) {
        final MailTemplate template1 = app.nodeQuery(MailTemplate.class).and(MailTemplate.name, "template1").getFirst();
        final MailTemplate template2 = app.nodeQuery(MailTemplate.class).and(MailTemplate.name, "template2").getFirst();
        Assert.assertNotNull("Invalid deployment result", template1);
        Assert.assertNotNull("Invalid deployment result", template2);
        Assert.assertEquals("Invalid MailTemplate deployment result", "template1", template1.getProperty(StructrApp.key(MailTemplate.class, "name")));
        Assert.assertEquals("Invalid MailTemplate deployment result", "de_DE", template1.getProperty(StructrApp.key(MailTemplate.class, "locale")));
        Assert.assertEquals("Invalid MailTemplate deployment result", "text1", template1.getProperty(StructrApp.key(MailTemplate.class, "text")));
        Assert.assertEquals("Invalid MailTemplate deployment result", true, template1.getProperty(StructrApp.key(MailTemplate.class, "visibleToPublicUsers")));
        Assert.assertEquals("Invalid MailTemplate deployment result", false, template1.getProperty(StructrApp.key(MailTemplate.class, "visibleToAuthenticatedUsers")));
        Assert.assertEquals("Invalid MailTemplate deployment result", "template2", template2.getProperty(StructrApp.key(MailTemplate.class, "name")));
        Assert.assertEquals("Invalid MailTemplate deployment result", "en", template2.getProperty(StructrApp.key(MailTemplate.class, "locale")));
        Assert.assertEquals("Invalid MailTemplate deployment result", "text2", template2.getProperty(StructrApp.key(MailTemplate.class, "text")));
        Assert.assertEquals("Invalid MailTemplate deployment result", false, template2.getProperty(StructrApp.key(MailTemplate.class, "visibleToPublicUsers")));
        Assert.assertEquals("Invalid MailTemplate deployment result", true, template2.getProperty(StructrApp.key(MailTemplate.class, "visibleToAuthenticatedUsers")));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) MailTemplate(org.structr.core.entity.MailTemplate) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 4 with FrameworkException

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

the class DeploymentTest method test37SharedComponentTemplate.

@Test
public void test37SharedComponentTemplate() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createSimplePage(securityContext, "page1");
        final Div div = (Div) page.getElementsByTagName("div").item(0);
        try {
            final DOMNode newNode = (DOMNode) page.createTextNode("#template");
            newNode.unlockSystemPropertiesOnce();
            newNode.setProperties(newNode.getSecurityContext(), new PropertyMap(NodeInterface.type, Template.class.getSimpleName()));
            // append template
            div.appendChild(newNode);
            // create component from div
            createComponent(div);
        } catch (FrameworkException fex) {
            fex.printStackTrace();
            fail("Unexpected exception.");
        }
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    compare(calculateHash(), true);
}
Also used : Div(org.structr.web.entity.html.Div) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Page(org.structr.web.entity.dom.Page) DOMNode(org.structr.web.entity.dom.DOMNode) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 5 with FrameworkException

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

the class DeploymentTest method test35WidgetWithSharedComponentCreation.

@Test
public void test35WidgetWithSharedComponentCreation() {
    // 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:component src=\"TestComponent\">\n" + "	<div data-structr-meta-name=\"TestComponent\">\n" + "		Test123\n" + "	</div>\n" + "</structr:component>"), new NodeAttribute<>(StructrApp.key(Widget.class, "configuration"), ""), new NodeAttribute<>(StructrApp.key(Widget.class, "visibleToPublicUsers"), true), new NodeAttribute<>(StructrApp.key(Widget.class, "visibleToAuthenticatedUsers"), true));
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("widgetHostBaseUrl", "https://widgets.structr.org/structr/rest/widgets");
        paramMap.put("parentId", widgetToImport.getProperty(new StartNode<>("owner", PrincipalOwnsNode.class)));
        paramMap.put("source", widgetToImport.getProperty(new StringProperty("source")));
        paramMap.put("processDeploymentInfo", false);
        Widget.expandWidget(securityContext, testPage, div, baseUri, paramMap, false);
        Widget.expandWidget(securityContext, testPage, div, baseUri, paramMap, false);
        makePublic(testPage, html, head, body, div, div2);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // test
    try (final Tx tx = app.tx()) {
        Div div = app.nodeQuery(Div.class).andName("WidgetTestPage-Div").getFirst();
        assertEquals(2, div.treeGetChildCount());
        Object obj = null;
        for (DOMNode n : div.getAllChildNodes()) {
            obj = n;
            break;
        }
        assertTrue(Div.class.isAssignableFrom(obj.getClass()));
        Div clonedNode = (Div) obj;
        assertEquals(0, clonedNode.getChildNodes().getLength());
        assertEquals(3, app.nodeQuery(Div.class).andName("TestComponent").getResult().size());
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : StartNode(org.structr.core.property.StartNode) Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) HashMap(java.util.HashMap) 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) Div(org.structr.web.entity.html.Div) GraphObject(org.structr.core.GraphObject) DOMNode(org.structr.web.entity.dom.DOMNode) Body(org.structr.web.entity.html.Body) 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