Search in sources :

Example 51 with Result

use of org.structr.core.Result in project structr by structr.

the class SearchAndSortingTest method test10SearchByEmptyDateField.

@Test
public void test10SearchByEmptyDateField() {
    try {
        PropertyMap props = new PropertyMap();
        AbstractNode node = createTestNode(TestOne.class, props);
        try (final Tx tx = app.tx()) {
            Result result = app.nodeQuery(TestOne.class).and(TestOne.aDate, null).includeDeletedAndHidden().getResult();
            assertTrue(result.size() == 1);
            assertTrue(result.get(0).equals(node));
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) TestOne(org.structr.core.entity.TestOne) Result(org.structr.core.Result) Test(org.junit.Test)

Example 52 with Result

use of org.structr.core.Result in project structr by structr.

the class SearchAndSortingTest method test13SearchByEmptyDoubleField.

@Test
public void test13SearchByEmptyDoubleField() {
    try {
        PropertyMap props = new PropertyMap();
        AbstractNode node = createTestNode(TestOne.class, props);
        try (final Tx tx = app.tx()) {
            Result result = app.nodeQuery(TestOne.class).and(TestOne.aDouble, null).includeDeletedAndHidden().getResult();
            assertTrue(result.size() == 1);
            assertTrue(result.get(0).equals(node));
            tx.success();
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) TestOne(org.structr.core.entity.TestOne) Result(org.structr.core.Result) Test(org.junit.Test)

Example 53 with Result

use of org.structr.core.Result 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)

Example 54 with Result

use of org.structr.core.Result in project structr by structr.

the class SearchAndSortingTest method test04SeachByNamePropertyLooseUppercase.

@Test
public void test04SeachByNamePropertyLooseUppercase() {
    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", 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 55 with Result

use of org.structr.core.Result in project structr by structr.

the class AccessControlTest method test01PublicAccessToNonPublicNode.

@Test
public void test01PublicAccessToNonPublicNode() {
    final Class principalType = StructrApp.getConfiguration().getNodeEntityClass("Principal");
    // remove auto-generated resource access objects
    clearResourceAccess();
    try {
        Principal user = (Principal) createTestNode(principalType);
        // Create node with user context
        Class type = TestOne.class;
        createTestNode(TestOne.class, user);
        SecurityContext publicContext = SecurityContext.getInstance(null, AccessMode.Frontend);
        try (final Tx tx = app.tx()) {
            Result result = StructrApp.getInstance(publicContext).nodeQuery(type).getResult();
            // Node should not be visible in public context (no user logged in)
            assertTrue(result.isEmpty());
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) Principal(org.structr.core.entity.Principal) Result(org.structr.core.Result) Test(org.junit.Test)

Aggregations

Result (org.structr.core.Result)66 FrameworkException (org.structr.common.error.FrameworkException)45 Tx (org.structr.core.graph.Tx)36 Test (org.junit.Test)34 TestOne (org.structr.core.entity.TestOne)31 PropertyKey (org.structr.core.property.PropertyKey)28 PropertyMap (org.structr.core.property.PropertyMap)21 NodeInterface (org.structr.core.graph.NodeInterface)18 GraphObject (org.structr.core.GraphObject)14 AbstractNode (org.structr.core.entity.AbstractNode)12 RestMethodResult (org.structr.rest.RestMethodResult)12 Random (java.util.Random)11 SecurityContext (org.structr.common.SecurityContext)11 GraphObjectMap (org.structr.core.GraphObjectMap)10 LinkedList (java.util.LinkedList)9 Query (org.structr.core.app.Query)9 App (org.structr.core.app.App)8 StructrApp (org.structr.core.app.StructrApp)8 List (java.util.List)7 Principal (org.structr.core.entity.Principal)7