use of org.structr.core.entity.TestThree in project structr by structr.
the class BasicTest method testRelationshipEndNodeTypeRestriction.
@Test
public void testRelationshipEndNodeTypeRestriction() {
// types are filtered according to the types of their end nodes
try (final Tx tx = app.tx()) {
// create two OWNS relationships with different end node types
final TestOne testOne = app.create(TestOne.class, "testone");
final TestThree testThree = app.create(TestThree.class, "testthree");
final Principal testUser = app.create(Principal.class, "testuser");
testOne.setProperty(TestOne.testThree, testThree);
testThree.setProperty(TestThree.owner, testUser);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
final List<OneThreeOneToOne> rels = app.relationshipQuery(OneThreeOneToOne.class).getAsList();
assertEquals("Relationship query returns wrong number of results", 1, rels.size());
for (final OneThreeOneToOne rel : rels) {
assertEquals("Relationship query returns wrong type", OneThreeOneToOne.class, rel.getClass());
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
use of org.structr.core.entity.TestThree 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.TestThree 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.TestThree 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.TestThree in project structr by structr.
the class ScriptingTest method testDateCopy.
@Test
public void testDateCopy() {
final Date now = new Date();
final Date futureDate = new Date(now.getTime() + 600000);
final SimpleDateFormat isoDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
try (final Tx tx = app.tx()) {
final ActionContext ctx = new ActionContext(securityContext, null);
// Copy dates with/without format in StructrScript
TestOne testOne = createTestNode(TestOne.class);
TestThree testThree = createTestNode(TestThree.class);
testOne.setProperty(TestOne.aDate, now);
Scripting.replaceVariables(ctx, testThree, "${set(this, 'aDateWithFormat', get(find('TestOne', '" + testOne.getUuid() + "'), 'aDate'))}");
assertEquals("Copying a date (with default format) to a date (with custom format) failed [StructrScript]", isoDateFormat.format(testOne.getProperty(TestOne.aDate)), isoDateFormat.format(testThree.getProperty(TestThree.aDateWithFormat)));
testThree.setProperty(TestThree.aDateWithFormat, futureDate);
Scripting.replaceVariables(ctx, testOne, "${set(this, 'aDate', get(find('TestThree', '" + testThree.getUuid() + "'), 'aDateWithFormat'))}");
assertEquals("Copying a date (with custom format) to a date (with default format) failed [StructrScript]", isoDateFormat.format(testOne.getProperty(TestOne.aDate)), isoDateFormat.format(testThree.getProperty(TestThree.aDateWithFormat)));
// Perform the same tests in JavaScript
testOne.setProperty(TestOne.aDate, null);
testThree.setProperty(TestThree.aDateWithFormat, null);
testOne.setProperty(TestOne.aDate, now);
Scripting.replaceVariables(ctx, testThree, "${{ var testThree = Structr.this; var testOne = Structr.find('TestOne', '" + testOne.getUuid() + "'); testThree.aDateWithFormat = testOne.aDate; }}");
assertEquals("Copying a date (with default format) to a date (with custom format) failed [JavaScript]", isoDateFormat.format(testOne.getProperty(TestOne.aDate)), isoDateFormat.format(testThree.getProperty(TestThree.aDateWithFormat)));
testThree.setProperty(TestThree.aDateWithFormat, futureDate);
Scripting.replaceVariables(ctx, testOne, "${{ var testOne = Structr.this; var testThree = Structr.find('TestThree', '" + testThree.getUuid() + "'); testOne.aDate = testThree.aDateWithFormat; }}");
assertEquals("Copying a date (with custom format) to a date (with default format) failed [JavaScript]", isoDateFormat.format(testOne.getProperty(TestOne.aDate)), isoDateFormat.format(testThree.getProperty(TestThree.aDateWithFormat)));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail(fex.getMessage());
}
}
Aggregations