Search in sources :

Example 96 with Tx

use of org.structr.core.graph.Tx in project structr by structr.

the class StructrMessagingEngineModuleTest method cleanDatabase.

@Before
public void cleanDatabase() {
    try (final Tx tx = app.tx()) {
        final List<? extends NodeInterface> nodes = app.nodeQuery().getAsList();
        logger.info("Cleaning database: {} nodes", nodes.size());
        for (final NodeInterface node : nodes) {
            app.delete(node);
        }
        // delete remaining nodes without UUIDs etc.
        app.cypher("MATCH (n)-[r]-(m) DELETE n, r, m", Collections.emptyMap());
        tx.success();
    } catch (FrameworkException fex) {
        logger.error("Exception while trying to clean database: {}", fex);
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NodeInterface(org.structr.core.graph.NodeInterface)

Example 97 with Tx

use of org.structr.core.graph.Tx in project structr by structr.

the class ODFTest method testODS.

@Test
public void testODS() {
    final Class type = StructrApp.getConfiguration().getNodeEntityClass("ODSExporter");
    File template = null;
    String uuid = null;
    assertNotNull("Type ODSExporter should exist", type);
    try (final Tx tx = app.tx()) {
        app.create(User.class, new NodeAttribute<>(StructrApp.key(User.class, "name"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "isAdmin"), true));
        // read test file from sources
        try (final InputStream is = ODFTest.class.getResourceAsStream("/test.odt")) {
            template = FileHelper.createFile(securityContext, is, "", File.class, "template");
        }
        assertNotNull("Test file must exist", template);
        final NodeInterface node = app.create(type, new NodeAttribute<>(StructrApp.key(ODFExporter.class, "name"), "test.ods"), new NodeAttribute<>(StructrApp.key(ODFExporter.class, "documentTemplate"), template));
        uuid = node.getUuid();
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
    }
    // use RestAssured to call exported methods on file
    RestAssured.given().filter(ResponseLoggingFilter.logResponseTo(System.out)).header("X-User", "admin").header("X-Password", "admin").expect().statusCode(200).when().post("/ODSExporter/" + uuid + "/createDocumentFromTemplate");
    // use RestAssured to call exported methods on file
    RestAssured.given().filter(ResponseLoggingFilter.logResponseTo(System.out)).header("X-User", "admin").header("X-Password", "admin").expect().statusCode(200).body("result_count", equalTo(2)).body("result", hasSize(2)).body("result[0].name", equalTo("template")).body("result[1].name", equalTo("test.ods_template")).when().get("/File");
    // use RestAssured to call exported methods on file
    RestAssured.given().filter(ResponseLoggingFilter.logResponseTo(System.out)).header("X-User", "admin").header("X-Password", "admin").expect().statusCode(200).body("result[0].type", equalTo("ODSExporter")).body("result[0].documentTemplate.type", equalTo("File")).body("result[0].documentTemplate.name", equalTo("template")).body("result[0].documentTemplate.path", equalTo("/template")).body("result[0].resultDocument.type", equalTo("File")).body("result[0].resultDocument.name", equalTo("test.ods_template")).body("result[0].resultDocument.path", equalTo("/test.ods_template")).when().get("/ODFExporter");
}
Also used : Tx(org.structr.core.graph.Tx) InputStream(java.io.InputStream) File(org.structr.web.entity.File) NodeInterface(org.structr.core.graph.NodeInterface) Test(org.junit.Test)

Example 98 with Tx

use of org.structr.core.graph.Tx in project structr by structr.

the class StructrODFModuleTest method cleanDatabase.

@After
@Before
public void cleanDatabase() {
    try (final Tx tx = app.tx()) {
        final List<? extends NodeInterface> nodes = app.nodeQuery().getAsList();
        logger.info("Cleaning database: {} nodes", nodes.size());
        for (final NodeInterface node : nodes) {
            app.delete(node);
        }
        // delete remaining nodes without UUIDs etc.
        app.cypher("MATCH (n)-[r]-(m) DELETE n, r, m", Collections.emptyMap());
        tx.success();
    } catch (FrameworkException fex) {
        logger.error("Exception while trying to clean database: {}", fex);
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NodeInterface(org.structr.core.graph.NodeInterface) Before(org.junit.Before) After(org.junit.After)

Example 99 with Tx

use of org.structr.core.graph.Tx in project structr by structr.

the class StructrODFModuleTest method createTestRelationship.

protected <T extends Relation> T createTestRelationship(final AbstractNode startNode, final AbstractNode endNode, final Class<T> relType) throws FrameworkException {
    try (final Tx tx = app.tx()) {
        final T rel = (T) app.create(startNode, endNode, relType);
        tx.success();
        return rel;
    }
}
Also used : Tx(org.structr.core.graph.Tx)

Example 100 with Tx

use of org.structr.core.graph.Tx in project structr by structr.

the class StructrODFModuleTest method createTestNode.

protected <T extends AbstractNode> T createTestNode(final Class<T> type, final NodeAttribute... attributes) throws FrameworkException {
    try (final Tx tx = app.tx()) {
        final T newNode = app.create(type, attributes);
        tx.success();
        return newNode;
    }
}
Also used : Tx(org.structr.core.graph.Tx)

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