use of org.structr.core.property.StringProperty in project structr by structr.
the class SystemTest method testFlawedParallelInstantiation.
/**
* disabled, failing test to check for (existing, confirmed) flaw in parallel node instantiation)
*/
@Test
public void testFlawedParallelInstantiation() {
final int nodeCount = 1000;
SchemaNode createTestType = null;
// setup: create dynamic type with onCreate() method
try (final Tx tx = app.tx()) {
createTestType = createTestNode(SchemaNode.class, "CreateTest");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
Class testType = StructrApp.getConfiguration().getNodeEntityClass("CreateTest");
assertNotNull("Type CreateTest should have been created", testType);
// second step: create 1000 test nodes
try (final Tx tx = app.tx()) {
createTestNodes(testType, nodeCount);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
createTestType.setProperty(new StringProperty("_testCount"), "Integer");
createTestType.setProperty(new StringProperty("___onCreate"), "set(this, 'testCount', size(find('CreateTest')))");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
testType = StructrApp.getConfiguration().getNodeEntityClass("CreateTest");
NodeInterface node = null;
// third step: create a single node in a separate transaction
try (final Tx tx = app.tx()) {
node = createTestNode(testType, "Tester");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// fourth step: check property value
try (final Tx tx = app.tx()) {
final Integer testCount = node.getProperty(new IntProperty("testCount"));
assertEquals("Invalid node count, check parallel instantiation!", (int) nodeCount + 1, (int) testCount);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class BasicTest method test02ModifyRelationship.
/**
* Test the results of setProperty and getProperty of a relationship
*/
@Test
public void test02ModifyRelationship() {
try {
final NodeHasLocation rel = (createTestRelationships(NodeHasLocation.class, 1)).get(0);
final PropertyKey key1 = new StringProperty("jghsdkhgshdhgsdjkfgh");
final String val1 = "54354354546806849870";
try (final Tx tx = app.tx()) {
rel.setProperty(key1, val1);
tx.success();
}
try (final Tx tx = app.tx()) {
assertTrue("Expected relationship to have a value for key '" + key1.dbName() + "'", rel.getRelationship().hasProperty(key1.dbName()));
assertEquals(val1, rel.getRelationship().getProperty(key1.dbName()));
Object vrfy1 = rel.getProperty(key1);
assertEquals(val1, vrfy1);
}
final String val2 = "öljkhöohü8osdfhoödhi";
try (final Tx tx = app.tx()) {
rel.setProperty(key1, val2);
tx.success();
}
try (final Tx tx = app.tx()) {
Object vrfy2 = rel.getProperty(key1);
assertEquals(val2, vrfy2);
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class UiScriptingTest method testSpecialHeaders.
@Test
public void testSpecialHeaders() {
String uuid = null;
// schema setup
try (final Tx tx = app.tx()) {
// create list of 100 folders
final List<Folder> folders = new LinkedList<>();
for (int i = 0; i < 100; i++) {
folders.add(createTestNode(Folder.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Folder" + i)));
}
// create parent folder
final Folder parent = createTestNode(Folder.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Parent"), new NodeAttribute<>(StructrApp.key(Folder.class, "folders"), folders));
uuid = parent.getUuid();
// create function property that returns folder children
final SchemaNode schemaNode = app.nodeQuery(SchemaNode.class).andName("Folder").getFirst();
schemaNode.setProperty(new StringProperty("_testFunction"), "Function(this.folders)");
// 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) {
logger.warn("", fex);
fail("Unexpected exception");
}
RestAssured.basePath = "/structr/rest";
RestAssured.given().contentType("application/json; charset=UTF-8").accept("application/json; properties=id,type,name,folders,testFunction").header("Range", "folders=0-10;testFunction=0-10").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", "admin", "X-Password", "admin").expect().statusCode(200).body("result.folders", Matchers.hasSize(10)).body("result.testFunction", Matchers.hasSize(10)).when().get("/Folder/" + uuid + "/ui");
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class RenderContextTest method testNotionTransformedPropertyAccess.
@Test
public void testNotionTransformedPropertyAccess() {
NodeInterface project = null;
NodeInterface task1 = null;
NodeInterface task2 = null;
NodeInterface task3 = null;
try (final Tx tx = app.tx()) {
final SchemaNode projectNode = app.create(SchemaNode.class, new NodeAttribute(SchemaNode.name, "Project"), new NodeAttribute(new StringProperty("_taskList"), "Notion(tasks, id, name)"), new NodeAttribute(new StringProperty("_taskNames"), "Notion(tasks, name)"));
final SchemaNode taskNode = app.create(SchemaNode.class, new NodeAttribute(SchemaNode.name, "Task"));
// create schema relationship
final PropertyMap taskProperties = new PropertyMap();
taskProperties.put(SchemaRelationshipNode.sourceNode, projectNode);
taskProperties.put(SchemaRelationshipNode.targetNode, taskNode);
taskProperties.put(SchemaRelationshipNode.relationshipType, "TASK");
taskProperties.put(SchemaRelationshipNode.relationshipType, "TASK");
taskProperties.put(SchemaRelationshipNode.sourceMultiplicity, "1");
taskProperties.put(SchemaRelationshipNode.targetMultiplicity, "*");
taskProperties.put(SchemaRelationshipNode.sourceJsonName, "project");
taskProperties.put(SchemaRelationshipNode.targetJsonName, "tasks");
app.create(SchemaRelationshipNode.class, taskProperties);
// create schema relationship
final PropertyMap currentTaskProperties = new PropertyMap();
currentTaskProperties.put(SchemaRelationshipNode.sourceNode, projectNode);
currentTaskProperties.put(SchemaRelationshipNode.targetNode, taskNode);
currentTaskProperties.put(SchemaRelationshipNode.relationshipType, "CURRENT");
currentTaskProperties.put(SchemaRelationshipNode.sourceMultiplicity, "1");
currentTaskProperties.put(SchemaRelationshipNode.targetMultiplicity, "1");
currentTaskProperties.put(SchemaRelationshipNode.sourceJsonName, "project");
currentTaskProperties.put(SchemaRelationshipNode.targetJsonName, "currentTask");
app.create(SchemaRelationshipNode.class, currentTaskProperties);
// compile the stuff
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception");
}
final ConfigurationProvider config = StructrApp.getConfiguration();
final Class projectClass = config.getNodeEntityClass("Project");
final Class taskClass = config.getNodeEntityClass("Task");
final PropertyKey currentTaskKey = StructrApp.key(projectClass, "currentTask");
final PropertyKey tasksKey = StructrApp.key(projectClass, "tasks");
// create parent/child relationship
try (final Tx tx = app.tx()) {
project = app.create(projectClass, new NodeAttribute(SchemaNode.name, "Project1"));
task1 = app.create(taskClass, new NodeAttribute(SchemaNode.name, "Task1"));
task2 = app.create(taskClass, new NodeAttribute(SchemaNode.name, "Task2"));
task3 = app.create(taskClass, new NodeAttribute(SchemaNode.name, "Task3"));
// add task to project
final List tasks = new LinkedList<>();
tasks.add(task1);
tasks.add(task2);
tasks.add(task3);
final PropertyMap projectProperties = new PropertyMap();
projectProperties.put(tasksKey, tasks);
projectProperties.put(currentTaskKey, task3);
project.setProperties(project.getSecurityContext(), projectProperties);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception");
}
// check property access in template expressions
try (final Tx tx = app.tx()) {
final RenderContext renderContext = new RenderContext(securityContext);
renderContext.putDataObject("project", project);
renderContext.putDataObject("task", task1);
assertEquals("Invalid dot syntax result: ", "Project1", Scripting.replaceVariables(renderContext, project, "${project.name}"));
assertEquals("Invalid dot syntax result: ", "Task1", Scripting.replaceVariables(renderContext, project, "${project.tasks[0].name}"));
assertEquals("Invalid dot syntax result: ", "Task2", Scripting.replaceVariables(renderContext, project, "${project.tasks[1].name}"));
assertEquals("Invalid dot syntax result: ", "Task3", Scripting.replaceVariables(renderContext, project, "${project.tasks[2].name}"));
assertEquals("Invalid dot syntax result: ", "[Task1, Task2, Task3]", Scripting.replaceVariables(renderContext, project, "${project.taskNames}"));
assertEquals("Invalid dot syntax result: ", "Task1", Scripting.replaceVariables(renderContext, project, "${project.taskNames[0]}"));
assertEquals("Invalid dot syntax result: ", "Task2", Scripting.replaceVariables(renderContext, project, "${project.taskNames[1]}"));
assertEquals("Invalid dot syntax result: ", "Task3", Scripting.replaceVariables(renderContext, project, "${project.taskNames[2]}"));
assertEquals("Invalid dot syntax result: ", "Task3", Scripting.replaceVariables(renderContext, project, "${project.currentTask.name}"));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception");
}
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class ScriptingTest method testPrivilegedFind.
@Test
public void testPrivilegedFind() {
final ActionContext ctx = new ActionContext(securityContext, null);
TestOne testNode = null;
String uuid = "";
try (final Tx tx = app.tx()) {
testNode = createTestNode(TestOne.class);
testNode.setProperty(TestOne.aString, "InitialString");
testNode.setProperty(TestOne.anInt, 42);
uuid = testNode.getProperty(new StringProperty("id"));
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
assertEquals("JavaScript: Trying to find entity with type,key,value!", "InitialString", Scripting.replaceVariables(ctx, testNode, "${{ var t1 = Structr.first(Structr.find_privileged('TestOne','anInt','42')); Structr.print(t1.aString); }}"));
assertEquals("JavaScript: Trying to find entity with type,id!", "InitialString", Scripting.replaceVariables(ctx, testNode, "${{ var t1 = Structr.find_privileged('TestOne','" + uuid + "'); Structr.print(t1.aString); }}"));
assertEquals("JavaScript: Trying to find entity with type,key,value,key,value!", "InitialString", Scripting.replaceVariables(ctx, testNode, "${{ var t1 = Structr.first(Structr.find_privileged('TestOne','anInt','42','aString','InitialString')); Structr.print(t1.aString); }}"));
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
Aggregations