use of org.structr.core.entity.TestSix in project structr by structr.
the class CypherTest method test05RollbackDelete.
@Test
public void test05RollbackDelete() {
try {
final TestOne testOne = createTestNode(TestOne.class);
final TestSix testSix = createTestNode(TestSix.class);
String relId = null;
SixOneOneToOne rel = null;
assertNotNull(testOne);
assertNotNull(testSix);
try (final Tx tx = app.tx()) {
rel = app.create(testSix, testOne, SixOneOneToOne.class);
relId = rel.getUuid();
tx.success();
}
assertNotNull(rel);
try (final Tx tx = app.tx()) {
// do not commit transaction
testOne.getRelationships().iterator().next().getRelationship().delete();
}
try (final Tx tx = app.tx()) {
assertEquals("UUID of relationship should be readable after rollback", relId, rel.getUuid());
tx.success();
} catch (NotFoundException iex) {
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestSix in project structr by structr.
the class SearchAndSortingTest method test09SearchBySourceAndTargetId.
@Test
public void test09SearchBySourceAndTargetId() {
try {
final TestOne test1 = createTestNode(TestOne.class);
final List<TestSix> tests = createTestNodes(TestSix.class, 5);
try (final Tx tx = app.tx()) {
test1.setProperty(TestOne.manyToManyTestSixs, tests);
tx.success();
}
try (final Tx tx = app.tx()) {
final List<SixOneManyToMany> result1 = app.relationshipQuery(SixOneManyToMany.class).and(SixOneManyToMany.sourceId, tests.get(0).getUuid()).getAsList();
assertEquals("Invalid sourceId query result", 1, result1.size());
tx.success();
}
try (final Tx tx = app.tx()) {
final List<SixOneManyToMany> result1 = app.relationshipQuery(SixOneManyToMany.class).and(SixOneManyToMany.targetId, test1.getUuid()).getAsList();
assertEquals("Invalid targetId query result", 5, result1.size());
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestSix in project structr by structr.
the class PropertyTest method testOneToOneOnEntityProperty.
// ----- entity property tests -----
@Test
public void testOneToOneOnEntityProperty() throws Exception {
try {
final TestSix a = createTestNode(TestSix.class);
final TestSix c = createTestNode(TestSix.class);
final TestThree b = createTestNode(TestThree.class);
final TestThree d = createTestNode(TestThree.class);
try (final Tx tx = app.tx()) {
a.setProperty(AbstractNode.name, "a");
c.setProperty(AbstractNode.name, "c");
b.setProperty(AbstractNode.name, "b");
d.setProperty(AbstractNode.name, "d");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unable to create test nodes");
}
assertNotNull(a);
assertNotNull(c);
assertNotNull(b);
assertNotNull(d);
// create two connections
try (final Tx tx = app.tx()) {
a.setProperty(TestSix.oneToOneTestThree, b);
c.setProperty(TestSix.oneToOneTestThree, d);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unable to link test nodes");
}
try (final Tx tx = app.tx()) {
// verify connections
TestThree verifyB = a.getProperty(TestSix.oneToOneTestThree);
TestThree verifyD = c.getProperty(TestSix.oneToOneTestThree);
assertTrue(verifyB != null && verifyB.equals(b));
assertTrue(verifyD != null && verifyD.equals(d));
}
try (final Tx tx = app.tx()) {
a.setProperty(TestSix.oneToOneTestThree, d);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unable to link test nodes");
}
try (final Tx tx = app.tx()) {
// verify connection
TestThree verifyD2 = a.getProperty(TestSix.oneToOneTestThree);
assertTrue(verifyD2 != null && verifyD2.equals(d));
// testSix2 should not have a testThree associated
TestThree vrfy4 = c.getProperty(TestSix.oneToOneTestThree);
assertNull(vrfy4);
}
} catch (FrameworkException fex) {
}
}
use of org.structr.core.entity.TestSix in project structr by structr.
the class PropertyTest method testOneToManyOnCollectionProperty.
// ----- collection property tests -----
@Test
public void testOneToManyOnCollectionProperty() throws Exception {
TestOne testOne = null;
List<TestSix> testSixs = null;
List<TestSix> testSixs2 = null;
int index = 0;
List<Integer> index1 = new LinkedList();
List<Integer> index2 = new LinkedList();
try (final Tx tx = app.tx()) {
testOne = createTestNode(TestOne.class);
testSixs = createTestNodes(TestSix.class, 20);
for (final TestSix testSix : testSixs) {
int i = index++;
testSix.setProperty(TestSix.index, i);
System.out.println(i + " ");
index1.add(i);
}
testOne.setProperty(TestOne.manyToManyTestSixs, testSixs);
tx.success();
}
try (final Tx tx = app.tx()) {
testSixs2 = testOne.getProperty(TestOne.manyToManyTestSixs);
for (final TestSix testSix : testSixs2) {
int i = testSix.getProperty(TestSix.index);
System.out.println(i + " ");
index2.add(i);
}
assertEquals(index1, index2);
tx.success();
}
}
use of org.structr.core.entity.TestSix in project structr by structr.
the class PropertyTest method testManyToManyOnCollectionProperty.
@Test
public void testManyToManyOnCollectionProperty() throws Exception {
try {
Property<List<TestOne>> instance = TestSix.manyToManyTestOnes;
TestSix testSix1 = null;
TestSix testSix2 = null;
TestOne testOne1 = null;
TestOne testOne2 = null;
testSix1 = createTestNode(TestSix.class);
testSix2 = createTestNode(TestSix.class);
testOne1 = createTestNode(TestOne.class);
testOne2 = createTestNode(TestOne.class);
assertNotNull(testSix1);
assertNotNull(testSix2);
assertNotNull(testOne1);
assertNotNull(testOne2);
// set two TestOne entities on both TestSix entities
List<TestOne> twoTestOnesList = new LinkedList<>();
twoTestOnesList.add(testOne1);
twoTestOnesList.add(testOne2);
try (final Tx tx = app.tx()) {
instance.setProperty(securityContext, testSix1, twoTestOnesList);
instance.setProperty(securityContext, testSix2, twoTestOnesList);
tx.success();
}
try (final Tx tx = app.tx()) {
List<TestOne> testOnesFromTestSix1 = instance.getProperty(securityContext, testSix1, true);
List<TestOne> testOnesFromTestSix2 = instance.getProperty(securityContext, testSix2, true);
assertNotNull(testOnesFromTestSix1);
assertNotNull(testOnesFromTestSix2);
// both entities should have the two related nodes
assertEquals(2, testOnesFromTestSix1.size());
assertEquals(2, testOnesFromTestSix2.size());
}
// create new list with one TestOne entity
List<TestOne> oneTestOneList = new LinkedList<>();
oneTestOneList.add(testOne1);
try (final Tx tx = app.tx()) {
// set list with one TestOne node as related nodes
instance.setProperty(securityContext, testSix1, oneTestOneList);
tx.success();
}
try (final Tx tx = app.tx()) {
List<TestOne> oneTestOnesFromTestSix1 = instance.getProperty(securityContext, testSix1, true);
// entity should have exactly one related node
assertNotNull(oneTestOnesFromTestSix1);
assertEquals(1, oneTestOnesFromTestSix1.size());
assertEquals(oneTestOnesFromTestSix1.get(0).getUuid(), testOne1.getUuid());
}
} catch (FrameworkException fex) {
}
}
Aggregations