public void testOneToMany() 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) {
fex.printStackTrace();
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) {
fex.printStackTrace();
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) {
fex.printStackTrace();
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) {