use of org.structr.core.graph.NodeAttribute 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.core.graph.NodeAttribute 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.");
}
}
use of org.structr.core.graph.NodeAttribute in project structr by structr.
the class UiTest method testAutoRenameFileWithIdenticalPathInSubFolder.
@Test
public void testAutoRenameFileWithIdenticalPathInSubFolder() {
Settings.UniquePaths.setValue(Boolean.TRUE);
Folder folder = null;
File file1 = null;
File file2 = null;
try (final Tx tx = app.tx()) {
folder = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), "/my/test/folder");
assertNotNull(folder);
assertEquals(folder.getPath(), "/my/test/folder");
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
file1 = app.create(File.class, new NodeAttribute<>(AbstractNode.name, "test.txt"), new NodeAttribute<>(StructrApp.key(AbstractFile.class, "parent"), folder));
assertNotNull(file1);
assertEquals("Testfolder should have exactly one child", 1, Iterables.count(folder.getChildren()));
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
file2 = app.create(File.class, new NodeAttribute<>(AbstractNode.name, "test.txt"), new NodeAttribute<>(StructrApp.key(AbstractFile.class, "parent"), folder));
assertNotNull(file2);
assertEquals("Testfolder should have exactly two children", 2, Iterables.count(folder.getChildren()));
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
assertNotEquals(file1.getName(), file2.getName());
}
use of org.structr.core.graph.NodeAttribute in project structr by structr.
the class StructrLDAPWrapper method getRoot.
private LDAPNode getRoot() throws FrameworkException {
final Class type = StructrApp.getConfiguration().getNodeEntityClass("LDAPNode");
final App app = app();
LDAPNode root = (LDAPNode) app.nodeQuery(type).andName(partitionId).getFirst();
if (root == null) {
root = app.create(type, new NodeAttribute<>(StructrApp.key(LDAPNode.class, "name"), partitionId), new NodeAttribute<>(StructrApp.key(LDAPNode.class, "isRoot"), true));
}
return root;
}
use of org.structr.core.graph.NodeAttribute in project structr by structr.
the class LDAPService method synchronizeUserEntry.
// ----- private methods -----
private String synchronizeUserEntry(final LdapConnection connection, final Entry entry) {
final PropertyKey<String> dnKey = StructrApp.key(LDAPUser.class, "distinguishedName");
final App app = StructrApp.getInstance();
final Dn dn = entry.getDn();
final String dnString = dn.toString();
try (final Tx tx = app.tx()) {
LDAPUser user = app.nodeQuery(LDAPUser.class).and(dnKey, dnString).getFirst();
if (user == null) {
user = app.create(LDAPUser.class, new NodeAttribute(dnKey, dnString));
user.initializeFrom(entry);
final String uuid = user.getUuid();
if (user.getEntryUuid() == null) {
try {
// try to set "our" UUID in the remote database
final Modification addUuid = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, "entryUUID", normalizeUUID(uuid));
connection.modify(dn, addUuid);
} catch (LdapException ex) {
logger.warn("Unable to set entryUUID: {}", ex.getMessage());
}
}
}
tx.success();
return user.getUuid();
} catch (FrameworkException | LdapInvalidAttributeValueException fex) {
logger.warn("Unable to update LDAP information", fex);
}
return null;
}
Aggregations