use of org.structr.core.entity.TestOne in project structr by structr.
the class SearchAndSortingTest method test04SeachByNamePropertyLooseUppercase.
@Test
public void test04SeachByNamePropertyLooseUppercase() {
try {
Class type = TestOne.class;
int number = 4;
final List<NodeInterface> nodes = this.createTestNodes(type, number);
final int offset = 10;
Collections.shuffle(nodes, new Random(System.nanoTime()));
try (final Tx tx = app.tx()) {
int i = offset;
String name;
for (NodeInterface node : nodes) {
// System.out.println("Node ID: " + node.getNodeId());
name = "TestOne-" + i;
i++;
node.setProperty(AbstractNode.name, name);
}
tx.success();
}
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(type).and(TestOne.name, "TestOne", false).getResult();
assertEquals(4, result.size());
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class SystemTest method testTransactionIsolation.
@Test
public void testTransactionIsolation() {
try {
final TestOne test = createTestNode(TestOne.class);
final ExecutorService executor = Executors.newCachedThreadPool();
final List<TestRunner> tests = new LinkedList<>();
final List<Future> futures = new LinkedList<>();
// create and run test runners
for (int i = 0; i < 25; i++) {
final TestRunner runner = new TestRunner(app, test);
futures.add(executor.submit(runner));
tests.add(runner);
}
// wait for termination
for (final Future future : futures) {
future.get();
System.out.print(".");
}
System.out.println();
// check for success
for (final TestRunner runner : tests) {
assertTrue("Could not validate transaction isolation", runner.success());
}
executor.shutdownNow();
} catch (Throwable fex) {
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class SystemTest method testConcurrentIdenticalRelationshipCreation.
@Test
public void testConcurrentIdenticalRelationshipCreation() {
try {
final ExecutorService service = Executors.newCachedThreadPool();
final TestSix source = createTestNode(TestSix.class);
final TestOne target = createTestNode(TestOne.class);
final Future one = service.submit(new RelationshipCreator(source, target));
final Future two = service.submit(new RelationshipCreator(source, target));
// wait for completion
one.get();
two.get();
try (final Tx tx = app.tx()) {
// check for a single relationship since all three parts of
// both relationships are equal => only one should be created
final List<TestOne> list = source.getProperty(TestSix.oneToManyTestOnes);
assertEquals("Invalid concurrent identical relationship creation result", 1, list.size());
tx.success();
}
service.shutdownNow();
} catch (ExecutionException | InterruptedException | FrameworkException fex) {
logger.warn("", fex);
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class SystemTest method testEnsureCardinalityPerformance.
@Test
public void testEnsureCardinalityPerformance() {
final List<TestOne> list = new LinkedList<>();
final int num = 1000;
// test setup, create a supernode with 10000 relationships
try (final Tx tx = app.tx()) {
System.out.println("Creating supernode with " + num + " relationships.");
list.add(createTestNode(TestOne.class, new NodeAttribute<>(TestOne.manyToManyTestSixs, createTestNodes(TestSix.class, num))));
tx.success();
} catch (Throwable fex) {
fail("Unexpected exception");
}
// actual test: test performance of node association on supernode
try (final Tx tx = app.tx()) {
for (int i = 0; i < 10; i++) {
final long t0 = System.currentTimeMillis();
createTestNode(TestSix.class, new NodeAttribute<>(TestSix.manyToManyTestOnes, list));
final long t1 = System.currentTimeMillis();
System.out.println((t1 - t0) + "ms");
}
tx.success();
} catch (Throwable fex) {
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class AccessControlTest method test03PublicAccessToProtectedNode.
@Test
public void test03PublicAccessToProtectedNode() {
// remove auto-generated resource access objects
clearResourceAccess();
try {
List<Principal> users = createTestNodes(Principal.class, 1);
Principal user = (Principal) users.get(0);
PropertyMap props = new PropertyMap();
props.put(AbstractNode.visibleToPublicUsers, true);
// Create two nodes with user context, one of them is visible to public users
Class type = TestOne.class;
TestOne t1 = createTestNode(TestOne.class, props, user);
props = new PropertyMap();
props.put(AbstractNode.visibleToAuthenticatedUsers, true);
TestOne t2 = createTestNode(TestOne.class, props, user);
SecurityContext publicContext = SecurityContext.getInstance(null, AccessMode.Frontend);
try (final Tx tx = app.tx()) {
Result result = StructrApp.getInstance(publicContext).nodeQuery(type).getResult();
assertEquals(1, result.size());
assertEquals(t1.getUuid(), result.get(0).getUuid());
}
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
Aggregations