Search in sources :

Example 1 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class DeploymentTest method test38DynamicFileExport.

@Test
public void test38DynamicFileExport() {
    // setup
    try (final Tx tx = app.tx()) {
        app.create(SchemaNode.class, new NodeAttribute<>(SchemaNode.name, "ExtendedFile"), new NodeAttribute<>(SchemaNode.extendsClass, "org.structr.dynamic.File"), new NodeAttribute<>(new StringProperty("_test"), "String"));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    final Class type = StructrApp.getConfiguration().getNodeEntityClass("ExtendedFile");
    final PropertyKey test = StructrApp.key(type, "test");
    Assert.assertNotNull("Extended file type should exist", type);
    Assert.assertNotNull("Extended file property should exist", test);
    try (final Tx tx = app.tx()) {
        final NodeInterface node = FileHelper.createFile(securityContext, "test".getBytes("utf-8"), "text/plain", type, "test.txt");
        node.setProperty(StructrApp.key(File.class, "includeInFrontendExport"), true);
        node.setProperty(test, "test");
        tx.success();
    } catch (IOException | FrameworkException fex) {
        fex.printStackTrace();
        fail("Unexpected exception.");
    }
    compare(calculateHash(), true);
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StringProperty(org.structr.core.property.StringProperty) IOException(java.io.IOException) File(org.structr.web.entity.File) PropertyKey(org.structr.core.property.PropertyKey) NodeInterface(org.structr.core.graph.NodeInterface) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 2 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class AdvancedSchemaTest method test04SchemaPropertyOrderInCustomViews.

@Test
public void test04SchemaPropertyOrderInCustomViews() {
    try (final Tx tx = app.tx()) {
        createAdminUser();
        createResourceAccess("_schema", UiAuthenticator.AUTH_USER_GET);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    final GenericProperty jsonName = new GenericProperty("jsonName");
    SchemaView testView = null;
    String id = null;
    try (final Tx tx = app.tx()) {
        // create test type
        final SchemaNode test = app.create(SchemaNode.class, "Test");
        // create view with sort order
        testView = app.create(SchemaView.class, new NodeAttribute<>(SchemaView.name, "test"), new NodeAttribute<>(SchemaView.schemaNode, test), new NodeAttribute<>(SchemaView.sortOrder, "one, two, three, four, id, type, name"), new NodeAttribute<>(SchemaView.nonGraphProperties, "id, type, name"));
        final List<SchemaView> list = new LinkedList<>();
        list.add(testView);
        // create properties
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, test), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "one"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, test), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "two"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, test), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "three"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, test), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "four"));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final Class type = StructrApp.getConfiguration().getNodeEntityClass("Test");
    final List<PropertyKey> list = new LinkedList<>(StructrApp.getConfiguration().getPropertySet(type, "test"));
    Assert.assertEquals("Invalid number of properties in sorted view", 7, list.size());
    Assert.assertEquals("one", list.get(0).dbName());
    Assert.assertEquals("two", list.get(1).dbName());
    Assert.assertEquals("three", list.get(2).dbName());
    Assert.assertEquals("four", list.get(3).dbName());
    Assert.assertEquals("id", list.get(4).dbName());
    Assert.assertEquals("type", list.get(5).dbName());
    Assert.assertEquals("name", list.get(6).dbName());
    try (final Tx tx = app.tx()) {
        // modify sort order
        testView.setProperty(SchemaView.sortOrder, "type, one, id, two, three, four, name");
        // create test entity
        final NodeInterface node = app.create(StructrApp.getConfiguration().getNodeEntityClass("Test"));
        id = node.getUuid();
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final List<PropertyKey> list2 = new LinkedList<>(StructrApp.getConfiguration().getPropertySet(type, "test"));
    Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
    Assert.assertEquals("type", list2.get(0).dbName());
    Assert.assertEquals("one", list2.get(1).dbName());
    Assert.assertEquals("id", list2.get(2).dbName());
    Assert.assertEquals("two", list2.get(3).dbName());
    Assert.assertEquals("three", list2.get(4).dbName());
    Assert.assertEquals("four", list2.get(5).dbName());
    Assert.assertEquals("name", list2.get(6).dbName());
    // test schema resource
    RestAssured.given().contentType("application/json; charset=UTF-8").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(7)).body("result[0].jsonName", equalTo("type")).body("result[1].jsonName", equalTo("one")).body("result[2].jsonName", equalTo("id")).body("result[3].jsonName", equalTo("two")).body("result[4].jsonName", equalTo("three")).body("result[5].jsonName", equalTo("four")).body("result[6].jsonName", equalTo("name")).when().get("/_schema/Test/test");
    // test actual REST resource (not easy to extract and verify
    // JSON property order, that's why we're using replaceAll and
    // string comparison..
    final String[] actual = 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).when().get("/Test/test").body().asString().replaceAll("[\\s]+", "").split("[\\W]+");
    // we can only test the actual ORDER of the JSON result object by splitting it on whitespace and validating the resulting array
    assertEquals("Invalid JSON result for sorted property view", "", actual[0]);
    assertEquals("Invalid JSON result for sorted property view", "query_time", actual[1]);
    assertEquals("Invalid JSON result for sorted property view", "0", actual[2]);
    assertEquals("Invalid JSON result for sorted property view", "result_count", actual[4]);
    assertEquals("Invalid JSON result for sorted property view", "1", actual[5]);
    assertEquals("Invalid JSON result for sorted property view", "result", actual[6]);
    assertEquals("Invalid JSON result for sorted property view", "type", actual[7]);
    assertEquals("Invalid JSON result for sorted property view", "Test", actual[8]);
    assertEquals("Invalid JSON result for sorted property view", "one", actual[9]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[10]);
    assertEquals("Invalid JSON result for sorted property view", "id", actual[11]);
    assertEquals("Invalid JSON result for sorted property view", id, actual[12]);
    assertEquals("Invalid JSON result for sorted property view", "two", actual[13]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[14]);
    assertEquals("Invalid JSON result for sorted property view", "three", actual[15]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[16]);
    assertEquals("Invalid JSON result for sorted property view", "four", actual[17]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[18]);
    assertEquals("Invalid JSON result for sorted property view", "name", actual[19]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[20]);
    assertEquals("Invalid JSON result for sorted property view", "serialization_time", actual[21]);
    // try built-in function
    try {
        final List<GraphObjectMap> list3 = (List) new TypeInfoFunction().apply(new ActionContext(securityContext), null, new Object[] { "Test", "test" });
        Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
        Assert.assertEquals("type", list3.get(0).get(jsonName));
        Assert.assertEquals("one", list3.get(1).get(jsonName));
        Assert.assertEquals("id", list3.get(2).get(jsonName));
        Assert.assertEquals("two", list3.get(3).get(jsonName));
        Assert.assertEquals("three", list3.get(4).get(jsonName));
        Assert.assertEquals("four", list3.get(5).get(jsonName));
        Assert.assertEquals("name", list3.get(6).get(jsonName));
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    // try scripting call
    try {
        final List<GraphObjectMap> list4 = (List) Scripting.evaluate(new ActionContext(securityContext), null, "${type_info('Test', 'test')}", "test");
        Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
        Assert.assertEquals("type", list4.get(0).get(jsonName));
        Assert.assertEquals("one", list4.get(1).get(jsonName));
        Assert.assertEquals("id", list4.get(2).get(jsonName));
        Assert.assertEquals("two", list4.get(3).get(jsonName));
        Assert.assertEquals("three", list4.get(4).get(jsonName));
        Assert.assertEquals("four", list4.get(5).get(jsonName));
        Assert.assertEquals("name", list4.get(6).get(jsonName));
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ActionContext(org.structr.schema.action.ActionContext) FrameworkException(org.structr.common.error.FrameworkException) LinkedList(java.util.LinkedList) SchemaView(org.structr.core.entity.SchemaView) SchemaNode(org.structr.core.entity.SchemaNode) TypeInfoFunction(org.structr.core.function.TypeInfoFunction) GraphObjectMap(org.structr.core.GraphObjectMap) GenericProperty(org.structr.core.property.GenericProperty) LinkedList(java.util.LinkedList) List(java.util.List) PropertyKey(org.structr.core.property.PropertyKey) NodeInterface(org.structr.core.graph.NodeInterface) FrontendTest(org.structr.web.basic.FrontendTest) ResourceAccessTest(org.structr.web.basic.ResourceAccessTest) Test(org.junit.Test)

Example 3 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class AdvancedSchemaTest method testSchemaPropertyOrderInInheritedViews.

@Test
public void testSchemaPropertyOrderInInheritedViews() {
    try (final Tx tx = app.tx()) {
        createAdminUser();
        createResourceAccess("_schema", UiAuthenticator.AUTH_USER_GET);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    final GenericProperty jsonName = new GenericProperty("jsonName");
    SchemaView testView = null;
    String id = null;
    try (final Tx tx = app.tx()) {
        final SchemaNode testBase = app.create(SchemaNode.class, "TestBase");
        final SchemaNode test = app.create(SchemaNode.class, new NodeAttribute<>(SchemaNode.name, "Test"), new NodeAttribute<>(SchemaNode.extendsClass, "org.structr.dynamic.TestBase"));
        // create view with sort order
        testView = app.create(SchemaView.class, new NodeAttribute<>(SchemaView.name, "test"), new NodeAttribute<>(SchemaView.schemaNode, test), new NodeAttribute<>(SchemaView.sortOrder, "one, two, three, four, id, type, name"), new NodeAttribute<>(SchemaView.nonGraphProperties, "id, type, name"));
        final List<SchemaView> list = new LinkedList<>();
        list.add(testView);
        // create properties
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, testBase), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "one"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, testBase), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "two"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, testBase), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "three"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, testBase), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "four"));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final Class type = StructrApp.getConfiguration().getNodeEntityClass("Test");
    final List<PropertyKey> list = new LinkedList<>(StructrApp.getConfiguration().getPropertySet(type, "test"));
    Assert.assertEquals("Invalid number of properties in sorted view", 7, list.size());
    Assert.assertEquals("one", list.get(0).dbName());
    Assert.assertEquals("two", list.get(1).dbName());
    Assert.assertEquals("three", list.get(2).dbName());
    Assert.assertEquals("four", list.get(3).dbName());
    Assert.assertEquals("id", list.get(4).dbName());
    Assert.assertEquals("type", list.get(5).dbName());
    Assert.assertEquals("name", list.get(6).dbName());
    try (final Tx tx = app.tx()) {
        // modify sort order
        testView.setProperty(SchemaView.sortOrder, "type, one, id, two, three, four, name");
        // create test entity
        final NodeInterface node = app.create(StructrApp.getConfiguration().getNodeEntityClass("Test"));
        id = node.getUuid();
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final List<PropertyKey> list2 = new LinkedList<>(StructrApp.getConfiguration().getPropertySet(type, "test"));
    Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
    Assert.assertEquals("type", list2.get(0).dbName());
    Assert.assertEquals("one", list2.get(1).dbName());
    Assert.assertEquals("id", list2.get(2).dbName());
    Assert.assertEquals("two", list2.get(3).dbName());
    Assert.assertEquals("three", list2.get(4).dbName());
    Assert.assertEquals("four", list2.get(5).dbName());
    Assert.assertEquals("name", list2.get(6).dbName());
    // test schema resource
    RestAssured.given().contentType("application/json; charset=UTF-8").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(7)).body("result[0].jsonName", equalTo("type")).body("result[1].jsonName", equalTo("one")).body("result[2].jsonName", equalTo("id")).body("result[3].jsonName", equalTo("two")).body("result[4].jsonName", equalTo("three")).body("result[5].jsonName", equalTo("four")).body("result[6].jsonName", equalTo("name")).when().get("/_schema/Test/test");
    // test actual REST resource (not easy to extract and verify
    // JSON property order, that's why we're using replaceAll and
    // string comparison..
    final String[] actual = 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).when().get("/Test/test").body().asString().replaceAll("[\\s]+", "").split("[\\W]+");
    // we can only test the actual ORDER of the JSON result object by splitting it on whitespace and validating the resulting array
    assertEquals("Invalid JSON result for sorted property view", "", actual[0]);
    assertEquals("Invalid JSON result for sorted property view", "query_time", actual[1]);
    assertEquals("Invalid JSON result for sorted property view", "0", actual[2]);
    assertEquals("Invalid JSON result for sorted property view", "result_count", actual[4]);
    assertEquals("Invalid JSON result for sorted property view", "1", actual[5]);
    assertEquals("Invalid JSON result for sorted property view", "result", actual[6]);
    assertEquals("Invalid JSON result for sorted property view", "type", actual[7]);
    assertEquals("Invalid JSON result for sorted property view", "Test", actual[8]);
    assertEquals("Invalid JSON result for sorted property view", "one", actual[9]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[10]);
    assertEquals("Invalid JSON result for sorted property view", "id", actual[11]);
    assertEquals("Invalid JSON result for sorted property view", id, actual[12]);
    assertEquals("Invalid JSON result for sorted property view", "two", actual[13]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[14]);
    assertEquals("Invalid JSON result for sorted property view", "three", actual[15]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[16]);
    assertEquals("Invalid JSON result for sorted property view", "four", actual[17]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[18]);
    assertEquals("Invalid JSON result for sorted property view", "name", actual[19]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[20]);
    assertEquals("Invalid JSON result for sorted property view", "serialization_time", actual[21]);
    // try built-in function
    try {
        final List<GraphObjectMap> list3 = (List) new TypeInfoFunction().apply(new ActionContext(securityContext), null, new Object[] { "Test", "test" });
        Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
        Assert.assertEquals("type", list3.get(0).get(jsonName));
        Assert.assertEquals("one", list3.get(1).get(jsonName));
        Assert.assertEquals("id", list3.get(2).get(jsonName));
        Assert.assertEquals("two", list3.get(3).get(jsonName));
        Assert.assertEquals("three", list3.get(4).get(jsonName));
        Assert.assertEquals("four", list3.get(5).get(jsonName));
        Assert.assertEquals("name", list3.get(6).get(jsonName));
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    // try scripting call
    try {
        final List<GraphObjectMap> list4 = (List) Scripting.evaluate(new ActionContext(securityContext), null, "${type_info('Test', 'test')}", "test");
        Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
        Assert.assertEquals("type", list4.get(0).get(jsonName));
        Assert.assertEquals("one", list4.get(1).get(jsonName));
        Assert.assertEquals("id", list4.get(2).get(jsonName));
        Assert.assertEquals("two", list4.get(3).get(jsonName));
        Assert.assertEquals("three", list4.get(4).get(jsonName));
        Assert.assertEquals("four", list4.get(5).get(jsonName));
        Assert.assertEquals("name", list4.get(6).get(jsonName));
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ActionContext(org.structr.schema.action.ActionContext) FrameworkException(org.structr.common.error.FrameworkException) LinkedList(java.util.LinkedList) SchemaView(org.structr.core.entity.SchemaView) SchemaNode(org.structr.core.entity.SchemaNode) TypeInfoFunction(org.structr.core.function.TypeInfoFunction) GraphObjectMap(org.structr.core.GraphObjectMap) GenericProperty(org.structr.core.property.GenericProperty) LinkedList(java.util.LinkedList) List(java.util.List) PropertyKey(org.structr.core.property.PropertyKey) NodeInterface(org.structr.core.graph.NodeInterface) FrontendTest(org.structr.web.basic.FrontendTest) ResourceAccessTest(org.structr.web.basic.ResourceAccessTest) Test(org.junit.Test)

Example 4 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class RenderContextTest method testVariableReplacementInDynamicTypes.

@Test
public void testVariableReplacementInDynamicTypes() {
    SchemaNode itemNode = null;
    NodeInterface parent = null;
    NodeInterface child1 = null;
    NodeInterface child2 = null;
    try (final Tx tx = app.tx()) {
        itemNode = app.create(SchemaNode.class, new NodeAttribute(SchemaNode.name, "Item"));
        final PropertyMap properties = new PropertyMap();
        properties.put(SchemaRelationshipNode.sourceId, itemNode.getUuid());
        properties.put(SchemaRelationshipNode.targetId, itemNode.getUuid());
        properties.put(SchemaRelationshipNode.relationshipType, "CHILD");
        properties.put(SchemaRelationshipNode.sourceMultiplicity, "1");
        properties.put(SchemaRelationshipNode.targetMultiplicity, "*");
        properties.put(SchemaRelationshipNode.sourceJsonName, "parentItem");
        properties.put(SchemaRelationshipNode.targetJsonName, "children");
        app.create(SchemaRelationshipNode.class, properties);
        // compile the stuff
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception");
    }
    final ConfigurationProvider config = StructrApp.getConfiguration();
    final Class itemClass = config.getNodeEntityClass("Item");
    final PropertyKey childrenProperty = StructrApp.key(itemClass, "children");
    // create parent/child relationship
    try (final Tx tx = app.tx()) {
        parent = app.create(itemClass);
        child1 = app.create(itemClass);
        child2 = app.create(itemClass);
        final List<NodeInterface> children = new LinkedList<>();
        children.add(child1);
        children.add(child2);
        parent.setProperties(parent.getSecurityContext(), new PropertyMap(childrenProperty, children));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception");
    }
    // verify that parent has two children
    try (final Tx tx = app.tx()) {
        // verify that parentItem can be accessed....
        final Object value = parent.getProperty(childrenProperty);
        assertTrue(value instanceof Collection);
        final Collection coll = (Collection) value;
        assertEquals(2, coll.size());
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception");
    }
    // check property access in template expressions
    try (final Tx tx = app.tx()) {
        assertEquals(parent.toString(), Scripting.replaceVariables(new ActionContext(securityContext), child1, "${this.parentItem}"));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception");
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ConfigurationProvider(org.structr.schema.ConfigurationProvider) ActionContext(org.structr.schema.action.ActionContext) LinkedList(java.util.LinkedList) SchemaNode(org.structr.core.entity.SchemaNode) PropertyMap(org.structr.core.property.PropertyMap) Collection(java.util.Collection) NodeInterface(org.structr.core.graph.NodeInterface) PropertyKey(org.structr.core.property.PropertyKey) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 5 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class RenderContextTest method testFunctionEvaluationInDynamicTypes.

@Test
public void testFunctionEvaluationInDynamicTypes() {
    NodeInterface item = null;
    try (final Tx tx = app.tx()) {
        app.create(SchemaNode.class, new NodeAttribute(SchemaNode.name, "Item"), new NodeAttribute(new StringProperty("_testMethodCalled"), "Boolean"), new NodeAttribute(new StringProperty("___testMethod"), "set(this, 'testMethodCalled', true)"));
        // compile the stuff
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
        fail("Unexpected exception");
    }
    final ConfigurationProvider config = StructrApp.getConfiguration();
    final Class itemClass = config.getNodeEntityClass("Item");
    // create parent/child relationship
    try (final Tx tx = app.tx()) {
        item = app.create(itemClass, new NodeAttribute(SchemaNode.name, "Item"));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception");
    }
    // check property access in template expressions
    try (final Tx tx = app.tx()) {
        final RenderContext renderContext = new RenderContext(securityContext);
        renderContext.putDataObject("item", item);
        assertEquals("Invalid combined array dot syntax result: ", "Item", Scripting.replaceVariables(renderContext, item, "${find('Item')[0].name}"));
        Scripting.replaceVariables(renderContext, item, "${item.testMethod()}");
        assertEquals("Invalid method evaluation result: ", "true", Scripting.replaceVariables(renderContext, item, "${item.testMethodCalled}"));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception");
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) RenderContext(org.structr.web.common.RenderContext) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ConfigurationProvider(org.structr.schema.ConfigurationProvider) StringProperty(org.structr.core.property.StringProperty) NodeInterface(org.structr.core.graph.NodeInterface) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

NodeInterface (org.structr.core.graph.NodeInterface)186 FrameworkException (org.structr.common.error.FrameworkException)120 Tx (org.structr.core.graph.Tx)116 Test (org.junit.Test)81 PropertyKey (org.structr.core.property.PropertyKey)61 LinkedList (java.util.LinkedList)36 StructrTest (org.structr.common.StructrTest)29 PropertyMap (org.structr.core.property.PropertyMap)26 TestOne (org.structr.core.entity.TestOne)24 List (java.util.List)23 GraphObject (org.structr.core.GraphObject)22 App (org.structr.core.app.App)21 StructrApp (org.structr.core.app.StructrApp)21 GenericNode (org.structr.core.entity.GenericNode)21 Before (org.junit.Before)18 Result (org.structr.core.Result)18 AbstractRelationship (org.structr.core.entity.AbstractRelationship)16 Random (java.util.Random)15 RelationshipInterface (org.structr.core.graph.RelationshipInterface)14 ErrorToken (org.structr.common.error.ErrorToken)12