use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldSupplyArgumentsAsFile.
@Test
void shouldSupplyArgumentsAsFile() throws Exception {
// given
List<String> nodeIds = nodeIds();
Configuration config = COMMAS;
Path argumentFile = file("args");
String nodesEscapedSpaces = nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString();
String relationshipsEscapedSpaced = relationshipData(true, config, nodeIds, TRUE, true).toAbsolutePath().toString();
Path dbConfig = prepareDefaultConfigFile();
String arguments = format("--additional-config=%s%n" + "--nodes=%s%n" + "--relationships=%s%n", dbConfig.toAbsolutePath().toString(), nodesEscapedSpaces, relationshipsEscapedSpaced);
writeToFile(argumentFile, arguments, false);
// when
runImport("@" + argumentFile.toAbsolutePath().toString());
// then
verifyData();
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldAcceptSpecialTabCharacterAsDelimiterConfiguration.
@Test
void shouldAcceptSpecialTabCharacterAsDelimiterConfiguration() throws Exception {
// GIVEN
List<String> nodeIds = nodeIds();
Configuration config = Configuration.TABS;
Path dbConfig = prepareDefaultConfigFile();
// WHEN
runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--delimiter", "\\t", "--array-delimiter", String.valueOf(config.arrayDelimiter()), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true).toAbsolutePath().toString());
// THEN
verifyData();
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldBeAbleToImportAnonymousNodes.
@Test
void shouldBeAbleToImportAnonymousNodes() throws Exception {
// GIVEN
List<String> nodeIds = asList("1", "", "", "", "3", "", "", "", "", "", "5");
Configuration config = Configuration.COMMAS;
List<RelationshipDataLine> relationshipData = asList(relationship("1", "3", "KNOWS"));
Path dbConfig = prepareDefaultConfigFile();
// WHEN
runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--relationships", relationshipData(true, config, relationshipData.iterator(), TRUE, true).toAbsolutePath().toString());
// THEN
GraphDatabaseService db = getDatabaseApi();
try (Transaction tx = db.beginTx()) {
Iterable<Node> allNodes = tx.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.commit();
}
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldIncludeSourceInformationInNodeIdCollisionError.
@Test
void shouldIncludeSourceInformationInNodeIdCollisionError() throws Exception {
// GIVEN
List<String> nodeIds = asList("a", "b", "c", "d", "e", "f", "a", "g");
Configuration config = Configuration.COMMAS;
Path nodeHeaderFile = nodeHeader(config);
Path nodeData1 = nodeData(false, config, nodeIds, lines(0, 4));
Path nodeData2 = nodeData(false, config, nodeIds, lines(4, nodeIds.size()));
// WHEN
var e = assertThrows(Exception.class, () -> runImport("--nodes", nodeHeaderFile.toAbsolutePath().toString() + "," + nodeData1.toAbsolutePath().toString() + "," + nodeData2.toAbsolutePath().toString()));
assertExceptionContains(e, "'a' is defined more than once", DuplicateInputIdException.class);
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldKeepStoreFilesAfterFailedImport.
@Test
void shouldKeepStoreFilesAfterFailedImport() throws Exception {
// GIVEN
List<String> nodeIds = nodeIds();
Configuration config = Configuration.COMMAS;
final var configFile = prepareDefaultConfigFile();
// WHEN data file contains more columns than header file
int extraColumns = 3;
var e = assertThrows(InputException.class, () -> runImport("--additional-config=" + configFile.toAbsolutePath().toString(), "--nodes", nodeHeader(config).toAbsolutePath().toString() + "," + nodeData(false, config, nodeIds, TRUE, Charset.defaultCharset(), extraColumns).toAbsolutePath().toString()));
// THEN the store files should be there
for (StoreType storeType : StoreType.values()) {
assertTrue(Files.exists(databaseLayout.file(storeType.getDatabaseFile())));
}
List<String> errorLines = suppressOutput.getErrorVoice().lines();
assertContains(errorLines, "Starting a database on these store files will likely fail or observe inconsistent records");
}
Aggregations