Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
updating to Neo4j 2.0.0-M05
Browse files Browse the repository at this point in the history
  • Loading branch information
peterneubauer committed Oct 3, 2013
1 parent 5421584 commit 59fe411
Show file tree
Hide file tree
Showing 7 changed files with 2,380 additions and 1,744 deletions.
9 changes: 5 additions & 4 deletions geoff-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
<parent>
<groupId>org.neo4j.build</groupId>
<artifactId>parent-central</artifactId>
<version>35</version>
<version>39</version>
</parent>

<groupId>org.neo4j</groupId>
<artifactId>neo4j-geoff-core</artifactId>
<version>1.9.4</version>
<version>2.0-SNPASHOT</version>
<name>Neo4j - GEOFF</name>
<description>Utility component to parse Neo4j graphs in GEOFF format, see http://py2neo.org/geoff.</description>

<properties>
<bundle.namespace>org.neo4j.visualization</bundle.namespace>
<neo4j.version>2.0.0-M05</neo4j.version>
</properties>
<licenses>
<license>
Expand Down Expand Up @@ -50,12 +51,12 @@ the relevant Commercial Agreement.
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>1.9.4</version>
<version>${neo4j.version}</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>1.9.4</version>
<version>${neo4j.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
176 changes: 104 additions & 72 deletions geoff-core/src/test/java/org/neo4j/geoff/test/MiscellaneousTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.Transaction;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -34,83 +35,114 @@
import static org.junit.Assert.assertTrue;
import static org.neo4j.geoff.test.TestDatabase.*;

public class MiscellaneousTest extends TestBase{
public class MiscellaneousTest extends TestBase {


@Test
public void canCreateGraphFromSingleString() throws Exception {
Subgraph subgraph = new Subgraph("" +
"(doc) {\"name\": \"doctor\"}\n" +
"(dal) {\"name\": \"dalek\"}\n" +
"(doc)-[:ENEMY_OF]->(dal) {\"since\":\"forever\"}\n" +
"(doc)<=|People| {\"name\": \"The Doctor\"}\n" +
"");
Geoff.insertIntoNeo4j(subgraph, db, null);
assertTrue(db.index().existsForNodes("People"));
assertTrue(db.index().forNodes("People").get("name", "The Doctor").hasNext());
assertEquals("doctor", db.index().forNodes("People").get("name", "The Doctor").getSingle().getProperty("name"));
}
@Test
public void canCreateGraphFromSingleString() throws Exception {
Subgraph subgraph = new Subgraph("" +
"(doc) {\"name\": \"doctor\"}\n" +
"(dal) {\"name\": \"dalek\"}\n" +
"(doc)-[:ENEMY_OF]->(dal) {\"since\":\"forever\"}\n" +
"(doc)<=|People| {\"name\": \"The Doctor\"}\n" +
"");
Geoff.insertIntoNeo4j(subgraph, db, null);
Transaction tx = db.beginTx();
try {
assertTrue(db.index().existsForNodes("People"));
assertTrue(db.index().forNodes("People").get("name", "The Doctor").hasNext());
assertEquals("doctor", db.index().forNodes("People").get("name", "The Doctor").getSingle().getProperty("name"));
tx.success();
} finally {
tx.close();
}

@Test
public void canCreateGraphWithHookToReferenceNode() throws Exception {
Subgraph subgraph = new Subgraph("" +
"(doc) {\"name\": \"doctor\"}\n" +
"(dal) {\"name\": \"dalek\"}\n" +
"(doc)-[:ENEMY_OF]->(dal) {\"since\":\"forever\"}\n" +
"(doc)<=|People| {\"name\": \"The Doctor\"}\n" +
"(ref)-[:TIMELORD]->(doc)");
HashMap<String,PropertyContainer> hooks = new HashMap<String,PropertyContainer>(1);
hooks.put("ref", db.getReferenceNode());
Geoff.insertIntoNeo4j(subgraph, db, hooks);
assertTrue(db.index().existsForNodes("People"));
assertTrue(db.index().forNodes("People").get("name", "The Doctor").hasNext());
assertEquals("doctor", db.index().forNodes("People").get("name", "The Doctor").getSingle().getProperty("name"));
assertTrue(db.getReferenceNode().hasRelationship(DynamicRelationshipType.withName("TIMELORD")));
}
}

@Test
public void canLoadRulesCreatedFromValues() throws Exception {
Subgraph rules = new Subgraph();
rules.add(Rule.fromValues("(doc)", "name", "doctor", "age", 991));
rules.add(Rule.fromValues("(doc)<=|People|", "name", "The Doctor"));
Geoff.insertIntoNeo4j(rules, db, null);
assertTrue(db.index().existsForNodes("People"));
assertTrue(db.index().forNodes("People").get("name", "The Doctor").hasNext());
assertEquals("doctor", db.index().forNodes("People").get("name", "The Doctor").getSingle().getProperty("name"));
}
@Test
public void canCreateGraphWithHookToReferenceNode() throws Exception {
Subgraph subgraph = new Subgraph("" +
"(doc) {\"name\": \"doctor\"}\n" +
"(dal) {\"name\": \"dalek\"}\n" +
"(doc)-[:ENEMY_OF]->(dal) {\"since\":\"forever\"}\n" +
"(doc)<=|People| {\"name\": \"The Doctor\"}\n" +
"(ref)-[:TIMELORD]->(doc)");
HashMap<String, PropertyContainer> hooks = new HashMap<String, PropertyContainer>(1);
Transaction tx = db.beginTx();
try {
hooks.put("ref", db.getReferenceNode());
Geoff.insertIntoNeo4j(subgraph, db, hooks);
assertTrue(db.index().existsForNodes("People"));
assertTrue(db.index().forNodes("People").get("name", "The Doctor").hasNext());
assertEquals("doctor", db.index().forNodes("People").get("name", "The Doctor").getSingle().getProperty("name"));
assertTrue(db.getReferenceNode().hasRelationship(DynamicRelationshipType.withName("TIMELORD")));
tx.success();
} finally {
tx.close();
}
}

@Test
public void canCreateNodesBeforeRelationship() throws Exception {
TestDatabase db = new TestDatabase();
Subgraph geoff = new Subgraph();
geoff.add("(A) {\"name\": \"Alice Allison\"}");
geoff.add("(B) {\"name\": \"Bob Robertson\"}");
geoff.add("(A)-[R:KNOWS]->(B) {\"since\": 1977}");
Map<String, PropertyContainer> out = Geoff.insertIntoNeo4j(geoff, db, null);
assertNodesExist(out, "(A)", "(B)");
assertAlice((Node) out.get("(A)"));
assertBob((Node) out.get("(B)"));
assertRelationshipsExist(out, "[R]");
assertTrue(out.get("[R]").hasProperty("since"));
assertEquals(1977, out.get("[R]").getProperty("since"));
db.assertCounts(3, 1);
}
@Test
public void canLoadRulesCreatedFromValues() throws Exception {
Subgraph rules = new Subgraph();
rules.add(Rule.fromValues("(doc)", "name", "doctor", "age", 991));
rules.add(Rule.fromValues("(doc)<=|People|", "name", "The Doctor"));
Geoff.insertIntoNeo4j(rules, db, null);
Transaction tx = db.beginTx();
try {
assertTrue(db.index().existsForNodes("People"));
assertTrue(db.index().forNodes("People").get("name", "The Doctor").hasNext());
assertEquals("doctor", db.index().forNodes("People").get("name", "The Doctor").getSingle().getProperty("name"));
tx.success();
} finally {
tx.close();
}
}

@Test
public void canCreateRelationshipBeforeNodes() throws Exception {
TestDatabase db = new TestDatabase();
Subgraph geoff = new Subgraph();
geoff.add("(A)-[R:KNOWS]->(B) {\"since\": 1977}");
geoff.add("(A) {\"name\": \"Alice Allison\"}");
geoff.add("(B) {\"name\": \"Bob Robertson\"}");
Map<String, PropertyContainer> out = Geoff.insertIntoNeo4j(geoff, db, null);
assertNodesExist(out, "(A)", "(B)");
assertAlice((Node) out.get("(A)"));
assertBob((Node) out.get("(B)"));
assertRelationshipsExist(out, "[R]");
assertTrue(out.get("[R]").hasProperty("since"));
assertEquals(1977, out.get("[R]").getProperty("since"));
db.assertCounts(3, 1);
}
@Test
public void canCreateNodesBeforeRelationship() throws Exception {
TestDatabase db = new TestDatabase();
Subgraph geoff = new Subgraph();
geoff.add("(A) {\"name\": \"Alice Allison\"}");
geoff.add("(B) {\"name\": \"Bob Robertson\"}");
geoff.add("(A)-[R:KNOWS]->(B) {\"since\": 1977}");
Map<String, PropertyContainer> out = Geoff.insertIntoNeo4j(geoff, db, null);
Transaction tx = db.beginTx();
try {
assertNodesExist(out, "(A)", "(B)");
assertAlice((Node) out.get("(A)"));
assertBob((Node) out.get("(B)"));
assertRelationshipsExist(out, "[R]");
assertTrue(out.get("[R]").hasProperty("since"));
assertEquals(1977, out.get("[R]").getProperty("since"));
db.assertCounts(3, 1);
tx.success();
} finally {
tx.close();
}
}

@Test
public void canCreateRelationshipBeforeNodes() throws Exception {
TestDatabase db = new TestDatabase();
Subgraph geoff = new Subgraph();
geoff.add("(A)-[R:KNOWS]->(B) {\"since\": 1977}");
geoff.add("(A) {\"name\": \"Alice Allison\"}");
geoff.add("(B) {\"name\": \"Bob Robertson\"}");
Map<String, PropertyContainer> out = Geoff.insertIntoNeo4j(geoff, db, null);
Transaction tx = db.beginTx();
try {
assertNodesExist(out, "(A)", "(B)");
assertAlice((Node) out.get("(A)"));
assertBob((Node) out.get("(B)"));
assertRelationshipsExist(out, "[R]");
assertTrue(out.get("[R]").hasProperty("since"));
assertEquals(1977, out.get("[R]").getProperty("since"));
db.assertCounts(3, 1);
tx.success();
} finally {
tx.close();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,38 @@
package org.neo4j.geoff.test;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.neo4j.geoff.Geoff;
import org.neo4j.geoff.except.SubgraphError;
import org.neo4j.geoff.except.SyntaxError;
import org.neo4j.graphdb.Transaction;

import java.io.IOException;

public class Neo4jGraphDeleteTest extends TestBase {

private final TestTransaction[] testTransactions;

public Neo4jGraphDeleteTest() throws IOException, SyntaxError {
this.testTransactions = getTestTransactions(50);
}

@Before
public void setUp() throws IOException, SubgraphError {
db = new TestDatabase();
for (TestTransaction txn : this.testTransactions) {
Geoff.insertIntoNeo4j(txn, db, null);
}
}
private final TestTransaction[] testTransactions;

public void canDeleteAllTestTransactions() throws IOException, SubgraphError {
for (TestTransaction txn : this.testTransactions) {
Geoff.deleteFromNeo4j(txn, db, null);
}
db.assertCounts(1, 0);
}
public Neo4jGraphDeleteTest() throws IOException, SyntaxError {
this.testTransactions = getTestTransactions(50);
}

@Before
public void setUp() throws IOException, SubgraphError {
db = new TestDatabase();
for (TestTransaction txn : this.testTransactions) {
Geoff.insertIntoNeo4j(txn, db, null);
}
}

public void canDeleteAllTestTransactions() throws IOException, SubgraphError {
for (TestTransaction txn : this.testTransactions) {
Geoff.deleteFromNeo4j(txn, db, null);
}
Transaction tx = db.beginTx();
try {
db.assertCounts(1, 0);
} finally {
tx.close();
}
}
}
Loading

0 comments on commit 59fe411

Please sign in to comment.