use of org.structr.common.error.FrameworkException 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.common.error.FrameworkException in project structr by structr.
the class UiScriptingTest method testMultiRequestParameters.
@Test
public void testMultiRequestParameters() {
try (final Tx tx = app.tx()) {
Page page = (Page) app.create(Page.class, new NodeAttribute(Page.name, "test"), new NodeAttribute(Page.visibleToPublicUsers, true));
Template template = (Template) app.create(Template.class, new NodeAttribute(Page.visibleToPublicUsers, true));
template.setContent("${each(request.param, print(data))}");
page.appendChild(template);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
RestAssured.given().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(equalTo("abc")).when().get("http://localhost:8875/test?param=a¶m=b¶m=c");
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
}
use of org.structr.common.error.FrameworkException 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);
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class UiScriptingTest method testSingleRequestParameters.
@Test
public void testSingleRequestParameters() {
try (final Tx tx = app.tx()) {
Page page = (Page) app.create(Page.class, new NodeAttribute(Page.name, "test"), new NodeAttribute(Page.visibleToPublicUsers, true));
Template template = (Template) app.create(Template.class, new NodeAttribute(Page.visibleToPublicUsers, true));
template.setContent("${request.param}");
page.appendChild(template);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
RestAssured.given().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(equalTo("a")).when().get("http://localhost:8875/test?param=a");
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class UiScriptingTest method testGroupFunctions.
@Test
public void testGroupFunctions() {
Group group = null;
User tester = null;
try (final Tx tx = app.tx()) {
// create test user
tester = createTestNode(User.class, new NodeAttribute<>(StructrApp.key(User.class, "name"), "tester"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "test"));
// create test group
group = createTestNode(Group.class, new NodeAttribute<>(StructrApp.key(Group.class, "name"), "test"));
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception.");
}
final RenderContext renderContext = new RenderContext(securityContext, new RequestMockUp(), new ResponseMockUp(), RenderContext.EditMode.NONE);
try (final Tx tx = app.tx()) {
// check that the user is not in the group at first
assertFalse("User should not be in the test group before testing", group.getMembers().contains(tester));
// check that is_in_group returns the correct result
assertEquals("Function is_in_group should return false.", false, Scripting.evaluate(renderContext, null, "${is_in_group(first(find('Group')), first(find('User')))}", "test"));
// add user to group
Scripting.evaluate(renderContext, null, "${add_to_group(first(find('Group')), first(find('User')))}", "test");
// check that the user is in the group after the call to add_to_group
final List<Principal> members = group.getMembers();
assertTrue("User should be in the test group now", members.contains(tester));
// check that is_in_group returns the correct result
assertEquals("Function is_in_group should return true.", true, Scripting.evaluate(renderContext, null, "${is_in_group(first(find('Group')), first(find('User')))}", "test"));
// remove user from group
Scripting.evaluate(renderContext, null, "${remove_from_group(first(find('Group')), first(find('User')))}", "test");
// check that the user is not in the group any more after the call to remove_from_group
assertFalse("User should not be in the test group before testing", group.getMembers().contains(tester));
// check that is_in_group returns the correct result
assertEquals("Function is_in_group should return false.", false, Scripting.evaluate(renderContext, null, "${is_in_group(first(find('Group')), first(find('User')))}", "test"));
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception.");
}
}
Aggregations