use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method testNodeCreationWithForcedUuid.
@Test
public void testNodeCreationWithForcedUuid() {
final String uuid = NodeServiceCommand.getNextUuid();
TestOne test = null;
// create object with user context
try (final Tx tx = app.tx()) {
test = app.create(TestOne.class, new NodeAttribute<>(AbstractNode.name, "test"), new NodeAttribute<>(GraphObject.id, uuid));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
final String uuid1 = test.getProperty(GraphObject.id);
final String uuid2 = test.getUuid();
assertEquals("Object creation does not accept provided UUID", uuid, uuid1);
assertEquals("UUID mismatch in getProperty() and getUuid()", uuid1, uuid2);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method testNodeCacheInvalidationWithLongLivedReferences.
@Test
public void testNodeCacheInvalidationWithLongLivedReferences() {
TestOne longLivedReference = null;
try (final Tx tx = app.tx()) {
longLivedReference = createTestNode(TestOne.class, "test1");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// fill cache with other nodes
try {
createTestNodes(TestSix.class, 1000);
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
final TestOne freshReference = app.nodeQuery(TestOne.class).getFirst();
freshReference.setProperty(AbstractNode.name, "test2");
assertEquals("Cache invalidation failure!", "test2", longLivedReference.getProperty(AbstractNode.name));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method test01CompareDescending.
@Test
public void test01CompareDescending() {
try {
TestOne a = createTestNode(TestOne.class);
TestOne b = createTestNode(TestOne.class);
GraphObjectComparator comp = new GraphObjectComparator(TestOne.anInt, GraphObjectComparator.DESCENDING);
try {
comp.compare(null, null);
fail("Should have raised an NullPointerException");
} catch (NullPointerException e) {
}
try {
comp.compare(a, null);
fail("Should have raised an NullPointerException");
} catch (NullPointerException e) {
}
try {
comp.compare(null, b);
fail("Should have raised an NullPointerException");
} catch (NullPointerException e) {
}
try {
comp.compare(null, b);
fail("Should have raised an NullPointerException");
} catch (NullPointerException e) {
}
try (final Tx tx = app.tx()) {
// a: null
// b: null
// a == b => 0
assertEquals(0, comp.compare(a, b));
}
// a: 0
// b: null
// a > b => 1
setPropertyTx(a, TestOne.anInt, 0);
try (final Tx tx = app.tx()) {
assertEquals(1, comp.compare(a, b));
}
// a: null
// b: 0
// a < b => -1
setPropertyTx(a, TestOne.anInt, null);
setPropertyTx(b, TestOne.anInt, 0);
try (final Tx tx = app.tx()) {
assertEquals(-1, comp.compare(a, b));
}
// a: 1
// b: 2
// a > b => 1
setPropertyTx(a, TestOne.anInt, 1);
setPropertyTx(b, TestOne.anInt, 2);
try (final Tx tx = app.tx()) {
assertEquals(1, comp.compare(a, b));
}
// a: 2
// b: 1
// a < b => -1
setPropertyTx(a, TestOne.anInt, 2);
setPropertyTx(b, TestOne.anInt, 1);
try (final Tx tx = app.tx()) {
assertEquals(-1, comp.compare(a, b));
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method test01DeleteRelationship.
@Test
public void test01DeleteRelationship() {
try {
final TestOne testOne = createTestNode(TestOne.class);
final TestSix testSix = createTestNode(TestSix.class);
SixOneOneToOne rel = null;
assertNotNull(testOne);
assertNotNull(testSix);
try (final Tx tx = app.tx()) {
rel = app.create(testSix, testOne, SixOneOneToOne.class);
tx.success();
}
assertNotNull(rel);
try {
// try to delete relationship
rel.getRelationship().delete();
fail("Should have raised an org.neo4j.graphdb.NotInTransactionException");
} catch (NotInTransactionException e) {
}
// Relationship still there
assertNotNull(rel);
try (final Tx tx = app.tx()) {
app.delete(rel);
tx.success();
}
try (final Tx tx = app.tx()) {
String uuid = rel.getUuid();
fail("Deleted entity should have thrown an exception on access.");
} catch (NotFoundException iex) {
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method testRelationshipsOnNodeCreation.
@Test
public void testRelationshipsOnNodeCreation() {
Principal user = null;
TestOne test = null;
// create user
try (final Tx tx = app.tx()) {
user = app.create(Principal.class, "tester");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
final SecurityContext ctx = SecurityContext.getInstance(user, AccessMode.Backend);
final App app = StructrApp.getInstance(ctx);
// create object with user context
try (final Tx tx = app.tx()) {
test = app.create(TestOne.class);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// query for relationships
try (final Tx tx = app.tx()) {
final List<? extends RelationshipInterface> rels1 = app.relationshipQuery().and(AbstractRelationship.sourceId, user.getUuid()).getAsList();
final List<Class> classes1 = rels1.stream().map(r -> r.getClass()).collect(Collectors.toList());
assertEquals("Invalid number of relationships after object creation", 2, rels1.size());
assertTrue("Invalid relationship type after object creation", classes1.contains(Security.class));
assertTrue("Invalid relationship type after object creation", classes1.contains(PrincipalOwnsNode.class));
final List<? extends RelationshipInterface> rels2 = app.relationshipQuery().and(AbstractRelationship.targetId, test.getUuid()).getAsList();
final List<Class> classes2 = rels2.stream().map(r -> r.getClass()).collect(Collectors.toList());
assertEquals("Invalid number of relationships after object creation", 2, rels2.size());
assertTrue("Invalid relationship type after object creation", classes2.contains(Security.class));
assertTrue("Invalid relationship type after object creation", classes2.contains(PrincipalOwnsNode.class));
final List<? extends RelationshipInterface> rels3 = Iterables.toList(test.getIncomingRelationships());
final List<Class> classes3 = rels3.stream().map(r -> r.getClass()).collect(Collectors.toList());
assertEquals("Invalid number of relationships after object creation", 2, rels3.size());
assertTrue("Invalid relationship type after object creation", classes3.contains(Security.class));
assertTrue("Invalid relationship type after object creation", classes3.contains(PrincipalOwnsNode.class));
final Security sec = app.relationshipQuery(Security.class).getFirst();
assertNotNull("Relationship caching on node creation is broken", sec);
final PrincipalOwnsNode owns = app.relationshipQuery(PrincipalOwnsNode.class).getFirst();
assertNotNull("Relationship caching on node creation is broken", owns);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
Aggregations