use of org.structr.rest.entity.TestThree 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");
}
use of org.structr.rest.entity.TestThree in project structr by structr.
the class AdvancedSearchTest method testSearchWithOwnerAndEnum.
@Test
public void testSearchWithOwnerAndEnum() {
final Class testUserType = createTestUserType();
try {
final List<Principal> users = createTestNodes(testUserType, 3);
final List<TestThree> testThrees = new LinkedList<>();
final Random random = new Random();
String uuid = null;
int count = 0;
try (final Tx tx = app.tx()) {
for (final Principal user : users) {
// create 20 entities for every user
for (int i = 0; i < 20; i++) {
testThrees.add(app.create(TestThree.class, new NodeAttribute(AbstractNode.name, "test" + count++), new NodeAttribute(AbstractNode.owner, user), new NodeAttribute(TestThree.enumProperty, TestEnum.values()[random.nextInt(TestEnum.values().length)])));
}
}
uuid = users.get(0).getUuid();
tx.success();
}
// test with core API
try (final Tx tx = app.tx()) {
for (final Principal user : users) {
for (final TestThree test : app.nodeQuery(TestThree.class).and(AbstractNode.owner, user).and(TestThree.enumProperty, TestEnum.Status1).getAsList()) {
assertEquals("Invalid enum query result", TestEnum.Status1, test.getProperty(TestThree.enumProperty));
}
}
tx.success();
}
// test via REST
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).when().get(concat("/test_threes?sort=createdDate&owner=" + uuid + "&enumProperty=" + TestEnum.Status1));
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
use of org.structr.rest.entity.TestThree 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");
}
use of org.structr.rest.entity.TestThree 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);
}
}
Aggregations