Search in sources :

Example 16 with FrameworkException

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

the class DeploymentTest method calculateHash.

private String calculateHash() {
    final StringBuilder buf = new StringBuilder();
    try (final Tx tx = app.tx()) {
        for (final Page page : app.nodeQuery(Page.class).sort(AbstractNode.name).getAsList()) {
            System.out.print("############################# ");
            calculateHash(page, buf, 0);
        }
        for (final Folder folder : app.nodeQuery(Folder.class).sort(AbstractNode.name).getAsList()) {
            if (DeployCommand.okToExport(folder) && folder.includeInFrontendExport()) {
                System.out.print("############################# ");
                calculateHash(folder, buf, 0);
            }
        }
        for (final File file : app.nodeQuery(File.class).sort(AbstractNode.name).getAsList()) {
            if (DeployCommand.okToExport(file) && file.includeInFrontendExport()) {
                System.out.print("############################# ");
                calculateHash(file, buf, 0);
            }
        }
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
    // DigestUtils.md5Hex(buf.toString());
    return buf.toString();
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Page(org.structr.web.entity.dom.Page) Folder(org.structr.web.entity.Folder) File(org.structr.web.entity.File)

Example 17 with FrameworkException

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

the class DeploymentTest method test01SimplePage.

@Test
public void test01SimplePage() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createSimplePage(securityContext, "test01");
        // test special properties
        page.setProperty(StructrApp.key(Page.class, "showOnErrorCodes"), "404");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true);
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Page(org.structr.web.entity.dom.Page) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 18 with FrameworkException

use of org.structr.common.error.FrameworkException 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 19 with FrameworkException

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

the class DeploymentTest method test23FileOwnershipAndGrants.

@Test
public void test23FileOwnershipAndGrants() {
    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 some files and folders
        final Folder folder1 = app.create(Folder.class, new NodeAttribute<>(Folder.name, "Folder1"), new NodeAttribute<>(StructrApp.key(Folder.class, "includeInFrontendExport"), true));
        final Folder folder2 = app.create(Folder.class, new NodeAttribute<>(Folder.name, "Folder2"), new NodeAttribute<>(StructrApp.key(Folder.class, "parent"), folder1));
        final File file1 = FileHelper.createFile(securityContext, "test".getBytes(), "text/plain", File.class, "test1.txt");
        final File file2 = FileHelper.createFile(securityContext, "test".getBytes(), "text/plain", File.class, "test2.txt");
        file1.setParent(folder2);
        file2.setParent(folder2);
        folder1.setProperty(Folder.owner, user1);
        folder1.grant(Permission.read, user2);
        folder2.setProperty(Folder.owner, user2);
        folder2.grant(Permission.write, user1);
        file1.setProperty(File.owner, user1);
        file2.setProperty(File.owner, user2);
        file1.setProperty(Folder.owner, user1);
        file1.grant(Permission.read, user2);
        file2.setProperty(Folder.owner, user2);
        file2.grant(Permission.write, user1);
        tx.success();
    } catch (IOException | 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) User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) IOException(java.io.IOException) Folder(org.structr.web.entity.Folder) Function(java.util.function.Function) GraphObject(org.structr.core.GraphObject) File(org.structr.web.entity.File) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 20 with FrameworkException

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

the class DeploymentTest method test33SchemaMethods.

@Test
public void test33SchemaMethods() {
    // setup
    try (final Tx tx = app.tx()) {
        app.create(SchemaMethod.class, new NodeAttribute<>(SchemaMethod.name, "method1"), new NodeAttribute<>(SchemaMethod.comment, "comment1"), new NodeAttribute<>(SchemaMethod.source, "source1"), new NodeAttribute<>(SchemaMethod.virtualFileName, "virtualFileName1"), new NodeAttribute<>(SchemaMethod.visibleToPublicUsers, true), new NodeAttribute<>(SchemaMethod.visibleToAuthenticatedUsers, false));
        app.create(SchemaMethod.class, new NodeAttribute<>(SchemaMethod.name, "method2"), new NodeAttribute<>(SchemaMethod.comment, "comment2"), new NodeAttribute<>(SchemaMethod.source, "source2"), new NodeAttribute<>(SchemaMethod.virtualFileName, "virtualFileName2"), new NodeAttribute<>(SchemaMethod.visibleToPublicUsers, false), new NodeAttribute<>(SchemaMethod.visibleToAuthenticatedUsers, true));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // test
    doImportExportRoundtrip(true);
    // check
    try (final Tx tx = app.tx()) {
        final SchemaMethod method1 = app.nodeQuery(SchemaMethod.class).and(SchemaMethod.name, "method1").getFirst();
        final SchemaMethod method2 = app.nodeQuery(SchemaMethod.class).and(SchemaMethod.name, "method2").getFirst();
        Assert.assertNotNull("Invalid deployment result", method1);
        Assert.assertNotNull("Invalid deployment result", method2);
        Assert.assertEquals("Invalid SchemaMethod deployment result", "method1", method1.getProperty(SchemaMethod.name));
        Assert.assertEquals("Invalid SchemaMethod deployment result", "comment1", method1.getProperty(SchemaMethod.comment));
        Assert.assertEquals("Invalid SchemaMethod deployment result", "source1", method1.getProperty(SchemaMethod.source));
        Assert.assertEquals("Invalid SchemaMethod deployment result", "virtualFileName1", method1.getProperty(SchemaMethod.virtualFileName));
        Assert.assertEquals("Invalid SchemaMethod deployment result", true, method1.getProperty(SchemaMethod.visibleToPublicUsers));
        Assert.assertEquals("Invalid SchemaMethod deployment result", false, method1.getProperty(SchemaMethod.visibleToAuthenticatedUsers));
        Assert.assertEquals("Invalid SchemaMethod deployment result", "method2", method2.getProperty(SchemaMethod.name));
        Assert.assertEquals("Invalid SchemaMethod deployment result", "comment2", method2.getProperty(SchemaMethod.comment));
        Assert.assertEquals("Invalid SchemaMethod deployment result", "source2", method2.getProperty(SchemaMethod.source));
        Assert.assertEquals("Invalid SchemaMethod deployment result", "virtualFileName2", method2.getProperty(SchemaMethod.virtualFileName));
        Assert.assertEquals("Invalid SchemaMethod deployment result", false, method2.getProperty(SchemaMethod.visibleToPublicUsers));
        Assert.assertEquals("Invalid SchemaMethod deployment result", true, method2.getProperty(SchemaMethod.visibleToAuthenticatedUsers));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) SchemaMethod(org.structr.core.entity.SchemaMethod) 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