Search in sources :

Example 21 with Configuration

use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.

the class ImportCommandTest method shouldImportWithoutTypeSpecifiedInRelationshipHeaderbutWithDefaultTypeInArgument.

@Test
void shouldImportWithoutTypeSpecifiedInRelationshipHeaderbutWithDefaultTypeInArgument() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    String type = randomType();
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), // there will be no :TYPE specified in the header of the relationships below
    "--relationships", type + "=" + relationshipData(true, config, nodeIds, TRUE, false).toAbsolutePath().toString());
    // THEN
    verifyData();
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 22 with Configuration

use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.

the class ImportCommandTest method importIntoLowerCasedDatabaseName.

@Test
void importIntoLowerCasedDatabaseName() throws Exception {
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    Path dbConfig = prepareDefaultConfigFile();
    var mixedCaseDatabaseName = "TestDataBase";
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--database", mixedCaseDatabaseName);
    var db = getDatabaseApi(mixedCaseDatabaseName.toLowerCase());
    assertEquals(mixedCaseDatabaseName.toLowerCase(), db.databaseName());
    try (Transaction tx = db.beginTx()) {
        int nodeCount = 0;
        for (Node node : tx.getAllNodes()) {
            assertTrue(node.hasProperty("name"));
            nodeCount++;
            assertFalse(node.hasRelationship());
        }
        assertEquals(NODE_COUNT, nodeCount);
        tx.commit();
    }
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.jupiter.api.Test)

Example 23 with Configuration

use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.

the class ImportCommandTest method shouldReportBadDelimiterConfiguration.

@Test
void shouldReportBadDelimiterConfiguration() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.TABS;
    // WHEN
    var e = assertThrows(ParameterException.class, () -> runImport("--delimiter", "\\bogus", "--array-delimiter", String.valueOf(config.arrayDelimiter()), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true).toAbsolutePath().toString()));
    assertThat(e).hasMessageContaining("bogus");
}
Also used : Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 24 with Configuration

use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.

the class ImportCommandTest method shouldImportFromInputDataEncodedWithSpecificCharset.

@Test
void shouldImportFromInputDataEncodedWithSpecificCharset() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    Charset charset = StandardCharsets.UTF_16;
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--input-encoding", charset.name(), "--nodes", nodeData(true, config, nodeIds, TRUE, charset).toAbsolutePath().toString(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true, charset).toAbsolutePath().toString());
    // THEN
    verifyData();
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Charset(java.nio.charset.Charset) Test(org.junit.jupiter.api.Test)

Example 25 with Configuration

use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.

the class ImportCommandTest method shouldImportOnlyNodes.

@Test
void shouldImportOnlyNodes() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString());
    // no relationships
    // THEN
    GraphDatabaseService db = getDatabaseApi();
    try (Transaction tx = db.beginTx()) {
        int nodeCount = 0;
        for (Node node : tx.getAllNodes()) {
            assertTrue(node.hasProperty("name"));
            nodeCount++;
            assertFalse(node.hasRelationship());
        }
        assertEquals(NODE_COUNT, nodeCount);
        tx.commit();
    }
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Configuration(org.neo4j.csv.reader.Configuration) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.jupiter.api.Test)

Aggregations

Configuration (org.neo4j.csv.reader.Configuration)31 Test (org.junit.jupiter.api.Test)27 Path (java.nio.file.Path)24 Node (org.neo4j.graphdb.Node)5 Transaction (org.neo4j.graphdb.Transaction)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)4 Configuration.defaultConfiguration (org.neo4j.internal.batchimport.Configuration.defaultConfiguration)3 Label (org.neo4j.graphdb.Label)2 Input (org.neo4j.internal.batchimport.input.Input)2 Charset (java.nio.charset.Charset)1 HashSet (java.util.HashSet)1 MutableInt (org.apache.commons.lang3.mutable.MutableInt)1 Test (org.junit.Test)1 Config (org.neo4j.configuration.Config)1 Extractors (org.neo4j.csv.reader.Extractors)1 BatchImporter (org.neo4j.internal.batchimport.BatchImporter)1 IndexConfig (org.neo4j.internal.batchimport.IndexConfig)1 InputIterator (org.neo4j.internal.batchimport.InputIterator)1 ParallelBatchImporter (org.neo4j.internal.batchimport.ParallelBatchImporter)1 DataGeneratorInput (org.neo4j.internal.batchimport.input.DataGeneratorInput)1