Search in sources :

Example 6 with TestOne

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

the class BasicTest method test02CreateTwoNodesWithSameUuidInSameTx.

@Test
public void test02CreateTwoNodesWithSameUuidInSameTx() {
    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);
            assertTrue(node != null);
            assertTrue(node instanceof TestOne);
            assertEquals(node.getUuid(), uuid);
            node = app.create(TestOne.class, props);
            tx.success();
            fail("Validation failed!");
        }
    } catch (FrameworkException ex) {
    }
}
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 7 with TestOne

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

the class BasicTest method testCreateNodeWithAdditionalProperties.

@Test
public void testCreateNodeWithAdditionalProperties() {
    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.visibleToPublicUsers, true), new NodeAttribute<>(GraphObject.visibleToAuthenticatedUsers, true), new NodeAttribute<>(AbstractNode.deleted, true), new NodeAttribute<>(AbstractNode.hidden, true));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // create object with user context
    try (final Tx tx = app.tx()) {
        assertEquals("Invalid create node result", "test", test.getProperty(AbstractNode.name));
        assertEquals("Invalid create node result", true, test.getProperty(GraphObject.visibleToPublicUsers));
        assertEquals("Invalid create node result", true, test.getProperty(GraphObject.visibleToAuthenticatedUsers));
        assertEquals("Invalid create node result", true, test.getProperty(AbstractNode.deleted));
        assertEquals("Invalid create node result", true, test.getProperty(AbstractNode.hidden));
        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 8 with TestOne

use of org.structr.core.entity.TestOne 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.");
    }
}
Also used : OneThreeOneToOne(org.structr.core.entity.OneThreeOneToOne) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestThree(org.structr.core.entity.TestThree) TestOne(org.structr.core.entity.TestOne) Principal(org.structr.core.entity.Principal) Test(org.junit.Test)

Example 9 with TestOne

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

the class BasicTest method test06DuplicateRelationshipsManyToMany.

@Test
public void test06DuplicateRelationshipsManyToMany() {
    try (final Tx tx = app.tx()) {
        final TestSix test1 = app.create(TestSix.class);
        final TestOne test2 = app.create(TestOne.class);
        // test duplicate prevention
        app.create(test1, test2, SixOneManyToMany.class);
        app.create(test1, test2, SixOneManyToMany.class);
        fail("Creating duplicate relationships should throw an exception.");
        tx.success();
    } catch (FrameworkException ex) {
    }
    // for manyToMany only.
    try (final Tx tx = app.tx()) {
        final TestSix test1 = app.create(TestSix.class);
        final TestOne test2 = app.create(TestOne.class);
        // test duplicate prevention
        final List<TestOne> list = new LinkedList<>();
        list.add(test2);
        list.add(test2);
        test1.setProperty(TestSix.manyToManyTestOnes, list);
        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) TestOne(org.structr.core.entity.TestOne) LinkedList(java.util.LinkedList) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 10 with TestOne

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

the class BasicTest method test01CompareAscending.

@Test
public void test01CompareAscending() {
    try {
        TestOne a = createTestNode(TestOne.class);
        TestOne b = createTestNode(TestOne.class);
        try (final Tx tx = app.tx()) {
            GraphObjectComparator comp = new GraphObjectComparator(TestOne.anInt, GraphObjectComparator.ASCENDING);
            try {
                comp.compare(null, null);
                fail("Should have raised an NullPointerException");
            } catch (NullPointerException e) {
            }
            try {
                comp.compare(a, null);
                fail("Should have raised an NullPointerException");
            } catch (NullPointerException e) {
            }
            try {
                comp.compare(null, b);
                fail("Should have raised an NullPointerException");
            } catch (NullPointerException e) {
            }
            try {
                comp.compare(null, b);
                fail("Should have raised an NullPointerException");
            } catch (NullPointerException e) {
            }
            // a: null
            // b: null
            // a == b => 0
            assertEquals(0, comp.compare(a, b));
            // a: 0
            // b: null
            // a < b => -1
            setPropertyTx(a, TestOne.anInt, 0);
            assertEquals(-1, comp.compare(a, b));
            // a: null
            // b: 0
            // a > b => 1
            setPropertyTx(a, TestOne.anInt, null);
            setPropertyTx(b, TestOne.anInt, 0);
            assertEquals(1, comp.compare(a, b));
            // a: 1
            // b: 2
            // a < b => -1
            setPropertyTx(a, TestOne.anInt, 1);
            setPropertyTx(b, TestOne.anInt, 2);
            assertEquals(-1, comp.compare(a, b));
            // a: 2
            // b: 1
            // a > b => 1
            setPropertyTx(a, TestOne.anInt, 2);
            setPropertyTx(b, TestOne.anInt, 1);
            assertEquals(1, comp.compare(a, b));
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) 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