Search in sources :

Example 61 with TestOne

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

the class CypherTest method test04DeleteAfterIndexLookup.

@Test
public void test04DeleteAfterIndexLookup() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestSix testSix = createTestNode(TestSix.class);
        SixOneOneToOne rel = null;
        assertNotNull(testOne);
        assertNotNull(testSix);
        try (final Tx tx = app.tx()) {
            rel = app.create(testSix, testOne, SixOneOneToOne.class);
            tx.success();
        }
        assertNotNull(rel);
        try (final Tx tx = app.tx()) {
            GraphObject searchRes = app.getNodeById(testSix.getUuid());
            assertNotNull(searchRes);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            testSix.getRelationships().iterator().next().getRelationship().delete();
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            rel.getUuid();
            fail("Accessing a deleted relationship should thow an exception.");
            tx.success();
        } catch (NotFoundException nfex) {
            assertNotNull(nfex.getMessage());
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NotFoundException(org.structr.api.NotFoundException) TestOne(org.structr.core.entity.TestOne) GraphObject(org.structr.core.GraphObject) SixOneOneToOne(org.structr.core.entity.SixOneOneToOne) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 62 with TestOne

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

the class PropertyTest method testSimpleLongPropertySearchOnRelationship.

@Test
public void testSimpleLongPropertySearchOnRelationship() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestFour testFour = createTestNode(TestFour.class);
        final Property<Long> key = OneFourOneToOne.longProperty;
        assertNotNull(testOne);
        assertNotNull(testFour);
        final OneFourOneToOne testEntity = createTestRelationship(testOne, testFour, OneFourOneToOne.class);
        assertNotNull(testEntity);
        try (final Tx tx = app.tx()) {
            testEntity.setProperty(key, 2857312362L);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            // check value from database
            assertEquals((Long) 2857312362L, (Long) testEntity.getProperty(key));
            Result<OneFourOneToOne> result = app.relationshipQuery(OneFourOneToOne.class).and(key, 2857312362L).getResult();
            assertEquals(1, result.size());
            assertEquals(testEntity, result.get(0));
        }
    } catch (FrameworkException fex) {
        fail("Unable to store array");
    }
}
Also used : OneFourOneToOne(org.structr.core.entity.OneFourOneToOne) TestFour(org.structr.core.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 63 with TestOne

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

the class PropertyTest method testSimpleIntPropertySearchOnRelationship.

@Test
public void testSimpleIntPropertySearchOnRelationship() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestFour testFour = createTestNode(TestFour.class);
        final Property<Integer> key = OneFourOneToOne.integerProperty;
        assertNotNull(testOne);
        assertNotNull(testFour);
        final OneFourOneToOne testEntity = createTestRelationship(testOne, testFour, OneFourOneToOne.class);
        assertNotNull(testEntity);
        try (final Tx tx = app.tx()) {
            testEntity.setProperty(key, 2345);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            // check value from database
            assertEquals((Integer) 2345, (Integer) testEntity.getProperty(key));
            Result<OneFourOneToOne> result = app.relationshipQuery(OneFourOneToOne.class).and(key, 2345).getResult();
            assertEquals(1, result.size());
            assertEquals(testEntity, result.get(0));
        }
    } catch (FrameworkException fex) {
        fail("Unable to store array");
    }
}
Also used : OneFourOneToOne(org.structr.core.entity.OneFourOneToOne) TestFour(org.structr.core.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 64 with TestOne

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

the class PropertyTest method testSimpleStringPropertySearchOnRelationship.

@Test
public void testSimpleStringPropertySearchOnRelationship() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestFour testFour = createTestNode(TestFour.class);
        final Property<String> key = OneFourOneToOne.stringProperty;
        assertNotNull(testOne);
        assertNotNull(testFour);
        final OneFourOneToOne testEntity = createTestRelationship(testOne, testFour, OneFourOneToOne.class);
        assertNotNull(testEntity);
        try (final Tx tx = app.tx()) {
            testEntity.setProperty(key, "test");
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            // check value from database
            assertEquals("test", testEntity.getProperty(key));
            Result<OneFourOneToOne> result = app.relationshipQuery(OneFourOneToOne.class).and(key, "test").getResult();
            assertEquals(1, result.size());
            assertEquals(testEntity, result.get(0));
        }
    } catch (FrameworkException fex) {
        fail("Error in test");
    }
}
Also used : OneFourOneToOne(org.structr.core.entity.OneFourOneToOne) TestFour(org.structr.core.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 65 with TestOne

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

the class ScriptingTest method testEnumPropertyGet.

@Test
public void testEnumPropertyGet() {
    // setup phase
    try (final Tx tx = app.tx()) {
        final ActionContext actionContext = new ActionContext(securityContext);
        final TestOne context = app.create(TestOne.class);
        Scripting.evaluate(actionContext, context, "${{ var e = Structr.get('this'); e.anEnum = 'One'; }}", "test");
        assertEquals("Invalid enum get result", "One", Scripting.evaluate(actionContext, context, "${{ var e = Structr.get('this'); return e.anEnum; }}", "test"));
        assertEquals("Invaliid Javascript enum comparison result", true, Scripting.evaluate(actionContext, context, "${{ var e = Structr.get('this'); return e.anEnum == 'One'; }}", "test"));
        tx.success();
    } catch (UnlicensedException | FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : UnlicensedException(org.structr.common.error.UnlicensedException) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) ActionContext(org.structr.schema.action.ActionContext) StructrTest(org.structr.common.StructrTest) 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