Search in sources :

Example 11 with TestOne

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

the class AdvancedPagingTest method test01PagingWithDeletedNodes.

/* moved from AccessControlTest to improve performance */
@Test
public void test01PagingWithDeletedNodes() {
    final Class testUserType = createTestUserType();
    final PropertyKey<String> passwordKey = StructrApp.key(testUserType, "password");
    final PropertyKey<Boolean> isAdminKey = StructrApp.key(testUserType, "isAdmin");
    List<TestOne> testOnes = null;
    // Create two User and ten TestOne nodes
    try (final Tx tx = StructrApp.getInstance().tx()) {
        createEntityAsSuperUser("/resource_access", "{'signature': 'TestOne', 'flags': 4095}");
        List<Principal> users = createTestNodes(testUserType, 2);
        users.get(0).setProperty(Principal.name, "user1");
        users.get(0).setProperty(passwordKey, "user1");
        users.get(1).setProperty(Principal.name, "user2");
        users.get(1).setProperty(passwordKey, "user2");
        users.get(1).setProperty(isAdminKey, true);
        testOnes = createTestNodes(TestOne.class, 3);
        int i = 0;
        // First test user is owner
        for (TestOne t : testOnes) {
            i++;
            t.setProperty(TestOne.name, "t-one-" + i);
            t.setProperty(TestOne.owner, users.get(0));
            t.setProperty(TestOne.visibleToAuthenticatedUsers, true);
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        fail(ex.getMessage());
    }
    // Check as user1 with pageSize=1
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).header("X-User", "user1").header("X-Password", "user1").expect().statusCode(200).body("result", hasSize(1)).body("result_count", equalTo(3)).when().get("/test_ones?pageSize=1&page=1");
    // Check as user2 with pageSize=1
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).header("X-User", "user2").header("X-Password", "user2").expect().statusCode(200).body("result", hasSize(1)).body("result_count", equalTo(3)).when().get("/test_ones?pageSize=1&page=1");
    try (final Tx tx = StructrApp.getInstance().tx()) {
        // "soft delete" first node
        testOnes.get(0).setProperty(TestOne.name, "deleted");
        testOnes.get(0).setProperty(TestOne.deleted, true);
        // testOnes.get(0).setProperty(TestOne.hidden, true);
        tx.success();
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        fail(ex.getMessage());
    }
    // Check as user1 with pageSize=1
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).header("X-User", "user2").header("X-Password", "user2").expect().statusCode(200).body("result", hasSize(1)).body("result_count", equalTo(3)).when().get("/test_ones?sort=name&pageSize=1&page=1");
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.rest.entity.TestOne) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrRestTest(org.structr.rest.common.StructrRestTest)

Example 12 with TestOne

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

the class AdvancedPagingTest method test02PagingWithSoftDeletedNodes.

/**
 * Paging with soft-deleted nodes
 */
@Test
public void test02PagingWithSoftDeletedNodes() {
    final Class testUserType = createTestUserType();
    final PropertyKey<String> passwordKey = StructrApp.key(testUserType, "password");
    final PropertyKey<Boolean> isAdminKey = StructrApp.key(testUserType, "isAdmin");
    List<TestOne> testOnes = null;
    // Create two User and ten TestOne nodes
    try (final Tx tx = StructrApp.getInstance().tx()) {
        createEntityAsSuperUser("/resource_access", "{'signature': 'TestOne', 'flags': 4095}");
        List<Principal> users = createTestNodes(testUserType, 2);
        users.get(0).setProperty(Principal.name, "user1");
        users.get(0).setProperty(passwordKey, "user1");
        users.get(1).setProperty(Principal.name, "user2");
        users.get(1).setProperty(passwordKey, "user2");
        users.get(1).setProperty(isAdminKey, true);
        testOnes = createTestNodes(TestOne.class, 3);
        int i = 0;
        // First test user is owner
        for (TestOne t : testOnes) {
            i++;
            t.setProperty(TestOne.name, "t-one-" + i);
            t.setProperty(TestOne.owner, users.get(0));
            t.setProperty(TestOne.visibleToAuthenticatedUsers, true);
        }
        // "soft delete" first node
        testOnes.get(0).setProperty(TestOne.name, "deleted");
        testOnes.get(0).setProperty(TestOne.deleted, true);
        // testOnes.get(0).setProperty(TestOne.hidden, true);
        tx.success();
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        fail(ex.getMessage());
    }
    // Check as user1 with pageSize=1
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).header("X-User", "user2").header("X-Password", "user2").expect().statusCode(200).body("result", hasSize(1)).body("result_count", equalTo(3)).when().get("/test_ones?sort=name&pageSize=1&page=1");
    // Check as user1 with pageSize=1
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).header("X-User", "user2").header("X-Password", "user2").expect().statusCode(200).body("result", hasSize(1)).body("result_count", equalTo(2)).when().get("/test_ones?deleted=false&sort=name&pageSize=1&page=1");
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.rest.entity.TestOne) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrRestTest(org.structr.rest.common.StructrRestTest)

Example 13 with TestOne

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

the class StructrRestTest method createTestRelationships.

protected <T extends Relation> List<T> createTestRelationships(final Class<T> relType, final int number) throws FrameworkException {
    final App app = StructrApp.getInstance(securityContext);
    final List<TestOne> nodes = createTestNodes(TestOne.class, 2);
    final TestOne startNode = nodes.get(0);
    final TestOne endNode = nodes.get(1);
    final List<T> rels = new LinkedList<>();
    try (final Tx tx = app.tx()) {
        for (int i = 0; i < number; i++) {
            rels.add((T) app.create(startNode, endNode, relType));
        }
        tx.success();
    }
    return rels;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) TestOne(org.structr.rest.entity.TestOne) LinkedList(java.util.LinkedList)

Example 14 with TestOne

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

the class EntityResourceBasicTest method testInvokeMethodResult.

@Test
public void testInvokeMethodResult() {
    String id = null;
    try (final Tx tx = app.tx()) {
        final TestOne test = app.create(TestOne.class);
        // store ID for later use
        id = test.getUuid();
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // execute test method, expect sane result (not 500)
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).when().post(concat("/test_ones/", id, "/test01"));
    // execute test method, expect sane result (not 500)
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).when().post(concat("/test_ones/", id, "/test02"));
    // execute test method, expect sane result (not 500)
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).when().post(concat("/test_ones/", id, "/test03"));
    // execute test method, expect sane result (not 500)
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).when().post(concat("/test_ones/", id, "/test04"));
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.rest.entity.TestOne) Test(org.junit.Test) StructrRestTest(org.structr.rest.common.StructrRestTest)

Aggregations

Tx (org.structr.core.graph.Tx)14 TestOne (org.structr.rest.entity.TestOne)14 FrameworkException (org.structr.common.error.FrameworkException)10 Test (org.junit.Test)9 StructrRestTest (org.structr.rest.common.StructrRestTest)7 LinkedList (java.util.LinkedList)4 App (org.structr.core.app.App)4 StructrApp (org.structr.core.app.StructrApp)4 Principal (org.structr.core.entity.Principal)2 TestFive (org.structr.rest.entity.TestFive)2 TestTwo (org.structr.rest.entity.TestTwo)2