use of org.structr.core.entity.TestSix in project structr by structr.
the class PropertyTest method testOneToManyOnEntityProperty.
@Test
public void testOneToManyOnEntityProperty() throws Exception {
try {
final TestSix testSix1 = createTestNode(TestSix.class);
final TestSix testSix2 = createTestNode(TestSix.class);
final TestThree testThree1 = createTestNode(TestThree.class);
final TestThree testThree2 = createTestNode(TestThree.class);
try (final Tx tx = app.tx()) {
testSix1.setProperty(AbstractNode.name, "a");
testSix2.setProperty(AbstractNode.name, "c");
testThree1.setProperty(AbstractNode.name, "b");
testThree2.setProperty(AbstractNode.name, "d");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unable to create test nodes");
}
assertNotNull(testSix1);
assertNotNull(testThree1);
assertNotNull(testSix2);
assertNotNull(testThree2);
/**
* We test the following here:
* A -> B
* C -> D
*
* then connect A -> D, so C and B should not
* be related any more
*/
try (final Tx tx = app.tx()) {
testSix1.setProperty(TestSix.oneToManyTestThrees, toList(testThree1));
testSix2.setProperty(TestSix.oneToManyTestThrees, toList(testThree2));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unable to link test nodes");
}
try (final Tx tx = app.tx()) {
// verify connections
List<TestThree> verifyB = testSix1.getProperty(TestSix.oneToManyTestThrees);
List<TestThree> verifyD = testSix2.getProperty(TestSix.oneToManyTestThrees);
assertTrue(verifyB != null && verifyB.get(0).equals(testThree1));
assertTrue(verifyD != null && verifyD.get(0).equals(testThree2));
}
try (final Tx tx = app.tx()) {
testSix1.setProperty(TestSix.oneToManyTestThrees, toList(testThree2));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unable to link test nodes");
}
try (final Tx tx = app.tx()) {
// verify connection
List<TestThree> verifyD2 = testSix1.getProperty(TestSix.oneToManyTestThrees);
assertEquals(1, verifyD2.size());
assertEquals(testThree2, verifyD2.get(0));
// testSix2 should not have a testThree associated
List<TestThree> vrfy4 = testSix2.getProperty(TestSix.oneToManyTestThrees);
assertEquals(0, vrfy4.size());
}
} catch (FrameworkException fex) {
}
}
use of org.structr.core.entity.TestSix 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.TestSix 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.TestSix in project structr by structr.
the class BasicTest method test06DuplicateRelationshipsOneToMany.
@Test
public void test06DuplicateRelationshipsOneToMany() {
try (final Tx tx = app.tx()) {
final TestSix test1 = app.create(TestSix.class);
final TestThree test2 = app.create(TestThree.class);
// test duplicate prevention
app.create(test1, test2, SixThreeOneToMany.class);
app.create(test1, test2, SixThreeOneToMany.class);
tx.success();
} catch (FrameworkException ex) {
fail("Creating duplicate relationships via app.create() should NOT throw an exception.");
}
// the duplicates in the list
try (final Tx tx = app.tx()) {
final TestSix test1 = app.create(TestSix.class);
final TestThree test2 = app.create(TestThree.class);
// test duplicate prevention
final List<TestThree> list = new LinkedList<>();
list.add(test2);
list.add(test2);
test1.setProperty(TestSix.oneToManyTestThrees, list);
tx.success();
} catch (FrameworkException ex) {
fail("Creating duplicate relationships via setProperty() should NOT throw an exception.");
}
}
use of org.structr.core.entity.TestSix in project structr by structr.
the class CypherTest method test04DeleteAfterIndexLookup.
@Test
public void test04DeleteAfterIndexLookup() {
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 (final Tx tx = app.tx()) {
GraphObject searchRes = app.getNodeById(testSix.getUuid());
assertNotNull(searchRes);
tx.success();
}
try (final Tx tx = app.tx()) {
testSix.getRelationships().iterator().next().getRelationship().delete();
tx.success();
}
try (final Tx tx = app.tx()) {
rel.getUuid();
fail("Accessing a deleted relationship should thow an exception.");
tx.success();
} catch (NotFoundException nfex) {
assertNotNull(nfex.getMessage());
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
Aggregations