Search in sources :

Example 31 with TestOne

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

the class PropertyTest method testSimpleBooleanPropertySearchOnRelationship.

@Test
public void testSimpleBooleanPropertySearchOnRelationship() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestFour testFour = createTestNode(TestFour.class);
        final Property<Boolean> key = OneFourOneToOne.booleanProperty;
        assertNotNull(testOne);
        assertNotNull(testFour);
        final OneFourOneToOne testEntity = createTestRelationship(testOne, testFour, OneFourOneToOne.class);
        assertNotNull(testEntity);
        try (final Tx tx = app.tx()) {
            testEntity.setProperty(key, true);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            // check value from database
            assertEquals((Boolean) true, (Boolean) testEntity.getProperty(key));
            Result<OneFourOneToOne> result = app.relationshipQuery(OneFourOneToOne.class).and(key, true).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 32 with TestOne

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

the class PropertyTest method testSimpleDoublePropertySearchOnRelationship.

@Test
public void testSimpleDoublePropertySearchOnRelationship() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestFour testFour = createTestNode(TestFour.class);
        final Property<Double> key = OneFourOneToOne.doubleProperty;
        assertNotNull(testOne);
        assertNotNull(testFour);
        final OneFourOneToOne testEntity = createTestRelationship(testOne, testFour, OneFourOneToOne.class);
        assertNotNull(testEntity);
        try (final Tx tx = app.tx()) {
            testEntity.setProperty(key, 3.141592653589793238);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            // check value from database
            assertEquals(3.141592653589793238, testEntity.getProperty(key), 0.0);
            Result<OneFourOneToOne> result = app.relationshipQuery(OneFourOneToOne.class).and(key, 3.141592653589793238).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 33 with TestOne

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

the class PropertyTest method testOneToManyOnCollectionProperty.

// ----- collection property tests -----
@Test
public void testOneToManyOnCollectionProperty() throws Exception {
    TestOne testOne = null;
    List<TestSix> testSixs = null;
    List<TestSix> testSixs2 = null;
    int index = 0;
    List<Integer> index1 = new LinkedList();
    List<Integer> index2 = new LinkedList();
    try (final Tx tx = app.tx()) {
        testOne = createTestNode(TestOne.class);
        testSixs = createTestNodes(TestSix.class, 20);
        for (final TestSix testSix : testSixs) {
            int i = index++;
            testSix.setProperty(TestSix.index, i);
            System.out.println(i + " ");
            index1.add(i);
        }
        testOne.setProperty(TestOne.manyToManyTestSixs, testSixs);
        tx.success();
    }
    try (final Tx tx = app.tx()) {
        testSixs2 = testOne.getProperty(TestOne.manyToManyTestSixs);
        for (final TestSix testSix : testSixs2) {
            int i = testSix.getProperty(TestSix.index);
            System.out.println(i + " ");
            index2.add(i);
        }
        assertEquals(index1, index2);
        tx.success();
    }
}
Also used : Tx(org.structr.core.graph.Tx) TestOne(org.structr.core.entity.TestOne) LinkedList(java.util.LinkedList) TestSix(org.structr.core.entity.TestSix) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 34 with TestOne

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

the class PropertyTest method testManyToManyOnCollectionProperty.

@Test
public void testManyToManyOnCollectionProperty() throws Exception {
    try {
        Property<List<TestOne>> instance = TestSix.manyToManyTestOnes;
        TestSix testSix1 = null;
        TestSix testSix2 = null;
        TestOne testOne1 = null;
        TestOne testOne2 = null;
        testSix1 = createTestNode(TestSix.class);
        testSix2 = createTestNode(TestSix.class);
        testOne1 = createTestNode(TestOne.class);
        testOne2 = createTestNode(TestOne.class);
        assertNotNull(testSix1);
        assertNotNull(testSix2);
        assertNotNull(testOne1);
        assertNotNull(testOne2);
        // set two TestOne entities on both TestSix entities
        List<TestOne> twoTestOnesList = new LinkedList<>();
        twoTestOnesList.add(testOne1);
        twoTestOnesList.add(testOne2);
        try (final Tx tx = app.tx()) {
            instance.setProperty(securityContext, testSix1, twoTestOnesList);
            instance.setProperty(securityContext, testSix2, twoTestOnesList);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            List<TestOne> testOnesFromTestSix1 = instance.getProperty(securityContext, testSix1, true);
            List<TestOne> testOnesFromTestSix2 = instance.getProperty(securityContext, testSix2, true);
            assertNotNull(testOnesFromTestSix1);
            assertNotNull(testOnesFromTestSix2);
            // both entities should have the two related nodes
            assertEquals(2, testOnesFromTestSix1.size());
            assertEquals(2, testOnesFromTestSix2.size());
        }
        // create new list with one TestOne entity
        List<TestOne> oneTestOneList = new LinkedList<>();
        oneTestOneList.add(testOne1);
        try (final Tx tx = app.tx()) {
            // set list with one TestOne node as related nodes
            instance.setProperty(securityContext, testSix1, oneTestOneList);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            List<TestOne> oneTestOnesFromTestSix1 = instance.getProperty(securityContext, testSix1, true);
            // entity should have exactly one related node
            assertNotNull(oneTestOnesFromTestSix1);
            assertEquals(1, oneTestOnesFromTestSix1.size());
            assertEquals(oneTestOnesFromTestSix1.get(0).getUuid(), testOne1.getUuid());
        }
    } catch (FrameworkException fex) {
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) LinkedList(java.util.LinkedList) List(java.util.List) TestOne(org.structr.core.entity.TestOne) LinkedList(java.util.LinkedList) TestSix(org.structr.core.entity.TestSix) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 35 with TestOne

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

the class PropertyTest method testSimpleEnumPropertySearchOnRelationship.

@Test
public void testSimpleEnumPropertySearchOnRelationship() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestFour testFour = createTestNode(TestFour.class);
        final Property<TestEnum> key = OneFourOneToOne.enumProperty;
        assertNotNull(testOne);
        assertNotNull(testFour);
        final OneFourOneToOne testEntity = createTestRelationship(testOne, testFour, OneFourOneToOne.class);
        assertNotNull(testEntity);
        try (final Tx tx = app.tx()) {
            testEntity.setProperty(key, TestEnum.Status1);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            // check value from database
            assertEquals(TestEnum.Status1, testEntity.getProperty(key));
            Result<OneFourOneToOne> result = app.relationshipQuery(OneFourOneToOne.class).and(key, TestEnum.Status1).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) TestEnum(org.structr.core.entity.TestEnum) TestOne(org.structr.core.entity.TestOne) 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