Search in sources :

Example 1 with TestOne

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

the class CsvTest method test03CsvImportDefaultSettingsAndPaging02.

/**
 * Test CSV import with default settings and paging
 */
@Test
public void test03CsvImportDefaultSettingsAndPaging02() {
    RestAssured.given().contentType("text/csv; charset=UTF-8").header(CsvServlet.DEFAULT_RANGE_HEADER_NAME, "1,2,4").body(testOneCSVWithDefaultCharacters5EntriesNoError).expect().statusCode(201).when().post("http://" + host + ":" + httpPort + csvUrl + testOneResource);
    try (final Tx tx = app.tx()) {
        final List<TestOne> result = app.nodeQuery(TestOne.class).getAsList();
        assertEquals(3, result.size());
        assertEquals("0979aebeb9ae42a7b3594db3da12875e", result.get(0).getUuid());
        assertEquals("a3e07672b1064c28a1093b7024c7087d", result.get(1).getUuid());
        assertEquals("673a27250c204995b4ba6c72edb1df66", result.get(2).getUuid());
        tx.success();
    } catch (FrameworkException ex) {
        fail();
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.rest.entity.TestOne) Test(org.junit.Test)

Example 2 with TestOne

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

the class PropertyViewRestTest 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 : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) TestOne(org.structr.rest.entity.TestOne) LinkedList(java.util.LinkedList)

Example 3 with TestOne

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

the class StructrGraphQLTest 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 4 with TestOne

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

the class RestVerbsTest method createNodes.

private List<TestOne> createNodes(final int count) {
    // create 100 test nodes and set names
    try (final Tx tx = app.tx()) {
        final List<TestOne> nodes = createTestNodes(TestOne.class, 100);
        int i = 0;
        for (final TestOne node : nodes) {
            node.setProperty(AbstractNode.name, "node" + StringUtils.leftPad(Integer.toString(i++), 3, "0"));
        }
        tx.success();
        return nodes;
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    return null;
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.rest.entity.TestOne)

Example 5 with TestOne

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

the class TypeResourceRelationshipTest method testCardinalityManyToOne.

@Test
public void testCardinalityManyToOne() {
    String sourceNodeId = null;
    String targetNodeId = null;
    try (final Tx tx = app.tx()) {
        final TestFive sourceNode = app.create(TestFive.class);
        final TestOne targetNode = app.create(TestOne.class);
        // store IDs for later use
        sourceNodeId = sourceNode.getUuid();
        targetNodeId = targetNode.getUuid();
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    /**
     * Create two relationship using the TypeResource.
     *
     * The relation class is FiveOneManyToOne: (:TestFive) -*-[:OWNS]-1-> (:TestOne),
     * so between the same nodes, the second relationship should replace the first one
     * to enforce the correct cardinality.
     */
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).body(" { \"sourceId\" : \"" + sourceNodeId + "\", \"targetId\" : \"" + targetNodeId + "\" } ").expect().statusCode(201).when().post("/FiveOneManyToOne");
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).body(" { \"sourceId\" : \"" + sourceNodeId + "\", \"targetId\" : \"" + targetNodeId + "\" } ").expect().statusCode(201).when().post("/FiveOneManyToOne");
    // Check results: Only one relationship must exist
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("result_count", equalTo(1)).when().get("/FiveOneManyToOne");
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.rest.entity.TestOne) TestFive(org.structr.rest.entity.TestFive) 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