use of org.structr.core.entity.TestFive in project structr by structr.
the class SystemTest method testCallbacks.
private void testCallbacks(final SecurityContext securityContext) throws FrameworkException {
TestFive entity = null;
Integer zero = 0;
Integer one = 1;
try (final Tx tx = app.tx()) {
entity = app.create(TestFive.class);
tx.success();
} catch (Throwable t) {
logger.warn("", t);
}
assertNotNull("Entity should have been created", entity);
// creation assertions
try (final Tx tx = app.tx()) {
assertEquals("modifiedInBeforeCreation should have a value of 1: ", one, entity.getProperty(TestFive.modifiedInBeforeCreation));
assertEquals("modifiedInAfterCreation should have a value of 1: ", one, entity.getProperty(TestFive.modifiedInAfterCreation));
// modification assertions
assertEquals("modifiedInBeforeModification should have a value of 0: ", zero, entity.getProperty(TestFive.modifiedInBeforeModification));
assertEquals("modifiedInAfterModification should have a value of 0: ", zero, entity.getProperty(TestFive.modifiedInAfterModification));
}
// 2nd part of the test: modify node
try (final Tx tx = app.tx()) {
final TestFive finalEntity = entity;
finalEntity.setProperty(TestFive.intProperty, 123);
tx.success();
} catch (Throwable t) {
logger.warn("", t);
}
try (final Tx tx = app.tx()) {
// creation assertions
assertEquals("modifiedInBeforeCreation should have a value of 1: ", one, entity.getProperty(TestFive.modifiedInBeforeCreation));
assertEquals("modifiedInAfterCreation should have a value of 1: ", one, entity.getProperty(TestFive.modifiedInAfterCreation));
// modification assertions
assertEquals("modifiedInBeforeModification should have a value of 1: ", one, entity.getProperty(TestFive.modifiedInBeforeModification));
assertEquals("modifiedInAfterModification should have a value of 1: ", one, entity.getProperty(TestFive.modifiedInAfterModification));
}
}
use of org.structr.core.entity.TestFive in project structr by structr.
the class PropertyTest method testModifyType.
// ----- type property tests -----
@Test
public void testModifyType() {
final DatabaseService db = StructrApp.getInstance().getDatabaseService();
final Set<Label> labelsBefore = new LinkedHashSet<>();
final Set<Label> labelsAfter = new LinkedHashSet<>();
String id = null;
labelsBefore.add(db.forName(Label.class, AccessControllable.class.getSimpleName()));
labelsBefore.add(db.forName(Label.class, TestFour.class.getSimpleName()));
labelsAfter.add(db.forName(Label.class, AccessControllable.class.getSimpleName()));
labelsAfter.add(db.forName(Label.class, TestFive.class.getSimpleName()));
try (final Tx tx = app.tx()) {
// create entity of type TestFour
final TestFour testEntity = createTestNode(TestFour.class);
// check if node exists
assertNotNull(testEntity);
// check labels before type change
assertTrue(Iterables.toSet(testEntity.getNode().getLabels()).containsAll(labelsBefore));
// save ID for later use
id = testEntity.getUuid();
// change type to TestFive
// system properties have to be unlocked now, admin rights are not enough anymore
testEntity.unlockSystemPropertiesOnce();
testEntity.setProperty(GraphObject.type, TestFive.class.getSimpleName());
// commit transaction
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
final TestFive testEntity = app.get(TestFive.class, id);
assertNotNull(testEntity);
// check labels after type change
assertTrue(Iterables.toSet(testEntity.getNode().getLabels()).containsAll(labelsAfter));
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception");
}
}
Aggregations