Search in sources :

Example 1 with TestFour

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

the class TypeResourceRelationshipTest method testCardinalityOneToOneThreeNodes.

@Test
public void testCardinalityOneToOneThreeNodes() {
    String sourceNodeId = null;
    String targetNodeId = null;
    String newTargetNodeId = null;
    try (final Tx tx = app.tx()) {
        final TestFour sourceNode = app.create(TestFour.class);
        final TestThree targetNode = app.create(TestThree.class);
        final TestThree newTargetNode = app.create(TestThree.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 FourThreeOneToOne: (:TestFour) -1-[:OWNS]-1-> (:TestThree),
     * so 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("/FourThreeOneToOne");
    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("/FourThreeOneToOne");
    // 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("/FourThreeOneToOne");
}
Also used : TestFour(org.structr.rest.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestThree(org.structr.rest.entity.TestThree) Test(org.junit.Test) StructrRestTest(org.structr.rest.common.StructrRestTest)

Example 2 with TestFour

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

the class TypeResourceRelationshipTest method testCardinalityOneToOne.

@Test
public void testCardinalityOneToOne() {
    String sourceNodeId = null;
    String targetNodeId = null;
    try (final Tx tx = app.tx()) {
        final TestFour sourceNode = app.create(TestFour.class);
        final TestThree targetNode = app.create(TestThree.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 FourThreeOneToOne: (:TestFour) -1-[:OWNS]-1-> (:TestThree),
     * 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("/FourThreeOneToOne");
    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("/FourThreeOneToOne");
    // 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("/FourThreeOneToOne");
}
Also used : TestFour(org.structr.rest.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestThree(org.structr.rest.entity.TestThree) Test(org.junit.Test) StructrRestTest(org.structr.rest.common.StructrRestTest)

Aggregations

Test (org.junit.Test)2 FrameworkException (org.structr.common.error.FrameworkException)2 Tx (org.structr.core.graph.Tx)2 StructrRestTest (org.structr.rest.common.StructrRestTest)2 TestFour (org.structr.rest.entity.TestFour)2 TestThree (org.structr.rest.entity.TestThree)2