Search in sources :

Example 6 with TestOne

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

the class TypeResourceRelationshipTest method testCardinalityManyToOneThreeNodes.

@Test
public void testCardinalityManyToOneThreeNodes() {
    String sourceNodeId = null;
    String targetNodeId = null;
    String newTargetNodeId = null;
    try (final Tx tx = app.tx()) {
        final TestFive sourceNode = app.create(TestFive.class);
        final TestOne targetNode = app.create(TestOne.class);
        final TestOne newTargetNode = app.create(TestOne.class);
        // store IDs for later use
        sourceNodeId = sourceNode.getUuid();
        targetNodeId = targetNode.getUuid();
        newTargetNodeId = newTargetNode.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\" : \"" + newTargetNodeId + "\" } ").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)

Example 7 with TestOne

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

the class CsvTest method test03CsvImportDefaultSettingsAndPaging01.

/**
 * Test CSV import with default settings and paging
 */
@Test
public void test03CsvImportDefaultSettingsAndPaging01() {
    RestAssured.given().contentType("text/csv; charset=UTF-8").header(CsvServlet.DEFAULT_RANGE_HEADER_NAME, "2-3").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(2, result.size());
        assertEquals("a3e07672b1064c28a1093b7024c7087d", result.get(0).getUuid());
        assertEquals("cd512cb9b7a44d65928794ac2dc9b383", result.get(1).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 8 with TestOne

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

the class StructrCsvTest 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 9 with TestOne

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

the class TypeResourceRelationshipTest method testCardinalityOneToMany.

@Test
public void testCardinalityOneToMany() {
    String sourceNodeId = null;
    String targetNodeId = null;
    try (final Tx tx = app.tx()) {
        final TestTwo sourceNode = app.create(TestTwo.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 TwoOneOneToMany: (:TestTwo) -1-[:OWNS]-*-> (: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(" { \"startNodeId\" : \"" + sourceNodeId + "\", \"endNodeId\" : \"" + targetNodeId + "\" } ").expect().statusCode(201).when().post("/TwoOneOneToMany");
    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(" { \"startNodeId\" : \"" + sourceNodeId + "\", \"endNodeId\" : \"" + targetNodeId + "\" } ").expect().statusCode(201).when().post("/TwoOneOneToMany");
    // 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("/TwoOneOneToMany");
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestTwo(org.structr.rest.entity.TestTwo) TestOne(org.structr.rest.entity.TestOne) Test(org.junit.Test) StructrRestTest(org.structr.rest.common.StructrRestTest)

Example 10 with TestOne

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

the class TypeResourceRelationshipTest method testCreateRelationship.

@Test
public void testCreateRelationship() {
    String sourceNodeId = null;
    String targetNodeId = null;
    try (final Tx tx = app.tx()) {
        final TestTwo sourceNode = app.create(TestTwo.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.");
    }
    // Check nodes 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)).body("result", isEntity(TestTwo.class)).when().get(concat("/TestTwo/", sourceNodeId));
    /* Create relationship using the TypeResource.

		 * The relation class is TwoOneOneToMany: (:TestTwo) -1-[:OWNS]-*-> (:TestOne)
		 */
    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(" { \"startNodeId\" : \"" + sourceNodeId + "\", \"endNodeId\" : \"" + targetNodeId + "\" } ").expect().statusCode(201).when().post("/TwoOneOneToMany");
    // 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("/TwoOneOneToMany");
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestTwo(org.structr.rest.entity.TestTwo) 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