use of org.structr.common.error.FrameworkException in project structr by structr.
the class DeploymentTest method test20ExportOwnership.
@Test
public void test20ExportOwnership() {
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, "test20");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test20");
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");
// set owner to different user
div1.setProperty(AbstractNode.owner, user2);
content.setProperty(AbstractNode.owner, 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 test17NamedNonSharedTemplateWithChildren.
@Test
public void test17NamedNonSharedTemplateWithChildren() {
// setup
try (final Tx tx = app.tx()) {
final Page page = Page.createNewPage(securityContext, "test17");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test17");
final Body body = createElement(page, html, "body");
final Template template = createTemplate(page, body, "${render(children)}");
template.setProperty(AbstractNode.name, "a-template");
final Template sharedTemplate = createComponent(template);
// remove original template from page
app.delete(template);
createElement(page, sharedTemplate, "div");
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 DiffTest method testTreeRemovalFix.
@Test
public void testTreeRemovalFix() {
final String comment = "<!-- comment --->";
testDiff("<html><head><title>Title</title></head><body><div>" + comment + "<div>" + comment + "<div>test</div>" + comment + "<div></div></div></body></html>", (String from) -> {
String modified = from;
modified = modified.replace(comment, "");
return modified;
});
// test result on the node level
try (final Tx tx = app.tx()) {
final Page page = app.nodeQuery(Page.class).andName("test").getFirst();
assertNotNull(page);
final NodeList nodes = page.getElementsByTagName("div");
final List<Div> divs = collectNodes(nodes, Div.class);
assertEquals("Wrong number of divs returned from node query", 4, divs.size());
// check first div, should have no siblings and one child
final Div firstDiv = divs.get(0);
assertEquals("Wrong number of children", 1, firstDiv.getChildRelationships().size());
assertNull("Node should not have siblings", firstDiv.getNextSibling());
// check second div, should have no siblings and two children
final Div secondDiv = divs.get(1);
assertEquals("Wrong number of children", 2, secondDiv.getChildRelationships().size());
assertNull("Node should not have siblings", secondDiv.getNextSibling());
// check third div, should have one sibling and one #text child
final Div thirdDiv = divs.get(2);
assertEquals("Wrong number of children", 1, thirdDiv.getChildRelationships().size());
assertNotNull("Node should have one sibling", thirdDiv.getNextSibling());
// check fourth div, should have no siblings and no children
final Div fourthDiv = divs.get(3);
assertEquals("Wrong number of children", 0, fourthDiv.getChildRelationships().size());
assertNull("Node should not have siblings", fourthDiv.getNextSibling());
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class ImporterTest method assertFileNotExists.
private void assertFileNotExists(final String expectedPath) {
final File file;
try (final Tx tx = app.tx()) {
final String filename = PathHelper.getName(expectedPath);
file = app.nodeQuery(File.class).andName(filename).getFirst();
assertNull("File " + filename + " found", file);
} catch (FrameworkException ex) {
logger.warn("", ex);
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class ImporterTest method testWidgetWithScriptTags.
@Test
public void testWidgetWithScriptTags() {
try (final Tx tx = app.tx()) {
Settings.JsonIndentation.setValue(true);
Settings.HtmlIndentation.setValue(true);
final String source = testImportWidget("<div>\n" + " <script src=\"/structr/js/lib/jquery-1.11.1.min.js\" type=\"text/javascript\"></script>\n" + " <script type=\"text/javascript\"></script>\n" + "</div>", RenderContext.EditMode.WIDGET, "https://widgets.structr.org/structr/rest/widgets");
// System.out.println(source);
assertEquals("<!DOCTYPE html>\n" + "<html>\n" + " <head></head>\n" + " <body>\n" + " <div>\n" + " <script src=\"/structr/js/lib/jquery-1.11.1.min.js\" type=\"text/javascript\"></script>\n" + " <script type=\"text/javascript\"></script>\n" + " </div>\n" + " </body>\n" + "</html>", source);
Script secondScriptElement = (Script) app.nodeQuery(Script.class).blank(StructrApp.key(Script.class, "_html_src")).getFirst();
assertNull(secondScriptElement.getOutgoingRelationship(StructrApp.getConfiguration().getRelationshipEntityClass("LinkSourceLINKLinkable")));
} catch (FrameworkException ex) {
logger.warn("", ex);
}
}
Aggregations