Search in sources :

Example 51 with NodeAttribute

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

the class DeploymentTest method test22TemplateOwnershipAndGrants.

@Test
public void test22TemplateOwnershipAndGrants() {
    Principal user1 = null;
    Principal user2 = null;
    try (final Tx tx = app.tx()) {
        user1 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
        user2 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
        tx.success();
    } catch (FrameworkException ex) {
        fail("Unexpected exception.");
    }
    Assert.assertNotNull("User was not created, test cannot continue", user1);
    Assert.assertNotNull("User was not created, test cannot continue", user2);
    // setup
    try (final Tx tx = app.tx()) {
        // create first page
        final Page page1 = Page.createNewPage(securityContext, "test22_1");
        final Html html1 = createElement(page1, page1, "html");
        final Head head1 = createElement(page1, html1, "head");
        createElement(page1, head1, "title", "test22_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, "test22_2");
        final Html html2 = createElement(page2, page2, "html");
        final Head head2 = createElement(page2, html2, "head");
        createElement(page2, head2, "title", "test22_2");
        final Body body2 = createElement(page2, html2, "body");
        final Div div2 = createElement(page2, body2, "div");
        // re-use template from above
        final Div cloned = cloneComponent(component, div2);
        component.grant(Permission.read, user1);
        cloned.grant(Permission.read, user2);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    doImportExportRoundtrip(true, true, new Function() {

        @Override
        public Object apply(Object t) {
            try (final Tx tx = app.tx()) {
                createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
                createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
                tx.success();
            } catch (FrameworkException ex) {
                fail("Unexpected exception.");
            }
            return null;
        }
    });
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Head(org.structr.web.entity.html.Head) User(org.structr.web.entity.User) 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) Div(org.structr.web.entity.html.Div) Function(java.util.function.Function) GraphObject(org.structr.core.GraphObject) Body(org.structr.web.entity.html.Body) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 52 with NodeAttribute

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

the class PerformanceTest method testPerformanceOfNodeCreation.

/**
 * Tests basic throughput of node creation operations
 *
 * Note that this is just a very rought test as performance is heavily
 * depending on hardware and setup (cache parameters etc.)
 *
 * The assumed rate is low so if this test fails, there may be issues
 * with the test setup.
 *
 * If the test passes, one can expect structr to create nodes with typical performance.
 */
@Test
public void testPerformanceOfNodeCreation() {
    final List<TestOne> nodes = new LinkedList<>();
    final long number = 1000;
    // start measuring
    final long t0 = System.currentTimeMillis();
    final App app = StructrApp.getInstance(setup());
    try {
        try (final Tx tx = app.tx()) {
            final long t1 = System.currentTimeMillis();
            for (int i = 0; i < number; i++) {
                nodes.add(app.create(TestOne.class, new NodeAttribute(TestOne.name, "TestOne" + i), new NodeAttribute(TestOne.aDate, new Date()), new NodeAttribute(TestOne.aDouble, 1.234), new NodeAttribute(TestOne.aLong, 12345L), new NodeAttribute(TestOne.anInt, 123)));
            }
            final long t2 = System.currentTimeMillis();
            System.out.println((t2 - t1) + " ms");
            tx.success();
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
    final long t1 = System.currentTimeMillis();
    assertTrue(nodes.size() == number);
    DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
    Double time = (t1 - t0) / 1000.0;
    Double rate = number / ((t1 - t0) / 1000.0);
    logger.info("Created {} nodes in {} seconds ({} per s)", number, decimalFormat.format(time), decimalFormat.format(rate));
    assertTrue("Creation rate of nodes too low, expected > 100, was " + rate, rate > 50);
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DecimalFormat(java.text.DecimalFormat) TestOne(org.structr.web.entity.TestOne) LinkedList(java.util.LinkedList) Date(java.util.Date) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 53 with NodeAttribute

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

the class PerformanceTest method setup.

// ----- private methods -----
private SecurityContext setup() {
    final App app = StructrApp.getInstance();
    User user = null;
    try (final Tx tx = app.tx()) {
        user = app.create(User.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "isAdmin"), true));
        tx.success();
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
    return SecurityContext.getInstance(user, AccessMode.Backend);
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NodeAttribute(org.structr.core.graph.NodeAttribute) User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode)

Example 54 with NodeAttribute

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

the class SimpleTest method test08PassiveIndexing.

@Test
public void test08PassiveIndexing() {
    try {
        // create some test nodes
        File test1 = null;
        // check initial sort order
        try (final Tx tx = app.tx()) {
            // create some test nodes
            test1 = createTestNode(File.class, new NodeAttribute<>(AbstractNode.name, "aaaaa"));
            createTestNode(File.class, new NodeAttribute<>(AbstractNode.name, "bbbbb"));
            createTestNode(File.class, new NodeAttribute<>(AbstractNode.name, "ccccc"));
            createTestNode(File.class, new NodeAttribute<>(AbstractNode.name, "ddddd"));
            createTestNode(File.class, new NodeAttribute<>(AbstractNode.name, "eeeee"));
            tx.success();
        }
        // check initial sort order
        try (final Tx tx = app.tx()) {
            final List<File> files = app.nodeQuery(File.class).sort(StructrApp.key(File.class, "path")).getAsList();
            assertEquals("Invalid indexing sort result", "aaaaa", files.get(0).getName());
            assertEquals("Invalid indexing sort result", "bbbbb", files.get(1).getName());
            assertEquals("Invalid indexing sort result", "ccccc", files.get(2).getName());
            assertEquals("Invalid indexing sort result", "ddddd", files.get(3).getName());
            assertEquals("Invalid indexing sort result", "eeeee", files.get(4).getName());
            tx.success();
        }
        // modify file name to move the first file to the end of the sorted list
        try (final Tx tx = app.tx()) {
            test1.setProperties(test1.getSecurityContext(), new PropertyMap(AbstractNode.name, "zzzzz"));
            tx.success();
        }
        // check final sort order
        try (final Tx tx = app.tx()) {
            final List<File> files = app.nodeQuery(File.class).sort(StructrApp.key(File.class, "path")).getAsList();
            assertEquals("Invalid indexing sort result", "bbbbb", files.get(0).getName());
            assertEquals("Invalid indexing sort result", "ccccc", files.get(1).getName());
            assertEquals("Invalid indexing sort result", "ddddd", files.get(2).getName());
            assertEquals("Invalid indexing sort result", "eeeee", files.get(3).getName());
            assertEquals("Invalid indexing sort result", "zzzzz", files.get(4).getName());
            tx.success();
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) File(org.structr.web.entity.File) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 55 with NodeAttribute

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

the class UiScriptingTest method testSpecialHeaders.

@Test
public void testSpecialHeaders() {
    String uuid = null;
    // schema setup
    try (final Tx tx = app.tx()) {
        // create list of 100 folders
        final List<Folder> folders = new LinkedList<>();
        for (int i = 0; i < 100; i++) {
            folders.add(createTestNode(Folder.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Folder" + i)));
        }
        // create parent folder
        final Folder parent = createTestNode(Folder.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Parent"), new NodeAttribute<>(StructrApp.key(Folder.class, "folders"), folders));
        uuid = parent.getUuid();
        // create function property that returns folder children
        final SchemaNode schemaNode = app.nodeQuery(SchemaNode.class).andName("Folder").getFirst();
        schemaNode.setProperty(new StringProperty("_testFunction"), "Function(this.folders)");
        // create admin user
        createTestNode(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) {
        logger.warn("", fex);
        fail("Unexpected exception");
    }
    RestAssured.basePath = "/structr/rest";
    RestAssured.given().contentType("application/json; charset=UTF-8").accept("application/json; properties=id,type,name,folders,testFunction").header("Range", "folders=0-10;testFunction=0-10").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", "admin", "X-Password", "admin").expect().statusCode(200).body("result.folders", Matchers.hasSize(10)).body("result.testFunction", Matchers.hasSize(10)).when().get("/Folder/" + uuid + "/ui");
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) SchemaNode(org.structr.core.entity.SchemaNode) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) StringProperty(org.structr.core.property.StringProperty) Folder(org.structr.web.entity.Folder) LinkedList(java.util.LinkedList) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

NodeAttribute (org.structr.core.graph.NodeAttribute)73 Tx (org.structr.core.graph.Tx)55 FrameworkException (org.structr.common.error.FrameworkException)54 Test (org.junit.Test)45 App (org.structr.core.app.App)23 StructrApp (org.structr.core.app.StructrApp)23 StructrUiTest (org.structr.web.StructrUiTest)21 LinkedList (java.util.LinkedList)19 PropertyKey (org.structr.core.property.PropertyKey)17 SchemaNode (org.structr.core.entity.SchemaNode)14 NodeInterface (org.structr.core.graph.NodeInterface)13 Principal (org.structr.core.entity.Principal)12 PropertyMap (org.structr.core.property.PropertyMap)12 StringProperty (org.structr.core.property.StringProperty)10 ConfigurationProvider (org.structr.schema.ConfigurationProvider)10 File (org.structr.web.entity.File)10 Folder (org.structr.web.entity.Folder)9 AbstractFile (org.structr.web.entity.AbstractFile)8 List (java.util.List)7 StructrTest (org.structr.common.StructrTest)7