use of org.structr.core.graph.Tx in project structr by structr.
the class SchemaMethodsTest method test05InheritedSchemaMethodOnBuildinType.
@Test
public void test05InheritedSchemaMethodOnBuildinType() {
final String builtinTypeName = "File";
final String schemaMethodName = "testFileMethod";
User admin = null;
try (final Tx tx = app.tx()) {
admin = createAdminUser();
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
// Add schema method "testFileMethod" to built-in File class
SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
final PropertyMap testFileMethodProperties = new PropertyMap();
testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
testFileMethodProperties.put(SchemaMethod.source, "()");
testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post("/Image/" + schemaMethodName);
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.graph.Tx in project structr by structr.
the class SchemaMethodsTest method test06InheritedSchemaMethodOnEntityOfBuiltinType.
@Test
public void test06InheritedSchemaMethodOnEntityOfBuiltinType() {
final String builtinTypeName = "File";
final String schemaMethodName = "testFileMethod";
User admin = null;
try (final Tx tx = app.tx()) {
admin = createAdminUser();
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
// Add schema method "testFileMethod" to built-in File class
SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
final PropertyMap testFileMethodProperties = new PropertyMap();
testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
testFileMethodProperties.put(SchemaMethod.source, "()");
testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
String id = createEntityAsAdmin("Image", "{'name': 'Test Image'}");
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post("/Image/" + id + "/" + schemaMethodName);
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.graph.Tx in project structr by structr.
the class SchemaMethodsTest method test01SchemaMethodOnBuiltinType.
@Test
public void test01SchemaMethodOnBuiltinType() {
final String builtinTypeName = "File";
final String schemaMethodName = "testFileMethod";
try (final Tx tx = app.tx()) {
// Add schema method "testFileMethod" to built-in File class
SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
final PropertyMap testFileMethodProperties = new PropertyMap();
testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
testFileMethodProperties.put(SchemaMethod.source, "()");
testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
User admin = null;
try (final Tx tx = app.tx()) {
admin = createAdminUser();
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post(builtinTypeName + "/" + schemaMethodName);
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.graph.Tx in project structr by structr.
the class SimpleTest method test001EMailAddressConstraint.
@Test
public void test001EMailAddressConstraint() {
final PropertyKey<String> eMail = StructrApp.key(User.class, "eMail");
try (final Tx tx = app.tx()) {
app.create(User.class, new NodeAttribute(User.name, "TestUser1"), new NodeAttribute(eMail, "user@structr.test"));
app.create(User.class, new NodeAttribute(User.name, "TestUser2"), new NodeAttribute(eMail, "user@structr.test"));
tx.success();
fail("Expected exception to be thrown.");
} catch (FrameworkException fex) {
assertEquals("Invalid error code", 422, fex.getStatus());
}
check();
try (final Tx tx = app.tx()) {
app.create(User.class, new NodeAttribute(User.name, "TestUser1"), new NodeAttribute(eMail, "user@structr.test"));
app.create(User.class, new NodeAttribute(User.name, "TestUser2"), new NodeAttribute(eMail, "User@Structr.test"));
tx.success();
fail("Expected exception to be thrown.");
} catch (FrameworkException fex) {
assertEquals("Invalid error code", 422, fex.getStatus());
}
check();
}
use of org.structr.core.graph.Tx in project structr by structr.
the class SimpleTest method testIncreasePageVersion.
@Test
public void testIncreasePageVersion() {
Page page = null;
try (final Tx tx = app.tx()) {
page = Page.createSimplePage(securityContext, "test");
tx.success();
} catch (FrameworkException fex) {
fail("Unepxected exception.");
}
try (final Tx tx = app.tx()) {
assertEquals("Page version is not increased on modification", 0, page.getVersion());
final Element div = page.createElement("div");
// add new element
page.getElementsByTagName("div").item(0).appendChild(div);
tx.success();
} catch (FrameworkException fex) {
fail("Unepxected exception.");
}
try (final Tx tx = app.tx()) {
assertEquals("Page version is not increased on modification", 3, page.getVersion());
tx.success();
} catch (FrameworkException fex) {
fail("Unepxected exception.");
}
}
Aggregations