Search in sources :

Example 1 with TestFive

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

Example 2 with TestFive

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

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

the class AdvancedPagingTest method testPagingWithPageSizeAndFilterOnRemoteObject.

/**
 * This tests the scenario that the pagesize is taken into account **before** the filter has been taken into account
 * which results in less (or no) results being returned.
 */
@Test
public void testPagingWithPageSizeAndFilterOnRemoteObject() {
    /* Test Setup */
    final String connectedNodeName = "Test3-First-Connected";
    final String notConnectedNodeName = "Test3-Second";
    TestThree t3_connected = null;
    TestThree t3_not_connected = null;
    TestFive t5 = null;
    try (final Tx tx = app.tx(true, false, false)) {
        t3_connected = app.create(TestThree.class, connectedNodeName);
        t3_not_connected = app.create(TestThree.class, notConnectedNodeName);
        final PropertyMap t5Map = new PropertyMap(TestFive.oneToOneTestThree, t3_connected);
        t5 = app.create(TestFive.class, t5Map);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
    Assert.assertNotNull(t3_connected);
    Assert.assertNotNull(t3_not_connected);
    Assert.assertNotNull(t5);
    /* Test 1: Test that we created two TestThrees */
    RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(200).body("result", hasSize(2)).body("result_count", equalTo(2)).when().get("/test_threes");
    /* Test 2: Test that we created one TestFive */
    RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(200).body("result", hasSize(1)).body("result_count", equalTo(1)).when().get("/test_fives");
    /* Test 3: Test that we can correctly search for objects **without** a connection to another node */
    RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(200).body("result", hasSize(1)).body("result[0].name", equalTo(notConnectedNodeName)).body("result[0].id", equalTo(t3_not_connected.getUuid())).when().get("/test_threes?oneToOneTestFive=null");
    try {
        Settings.CypherDebugLogging.setValue(true);
        /* Test 4: Test that we can correctly search for objects **without** a connection to another node WHILE also reducing pagesize to 1	*/
        RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseTo(System.out)).expect().statusCode(200).body("result", hasSize(1)).body("result[0].name", equalTo(notConnectedNodeName)).body("result[0].id", equalTo(t3_not_connected.getUuid())).when().get("/test_threes?oneToOneTestFive=null&pageSize=1");
    } finally {
        Settings.CypherDebugLogging.setValue(false);
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestThree(org.structr.rest.entity.TestThree) TestFive(org.structr.rest.entity.TestFive) Test(org.junit.Test) StructrRestTest(org.structr.rest.common.StructrRestTest)

Aggregations

Test (org.junit.Test)3 FrameworkException (org.structr.common.error.FrameworkException)3 Tx (org.structr.core.graph.Tx)3 StructrRestTest (org.structr.rest.common.StructrRestTest)3 TestFive (org.structr.rest.entity.TestFive)3 TestOne (org.structr.rest.entity.TestOne)2 PropertyMap (org.structr.core.property.PropertyMap)1 TestThree (org.structr.rest.entity.TestThree)1