Search in sources :

Example 21 with FrameworkException

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);
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) 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) Content(org.structr.web.entity.dom.Content) SecurityContext(org.structr.common.SecurityContext) Body(org.structr.web.entity.html.Body) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 22 with FrameworkException

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);
}
Also used : Head(org.structr.web.entity.html.Head) 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) Body(org.structr.web.entity.html.Body) Template(org.structr.web.entity.dom.Template) MailTemplate(org.structr.core.entity.MailTemplate) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 23 with FrameworkException

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");
    }
}
Also used : Div(org.structr.web.entity.html.Div) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NodeList(org.w3c.dom.NodeList) Page(org.structr.web.entity.dom.Page) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 24 with FrameworkException

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);
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) File(org.structr.web.entity.File)

Example 25 with FrameworkException

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);
    }
}
Also used : Script(org.structr.web.entity.html.Script) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) 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