use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method shouldBeAbleToImportAnonymousNodes.
@Test
public void shouldBeAbleToImportAnonymousNodes() throws Exception {
// GIVEN
List<String> nodeIds = asList("1", "", "", "", "3", "", "", "", "", "", "5");
Configuration config = Configuration.COMMAS;
List<RelationshipDataLine> relationshipData = asList(relationship("1", "3", "KNOWS"));
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeData(true, config, nodeIds, TRUE).getAbsolutePath(), "--relationships", relationshipData(true, config, relationshipData.iterator(), TRUE, true).getAbsolutePath());
// THEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
Iterable<Node> allNodes = db.getAllNodes();
int anonymousCount = 0;
for (final String id : nodeIds) {
if (id.isEmpty()) {
anonymousCount++;
} else {
assertNotNull(Iterators.single(Iterators.filter(nodeFilter(id), allNodes.iterator())));
}
}
assertEquals(anonymousCount, count(Iterators.filter(nodeFilter(""), allNodes.iterator())));
tx.success();
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method shouldIgnoreWhitespaceInAndAroundIntegerArrays.
@Test
public void shouldIgnoreWhitespaceInAndAroundIntegerArrays() throws Exception {
// GIVEN
// Faster to do all successful in one import than in N separate tests
String[] values = new String[] { " 17", "21", "99 ", " 34 ", "-34", " -12", "-92 " };
File data = writeArrayCsv(new String[] { "s:short[]", "b:byte[]", "i:int[]", "l:long[]", "f:float[]", "d:double[]" }, values);
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--quote", "'", "--nodes", data.getAbsolutePath());
// THEN
// Expected value for integer types
String iExpected = "[";
for (String value : values) {
iExpected += value.trim() + ", ";
}
iExpected = iExpected.substring(0, iExpected.length() - 2) + "]";
// Expected value for floating point types
String fExpected = "[";
for (String value : values) {
fExpected += Double.valueOf(value.trim()) + ", ";
}
fExpected = fExpected.substring(0, fExpected.length() - 2) + "]";
int nodeCount = 0;
try (Transaction tx = dbRule.beginTx()) {
for (Node node : dbRule.getAllNodes()) {
nodeCount++;
assertEquals(6, node.getAllProperties().size());
for (String key : node.getPropertyKeys()) {
Object things = node.getProperty(key);
String result = "";
String expected = iExpected;
switch(key) {
case "s":
result = Arrays.toString((short[]) things);
break;
case "b":
result = Arrays.toString((byte[]) things);
break;
case "i":
result = Arrays.toString((int[]) things);
break;
case "l":
result = Arrays.toString((long[]) things);
break;
case "f":
result = Arrays.toString((float[]) things);
expected = fExpected;
break;
case "d":
result = Arrays.toString((double[]) things);
expected = fExpected;
break;
default:
break;
}
assertEquals(expected, result);
}
}
tx.success();
}
assertEquals(1, nodeCount);
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method allNodesById.
private Map<String, Node> allNodesById(GraphDatabaseService db) {
try (Transaction tx = db.beginTx()) {
Map<String, Node> nodes = new HashMap<>();
for (Node node : db.getAllNodes()) {
nodes.put(idOf(node), node);
}
tx.success();
return nodes;
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method shouldBeEquivalentToUseRawAsciiOrCharacterAsQuoteConfiguration2.
@Test
public void shouldBeEquivalentToUseRawAsciiOrCharacterAsQuoteConfiguration2() throws Exception {
// GIVEN
// 126 ~ (tilde)
char weirdDelimiter = 126;
String weirdStringDelimiter = "~";
String name1 = weirdDelimiter + "Weird" + weirdDelimiter;
String name2 = "Start " + weirdDelimiter + "middle thing" + weirdDelimiter + " end!";
File data = data(":ID,name", "1," + name1, "2," + name2);
// WHEN given as string
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", data.getAbsolutePath(), "--quote", weirdStringDelimiter);
// THEN
assertEquals(weirdStringDelimiter, "" + weirdDelimiter);
assertEquals(weirdStringDelimiter.charAt(0), weirdDelimiter);
Set<String> names = asSet("Weird", name2);
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
for (Node node : db.getAllNodes()) {
String name = (String) node.getProperty("name");
assertTrue("Didn't expect node with name '" + name + "'", names.remove(name));
}
assertTrue(names.isEmpty());
tx.success();
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method shouldSkipEmptyFiles.
@Test
public void shouldSkipEmptyFiles() throws Exception {
// GIVEN
File data = data("");
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", data.getAbsolutePath());
// THEN
GraphDatabaseService graphDatabaseService = dbRule.getGraphDatabaseAPI();
try (Transaction tx = graphDatabaseService.beginTx()) {
ResourceIterator<Node> allNodes = graphDatabaseService.getAllNodes().iterator();
assertFalse("Expected database to be empty", allNodes.hasNext());
tx.success();
}
}
Aggregations