Search in sources :

Example 71 with FrameworkException

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

the class ContentTest method testDeleteData.

@Test
public void testDeleteData() {
    try (final Tx tx = app.tx()) {
        Content content = getContentNode();
        assertNotNull(content);
        // test basic setting of content
        content.setData("Dies ist ein Test");
        assertEquals("Dies ist ein Test", content.getData());
        content.deleteData(5, 4);
        assertEquals("Dies ein Test", content.getData());
        tx.success();
    } catch (FrameworkException fex) {
        fail("unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DOMTest(org.structr.web.advanced.DOMTest) Test(org.junit.Test)

Example 72 with FrameworkException

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

the class ContentTest method testSplitText.

@Test
public void testSplitText() {
    try (final Tx tx = app.tx()) {
        Document document = getDocument();
        Text content = document.createTextNode("Dies ist ein Test");
        assertNotNull(content);
        Element div = document.createElement("div");
        assertNotNull(div);
        // add child
        div.appendChild(content);
        // test basic setting of content
        content.setData("Dies ist ein Test");
        assertEquals("Dies ist ein Test", content.getData());
        // test split method
        Content secondPart = (Content) content.splitText(8);
        assertNotNull(secondPart);
        assertEquals("Dies ist", content.getData());
        assertEquals(" ein Test", secondPart.getData());
        // check that parent has two children
        NodeList children = div.getChildNodes();
        assertNotNull(children);
        assertEquals(2, children.getLength());
        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 73 with FrameworkException

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

the class ContentTest method testSetData.

@Test
public void testSetData() {
    try (final Tx tx = app.tx()) {
        Content content = getContentNode();
        assertNotNull(content);
        // test basic setting of content
        content.setData("Dies ist ein Test");
        assertEquals("Dies ist ein Test", content.getData());
        tx.success();
    } catch (FrameworkException fex) {
        fail("unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DOMTest(org.structr.web.advanced.DOMTest) Test(org.junit.Test)

Example 74 with FrameworkException

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

the class ContentTest method testInsertData.

@Test
public void testInsertData() {
    try (final Tx tx = app.tx()) {
        Content content = getContentNode();
        assertNotNull(content);
        // test basic setting of content
        content.setData("Dies ein Test");
        assertEquals("Dies ein Test", content.getData());
        content.insertData(5, "ist ");
        assertEquals("Dies ist ein Test", content.getData());
        tx.success();
    } catch (FrameworkException fex) {
        fail("unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DOMTest(org.structr.web.advanced.DOMTest) Test(org.junit.Test)

Example 75 with FrameworkException

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

the class DOMElementTest method testAttributeNodeMethods.

@Test
public void testAttributeNodeMethods() {
    try (final Tx tx = StructrApp.getInstance(securityContext).tx()) {
        Page doc = (Page) getDocument();
        DOMElement elem = (DOMElement) doc.createElement("div");
        String name1 = "test1";
        String name2 = "test2";
        String name3 = "test3";
        String value1 = "value1";
        String value2 = "value2";
        String value3 = "value3";
        DOMAttribute attr1 = (DOMAttribute) doc.createAttribute(name1);
        assertNotNull(attr1);
        attr1.setValue(value1);
        elem.setAttributeNode(attr1);
        assertEquals(elem, attr1.getParentNode());
        DOMAttribute attr2 = (DOMAttribute) doc.createAttribute(name2);
        assertNotNull(attr2);
        attr2.setValue(value2);
        elem.setAttributeNode(attr2);
        assertEquals(elem, attr2.getParentNode());
        DOMAttribute attr3 = (DOMAttribute) doc.createAttribute(name3);
        assertNotNull(attr3);
        attr3.setValue(value3);
        elem.setAttributeNode(attr3);
        assertEquals(elem, attr3.getParentNode());
        assertEquals(true, elem.hasAttributes());
        assertEquals(3, elem.getAttributes().getLength());
        assertEquals(value1, elem.getAttribute(name1));
        assertEquals(attr1, elem.getAttributeNode(name1));
        assertEquals(value2, elem.getAttribute(name2));
        assertEquals(attr2, elem.getAttributeNode(name2));
        assertEquals(value3, elem.getAttribute(name3));
        assertEquals(attr3, elem.getAttributeNode(name3));
        // important for xpath: sibling methods
        assertEquals(attr2, attr1.getNextSibling());
        assertEquals(attr3, attr2.getNextSibling());
        assertEquals(attr2, attr3.getPreviousSibling());
        assertEquals(attr1, attr2.getPreviousSibling());
        tx.success();
    } catch (FrameworkException fex) {
        fail("unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) 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