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();
}
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);
}
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);
}
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;
}
});
}
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.");
}
}
Aggregations