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);
}
}
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");
}
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);
}
}
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;
}
}
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;
}
}
Aggregations