org.neo4j.driver.v1.types.Node.hasLabel()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(27.6k)|赞(0)|评价(0)|浏览(242)

本文整理了Java中org.neo4j.driver.v1.types.Node.hasLabel()方法的一些代码示例,展示了Node.hasLabel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.hasLabel()方法的具体详情如下:
包路径:org.neo4j.driver.v1.types.Node
类名称:Node
方法名:hasLabel

Node.hasLabel介绍

[英]Test if this node has a given label
[中]测试此节点是否具有给定的标签

代码示例

代码示例来源:origin: opencypher/cypher-for-gremlin

  1. @Test
  2. public void returnNodeAndRelationship() {
  3. Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
  4. try (Session session = driver.session()) {
  5. StatementResult result = session.run("CREATE (n1:Person {name: 'Marko'})-[r:knows {since:1999}]->(n2:Person)" +
  6. "RETURN n1,r,n2",
  7. parameters("message", "Hello"));
  8. Record record = result.single();
  9. Node n1 = record.get("n1").asNode();
  10. Relationship r = record.get("r").asRelationship();
  11. Node n2 = record.get("n2").asNode();
  12. assertThat(n1.hasLabel("Person")).isTrue();
  13. assertThat(n1.get("name").asString()).isEqualTo("Marko");
  14. assertThat(r.hasType("knows")).isTrue();
  15. assertThat(r.startNodeId()).isEqualTo(n1.id());
  16. assertThat(r.endNodeId()).isEqualTo(n2.id());
  17. assertThat(r.get("since").asLong()).isEqualTo(1999L);
  18. assertThat(n2.hasLabel("Person")).isTrue();
  19. }
  20. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldCreateAnEntityWithPropertiesWithAStateAndItsPropertiesWithAdditionalLabelButNoDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // When
  7. StatementResult result = session.run("CALL graph.versioner.init('Entity', {key:'value'}, {key:'value'}, 'Error')");
  8. StatementResult entityResult = session.run("MATCH (e:Entity) RETURN properties(e) as props");
  9. StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
  10. Node state = stateResult.single().get("s").asNode();
  11. StatementResult stateProps = session.run("MATCH (s:State) RETURN properties(s) as props");
  12. StatementResult currentResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN id(e) as id");
  13. StatementResult hasStatusResult = session.run("MATCH (e:Entity)-[:HAS_STATE]->(s:State) RETURN id(e) as id");
  14. // Then
  15. assertThat(result.single().get("node").asNode().id(), equalTo(0L));
  16. assertThat(entityResult.single().get("props").asMap().isEmpty(), equalTo(false));
  17. assertThat(state.id(), equalTo(1L));
  18. assertThat(stateProps.single().get("props").asMap().isEmpty(), equalTo(false));
  19. assertThat(currentResult.single().get("id").asLong(), equalTo(0L));
  20. assertThat(hasStatusResult.single().get("id").asLong(), equalTo(0L));
  21. assertThat(state.hasLabel("Error"), equalTo(true));
  22. }
  23. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldCreateAnEntityWithPropertiesWithAStateAndItsPropertiesWithAdditionalLabelAndDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // When
  7. StatementResult result = session.run("CALL graph.versioner.init('Entity', {key:'value'}, {key:'value'}, 'Error', localdatetime('1988-10-27T02:46:40'))");
  8. StatementResult entityResult = session.run("MATCH (e:Entity) RETURN properties(e) as props");
  9. StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
  10. Node state = stateResult.single().get("s").asNode();
  11. StatementResult stateProps = session.run("MATCH (s:State) RETURN properties(s) as props");
  12. StatementResult currentResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN id(e) as id");
  13. StatementResult hasStatusResult = session.run("MATCH (e:Entity)-[:HAS_STATE]->(s:State) RETURN id(e) as id");
  14. StatementResult hasStatusDateResult = session.run("MATCH (e:Entity)-[rel:CURRENT]->(s:State) RETURN rel.date as date");
  15. // Then
  16. assertThat(result.single().get("node").asNode().id(), equalTo(0L));
  17. assertThat(entityResult.single().get("props").asMap().isEmpty(), equalTo(false));
  18. assertThat(state.id(), equalTo(1L));
  19. assertThat(stateProps.single().get("props").asMap().isEmpty(), equalTo(false));
  20. assertThat(currentResult.single().get("id").asLong(), equalTo(0L));
  21. assertThat(hasStatusResult.single().get("id").asLong(), equalTo(0L));
  22. assertThat(state.hasLabel("Error"), equalTo(true));
  23. assertThat(hasStatusDateResult.single().get("date").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
  24. }
  25. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldRollbackNthWorkCorrectly() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(:State:Error {key:'initialValue'})"
  8. + "-[:PREVIOUS {date: localdatetime('1988-10-26T00:00:00')}]->(:State {key:'value'})-[:PREVIOUS {date: localdatetime('1988-10-25T00:00:00')}]->(:State:Test {key:'testValue'})");
  9. session.run("MATCH (e:Entity)-[:CURRENT]->(s:Error) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  10. 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)");
  11. 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)");
  12. // When
  13. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback.nth(e, 2) YIELD node RETURN node");
  14. // Then
  15. boolean failure = true;
  16. while (result.hasNext()) {
  17. failure = false;
  18. assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
  19. }
  20. session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN s");
  21. while(!failure && result.hasNext()) {
  22. assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
  23. }
  24. if (failure) {
  25. fail();
  26. }
  27. }
  28. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldGetNthStateNodeOfGivenEntity() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (:Entity {key:'immutableValue'})-[:CURRENT]->(:State:Error {key:'initialValue'})"
  8. + "-[:PREVIOUS]->(:State {key:'value'})-[:PREVIOUS]->(:State:Test {key:'testValue'})");
  9. // When
  10. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.nth.state(e, 2) YIELD node RETURN node");
  11. // Then
  12. boolean failure = true;
  13. while (result.hasNext()) {
  14. failure = false;
  15. assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
  16. }
  17. if (failure) {
  18. fail();
  19. }
  20. }
  21. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldRollbackNthToZeroWorkCorrectly() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(:State:Error {key:'initialValue'})"
  8. + "-[:PREVIOUS]->(:State {key:'value'})-[:PREVIOUS {date: localdatetime('1988-10-26T00:00:00')}]->(:State:Test {key:'testValue'})");
  9. session.run("MATCH (e:Entity)-[:CURRENT]->(s:Error) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  10. 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)");
  11. 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)");
  12. // When
  13. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback.nth(e, 0) YIELD node RETURN node");
  14. // Then
  15. Assertions.assertThat(result).isEmpty();
  16. result = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN s");
  17. Assertions.assertThat(result)
  18. .hasSize(1)
  19. .allMatch(node -> node.get("s").asNode().hasLabel("Error"));
  20. }
  21. }
  22. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldGetOneErrorStateNodeByGivenErrorLabel() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Error {key:'initialValue'})");
  8. // When
  9. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.by.label(e, 'Error') YIELD node RETURN node");
  10. // Then
  11. boolean failure = true;
  12. while (result.hasNext()) {
  13. failure = false;
  14. assertThat(result.next().get("node").asNode().hasLabel("Error"), equalTo(true));
  15. }
  16. if (failure) {
  17. fail();
  18. }
  19. }
  20. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldGetNthZeroStateNodeOfGivenEntity() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (:Entity {key:'immutableValue'})-[:CURRENT]->(:State:Error {key:'initialValue'})"
  8. + "-[:PREVIOUS]->(:State {key:'value'})-[:PREVIOUS]->(:State:Test {key:'testValue'})");
  9. // When
  10. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.nth.state(e, 0) YIELD node RETURN node");
  11. // Then
  12. boolean failure = true;
  13. while (result.hasNext()) {
  14. failure = false;
  15. assertThat(result.next().get("node").asNode().hasLabel("Error"), equalTo(true));
  16. }
  17. if (failure) {
  18. fail();
  19. }
  20. }
  21. }
  22. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldCreateANewStateWithAdditionalLabelButWithoutDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  9. // When
  10. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.update(e, {key:'newValue'}, 'Error') YIELD node RETURN node");
  11. StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
  12. StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
  13. StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
  14. StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
  15. // Then
  16. assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
  17. assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
  18. assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
  19. assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
  20. }
  21. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldCreateAndPatchANewStateWithAdditionalLabelButWithoutDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  9. // When
  10. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.patch(e, {key:'newValue', newKey:'newestValue'}, 'Error') YIELD node RETURN node");
  11. Node currentState = result.single().get("node").asNode();
  12. StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
  13. StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
  14. StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
  15. StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
  16. // Then
  17. assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
  18. assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
  19. assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
  20. assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
  21. assertThat(currentState.get("key").asString(), equalTo("newValue"));
  22. assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
  23. }
  24. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldGetAllErrorStateNodeByGivenErrorLabel() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Error {key:'initialValue'})");
  8. session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Error {key:'initialValue'})");
  9. session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Error {key:'initialValue'})");
  10. // When
  11. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.by.label(e, 'Error') YIELD node RETURN node");
  12. // Then
  13. boolean failure = true;
  14. while (result.hasNext()) {
  15. failure = false;
  16. assertThat(result.next().get("node").asNode().hasLabel("Error"), equalTo(true));
  17. }
  18. if (failure) {
  19. fail();
  20. }
  21. }
  22. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldGetSpecificStateNodeByGivenEntityAndDate() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Error {key:'initialValue'})");
  8. session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-28T00:00:00')}]->(s:State:Test {key:'initialValue'})");
  9. session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-29T00:00:00')}]->(s:State {key:'initialValue'})");
  10. // When
  11. 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");
  12. // Then
  13. boolean failure = true;
  14. while (result.hasNext()) {
  15. failure = false;
  16. assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
  17. }
  18. if (failure) {
  19. fail();
  20. }
  21. }
  22. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldCreateAndPatchANewStateWithAdditionalLabelAndDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  9. // When
  10. 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");
  11. Node currentState = result.single().get("node").asNode();
  12. StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
  13. StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
  14. StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
  15. StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
  16. StatementResult dateResult = session.run("MATCH (e:Entity)-[r:CURRENT]->(s) RETURN r.date as relDate");
  17. StatementResult hasStatusDateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State)-[:PREVIOUS]->(s2:State)<-[rel:HAS_STATE]-(e) RETURN rel.endDate as endDate");
  18. // Then
  19. assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
  20. assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
  21. assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
  22. assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
  23. assertThat(dateResult.single().get("relDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
  24. assertThat(hasStatusDateResult.single().get("endDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
  25. assertThat(currentState.get("key").asString(), equalTo("newValue"));
  26. assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
  27. }
  28. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldCreateANewStateWithAdditionalLabelAndDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  9. // When
  10. 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");
  11. StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
  12. StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
  13. StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
  14. StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
  15. StatementResult dateResult = session.run("MATCH (e:Entity)-[r:CURRENT]->(s) RETURN r.date as relDate");
  16. StatementResult hasStatusDateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State)-[:PREVIOUS]->(s2:State)<-[rel:HAS_STATE]-(e) RETURN rel.endDate as endDate");
  17. // Then
  18. assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
  19. assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
  20. assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
  21. assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
  22. assertThat(dateResult.single().get("relDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
  23. assertThat(hasStatusDateResult.single().get("endDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
  24. }
  25. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldRollbackToTheGivenStateNode() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. 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)");
  9. 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'})");
  10. session.run("MATCH (sc:State)<-[:CURRENT]-(e:Entity)-[:HAS_STATE]->(s:Test) CREATE (sc)-[:PREVIOUS {date:localdatetime('1988-10-26T00:00:00')}]->(s)");
  11. // When
  12. StatementResult result = session.run("MATCH (e:Entity)--(s:Test) WITH e, s CALL graph.versioner.rollback.to(e, s) YIELD node RETURN node");
  13. // Then
  14. boolean failure = true;
  15. while (result.hasNext()) {
  16. failure = false;
  17. assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
  18. }
  19. if (failure) {
  20. fail();
  21. }
  22. }
  23. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldGetOldNodeAfterARollbackOnATwoStateEntityNode() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. 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)");
  9. 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'})");
  10. session.run("MATCH (sc:State)<-[:CURRENT]-(e:Entity)-[:HAS_STATE]->(s:Test) CREATE (sc)-[:PREVIOUS {date:localdatetime('1988-10-26T00:00:00')}]->(s)");
  11. // When
  12. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback(e) YIELD node RETURN node");
  13. // Then
  14. boolean failure = true;
  15. while (result.hasNext()) {
  16. failure = false;
  17. assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
  18. }
  19. if (failure) {
  20. fail();
  21. }
  22. }
  23. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldCreateAndPatchANewStateWithAdditionalLabelAndDateButWithANewProp() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  9. // When
  10. 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");
  11. Node currentState = result.single().get("node").asNode();
  12. StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
  13. StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
  14. StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
  15. StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
  16. StatementResult dateResult = session.run("MATCH (e:Entity)-[r:CURRENT]->(s) RETURN r.date as relDate");
  17. StatementResult hasStatusDateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State)-[:PREVIOUS]->(s2:State)<-[rel:HAS_STATE]-(e) RETURN rel.endDate as endDate");
  18. // Then
  19. assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
  20. assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
  21. assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
  22. assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
  23. assertThat(dateResult.single().get("relDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
  24. assertThat(hasStatusDateResult.single().get("endDate").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
  25. assertThat(currentState.get("key").asString(), equalTo("initialValue"));
  26. assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
  27. }
  28. }

代码示例来源:origin: h-omer/neo4j-versioner-core

  1. @Test
  2. public void shouldUseExistingRollbackRelationshipToRollBackAgain() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. 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)");
  9. 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'})");
  10. 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)");
  11. 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'})");
  12. 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)");
  13. // When
  14. session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback(e) YIELD node RETURN node");
  15. StatementResult finalResult = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback(e) YIELD node RETURN node");
  16. // Then
  17. boolean failure = true;
  18. while (finalResult.hasNext()) {
  19. failure = false;
  20. assertThat(finalResult.next().get("node").asNode().hasLabel("Test"), equalTo(true));
  21. }
  22. if (failure) {
  23. fail();
  24. }
  25. }
  26. }

相关文章