Search in sources :

Example 1 with TestFive

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));
    }
}
Also used : Tx(org.structr.core.graph.Tx) TestFive(org.structr.core.entity.TestFive)

Example 2 with TestFive

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");
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TestFour(org.structr.core.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Label(org.structr.api.graph.Label) DatabaseService(org.structr.api.DatabaseService) TestFive(org.structr.core.entity.TestFive) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Aggregations

TestFive (org.structr.core.entity.TestFive)2 Tx (org.structr.core.graph.Tx)2 LinkedHashSet (java.util.LinkedHashSet)1 Test (org.junit.Test)1 DatabaseService (org.structr.api.DatabaseService)1 Label (org.structr.api.graph.Label)1 StructrTest (org.structr.common.StructrTest)1 FrameworkException (org.structr.common.error.FrameworkException)1 TestFour (org.structr.core.entity.TestFour)1