use of org.structr.common.error.FrameworkException 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.common.error.FrameworkException 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.");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class SimpleTest method test01DOMChildren.
@Test
public void test01DOMChildren() {
final String pageName = "page-01";
final String pageTitle = "Page Title";
try (final Tx tx = app.tx()) {
Page page = Page.createNewPage(securityContext, pageName);
if (page != null) {
DOMElement html = (DOMElement) page.createElement("html");
DOMElement head = (DOMElement) page.createElement("head");
DOMElement title = (DOMElement) page.createElement("title");
Text titleText = page.createTextNode(pageTitle);
for (AbstractRelationship r : page.getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("PAGE", r.getRelType().name());
}
html.appendChild(head);
for (AbstractRelationship r : head.getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("CONTAINS", r.getRelType().name());
}
head.appendChild(title);
title.appendChild(titleText);
for (AbstractRelationship r : ((DOMNode) titleText).getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("CONTAINS", r.getRelType().name());
}
}
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class SimpleTest method testPagePath.
@Test
public void testPagePath() {
final String pageName = "page-01";
try (final Tx tx = app.tx()) {
Page page = Page.createNewPage(securityContext, pageName);
assertTrue(page != null);
assertTrue(page instanceof Page);
DOMElement html = (DOMElement) page.createElement("html");
DOMElement head = (DOMElement) page.createElement("head");
DOMElement body = (DOMElement) page.createElement("body");
DOMElement title = (DOMElement) page.createElement("title");
DOMElement div = (DOMElement) page.createElement("div");
DOMElement div_2 = (DOMElement) page.createElement("div");
DOMElement div_3 = (DOMElement) page.createElement("div");
DOMElement h1 = (DOMElement) page.createElement("h1");
DOMElement h1_2 = (DOMElement) page.createElement("h1");
try {
// add HTML element to page
page.appendChild(html);
// add HEAD and BODY elements to HTML
html.appendChild(head);
html.appendChild(body);
// add TITLE element to HEAD
head.appendChild(title);
title.appendChild(page.createTextNode("Test Page"));
// add DIVs to BODY
body.appendChild(div);
body.appendChild(div_2);
body.appendChild(div_3);
// add H1 elements to DIV
div_3.appendChild(h1);
div_3.appendChild(h1_2);
h1.appendChild(page.createTextNode("Page Title"));
} catch (DOMException dex) {
throw new FrameworkException(422, dex.getMessage());
}
assertEquals(html.getPositionPath(), "/0");
assertEquals(head.getPositionPath(), "/0/0");
assertEquals(title.getPositionPath(), "/0/0/0");
assertEquals(body.getPositionPath(), "/0/1");
assertEquals(div.getPositionPath(), "/0/1/0");
assertEquals(div_2.getPositionPath(), "/0/1/1");
assertEquals(div_3.getPositionPath(), "/0/1/2");
assertEquals(h1.getPositionPath(), "/0/1/2/0");
assertEquals(h1_2.getPositionPath(), "/0/1/2/1");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class SimpleTest method testHttpResponseHeaders.
@Test
public void testHttpResponseHeaders() {
try (final Tx tx = app.tx()) {
Page.createSimplePage(securityContext, "test");
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));
tx.success();
} catch (FrameworkException fex) {
fail("Unepxected exception.");
}
RestAssured.given().header("X-User", "admin").header("X-Password", "admin").filter(ResponseLoggingFilter.logResponseTo(System.out)).expect().response().contentType("text/html").header("Expires", "Thu, 01 Jan 1970 00:00:00 GMT").header("X-Structr-Edition", "Community").header("Cache-Control", "private, max-age=0, s-maxage=0, no-cache, no-store, must-revalidate").header("Pragma", "no-cache, no-store").header("Content-Type", "text/html;charset=utf-8").header("Strict-Transport-Security", "max-age=60").header("X-Content-Type-Options", "nosniff").header("X-Frame-Options", "SAMEORIGIN").header("X-XSS-Protection", "1;mode=block").header("Vary", "Accept-Encoding, User-Agent").header("Content-Length", "133").header("Server", "Jetty(9.4.8.v20171121)").statusCode(200).when().get("http://127.0.0.1:8875/test");
}
Aggregations