Search in sources :

Example 1 with PropertyMap

use of org.structr.core.property.PropertyMap 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 2 with PropertyMap

use of org.structr.core.property.PropertyMap 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 3 with PropertyMap

use of org.structr.core.property.PropertyMap 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)

Example 4 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class AdvancedSchemaTest method test03InheritanceOfFileAttributesToSubclassOfImage.

@Test
public void test03InheritanceOfFileAttributesToSubclassOfImage() {
    try (final Tx tx = app.tx()) {
        createAdminUser();
        createResourceAccess("_schema", UiAuthenticator.AUTH_USER_GET);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName("File").getFirst();
        SchemaProperty testFileProperty = app.create(SchemaProperty.class);
        final PropertyMap testFileProperties = new PropertyMap();
        testFileProperties.put(SchemaProperty.name, "testFile");
        testFileProperties.put(SchemaProperty.propertyType, "String");
        testFileProperties.put(SchemaProperty.schemaNode, fileNodeDef);
        testFileProperty.setProperties(testFileProperty.getSecurityContext(), testFileProperties);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        // Create new schema node for dynamic class SubFile which extends File
        SchemaNode subFile = app.create(SchemaNode.class);
        final PropertyMap subFileProperties = new PropertyMap();
        subFileProperties.put(SchemaNode.name, "SubFile");
        subFileProperties.put(SchemaNode.extendsClass, "org.structr.dynamic.Image");
        subFile.setProperties(subFile.getSecurityContext(), subFileProperties);
        // Add String property "testSubFile" to new dynamic class
        SchemaProperty testFileProperty = app.create(SchemaProperty.class);
        final PropertyMap testFileProperties = new PropertyMap();
        testFileProperties.put(SchemaProperty.name, "testSubFile");
        testFileProperties.put(SchemaProperty.propertyType, "String");
        testFileProperties.put(SchemaProperty.schemaNode, subFile);
        testFileProperty.setProperties(testFileProperty.getSecurityContext(), testFileProperties);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).expect().statusCode(200).body("result", hasSize(count2 + 1)).body("result", Matchers.hasItem(Matchers.allOf(hasEntry("jsonName", "testFile"), hasEntry("declaringClass", "File")))).body("result", Matchers.hasItem(Matchers.allOf(hasEntry("jsonName", "testSubFile"), hasEntry("declaringClass", "SubFile")))).when().get("/_schema/SubFile/ui");
        tx.success();
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : SchemaNode(org.structr.core.entity.SchemaNode) SchemaProperty(org.structr.core.entity.SchemaProperty) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) FrameworkException(org.structr.common.error.FrameworkException) FrontendTest(org.structr.web.basic.FrontendTest) ResourceAccessTest(org.structr.web.basic.ResourceAccessTest) Test(org.junit.Test)

Example 5 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class AdvancedSchemaTest method test02InheritanceOfFileAttributesToSubclass.

@Test
public void test02InheritanceOfFileAttributesToSubclass() {
    try (final Tx tx = app.tx()) {
        createAdminUser();
        createResourceAccess("_schema", UiAuthenticator.AUTH_USER_GET);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName("File").getFirst();
        SchemaProperty testFileProperty = app.create(SchemaProperty.class);
        final PropertyMap changedProperties = new PropertyMap();
        changedProperties.put(SchemaProperty.name, "testFile");
        changedProperties.put(SchemaProperty.propertyType, "String");
        changedProperties.put(SchemaProperty.schemaNode, fileNodeDef);
        testFileProperty.setProperties(testFileProperty.getSecurityContext(), changedProperties);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        // Create new schema node for dynamic class SubFile which extends File
        SchemaNode subFile = app.create(SchemaNode.class);
        final PropertyMap subFileProperties = new PropertyMap();
        subFileProperties.put(SchemaNode.name, "SubFile");
        subFileProperties.put(SchemaNode.extendsClass, "org.structr.dynamic.File");
        subFile.setProperties(subFile.getSecurityContext(), subFileProperties);
        // Add String property "testSubFile" to new dynamic class
        SchemaProperty testFileProperty = app.create(SchemaProperty.class);
        final PropertyMap testFileProperties = new PropertyMap();
        testFileProperties.put(SchemaProperty.name, "testSubFile");
        testFileProperties.put(SchemaProperty.propertyType, "String");
        testFileProperties.put(SchemaProperty.schemaNode, subFile);
        testFileProperty.setProperties(testFileProperty.getSecurityContext(), testFileProperties);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).expect().statusCode(200).body("result", hasSize(count1 + 1)).body("result", Matchers.hasItem(Matchers.allOf(hasEntry("jsonName", "testFile"), hasEntry("declaringClass", "File")))).body("result", Matchers.hasItem(Matchers.allOf(hasEntry("jsonName", "testSubFile"), hasEntry("declaringClass", "SubFile")))).when().get("/_schema/SubFile/ui");
        tx.success();
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : SchemaNode(org.structr.core.entity.SchemaNode) SchemaProperty(org.structr.core.entity.SchemaProperty) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) FrameworkException(org.structr.common.error.FrameworkException) FrontendTest(org.structr.web.basic.FrontendTest) ResourceAccessTest(org.structr.web.basic.ResourceAccessTest) Test(org.junit.Test)

Aggregations

PropertyMap (org.structr.core.property.PropertyMap)233 FrameworkException (org.structr.common.error.FrameworkException)100 Tx (org.structr.core.graph.Tx)93 Test (org.junit.Test)60 App (org.structr.core.app.App)34 StructrApp (org.structr.core.app.StructrApp)34 PropertyKey (org.structr.core.property.PropertyKey)34 LinkedList (java.util.LinkedList)28 NodeInterface (org.structr.core.graph.NodeInterface)25 SchemaProperty (org.structr.core.entity.SchemaProperty)23 SecurityContext (org.structr.common.SecurityContext)22 StructrUiTest (org.structr.web.StructrUiTest)21 GraphObject (org.structr.core.GraphObject)20 Result (org.structr.core.Result)19 File (org.structr.web.entity.File)19 DOMNode (org.structr.web.entity.dom.DOMNode)19 TestOne (org.structr.core.entity.TestOne)17 AbstractNode (org.structr.core.entity.AbstractNode)16 Folder (org.structr.web.entity.Folder)15 Page (org.structr.web.entity.dom.Page)15