use of org.structr.core.entity.TestEight in project structr by structr.
the class SystemTest method testCallbackOrder.
@Test
public void testCallbackOrder() {
try {
// ##################################### test creation callbacks
TestEight test = null;
try (final Tx tx = app.tx()) {
test = app.create(TestEight.class, new NodeAttribute(TestEight.testProperty, 123));
tx.success();
}
// only the creation methods should have been called now!
assertTrue("onCreationTimestamp should be != 0", test.getOnCreationTimestamp() != 0L);
assertEquals("onModificationTimestamp should be == 0", 0L, test.getOnModificationTimestamp());
assertEquals("onDeletionTimestamp should be == 0", 0L, test.getOnDeletionTimestamp());
// only the creation methods should have been called now!
assertTrue("afterCreationTimestamp should be != 0", test.getAfterCreationTimestamp() != 0L);
assertEquals("afterModificationTimestamp should be == 0", 0L, test.getAfterModificationTimestamp());
// ##################################### test modification callbacks
// reset timestamps
test.resetTimestamps();
try (final Tx tx = app.tx()) {
test.setProperty(TestEight.testProperty, 234);
tx.success();
}
// only the modification methods should have been called now!
assertEquals("onCreationTimestamp should be == 0", 0L, test.getOnCreationTimestamp());
assertTrue("onModificationTimestamp should be != 0", test.getOnModificationTimestamp() != 0L);
assertEquals("onDeletionTimestamp should be == 0", 0L, test.getOnDeletionTimestamp());
// only the modification methods should have been called now!
assertEquals("afterCreationTimestamp should be == 0", 0L, test.getAfterCreationTimestamp());
assertTrue("afterModificationTimestamp should be != 0", test.getAfterModificationTimestamp() != 0L);
// ##################################### test non-modifying set operation
// reset timestamps
test.resetTimestamps();
try (final Tx tx = app.tx()) {
test.setProperty(TestEight.testProperty, 234);
tx.success();
}
// only the creation methods should have been called now!
assertEquals("onCreationTimestamp should be == 0", 0L, test.getOnCreationTimestamp());
assertEquals("onModificationTimestamp should be == 0", 0L, test.getOnModificationTimestamp());
assertEquals("onDeletionTimestamp should be == 0", 0L, test.getOnDeletionTimestamp());
// only the creation methods should have been called now!
assertEquals("afterCreationTimestamp should be == 0", 0L, test.getAfterCreationTimestamp());
assertEquals("afterModificationTimestamp should be == 0", 0L, test.getAfterModificationTimestamp());
// ##################################### test deletion
// reset timestamps
test.resetTimestamps();
try (final Tx tx = app.tx()) {
app.delete(test);
tx.success();
}
// only the creation methods should have been called now!
assertEquals("onCreationTimestamp should be == 0", 0L, test.getOnCreationTimestamp());
assertEquals("onModificationTimestamp should be == 0", 0L, test.getOnModificationTimestamp());
assertTrue("onDeletionTimestamp should be != 0", test.getOnDeletionTimestamp() != 0L);
// only the creation methods should have been called now!
assertEquals("afterCreationTimestamp should be == 0", 0L, test.getAfterCreationTimestamp());
assertEquals("afterModificationTimestamp should be == 0", 0L, test.getAfterModificationTimestamp());
} catch (FrameworkException ex) {
logger.error("Error", ex);
fail("Unexpected exception.");
}
}
Aggregations