use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method verifyData.
private void verifyData(Validator<Node> nodeAdditionalValidation, Validator<Relationship> relationshipAdditionalValidation) {
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
int nodeCount = 0, relationshipCount = 0;
for (Node node : db.getAllNodes()) {
assertTrue(node.hasProperty("name"));
nodeAdditionalValidation.validate(node);
nodeCount++;
}
assertEquals(NODE_COUNT, nodeCount);
for (Relationship relationship : db.getAllRelationships()) {
assertTrue(relationship.hasProperty("created"));
relationshipAdditionalValidation.validate(relationship);
relationshipCount++;
}
assertEquals(RELATIONSHIP_COUNT, relationshipCount);
tx.success();
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method shouldIgnoreWhitespaceAroundBooleans.
@Test
public void shouldIgnoreWhitespaceAroundBooleans() throws Exception {
// GIVEN
File data = file(fileName("whitespace.csv"));
try (PrintStream writer = new PrintStream(data)) {
writer.println(":LABEL,name,adult:boolean");
writer.println("PERSON,'t1',true");
writer.println("PERSON,'t2', true");
writer.println("PERSON,'t3',true ");
writer.println("PERSON,'t4', true ");
writer.println("PERSON,'f1',false");
writer.println("PERSON,'f2', false");
writer.println("PERSON,'f3',false ");
writer.println("PERSON,'f4', false ");
writer.println("PERSON,'f5', truebutactuallyfalse ");
writer.println("PERSON,'f6', non true things are interpreted as false ");
}
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--quote", "'", "--nodes", data.getAbsolutePath());
// THEN
try (Transaction tx = dbRule.beginTx()) {
for (Node node : dbRule.getAllNodes()) {
String name = (String) node.getProperty("name");
if (name.startsWith("t")) {
assertTrue("Wrong value on " + name, (boolean) node.getProperty("adult"));
} else {
assertFalse("Wrong value on " + name, (boolean) node.getProperty("adult"));
}
}
long nodeCount = Iterables.count(dbRule.getAllNodes());
assertEquals(10, nodeCount);
tx.success();
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method shouldIgnoreWhitespaceAroundIntegers.
@Test
public void shouldIgnoreWhitespaceAroundIntegers() throws Exception {
// GIVEN
// Faster to do all successful in one import than in N separate tests
List<String> values = Arrays.asList("17", " 21", "99 ", " 34 ", "-34", " -12", "-92 ");
File data = file(fileName("whitespace.csv"));
try (PrintStream writer = new PrintStream(data)) {
writer.println(":LABEL,name,s:short,b:byte,i:int,l:long,f:float,d:double");
// For each test value
for (String value : values) {
// Save value as a String in name
writer.print("PERSON,'" + value + "'");
// For each numerical type
for (int j = 0; j < 6; j++) {
writer.print("," + value);
}
// End line
writer.println();
}
}
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--quote", "'", "--nodes", data.getAbsolutePath());
// THEN
int nodeCount = 0;
try (Transaction tx = dbRule.beginTx()) {
for (Node node : dbRule.getAllNodes()) {
nodeCount++;
String name = (String) node.getProperty("name");
String expected = name.trim();
assertEquals(7, node.getAllProperties().size());
for (String key : node.getPropertyKeys()) {
if (key.equals("name")) {
continue;
} else if (key.equals("f") || key.equals("d")) {
// Floating points have decimals
expected = String.valueOf(Double.parseDouble(expected));
}
assertEquals("Wrong value for " + key, expected, node.getProperty(key).toString());
}
}
tx.success();
}
assertEquals(values.size(), nodeCount);
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method shouldSkipDuplicateNodesIfToldTo.
@Test
public void shouldSkipDuplicateNodesIfToldTo() throws Exception {
// GIVEN
List<String> nodeIds = asList("a", "b", "c", "d", "e", "f", "a", "g");
Configuration config = Configuration.COMMAS;
File nodeHeaderFile = nodeHeader(config);
File nodeData1 = nodeData(false, config, nodeIds, lines(0, 4));
File nodeData2 = nodeData(false, config, nodeIds, lines(4, nodeIds.size()));
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--skip-duplicate-nodes", "--nodes", nodeHeaderFile.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData1.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData2.getAbsolutePath());
// THEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
// there should not be duplicates of any node
Iterator<Node> nodes = db.getAllNodes().iterator();
Iterator<String> expectedIds = FilteringIterator.noDuplicates(nodeIds.iterator());
while (expectedIds.hasNext()) {
assertTrue(nodes.hasNext());
assertEquals(expectedIds.next(), nodes.next().getProperty("id"));
}
assertFalse(nodes.hasNext());
// also all nodes in the label index should exist
for (int i = 0; i < MAX_LABEL_ID; i++) {
Label label = Label.label(labelName(i));
try (ResourceIterator<Node> nodesByLabel = db.findNodes(label)) {
while (nodesByLabel.hasNext()) {
assertTrue(nodesByLabel.next().hasLabel(label));
}
}
}
tx.success();
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method shouldImportGroupsOfOverlappingIds.
@Test
public void shouldImportGroupsOfOverlappingIds() throws Exception {
// GIVEN
List<String> groupOneNodeIds = asList("1", "2", "3");
List<String> groupTwoNodeIds = asList("4", "5", "2");
List<RelationshipDataLine> rels = asList(relationship("1", "4", "TYPE"), relationship("2", "5", "TYPE"), relationship("3", "2", "TYPE"));
Configuration config = Configuration.COMMAS;
String groupOne = "Actor";
String groupTwo = "Movie";
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeHeader(config, groupOne) + MULTI_FILE_DELIMITER + nodeData(false, config, groupOneNodeIds, TRUE), "--nodes", nodeHeader(config, groupTwo) + MULTI_FILE_DELIMITER + nodeData(false, config, groupTwoNodeIds, TRUE), "--relationships", relationshipHeader(config, groupOne, groupTwo, true) + MULTI_FILE_DELIMITER + relationshipData(false, config, rels.iterator(), TRUE, true));
// THEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
int nodeCount = 0;
for (Node node : db.getAllNodes()) {
assertTrue(node.hasProperty("name"));
nodeCount++;
assertEquals(1, Iterables.count(node.getRelationships()));
}
assertEquals(6, nodeCount);
tx.success();
}
}
Aggregations