本文整理了Java中org.neo4j.driver.v1.types.Node.hasLabel()
方法的一些代码示例,展示了Node.hasLabel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.hasLabel()
方法的具体详情如下:
包路径:org.neo4j.driver.v1.types.Node
类名称:Node
方法名:hasLabel
[英]Test if this node has a given label
[中]测试此节点是否具有给定的标签
代码示例来源:origin: opencypher/cypher-for-gremlin
@Test
public void returnNodeAndRelationship() {
Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
try (Session session = driver.session()) {
StatementResult result = session.run("CREATE (n1:Person {name: 'Marko'})-[r:knows {since:1999}]->(n2:Person)" +
"RETURN n1,r,n2",
parameters("message", "Hello"));
Record record = result.single();
Node n1 = record.get("n1").asNode();
Relationship r = record.get("r").asRelationship();
Node n2 = record.get("n2").asNode();
assertThat(n1.hasLabel("Person")).isTrue();
assertThat(n1.get("name").asString()).isEqualTo("Marko");
assertThat(r.hasType("knows")).isTrue();
assertThat(r.startNodeId()).isEqualTo(n1.id());
assertThat(r.endNodeId()).isEqualTo(n2.id());
assertThat(r.get("since").asLong()).isEqualTo(1999L);
assertThat(n2.hasLabel("Person")).isTrue();
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldCreateAnEntityWithPropertiesWithAStateAndItsPropertiesWithAdditionalLabelButNoDate() throws Throwable {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// When
StatementResult result = session.run("CALL graph.versioner.init('Entity', {key:'value'}, {key:'value'}, 'Error')");
StatementResult entityResult = session.run("MATCH (e:Entity) RETURN properties(e) as props");
StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
Node state = stateResult.single().get("s").asNode();
StatementResult stateProps = session.run("MATCH (s:State) RETURN properties(s) as props");
StatementResult currentResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN id(e) as id");
StatementResult hasStatusResult = session.run("MATCH (e:Entity)-[:HAS_STATE]->(s:State) RETURN id(e) as id");
// Then
assertThat(result.single().get("node").asNode().id(), equalTo(0L));
assertThat(entityResult.single().get("props").asMap().isEmpty(), equalTo(false));
assertThat(state.id(), equalTo(1L));
assertThat(stateProps.single().get("props").asMap().isEmpty(), equalTo(false));
assertThat(currentResult.single().get("id").asLong(), equalTo(0L));
assertThat(hasStatusResult.single().get("id").asLong(), equalTo(0L));
assertThat(state.hasLabel("Error"), equalTo(true));
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldCreateAnEntityWithPropertiesWithAStateAndItsPropertiesWithAdditionalLabelAndDate() throws Throwable {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// When
StatementResult result = session.run("CALL graph.versioner.init('Entity', {key:'value'}, {key:'value'}, 'Error', localdatetime('1988-10-27T02:46:40'))");
StatementResult entityResult = session.run("MATCH (e:Entity) RETURN properties(e) as props");
StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
Node state = stateResult.single().get("s").asNode();
StatementResult stateProps = session.run("MATCH (s:State) RETURN properties(s) as props");
StatementResult currentResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN id(e) as id");
StatementResult hasStatusResult = session.run("MATCH (e:Entity)-[:HAS_STATE]->(s:State) RETURN id(e) as id");
StatementResult hasStatusDateResult = session.run("MATCH (e:Entity)-[rel:CURRENT]->(s:State) RETURN rel.date as date");
// Then
assertThat(result.single().get("node").asNode().id(), equalTo(0L));
assertThat(entityResult.single().get("props").asMap().isEmpty(), equalTo(false));
assertThat(state.id(), equalTo(1L));
assertThat(stateProps.single().get("props").asMap().isEmpty(), equalTo(false));
assertThat(currentResult.single().get("id").asLong(), equalTo(0L));
assertThat(hasStatusResult.single().get("id").asLong(), equalTo(0L));
assertThat(state.hasLabel("Error"), equalTo(true));
assertThat(hasStatusDateResult.single().get("date").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldRollbackNthWorkCorrectly() {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(:State:Error {key:'initialValue'})"
+ "-[:PREVIOUS {date: localdatetime('1988-10-26T00:00:00')}]->(:State {key:'value'})-[:PREVIOUS {date: localdatetime('1988-10-25T00:00:00')}]->(:State:Test {key:'testValue'})");
session.run("MATCH (e:Entity)-[:CURRENT]->(s:Error) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
session.run("MATCH (e:Entity), (s:State {key:'value'}) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-26T00:00:00'), endDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
session.run("MATCH (e:Entity), (s:Test) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-25T00:00:00'), endDate:localdatetime('1988-10-26T00:00:00')}]->(s)");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback.nth(e, 2) YIELD node RETURN node");
// Then
boolean failure = true;
while (result.hasNext()) {
failure = false;
assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
}
session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN s");
while(!failure && result.hasNext()) {
assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
}
if (failure) {
fail();
}
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldGetNthStateNodeOfGivenEntity() {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (:Entity {key:'immutableValue'})-[:CURRENT]->(:State:Error {key:'initialValue'})"
+ "-[:PREVIOUS]->(:State {key:'value'})-[:PREVIOUS]->(:State:Test {key:'testValue'})");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.nth.state(e, 2) YIELD node RETURN node");
// Then
boolean failure = true;
while (result.hasNext()) {
failure = false;
assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
}
if (failure) {
fail();
}
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldRollbackNthToZeroWorkCorrectly() {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(:State:Error {key:'initialValue'})"
+ "-[:PREVIOUS]->(:State {key:'value'})-[:PREVIOUS {date: localdatetime('1988-10-26T00:00:00')}]->(:State:Test {key:'testValue'})");
session.run("MATCH (e:Entity)-[:CURRENT]->(s:Error) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
session.run("MATCH (e:Entity), (s:State {key:'value'}) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-26T00:00:00'), endDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
session.run("MATCH (e:Entity), (s:Test) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-25T00:00:00'), endDate:localdatetime('1988-10-26T00:00:00')}]->(s)");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback.nth(e, 0) YIELD node RETURN node");
// Then
Assertions.assertThat(result).isEmpty();
result = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN s");
Assertions.assertThat(result)
.hasSize(1)
.allMatch(node -> node.get("s").asNode().hasLabel("Error"));
}
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldGetOneErrorStateNodeByGivenErrorLabel() {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Error {key:'initialValue'})");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.by.label(e, 'Error') YIELD node RETURN node");
// Then
boolean failure = true;
while (result.hasNext()) {
failure = false;
assertThat(result.next().get("node").asNode().hasLabel("Error"), equalTo(true));
}
if (failure) {
fail();
}
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldGetNthZeroStateNodeOfGivenEntity() {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (:Entity {key:'immutableValue'})-[:CURRENT]->(:State:Error {key:'initialValue'})"
+ "-[:PREVIOUS]->(:State {key:'value'})-[:PREVIOUS]->(:State:Test {key:'testValue'})");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.nth.state(e, 0) YIELD node RETURN node");
// Then
boolean failure = true;
while (result.hasNext()) {
failure = false;
assertThat(result.next().get("node").asNode().hasLabel("Error"), equalTo(true));
}
if (failure) {
fail();
}
}
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldCreateANewStateWithAdditionalLabelButWithoutDate() throws Throwable {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.update(e, {key:'newValue'}, 'Error') YIELD node RETURN node");
StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
// Then
assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldCreateAndPatchANewStateWithAdditionalLabelButWithoutDate() throws Throwable {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.patch(e, {key:'newValue', newKey:'newestValue'}, 'Error') YIELD node RETURN node");
Node currentState = result.single().get("node").asNode();
StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
// Then
assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
assertThat(currentState.get("key").asString(), equalTo("newValue"));
assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldGetAllErrorStateNodeByGivenErrorLabel() {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Error {key:'initialValue'})");
session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Error {key:'initialValue'})");
session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Error {key:'initialValue'})");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.by.label(e, 'Error') YIELD node RETURN node");
// Then
boolean failure = true;
while (result.hasNext()) {
failure = false;
assertThat(result.next().get("node").asNode().hasLabel("Error"), equalTo(true));
}
if (failure) {
fail();
}
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldGetSpecificStateNodeByGivenEntityAndDate() {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Error {key:'initialValue'})");
session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-28T00:00:00')}]->(s:State:Test {key:'initialValue'})");
session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-29T00:00:00')}]->(s:State {key:'initialValue'})");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.by.date(e, localdatetime('1988-10-28T00:00:00')) YIELD node RETURN node");
// Then
boolean failure = true;
while (result.hasNext()) {
failure = false;
assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
}
if (failure) {
fail();
}
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldCreateAndPatchANewStateWithAdditionalLabelAndDate() throws Throwable {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.patch(e, {key:'newValue', newKey:'newestValue'}, 'Error', localdatetime('1988-10-27T02:46:40')) YIELD node RETURN node");
Node currentState = result.single().get("node").asNode();
StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
StatementResult dateResult = session.run("MATCH (e:Entity)-[r:CURRENT]->(s) RETURN r.date as relDate");
StatementResult hasStatusDateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State)-[:PREVIOUS]->(s2:State)<-[rel:HAS_STATE]-(e) RETURN rel.endDate as endDate");
// Then
assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
assertThat(dateResult.single().get("relDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
assertThat(hasStatusDateResult.single().get("endDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
assertThat(currentState.get("key").asString(), equalTo("newValue"));
assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldCreateANewStateWithAdditionalLabelAndDate() throws Throwable {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.update(e, {key:'newValue'}, 'Error', localdatetime('1988-10-27T02:46:40')) YIELD node RETURN node");
StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
StatementResult dateResult = session.run("MATCH (e:Entity)-[r:CURRENT]->(s) RETURN r.date as relDate");
StatementResult hasStatusDateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State)-[:PREVIOUS]->(s2:State)<-[rel:HAS_STATE]-(e) RETURN rel.endDate as endDate");
// Then
assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
assertThat(dateResult.single().get("relDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
assertThat(hasStatusDateResult.single().get("endDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldRollbackToTheGivenStateNode() {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
session.run("MATCH (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'}) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-26T00:00:00'), endDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Test {key:'initialValue'})");
session.run("MATCH (sc:State)<-[:CURRENT]-(e:Entity)-[:HAS_STATE]->(s:Test) CREATE (sc)-[:PREVIOUS {date:localdatetime('1988-10-26T00:00:00')}]->(s)");
// When
StatementResult result = session.run("MATCH (e:Entity)--(s:Test) WITH e, s CALL graph.versioner.rollback.to(e, s) YIELD node RETURN node");
// Then
boolean failure = true;
while (result.hasNext()) {
failure = false;
assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
}
if (failure) {
fail();
}
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldGetOldNodeAfterARollbackOnATwoStateEntityNode() {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
session.run("MATCH (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'}) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-26T00:00:00'), endDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Test {key:'initialValue'})");
session.run("MATCH (sc:State)<-[:CURRENT]-(e:Entity)-[:HAS_STATE]->(s:Test) CREATE (sc)-[:PREVIOUS {date:localdatetime('1988-10-26T00:00:00')}]->(s)");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback(e) YIELD node RETURN node");
// Then
boolean failure = true;
while (result.hasNext()) {
failure = false;
assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
}
if (failure) {
fail();
}
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldCreateAndPatchANewStateWithAdditionalLabelAndDateButWithANewProp() throws Throwable {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
// When
StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.patch(e, {newKey:'newestValue'}, 'Error', localdatetime('1988-10-27T02:46:40')) YIELD node RETURN node");
Node currentState = result.single().get("node").asNode();
StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
StatementResult dateResult = session.run("MATCH (e:Entity)-[r:CURRENT]->(s) RETURN r.date as relDate");
StatementResult hasStatusDateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State)-[:PREVIOUS]->(s2:State)<-[rel:HAS_STATE]-(e) RETURN rel.endDate as endDate");
// Then
assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
assertThat(dateResult.single().get("relDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
assertThat(hasStatusDateResult.single().get("endDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
assertThat(currentState.get("key").asString(), equalTo("initialValue"));
assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldUseExistingRollbackRelationshipToRollBackAgain() {
// This is in a try-block, to make sure we close the driver after the test
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
session.run("MATCH (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'}) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-26T00:00:00'), endDate:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
session.run("MATCH (sc:State)<-[:CURRENT]-(e:Entity)-[:HAS_STATE {startDate:localdatetime('1988-10-26T00:00:00'), endDate:localdatetime('1988-10-27T00:00:00')}]->(s:State) CREATE (sc)-[:PREVIOUS {date:localdatetime('1988-10-26T00:00:00')}]->(s)");
session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-25T00:00:00'), endDate:localdatetime('1988-10-26T00:00:00')}]->(s:State:Test {key:'initialValue'})");
session.run("MATCH (new:State)<-[:HAS_STATE {startDate:localdatetime('1988-10-26T00:00:00'), endDate:localdatetime('1988-10-27T00:00:00')}]-(e:Entity)-[:HAS_STATE {startDate:localdatetime('1988-10-25T00:00:00'), endDate:localdatetime('1988-10-26T00:00:00')}]->(old:State) CREATE (new)-[:PREVIOUS {date:localdatetime('1988-10-25T00:00:00')}]->(old)");
// When
session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback(e) YIELD node RETURN node");
StatementResult finalResult = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback(e) YIELD node RETURN node");
// Then
boolean failure = true;
while (finalResult.hasNext()) {
failure = false;
assertThat(finalResult.next().get("node").asNode().hasLabel("Test"), equalTo(true));
}
if (failure) {
fail();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!