use of org.structr.core.graph.NodeInterface in project structr by structr.
the class BasicTest method test07CascadeDeleteConditional.
/**
* DELETE_IF_CONSTRAINT_WOULD_BE_VIOLATED should
* trigger delete cascade from start to end node only
* if the remote node would not be valid afterwards
*/
@Test
public void test07CascadeDeleteConditional() {
try {
AbstractRelationship rel = cascadeRel(TestOne.class, TestTwo.class, Relation.CONSTRAINT_BASED);
NodeInterface sourceNode;
String startNodeId;
String endNodeId;
try (final Tx tx = app.tx()) {
startNodeId = rel.getSourceNode().getUuid();
endNodeId = rel.getTargetNode().getUuid();
sourceNode = rel.getSourceNode();
}
deleteCascade(sourceNode);
try (final Tx tx = app.tx()) {
// Start node should be deleted
assertNodeNotFound(startNodeId);
// End node should be deleted
assertNodeNotFound(endNodeId);
}
rel = cascadeRel(TestOne.class, TestThree.class, Relation.CONSTRAINT_BASED);
try (final Tx tx = app.tx()) {
startNodeId = rel.getSourceNode().getUuid();
endNodeId = rel.getTargetNode().getUuid();
sourceNode = rel.getSourceNode();
}
deleteCascade(sourceNode);
try (final Tx tx = app.tx()) {
// Start node should be deleted
assertNodeNotFound(startNodeId);
// End node should still be there
assertNodeExists(endNodeId);
}
rel = cascadeRel(TestOne.class, TestFour.class, Relation.CONSTRAINT_BASED);
try (final Tx tx = app.tx()) {
startNodeId = rel.getSourceNode().getUuid();
endNodeId = rel.getTargetNode().getUuid();
sourceNode = rel.getSourceNode();
}
deleteCascade(sourceNode);
try (final Tx tx = app.tx()) {
// Start node should be deleted
assertNodeNotFound(startNodeId);
// End node should still be there
assertNodeExists(endNodeId);
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class CustomPermissionQueriesTest method test01SimplePermissionResolutionRead.
@Test
public void test01SimplePermissionResolutionRead() {
final Class<Principal> principalType = StructrApp.getConfiguration().getNodeEntityClass("Principal");
Principal user1 = null;
Class type1 = null;
try (final Tx tx = app.tx()) {
// create a test user
user1 = app.create(principalType, "user1");
final SchemaNode t1 = app.create(SchemaNode.class, "Type1");
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception");
}
Assert.assertNotNull("User should have been created", user1);
try (final Tx tx = app.tx()) {
type1 = StructrApp.getConfiguration().getNodeEntityClass("Type1");
Assert.assertNotNull("Node type Type1 should exist.", type1);
final NodeInterface instance1 = app.create(type1, "instance1OfType1");
Assert.assertNotNull("Instance of type Type1 should exist", instance1);
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception");
}
// check access for user1 on instance1
final App userApp = StructrApp.getInstance(SecurityContext.getInstance(user1, AccessMode.Backend));
try (final Tx tx = userApp.tx()) {
Assert.assertNull("User1 should NOT be able to find instance of type Type1", userApp.nodeQuery(type1).getFirst());
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception");
}
// set custom permission query on user
try (final Tx tx = userApp.tx()) {
// query returns always true if user exists
user1.setProperty(StructrApp.key(Principal.class, "customPermissionQueryRead"), "MATCH (p:Principal {id: {principalUuid}}) RETURN p IS NOT NULL");
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception");
}
// check access for user1 on instance1
try (final Tx tx = userApp.tx()) {
Assert.assertNotNull("User1 should be able to find instance of type Type1", userApp.nodeQuery(type1).getFirst());
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception");
}
// set custom permission query on user
try (final Tx tx = userApp.tx()) {
// query returns always false if user exists
user1.setProperty(StructrApp.key(Principal.class, "customPermissionQueryRead"), "MATCH (p:Principal {id: {principalUuid}}) RETURN p IS NULL");
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception");
}
// check access for user1 on instance1
try (final Tx tx = userApp.tx()) {
Assert.assertNull("User1 should NOT be able to find instance of type Type1", userApp.nodeQuery(type1).getFirst());
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception");
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class SearchAndSortingTest method test02Paging.
/**
* Test different pages and page sizes
*/
@Test
public void test02Paging() {
try {
boolean includeDeletedAndHidden = false;
boolean publicOnly = false;
Class type = TestOne.class;
// no more than 89 to avoid sort order TestOne-10, TestOne-100 ...
int number = 89;
final int offset = 10;
final List<NodeInterface> nodes = this.createTestNodes(type, number);
Collections.shuffle(nodes, new Random(System.nanoTime()));
try (final Tx tx = app.tx()) {
int i = offset;
for (NodeInterface node : nodes) {
// System.out.println("Node ID: " + node.getNodeId());
String _name = "TestOne-" + i;
i++;
node.setProperty(AbstractNode.name, _name);
}
tx.success();
}
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(type).getResult();
assertEquals(number, result.size());
PropertyKey sortKey = AbstractNode.name;
boolean sortDesc = false;
// test pages sizes from 0 to 10
for (int ps = 0; ps < 10; ps++) {
// test all pages
for (int p = 0; p < (number / Math.max(1, ps)) + 1; p++) {
testPaging(type, ps, p, number, offset, includeDeletedAndHidden, publicOnly, sortKey, sortDesc);
}
}
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class SearchAndSortingTest method test07SortByIntWithNullValues.
@Test
public void test07SortByIntWithNullValues() {
try {
final List<TestOne> nodes = this.createTestNodes(TestOne.class, 10);
try (final Tx tx = app.tx()) {
int i = 0;
for (NodeInterface node : nodes) {
node.setProperty(AbstractNode.name, Long.toString(i));
if (i < 7) {
node.setProperty(TestOne.anInt, i);
}
i++;
}
tx.success();
}
try (final Tx tx = app.tx()) {
boolean sortDesc = false;
final List<TestOne> result = app.nodeQuery(TestOne.class).sort(TestOne.anInt).order(sortDesc).getAsList();
// check that the sorting is stable, i.e. the position of nodes
// with equal values (and null) is not modified by sorting
final Iterator<TestOne> nameIterator = result.iterator();
while (nameIterator.hasNext()) {
// nulls first
assertEquals("Invalid sort result with mixed values (null vs. int)", "7", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "8", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "9", nameIterator.next().getProperty(TestOne.name));
// other values after that
assertEquals("Invalid sort result with mixed values (null vs. int)", "0", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "1", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "2", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "3", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "4", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "5", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "6", nameIterator.next().getProperty(TestOne.name));
}
// check that the sorting is "nulls first" as documented
final Iterator<TestOne> intIterator = result.iterator();
while (intIterator.hasNext()) {
// nulls first
assertEquals("Invalid sort result with mixed values (null vs. int)", null, intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", null, intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", null, intIterator.next().getProperty(TestOne.anInt));
// other values after that
assertEquals("Invalid sort result with mixed values (null vs. int)", 0L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 1L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 2L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 3L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 4L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 5L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 6L, (long) intIterator.next().getProperty(TestOne.anInt));
}
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class SearchAndSortingTest method test03SeachByNamePropertyLooseLowercase.
@Test
public void test03SeachByNamePropertyLooseLowercase() {
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");
}
}
Aggregations