Search in sources :

Example 1 with TestTwo

use of org.structr.rest.entity.TestTwo 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 2 with TestTwo

use of org.structr.rest.entity.TestTwo 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

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 TestOne (org.structr.rest.entity.TestOne)2 TestTwo (org.structr.rest.entity.TestTwo)2