Search in sources :

Example 76 with FrameworkException

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

the class DOMNodeTest method testGetChildNodes.

@Test
public void testGetChildNodes() {
    try (final Tx tx = app.tx()) {
        Document document = getDocument();
        assertNotNull(document);
        Text test1 = document.createTextNode("test1");
        Text test2 = document.createTextNode("test2");
        Text test3 = document.createTextNode("test3");
        assertNotNull(test1);
        assertNotNull(test2);
        assertNotNull(test3);
        Element div = document.createElement("div");
        assertNotNull(div);
        // add children
        div.appendChild(test1);
        div.appendChild(test2);
        div.appendChild(test3);
        NodeList children = div.getChildNodes();
        assertEquals(test1, children.item(0));
        assertEquals(test2, children.item(1));
        assertEquals(test3, children.item(2));
        tx.success();
    } catch (FrameworkException fex) {
        fail("unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) DOMTest(org.structr.web.advanced.DOMTest) Test(org.junit.Test)

Example 77 with FrameworkException

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

the class DOMNodeTest method testAppendChild.

@Test
public void testAppendChild() {
    try (final Tx tx = app.tx()) {
        final Class domChildrenType = StructrApp.getConfiguration().getRelationshipEntityClass("DOMNodeCONTAINSDOMNode");
        Page document = (Page) getDocument();
        assertNotNull(document);
        DOMElement div = (DOMElement) document.createElement("div");
        assertNotNull(div);
        Content content1 = (Content) document.createTextNode("content1");
        Content content2 = (Content) document.createTextNode("content2");
        Content content3 = (Content) document.createTextNode("content3");
        assertNotNull(content1);
        assertNotNull(content2);
        assertNotNull(content3);
        // first step
        div.appendChild(content1);
        // check for correct relationship management
        List<Relation> divRels = toList(div.getOutgoingRelationships(domChildrenType));
        assertEquals(1, divRels.size());
        assertEquals(Integer.valueOf(0), divRels.get(0).getProperty(div.getPositionProperty()));
        // second step
        div.appendChild(content2);
        // check for correct relationship management
        divRels = toList(div.getOutgoingRelationships(domChildrenType));
        assertEquals(2, divRels.size());
        assertEquals(Integer.valueOf(0), divRels.get(0).getProperty(div.getPositionProperty()));
        assertEquals(Integer.valueOf(1), divRels.get(1).getProperty(div.getPositionProperty()));
        // third step: test removal of old parent when appending an existing node
        div.appendChild(content3);
        // assert that div has 3 children now
        assertEquals(3, div.getChildNodes().getLength());
        // create new container
        Element div2 = document.createElement("div");
        assertNotNull(div2);
        div.appendChild(div2);
        // div should have 4 children by now
        assertEquals(4, div.getChildNodes().getLength());
        // move text node to div2
        div2.appendChild(content3);
        // div should have 3 children now,
        // div2 should have content3 as a child now
        assertEquals(3, div.getChildNodes().getLength());
        assertEquals(content3, div2.getChildNodes().item(0));
        tx.success();
    } catch (FrameworkException fex) {
        fail("unexpected exception");
    }
}
Also used : Relation(org.structr.core.entity.Relation) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Element(org.w3c.dom.Element) DOMTest(org.structr.web.advanced.DOMTest) Test(org.junit.Test)

Example 78 with FrameworkException

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

the class DOMNodeTest method testReplaceChild.

@Test
public void testReplaceChild() {
    try (final Tx tx = app.tx()) {
        Document document = getDocument();
        assertNotNull(document);
        Text test1 = document.createTextNode("test1");
        Text test2 = document.createTextNode("test2");
        Text test3 = document.createTextNode("test3");
        Text test4 = document.createTextNode("test4");
        Text test5 = document.createTextNode("test5");
        Text test6 = document.createTextNode("test6");
        assertNotNull(test1);
        assertNotNull(test2);
        assertNotNull(test3);
        assertNotNull(test4);
        assertNotNull(test5);
        assertNotNull(test6);
        Element div = document.createElement("div");
        assertNotNull(div);
        // add children
        div.appendChild(test1);
        div.appendChild(test2);
        div.appendChild(test3);
        div.appendChild(test4);
        div.appendChild(test5);
        // examine children
        NodeList children1 = div.getChildNodes();
        assertEquals(test1, children1.item(0));
        assertEquals(test2, children1.item(1));
        assertEquals(test3, children1.item(2));
        assertEquals(test4, children1.item(3));
        assertEquals(test5, children1.item(4));
        // test replace child
        div.replaceChild(test6, test3);
        // examine children
        NodeList children2 = div.getChildNodes();
        assertEquals(test1, children2.item(0));
        assertEquals(test2, children2.item(1));
        assertEquals(test6, children2.item(2));
        assertEquals(test4, children2.item(3));
        assertEquals(test5, children2.item(4));
        tx.success();
    } catch (FrameworkException fex) {
        fail("unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) DOMTest(org.structr.web.advanced.DOMTest) Test(org.junit.Test)

Example 79 with FrameworkException

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

the class DOMNodeTest method testReplaceChildWithFragment.

@Test
public void testReplaceChildWithFragment() {
    try (final Tx tx = app.tx()) {
        Document document = getDocument();
        org.w3c.dom.DocumentFragment fragment = document.createDocumentFragment();
        assertNotNull(document);
        assertNotNull(fragment);
        Text test1 = document.createTextNode("test1");
        Text test2 = document.createTextNode("test2");
        Text test3 = document.createTextNode("test3");
        Text test4 = document.createTextNode("test4");
        Text test5 = document.createTextNode("test5");
        Text test6 = document.createTextNode("test6");
        Text test7 = document.createTextNode("test7");
        Text test8 = document.createTextNode("test8");
        Text test9 = document.createTextNode("test9");
        assertNotNull(test1);
        assertNotNull(test2);
        assertNotNull(test3);
        assertNotNull(test4);
        assertNotNull(test5);
        assertNotNull(test6);
        assertNotNull(test7);
        assertNotNull(test8);
        assertNotNull(test9);
        Element div = document.createElement("div");
        assertNotNull(div);
        // add children
        div.appendChild(test1);
        div.appendChild(test2);
        div.appendChild(test3);
        div.appendChild(test4);
        div.appendChild(test5);
        // examine children
        NodeList children1 = div.getChildNodes();
        assertEquals(test1, children1.item(0));
        assertEquals(test2, children1.item(1));
        assertEquals(test3, children1.item(2));
        assertEquals(test4, children1.item(3));
        assertEquals(test5, children1.item(4));
        // add children to document fragment
        fragment.appendChild(test6);
        fragment.appendChild(test7);
        fragment.appendChild(test8);
        fragment.appendChild(test9);
        // test replace child
        div.replaceChild(fragment, test3);
        // examine children
        NodeList children2 = div.getChildNodes();
        assertEquals(test1, children2.item(0));
        assertEquals(test2, children2.item(1));
        assertEquals(test6, children2.item(2));
        assertEquals(test7, children2.item(3));
        assertEquals(test8, children2.item(4));
        assertEquals(test9, children2.item(5));
        assertEquals(test4, children2.item(6));
        assertEquals(test5, children2.item(7));
        tx.success();
    } catch (FrameworkException fex) {
        fail("unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) DOMTest(org.structr.web.advanced.DOMTest) Test(org.junit.Test)

Example 80 with FrameworkException

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

the class DOMNodeTest method testAppendChildErrors.

@Test
public void testAppendChildErrors() {
    try (final Tx tx = app.tx()) {
        Document wrongDocument = getDocument();
        Document document = getDocument();
        assertNotNull(document);
        assertNotNull(wrongDocument);
        Text wrongTextNode = wrongDocument.createTextNode("test");
        Text test1 = document.createTextNode("test1");
        Text test2 = document.createTextNode("test2");
        Text test3 = document.createTextNode("test3");
        assertNotNull(test1);
        assertNotNull(test2);
        assertNotNull(test3);
        Element div = document.createElement("div");
        assertNotNull(div);
        // add children
        div.appendChild(test1);
        div.appendChild(test2);
        div.appendChild(test3);
        NodeList children = div.getChildNodes();
        assertEquals(test1, children.item(0));
        assertEquals(test2, children.item(1));
        assertEquals(test3, children.item(2));
        Element div2 = document.createElement("div");
        assertNotNull(div2);
        div.appendChild(div2);
        assertEquals(div, div2.getParentNode());
        try {
            div.appendChild(wrongTextNode);
            fail("Adding a node that was not created using the correct document should raise a DOMException");
        } catch (DOMException dex) {
            assertEquals(DOMException.WRONG_DOCUMENT_ERR, dex.code);
        }
        try {
            div.appendChild(div);
            fail("Adding a node to itself should raise a DOMException");
        } catch (DOMException dex) {
            assertEquals(DOMException.HIERARCHY_REQUEST_ERR, dex.code);
        }
        try {
            div2.appendChild(div);
            fail("Adding one of its own ancestors to a node should raise a DOMException");
        } catch (DOMException dex) {
            assertEquals(DOMException.HIERARCHY_REQUEST_ERR, dex.code);
        }
        tx.success();
    } catch (FrameworkException fex) {
        fail("unexpected exception");
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) DOMTest(org.structr.web.advanced.DOMTest) Test(org.junit.Test)

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