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");
}
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");
}
Aggregations