Search in sources :

Example 41 with TestOne

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

the class SearchAndSortingTest method test08PagingWithHiddenOrDeletedElements.

@Test
public void test08PagingWithHiddenOrDeletedElements() {
    try {
        // create 10 nodes
        createTestNodes(TestOne.class, 10);
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final List<TestOne> testOnes = app.nodeQuery(TestOne.class).getAsList();
        final TestOne test1 = testOnes.get(3);
        final TestOne test2 = testOnes.get(4);
        final TestOne test3 = testOnes.get(7);
        test1.setProperty(AbstractNode.hidden, true);
        test2.setProperty(AbstractNode.deleted, true);
        test3.setProperty(AbstractNode.hidden, true);
        test3.setProperty(AbstractNode.deleted, true);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final Result<TestOne> result = app.nodeQuery(TestOne.class).includeDeletedAndHidden(false).getResult();
        assertEquals("Result count should not include deleted or hidden nodes", 7, (int) result.getRawResultCount());
        assertEquals("Actual result size should be equal to result count", 7, (int) result.getResults().size());
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) Tx(org.structr.core.graph.Tx) TestOne(org.structr.core.entity.TestOne) Test(org.junit.Test)

Example 42 with TestOne

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

the class SearchAndSortingTest method test01SortByName.

@Test
public void test01SortByName() {
    try {
        Class type = TestOne.class;
        // no more than 89 to avoid sort order TestOne-10, TestOne-100 ...
        int number = 4;
        final List<NodeInterface> nodes = this.createTestNodes(type, number);
        final int offset = 10;
        Collections.shuffle(nodes, new Random(System.nanoTime()));
        try (final Tx tx = app.tx()) {
            int i = offset;
            String name;
            for (NodeInterface node : nodes) {
                // System.out.println("Node ID: " + node.getNodeId());
                name = "TestOne-" + i;
                i++;
                node.setProperty(AbstractNode.name, name);
            }
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            Result result = app.nodeQuery(type).getResult();
            assertEquals(number, result.size());
            PropertyKey sortKey = AbstractNode.name;
            boolean sortDesc = false;
            int pageSize = 10;
            int page = 1;
            result = app.nodeQuery(type).sort(sortKey).order(sortDesc).page(page).pageSize(pageSize).getResult();
            logger.info("Raw result size: {}, expected: {}", new Object[] { result.getRawResultCount(), number });
            assertEquals(number, (int) result.getRawResultCount());
            logger.info("Result size: {}, expected: {}", new Object[] { result.size(), Math.min(number, pageSize) });
            assertEquals(Math.min(number, pageSize), result.size());
            for (int j = 0; j < Math.min(result.size(), pageSize); j++) {
                String expectedName = "TestOne-" + (offset + j);
                String gotName = result.get(j).getProperty(AbstractNode.name);
                System.out.println(expectedName + ", got: " + gotName);
                assertEquals(expectedName, gotName);
            }
            tx.success();
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Random(java.util.Random) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) NodeInterface(org.structr.core.graph.NodeInterface) PropertyKey(org.structr.core.property.PropertyKey) Result(org.structr.core.Result) Test(org.junit.Test)

Example 43 with TestOne

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

the class SearchAndSortingTest method test01ParallelInstantiationPerformance.

@Test
public void test01ParallelInstantiationPerformance() {
    try {
        for (int i = 0; i < 10; i++) {
            System.out.println("Creating nodes..");
            createTestNodes(TestOne.class, 100);
        }
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        System.out.println("Loading nodes..");
        final List<TestOne> testOnes = app.nodeQuery(TestOne.class).getAsList();
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) Tx(org.structr.core.graph.Tx) TestOne(org.structr.core.entity.TestOne) Test(org.junit.Test)

Example 44 with TestOne

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

the class SearchAndSortingTest method test05SeachByDefaultValue.

@Test
public void test05SeachByDefaultValue() {
    try {
        Class type = TestOne.class;
        int number = 4;
        final List<NodeInterface> nodes = this.createTestNodes(type, number);
        final int offset = 10;
        Collections.shuffle(nodes, new Random(System.nanoTime()));
        try (final Tx tx = app.tx()) {
            int i = offset;
            String name;
            for (NodeInterface node : nodes) {
                // System.out.println("Node ID: " + node.getNodeId());
                name = "TestOne-" + i;
                i++;
                node.setProperty(AbstractNode.name, name);
            }
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            Result result = app.nodeQuery(type).and(TestOne.stringWithDefault, "default value", false).getResult();
            assertEquals(4, result.size());
            tx.success();
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Random(java.util.Random) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) NodeInterface(org.structr.core.graph.NodeInterface) Result(org.structr.core.Result) Test(org.junit.Test)

Example 45 with TestOne

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

the class SearchAndSortingTest method test02SeachByNameProperty.

@Test
public void test02SeachByNameProperty() {
    try {
        Class type = TestOne.class;
        int number = 4;
        final List<NodeInterface> nodes = this.createTestNodes(type, number);
        final int offset = 10;
        Collections.shuffle(nodes, new Random(System.nanoTime()));
        try (final Tx tx = app.tx()) {
            int i = offset;
            String name;
            for (NodeInterface node : nodes) {
                // System.out.println("Node ID: " + node.getNodeId());
                name = "TestOne-" + i;
                i++;
                node.setProperty(AbstractNode.name, name);
            }
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            Result result = app.nodeQuery(type).and(TestOne.name, "TestOne-13").getResult();
            assertEquals(1, result.size());
            tx.success();
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Random(java.util.Random) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) NodeInterface(org.structr.core.graph.NodeInterface) Result(org.structr.core.Result) 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