Search in sources :

Example 76 with Tx

use of org.structr.core.graph.Tx 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 77 with Tx

use of org.structr.core.graph.Tx 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 78 with Tx

use of org.structr.core.graph.Tx 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 79 with Tx

use of org.structr.core.graph.Tx 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)

Example 80 with Tx

use of org.structr.core.graph.Tx 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)

Aggregations

Tx (org.structr.core.graph.Tx)892 FrameworkException (org.structr.common.error.FrameworkException)684 Test (org.junit.Test)461 App (org.structr.core.app.App)201 StructrApp (org.structr.core.app.StructrApp)201 StructrUiTest (org.structr.web.StructrUiTest)139 NodeInterface (org.structr.core.graph.NodeInterface)117 StructrTest (org.structr.common.StructrTest)108 IOException (java.io.IOException)105 PropertyMap (org.structr.core.property.PropertyMap)102 LinkedList (java.util.LinkedList)99 TestOne (org.structr.core.entity.TestOne)98 File (org.structr.web.entity.File)83 Page (org.structr.web.entity.dom.Page)71 Principal (org.structr.core.entity.Principal)65 Folder (org.structr.web.entity.Folder)65 PropertyKey (org.structr.core.property.PropertyKey)62 NodeAttribute (org.structr.core.graph.NodeAttribute)57 SchemaNode (org.structr.core.entity.SchemaNode)45 AbstractFile (org.structr.web.entity.AbstractFile)44