use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class ImportToolTest method shouldNotTrimStringsByDefault.
@Test
public void shouldNotTrimStringsByDefault() throws Exception {
// GIVEN
String name = " This is a line with leading and trailing whitespaces ";
File data = data(":ID,name", "1,\"" + name + "\"");
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", data.getAbsolutePath());
// THEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
ResourceIterator<Node> allNodes = db.getAllNodes().iterator();
Node node = Iterators.single(allNodes);
allNodes.close();
assertEquals(name, node.getProperty("name"));
tx.success();
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class ImportToolTest method shouldAcceptRawAsciiCharacterCodeAsQuoteConfiguration.
@Test
public void shouldAcceptRawAsciiCharacterCodeAsQuoteConfiguration() throws Exception {
// GIVEN
// not '1', just the character represented with code 1, which seems to be SOH
char weirdDelimiter = 1;
String name1 = weirdDelimiter + "Weird" + weirdDelimiter;
String name2 = "Start " + weirdDelimiter + "middle thing" + weirdDelimiter + " end!";
File data = data(":ID,name", "1," + name1, "2," + name2);
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", data.getAbsolutePath(), "--quote", String.valueOf(weirdDelimiter));
// THEN
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.GraphDatabaseService 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.GraphDatabaseService 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.GraphDatabaseService 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