Search in sources :

Example 11 with TestOne

use of org.structr.core.entity.TestOne in project structr by structr.

the class BasicTest method test01CreateNode.

@Test
public void test01CreateNode() {
    try {
        try {
            // Create node out of transaction => should give a NotInTransactionException
            app.create(TestOne.class);
            fail("Should have raised a NotInTransactionException");
        } catch (NotInTransactionException e) {
        }
        try {
            // Try to create node without parameters => should fail
            app.create(TestOne.class);
            fail("Should have raised a NotInTransactionException");
        } catch (NotInTransactionException e) {
        }
        AbstractNode node = null;
        try (final Tx tx = app.tx()) {
            node = app.create(TestOne.class);
            tx.success();
        }
        assertTrue(node != null);
        assertTrue(node instanceof TestOne);
    } catch (FrameworkException ex) {
        logger.error("", ex);
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NotInTransactionException(org.structr.api.NotInTransactionException) AbstractNode(org.structr.core.entity.AbstractNode) TestOne(org.structr.core.entity.TestOne) Test(org.junit.Test)

Example 12 with TestOne

use of org.structr.core.entity.TestOne in project structr by structr.

the class BasicTest method test06DuplicateRelationshipsOneToOne.

@Test
public void test06DuplicateRelationshipsOneToOne() {
    try (final Tx tx = app.tx()) {
        final TestOne test1 = app.create(TestOne.class);
        final TestTwo test2 = app.create(TestTwo.class);
        // test duplicate prevention
        app.create(test1, test2, OneTwoOneToOne.class);
        app.create(test1, test2, OneTwoOneToOne.class);
        tx.success();
    } catch (FrameworkException ex) {
        fail("Creating duplicate relationships via app.create() should NOT throw an exception.");
    }
    try (final Tx tx = app.tx()) {
        final TestOne test1 = app.create(TestOne.class);
        final TestTwo test2 = app.create(TestTwo.class);
        test1.setProperty(TestOne.testTwo, test2);
        test1.setProperty(TestOne.testTwo, test2);
        tx.success();
    } catch (FrameworkException ex) {
        fail("Creating duplicate relationships via setProperty() should NOT throw an exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestTwo(org.structr.core.entity.TestTwo) TestOne(org.structr.core.entity.TestOne) Test(org.junit.Test)

Example 13 with TestOne

use of org.structr.core.entity.TestOne in project structr by structr.

the class BasicTest method testNodeCreationWithForcedInvalidUuid.

@Test
public void testNodeCreationWithForcedInvalidUuid() {
    TestOne test = null;
    // create object with user context
    try (final Tx tx = app.tx()) {
        test = app.create(TestOne.class, new NodeAttribute<>(AbstractNode.name, "test"), new NodeAttribute<>(GraphObject.id, null));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final String uuid1 = test.getProperty(GraphObject.id);
        final String uuid2 = test.getUuid();
        assertEquals("UUID mismatch in getProperty() and getUuid()", uuid1, uuid2);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) Test(org.junit.Test)

Example 14 with TestOne

use of org.structr.core.entity.TestOne in project structr by structr.

the class BasicTest method test02CreateNodeWithExistingUuid.

@Test
public void test02CreateNodeWithExistingUuid() {
    try {
        final PropertyMap props = new PropertyMap();
        TestOne node = null;
        final String uuid = StringUtils.replace(UUID.randomUUID().toString(), "-", "");
        props.put(GraphObject.id, uuid);
        try (final Tx tx = app.tx()) {
            node = app.create(TestOne.class, props);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            assertTrue(node != null);
            assertTrue(node instanceof TestOne);
            assertEquals(node.getUuid(), uuid);
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) Test(org.junit.Test)

Example 15 with TestOne

use of org.structr.core.entity.TestOne in project structr by structr.

the class BasicTest method testNodeCacheInvalidationInRelationshipWrapper.

@Test
public void testNodeCacheInvalidationInRelationshipWrapper() {
    try (final Tx tx = app.tx()) {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestTwo testTwo1 = createTestNode(TestTwo.class, new NodeAttribute<>(TestTwo.testOne, testOne));
        final OneTwoOneToOne rel = testOne.getOutgoingRelationship(OneTwoOneToOne.class);
        final TestTwo testTwo2 = rel.getTargetNode();
        testTwo1.setProperty(AbstractNode.name, "test");
        assertEquals("Cache invalidation failure!", "test", testTwo2.getProperty(AbstractNode.name));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // fill cache with other nodes
    try {
        createTestNodes(TestSix.class, 1000);
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final TestOne testOne = app.nodeQuery(TestOne.class).getFirst();
        final TestTwo testTwo1 = app.nodeQuery(TestTwo.class).getFirst();
        final OneTwoOneToOne rel = testOne.getOutgoingRelationship(OneTwoOneToOne.class);
        final TestTwo testTwo2 = rel.getTargetNode();
        testTwo1.setProperty(AbstractNode.name, "test2");
        assertEquals("Cache invalidation failure!", "test2", testTwo2.getProperty(AbstractNode.name));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestTwo(org.structr.core.entity.TestTwo) TestOne(org.structr.core.entity.TestOne) OneTwoOneToOne(org.structr.core.entity.OneTwoOneToOne) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)74 TestOne (org.structr.core.entity.TestOne)74 Tx (org.structr.core.graph.Tx)72 FrameworkException (org.structr.common.error.FrameworkException)70 StructrTest (org.structr.common.StructrTest)20 Result (org.structr.core.Result)15 Principal (org.structr.core.entity.Principal)15 TestSix (org.structr.core.entity.TestSix)15 NodeInterface (org.structr.core.graph.NodeInterface)15 Random (java.util.Random)12 ActionContext (org.structr.schema.action.ActionContext)12 LinkedList (java.util.LinkedList)10 TestFour (org.structr.core.entity.TestFour)9 PropertyMap (org.structr.core.property.PropertyMap)9 PropertyKey (org.structr.core.property.PropertyKey)8 Date (java.util.Date)7 App (org.structr.core.app.App)7 StructrApp (org.structr.core.app.StructrApp)7 NotFoundException (org.structr.api.NotFoundException)6 UnlicensedException (org.structr.common.error.UnlicensedException)6