use of org.structr.web.entity.html.Div in project structr by structr.
the class DeploymentTest method test20ExportOwnership.
@Test
public void test20ExportOwnership() {
Principal user1 = null;
Principal user2 = null;
try (final Tx tx = app.tx()) {
user1 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
user2 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
tx.success();
} catch (FrameworkException ex) {
fail("Unexpected exception.");
}
Assert.assertNotNull("User was not created, test cannot continue", user1);
Assert.assertNotNull("User was not created, test cannot continue", user2);
// setup
final SecurityContext context1 = SecurityContext.getInstance(user1, AccessMode.Backend);
final App app1 = StructrApp.getInstance(context1);
try (final Tx tx = app1.tx()) {
final Page page = Page.createNewPage(context1, "test20");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test20");
final Body body = createElement(page, html, "body");
final Div div1 = createElement(page, body, "div");
final Content content = createContent(page, div1, "<b>Test</b>");
content.setProperty(StructrApp.key(Content.class, "contentType"), "text/html");
// set owner to different user
div1.setProperty(AbstractNode.owner, user2);
content.setProperty(AbstractNode.owner, user2);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
compare(calculateHash(), true, false);
}
use of org.structr.web.entity.html.Div in project structr by structr.
the class DiffTest method testTreeRemovalFix.
@Test
public void testTreeRemovalFix() {
final String comment = "<!-- comment --->";
testDiff("<html><head><title>Title</title></head><body><div>" + comment + "<div>" + comment + "<div>test</div>" + comment + "<div></div></div></body></html>", (String from) -> {
String modified = from;
modified = modified.replace(comment, "");
return modified;
});
// test result on the node level
try (final Tx tx = app.tx()) {
final Page page = app.nodeQuery(Page.class).andName("test").getFirst();
assertNotNull(page);
final NodeList nodes = page.getElementsByTagName("div");
final List<Div> divs = collectNodes(nodes, Div.class);
assertEquals("Wrong number of divs returned from node query", 4, divs.size());
// check first div, should have no siblings and one child
final Div firstDiv = divs.get(0);
assertEquals("Wrong number of children", 1, firstDiv.getChildRelationships().size());
assertNull("Node should not have siblings", firstDiv.getNextSibling());
// check second div, should have no siblings and two children
final Div secondDiv = divs.get(1);
assertEquals("Wrong number of children", 2, secondDiv.getChildRelationships().size());
assertNull("Node should not have siblings", secondDiv.getNextSibling());
// check third div, should have one sibling and one #text child
final Div thirdDiv = divs.get(2);
assertEquals("Wrong number of children", 1, thirdDiv.getChildRelationships().size());
assertNotNull("Node should have one sibling", thirdDiv.getNextSibling());
// check fourth div, should have no siblings and no children
final Div fourthDiv = divs.get(3);
assertEquals("Wrong number of children", 0, fourthDiv.getChildRelationships().size());
assertNull("Node should not have siblings", fourthDiv.getNextSibling());
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
}
use of org.structr.web.entity.html.Div in project structr by structr.
the class CustomHtmlAttributeTest method testCustomHtmlAttribute.
@Test
public void testCustomHtmlAttribute() {
try (final Tx tx = app.tx()) {
// create a page
final Page newPage = Page.createNewPage(securityContext, "customAttributeTestPage");
final Html html = createElement(newPage, newPage, "html");
final Head head = createElement(newPage, html, "head");
final Title title = createElement(newPage, head, "title", "Test Page for custom html attributes");
final Body body = createElement(newPage, html, "body");
final Div div1 = createElement(newPage, body, "div", "DIV with old-style data attribute");
div1.setProperty(new GenericProperty<String>("data-test-attribute-old-style"), "old-style data attribute");
final Div div2 = createElement(newPage, body, "div", "DIV with new-style custom html attribute");
div2.setProperty(new GenericProperty<String>("_custom_html_test-attribute-new-style"), "new-style custom attribute");
final Div div3 = createElement(newPage, body, "div", "DIV with data-attribute as new-style custom html attribute");
div3.setProperty(new GenericProperty<String>("_custom_html_data-test-attribute-new-style"), "new-style custom data-attribute");
final RenderContext renderContext = new RenderContext(securityContext);
newPage.render(renderContext, 0);
final String renderedHtml = StringUtils.join(renderContext.getBuffer().getQueue(), "");
final String expectedHtml = "<!DOCTYPE html>\n" + "<html>\n" + " <head>\n" + " <title>Test Page for custom html attributes</title>\n" + " </head>\n" + " <body>\n" + " <div data-test-attribute-old-style=\"old-style data attribute\">DIV with old-style data attribute</div>\n" + " <div test-attribute-new-style=\"new-style custom attribute\">DIV with new-style custom html attribute</div>\n" + " <div data-test-attribute-new-style=\"new-style custom data-attribute\">DIV with data-attribute as new-style custom html attribute</div>\n" + " </body>\n" + "</html>";
Assert.assertEquals(expectedHtml, renderedHtml);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
use of org.structr.web.entity.html.Div in project structr by structr.
the class UiScriptingTest method testRestQueryWithRemoteAttributeRepeater.
@Test
public void testRestQueryWithRemoteAttributeRepeater() {
String uuid = null;
try (final Tx tx = app.tx()) {
final Page page = Page.createSimplePage(securityContext, "test");
final Div div = (Div) page.getElementsByTagName("div").item(0);
final Content content = (Content) div.getFirstChild();
// Create second div without children
Div div2 = (Div) div.cloneNode(false);
div.getUuid();
// setup scripting repeater to repeat over (non-existing) children of second div
content.setProperty(StructrApp.key(Content.class, "restQuery"), "/Div/" + div2.getUuid() + "/children");
content.setProperty(StructrApp.key(Content.class, "dataKey"), "test");
content.setProperty(StructrApp.key(Content.class, "content"), "foo${test}");
// store UUID for later use
uuid = page.getUuid();
// create admin user
createTestNode(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) {
fex.printStackTrace();
fail("Unexpected exception.");
}
RestAssured.basePath = "/";
// test successful basic auth
RestAssured.given().headers("X-User", "admin", "X-Password", "admin").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("html.head.title", Matchers.equalTo("Test")).body("html.body.h1", Matchers.equalTo("Test")).body("html.body.div", Matchers.equalTo("")).when().get("/html/test/" + uuid);
}
use of org.structr.web.entity.html.Div in project structr by structr.
the class UiScriptingTest method testRestQueryRepeater.
@Test
public void testRestQueryRepeater() {
String uuid = null;
try (final Tx tx = app.tx()) {
final Page page = Page.createSimplePage(securityContext, "test");
final Div div = (Div) page.getElementsByTagName("div").item(0);
final Content content = (Content) div.getFirstChild();
// setup scripting repeater
content.setProperty(StructrApp.key(Content.class, "restQuery"), "/Page/${current.id}");
content.setProperty(StructrApp.key(Content.class, "dataKey"), "test");
content.setProperty(StructrApp.key(Content.class, "content"), "${test.id}");
// store UUID for later use
uuid = page.getUuid();
// create admin user
createTestNode(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) {
fex.printStackTrace();
fail("Unexpected exception.");
}
RestAssured.basePath = "/";
// test successful basic auth
RestAssured.given().headers("X-User", "admin", "X-Password", "admin").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("html.head.title", Matchers.equalTo("Test")).body("html.body.h1", Matchers.equalTo("Test")).body("html.body.div", Matchers.equalTo(uuid)).when().get("/html/test/" + uuid);
}
Aggregations