Search in sources :

Example 31 with TestFour

use of org.structr.core.entity.TestFour 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 32 with TestFour

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

the class PropertyTest method testSimpleLongPropertySearchOnNode.

@Test
public void testSimpleLongPropertySearchOnNode() {
    try {
        final PropertyMap properties = new PropertyMap();
        final PropertyKey<Long> key = TestFour.longProperty;
        properties.put(key, 2857312362L);
        final TestFour testEntity = createTestNode(TestFour.class, properties);
        assertNotNull(testEntity);
        try (final Tx tx = app.tx()) {
            // check value from database
            assertEquals((Long) 2857312362L, (Long) testEntity.getProperty(key));
            Result<TestFour> result = app.nodeQuery(TestFour.class).and(key, 2857312362L).getResult();
            assertEquals(1, result.size());
            assertEquals(testEntity, result.get(0));
        }
    } catch (FrameworkException fex) {
        fail("Unable to store array");
    }
}
Also used : TestFour(org.structr.core.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 33 with TestFour

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

the class PropertyTest method testSimpleStringArraySearchOnNode.

@Test
public void testSimpleStringArraySearchOnNode() {
    try {
        final PropertyMap properties = new PropertyMap();
        final PropertyKey<String[]> key = TestFour.stringArrayProperty;
        // store a string array in the test entitiy
        final String[] arr1 = new String[] { "one" };
        final String[] arr5 = new String[] { "one", "two", "three", "four", "five" };
        properties.put(key, arr1);
        TestFour testEntity = null;
        try (final Tx tx = app.tx()) {
            testEntity = createTestNode(TestFour.class, properties);
            tx.success();
        }
        assertNotNull(testEntity);
        Result<TestFour> result = null;
        try (final Tx tx = app.tx()) {
            result = app.nodeQuery(TestFour.class).and(key, new String[] { "one" }).getResult();
            assertEquals(1, result.size());
            assertEquals(result.get(0), testEntity);
        }
        try (final Tx tx = app.tx()) {
            testEntity.setProperty(key, arr5);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            result = app.nodeQuery(TestFour.class).and(key, new String[] { "one" }).getResult();
            assertEquals(1, result.size());
            assertEquals(result.get(0), testEntity);
        }
        try (final Tx tx = app.tx()) {
            result = app.nodeQuery(TestFour.class).and(key, new String[] { "one", "two" }).getResult();
            assertEquals(1, result.size());
            assertEquals(result.get(0), testEntity);
        }
        try (final Tx tx = app.tx()) {
            result = app.nodeQuery(TestFour.class).and(key, new String[] { "one", "foo" }).getResult();
            assertEquals(0, result.size());
        }
        try (final Tx tx = app.tx()) {
            result = app.nodeQuery(TestFour.class).and(key, new String[] { "one", "foo" }, false).getResult();
            assertEquals(1, result.size());
            assertEquals(result.get(0), testEntity);
        }
    } catch (FrameworkException fex) {
        fail("Unable to store array");
    }
}
Also used : TestFour(org.structr.core.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 34 with TestFour

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

the class PropertyTest method testDoublePropertyRangeSearchOnNode.

@Test
public void testDoublePropertyRangeSearchOnNode() {
    try {
        final PropertyMap properties = new PropertyMap();
        final Property<Double> key = OneFourOneToOne.doubleProperty;
        properties.put(key, 123456.2);
        final TestFour testEntity = createTestNode(TestFour.class, properties);
        assertNotNull(testEntity);
        try (final Tx tx = app.tx()) {
            // check value from database
            assertEquals((Double) 123456.2, testEntity.getProperty(key));
            Result<TestFour> result = app.nodeQuery(TestFour.class).andRange(key, 123455.1, 123457.6).getResult();
            assertEquals(1, result.size());
            assertEquals(testEntity, result.get(0));
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            Result<TestFour> result = app.nodeQuery(TestFour.class).andRange(key, 123456.3, 123456.7).getResult();
            assertEquals(0, result.size());
            tx.success();
        }
    } catch (FrameworkException fex) {
        fail("Unable to store array");
    }
}
Also used : TestFour(org.structr.core.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 35 with TestFour

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

the class PropertyTest method testLongPropertyRangeSearchOnNode.

@Test
public void testLongPropertyRangeSearchOnNode() {
    try {
        final PropertyMap properties = new PropertyMap();
        final PropertyKey<Long> key = TestFour.longProperty;
        properties.put(key, 123456L);
        final TestFour testEntity = createTestNode(TestFour.class, properties);
        assertNotNull(testEntity);
        try (final Tx tx = app.tx()) {
            // check value from database
            assertEquals((Long) 123456L, testEntity.getProperty(key));
            Result<TestFour> result = app.nodeQuery(TestFour.class).andRange(key, 123455L, 123457L).getResult();
            assertEquals(1, result.size());
            assertEquals(testEntity, result.get(0));
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            Result<TestFour> result = app.nodeQuery(TestFour.class).andRange(key, 123457L, 123458L).getResult();
            assertEquals(0, result.size());
            tx.success();
        }
    } catch (FrameworkException fex) {
        fail("Unable to store array");
    }
}
Also used : TestFour(org.structr.core.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)37 StructrTest (org.structr.common.StructrTest)37 FrameworkException (org.structr.common.error.FrameworkException)37 TestFour (org.structr.core.entity.TestFour)37 Tx (org.structr.core.graph.Tx)37 TestOne (org.structr.core.entity.TestOne)8 OneFourOneToOne (org.structr.core.entity.OneFourOneToOne)6 Date (java.util.Date)5 UnlicensedException (org.structr.common.error.UnlicensedException)2 TestEnum (org.structr.core.entity.TestEnum)2 TestSix (org.structr.core.entity.TestSix)2 TestThree (org.structr.core.entity.TestThree)2 TestTwo (org.structr.core.entity.TestTwo)2 ActionContext (org.structr.schema.action.ActionContext)2 DecimalFormat (java.text.DecimalFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1