use of org.structr.core.graph.NodeAttribute in project structr by structr.
the class DeploymentTest method test22TemplateOwnershipAndGrants.
@Test
public void test22TemplateOwnershipAndGrants() {
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
try (final Tx tx = app.tx()) {
// create first page
final Page page1 = Page.createNewPage(securityContext, "test22_1");
final Html html1 = createElement(page1, page1, "html");
final Head head1 = createElement(page1, html1, "head");
createElement(page1, head1, "title", "test22_1");
final Body body1 = createElement(page1, html1, "body");
final Div div1 = createElement(page1, body1, "div");
createElement(page1, div1, "div", "test1");
createElement(page1, div1, "div", "test1");
final Div component = createComponent(div1);
// create second page
final Page page2 = Page.createNewPage(securityContext, "test22_2");
final Html html2 = createElement(page2, page2, "html");
final Head head2 = createElement(page2, html2, "head");
createElement(page2, head2, "title", "test22_2");
final Body body2 = createElement(page2, html2, "body");
final Div div2 = createElement(page2, body2, "div");
// re-use template from above
final Div cloned = cloneComponent(component, div2);
component.grant(Permission.read, user1);
cloned.grant(Permission.read, user2);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
doImportExportRoundtrip(true, true, new Function() {
@Override
public Object apply(Object t) {
try (final Tx tx = app.tx()) {
createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
tx.success();
} catch (FrameworkException ex) {
fail("Unexpected exception.");
}
return null;
}
});
}
use of org.structr.core.graph.NodeAttribute in project structr by structr.
the class PerformanceTest method testPerformanceOfNodeCreation.
/**
* Tests basic throughput of node creation operations
*
* Note that this is just a very rought test as performance is heavily
* depending on hardware and setup (cache parameters etc.)
*
* The assumed rate is low so if this test fails, there may be issues
* with the test setup.
*
* If the test passes, one can expect structr to create nodes with typical performance.
*/
@Test
public void testPerformanceOfNodeCreation() {
final List<TestOne> nodes = new LinkedList<>();
final long number = 1000;
// start measuring
final long t0 = System.currentTimeMillis();
final App app = StructrApp.getInstance(setup());
try {
try (final Tx tx = app.tx()) {
final long t1 = System.currentTimeMillis();
for (int i = 0; i < number; i++) {
nodes.add(app.create(TestOne.class, new NodeAttribute(TestOne.name, "TestOne" + i), new NodeAttribute(TestOne.aDate, new Date()), new NodeAttribute(TestOne.aDouble, 1.234), new NodeAttribute(TestOne.aLong, 12345L), new NodeAttribute(TestOne.anInt, 123)));
}
final long t2 = System.currentTimeMillis();
System.out.println((t2 - t1) + " ms");
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
final long t1 = System.currentTimeMillis();
assertTrue(nodes.size() == number);
DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
Double time = (t1 - t0) / 1000.0;
Double rate = number / ((t1 - t0) / 1000.0);
logger.info("Created {} nodes in {} seconds ({} per s)", number, decimalFormat.format(time), decimalFormat.format(rate));
assertTrue("Creation rate of nodes too low, expected > 100, was " + rate, rate > 50);
}
use of org.structr.core.graph.NodeAttribute in project structr by structr.
the class PerformanceTest method setup.
// ----- private methods -----
private SecurityContext setup() {
final App app = StructrApp.getInstance();
User user = null;
try (final Tx tx = app.tx()) {
user = app.create(User.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "isAdmin"), true));
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
return SecurityContext.getInstance(user, AccessMode.Backend);
}
use of org.structr.core.graph.NodeAttribute in project structr by structr.
the class SimpleTest method test08PassiveIndexing.
@Test
public void test08PassiveIndexing() {
try {
// create some test nodes
File test1 = null;
// check initial sort order
try (final Tx tx = app.tx()) {
// create some test nodes
test1 = createTestNode(File.class, new NodeAttribute<>(AbstractNode.name, "aaaaa"));
createTestNode(File.class, new NodeAttribute<>(AbstractNode.name, "bbbbb"));
createTestNode(File.class, new NodeAttribute<>(AbstractNode.name, "ccccc"));
createTestNode(File.class, new NodeAttribute<>(AbstractNode.name, "ddddd"));
createTestNode(File.class, new NodeAttribute<>(AbstractNode.name, "eeeee"));
tx.success();
}
// check initial sort order
try (final Tx tx = app.tx()) {
final List<File> files = app.nodeQuery(File.class).sort(StructrApp.key(File.class, "path")).getAsList();
assertEquals("Invalid indexing sort result", "aaaaa", files.get(0).getName());
assertEquals("Invalid indexing sort result", "bbbbb", files.get(1).getName());
assertEquals("Invalid indexing sort result", "ccccc", files.get(2).getName());
assertEquals("Invalid indexing sort result", "ddddd", files.get(3).getName());
assertEquals("Invalid indexing sort result", "eeeee", files.get(4).getName());
tx.success();
}
// modify file name to move the first file to the end of the sorted list
try (final Tx tx = app.tx()) {
test1.setProperties(test1.getSecurityContext(), new PropertyMap(AbstractNode.name, "zzzzz"));
tx.success();
}
// check final sort order
try (final Tx tx = app.tx()) {
final List<File> files = app.nodeQuery(File.class).sort(StructrApp.key(File.class, "path")).getAsList();
assertEquals("Invalid indexing sort result", "bbbbb", files.get(0).getName());
assertEquals("Invalid indexing sort result", "ccccc", files.get(1).getName());
assertEquals("Invalid indexing sort result", "ddddd", files.get(2).getName());
assertEquals("Invalid indexing sort result", "eeeee", files.get(3).getName());
assertEquals("Invalid indexing sort result", "zzzzz", files.get(4).getName());
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.graph.NodeAttribute 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");
}
Aggregations