use of org.structr.common.error.FrameworkException in project structr by structr.
the class DeploymentTest method test21ExportGrants.
@Test
public void test21ExportGrants() {
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
final SecurityContext context1 = SecurityContext.getInstance(user1, AccessMode.Backend);
final App app1 = StructrApp.getInstance(context1);
try (final Tx tx = app1.tx()) {
final Page page = Page.createNewPage(context1, "test21");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test21");
final Body body = createElement(page, html, "body");
final Div div1 = createElement(page, body, "div");
final Content content = createContent(page, div1, "<b>Test</b>");
content.setProperty(StructrApp.key(Content.class, "contentType"), "text/html");
// create grants
page.grant(Permission.read, user2);
div1.grant(Permission.read, user2);
content.grant(Permission.read, user2);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
compare(calculateHash(), true, false);
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class DeploymentTest method test26Escaping.
@Test
public void test26Escaping() {
// setup
try (final Tx tx = app.tx()) {
final Page page = Page.createNewPage(securityContext, "test25");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test25");
final Body body = createElement(page, html, "body");
final Div div1 = createElement(page, body, "div");
final Content content1 = createContent(page, div1, "<div><script>var test = '<h3>Title</h3>';</script></div>");
content1.setProperty(StructrApp.key(Content.class, "contentType"), "text/html");
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
compare(calculateHash(), true);
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class DeploymentTest method test03ContentTypes.
@Test
public void test03ContentTypes() {
// setup
try (final Tx tx = app.tx()) {
final Page page = Page.createNewPage(securityContext, "test03");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test03");
final Body body = createElement(page, html, "body");
final Div div1 = createElement(page, body, "div");
final Script script = createElement(page, div1, "script");
final Content content = createContent(page, script, "$(function () {\n\n" + "$('a[data-toggle=\"tab\"]').on('click', function (e) {\n\n" + "var id = $(e.target).attr(\"href\").substr(1) // activated tab\n" + "window.location.hash = id;\n" + "});\n\n" + "});");
// workaround for strange importer behaviour
script.setProperty(StructrApp.key(Script.class, "_html_type"), "text/javascript");
content.setProperty(StructrApp.key(Content.class, "contentType"), "text/javascript");
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 test14FileAttributesInFolders.
@Test
public void test14FileAttributesInFolders() {
final String folderPath = "/deeply/nested/Folder Structure/with spaces";
final String fileName = "test14.txt";
// setup
try (final Tx tx = app.tx()) {
final Folder folder = FileHelper.createFolderPath(securityContext, folderPath);
final File file = FileHelper.createFile(securityContext, "test".getBytes("utf-8"), "text/plain", File.class, fileName);
final Folder rootFolder = getRootFolder(folder);
Assert.assertNotNull("Root folder should not be null", rootFolder);
// root folder needs to have "includeInFrontendExport" set
rootFolder.setProperty(StructrApp.key(Folder.class, "includeInFrontendExport"), true);
file.setProperty(StructrApp.key(File.class, "parent"), folder);
file.setProperty(StructrApp.key(File.class, "visibleToPublicUsers"), true);
file.setProperty(StructrApp.key(File.class, "visibleToAuthenticatedUsers"), true);
file.setProperty(StructrApp.key(File.class, "enableBasicAuth"), true);
file.setProperty(StructrApp.key(File.class, "useAsJavascriptLibrary"), true);
tx.success();
} catch (IOException | FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// test
doImportExportRoundtrip(true);
// check
try (final Tx tx = app.tx()) {
final Folder folder = app.nodeQuery(Folder.class).andName("with spaces").getFirst();
Assert.assertNotNull("Invalid deployment result", folder);
final File file = app.nodeQuery(File.class).and(StructrApp.key(File.class, "parent"), folder).and(File.name, fileName).getFirst();
Assert.assertNotNull("Invalid deployment result", file);
Assert.assertEquals("Deployment import does not restore attributes correctly", folder, file.getParent());
Assert.assertTrue("Deployment import does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "visibleToPublicUsers")));
Assert.assertTrue("Deployment import does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "visibleToAuthenticatedUsers")));
Assert.assertTrue("Deployment import does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "enableBasicAuth")));
Assert.assertTrue("Deployment import does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "useAsJavascriptLibrary")));
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class DeploymentTest method test08SharedTemplateInTwoPages.
@Test
public void test08SharedTemplateInTwoPages() {
// setup
try (final Tx tx = app.tx()) {
// create first page
final Page page1 = Page.createNewPage(securityContext, "test08_1");
final Html html1 = createElement(page1, page1, "html");
final Head head1 = createElement(page1, html1, "head");
createElement(page1, head1, "title", "test08_1");
final Body body1 = createElement(page1, html1, "body");
final Div div1 = createElement(page1, body1, "div");
final Template template1 = createTemplate(page1, div1, "template source - öäüÖÄÜß'\"'`");
final Template component = createComponent(template1);
// create second page
final Page page2 = Page.createNewPage(securityContext, "test08_2");
final Html html2 = createElement(page2, page2, "html");
final Head head2 = createElement(page2, html2, "head");
createElement(page2, head2, "title", "test08_2");
final Body body2 = createElement(page2, html2, "body");
final Div div2 = createElement(page2, body2, "div");
// re-use template from above
cloneComponent(component, div2);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
compare(calculateHash(), true);
}
Aggregations