Search in sources :

Example 46 with TestOne

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

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

the class SystemTest method testTransactionIsolation.

@Test
public void testTransactionIsolation() {
    try {
        final TestOne test = createTestNode(TestOne.class);
        final ExecutorService executor = Executors.newCachedThreadPool();
        final List<TestRunner> tests = new LinkedList<>();
        final List<Future> futures = new LinkedList<>();
        // create and run test runners
        for (int i = 0; i < 25; i++) {
            final TestRunner runner = new TestRunner(app, test);
            futures.add(executor.submit(runner));
            tests.add(runner);
        }
        // wait for termination
        for (final Future future : futures) {
            future.get();
            System.out.print(".");
        }
        System.out.println();
        // check for success
        for (final TestRunner runner : tests) {
            assertTrue("Could not validate transaction isolation", runner.success());
        }
        executor.shutdownNow();
    } catch (Throwable fex) {
        fail("Unexpected exception");
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) TestOne(org.structr.core.entity.TestOne) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 48 with TestOne

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

the class SystemTest method testConcurrentIdenticalRelationshipCreation.

@Test
public void testConcurrentIdenticalRelationshipCreation() {
    try {
        final ExecutorService service = Executors.newCachedThreadPool();
        final TestSix source = createTestNode(TestSix.class);
        final TestOne target = createTestNode(TestOne.class);
        final Future one = service.submit(new RelationshipCreator(source, target));
        final Future two = service.submit(new RelationshipCreator(source, target));
        // wait for completion
        one.get();
        two.get();
        try (final Tx tx = app.tx()) {
            // check for a single relationship since all three parts of
            // both relationships are equal => only one should be created
            final List<TestOne> list = source.getProperty(TestSix.oneToManyTestOnes);
            assertEquals("Invalid concurrent identical relationship creation result", 1, list.size());
            tx.success();
        }
        service.shutdownNow();
    } catch (ExecutionException | InterruptedException | FrameworkException fex) {
        logger.warn("", fex);
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) TestOne(org.structr.core.entity.TestOne) ExecutionException(java.util.concurrent.ExecutionException) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 49 with TestOne

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

the class SystemTest method testEnsureCardinalityPerformance.

@Test
public void testEnsureCardinalityPerformance() {
    final List<TestOne> list = new LinkedList<>();
    final int num = 1000;
    // test setup, create a supernode with 10000 relationships
    try (final Tx tx = app.tx()) {
        System.out.println("Creating supernode with " + num + " relationships.");
        list.add(createTestNode(TestOne.class, new NodeAttribute<>(TestOne.manyToManyTestSixs, createTestNodes(TestSix.class, num))));
        tx.success();
    } catch (Throwable fex) {
        fail("Unexpected exception");
    }
    // actual test: test performance of node association on supernode
    try (final Tx tx = app.tx()) {
        for (int i = 0; i < 10; i++) {
            final long t0 = System.currentTimeMillis();
            createTestNode(TestSix.class, new NodeAttribute<>(TestSix.manyToManyTestOnes, list));
            final long t1 = System.currentTimeMillis();
            System.out.println((t1 - t0) + "ms");
        }
        tx.success();
    } catch (Throwable fex) {
        fail("Unexpected exception");
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) TestOne(org.structr.core.entity.TestOne) LinkedList(java.util.LinkedList) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 50 with TestOne

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

the class AccessControlTest method test03PublicAccessToProtectedNode.

@Test
public void test03PublicAccessToProtectedNode() {
    // remove auto-generated resource access objects
    clearResourceAccess();
    try {
        List<Principal> users = createTestNodes(Principal.class, 1);
        Principal user = (Principal) users.get(0);
        PropertyMap props = new PropertyMap();
        props.put(AbstractNode.visibleToPublicUsers, true);
        // Create two nodes with user context, one of them is visible to public users
        Class type = TestOne.class;
        TestOne t1 = createTestNode(TestOne.class, props, user);
        props = new PropertyMap();
        props.put(AbstractNode.visibleToAuthenticatedUsers, true);
        TestOne t2 = createTestNode(TestOne.class, props, user);
        SecurityContext publicContext = SecurityContext.getInstance(null, AccessMode.Frontend);
        try (final Tx tx = app.tx()) {
            Result result = StructrApp.getInstance(publicContext).nodeQuery(type).getResult();
            assertEquals(1, result.size());
            assertEquals(t1.getUuid(), result.get(0).getUuid());
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) 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

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