Search in sources :

Example 11 with Configuration

use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.

the class ImportToolTest method shouldImportWithHeadersBeingInSeparateFiles.

@Test
public void shouldImportWithHeadersBeingInSeparateFiles() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.TABS;
    // WHEN
    importTool("--into", dbRule.getStoreDirAbsolutePath(), "--delimiter", "TAB", "--array-delimiter", String.valueOf(config.arrayDelimiter()), "--nodes", nodeHeader(config).getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData(false, config, nodeIds, TRUE).getAbsolutePath(), "--relationships", relationshipHeader(config).getAbsolutePath() + MULTI_FILE_DELIMITER + relationshipData(false, config, nodeIds, TRUE, true).getAbsolutePath());
    // THEN
    verifyData();
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 12 with Configuration

use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.

the class ImportToolTest method shouldImportWithAsManyDefaultsAsAvailable.

@Test
public void shouldImportWithAsManyDefaultsAsAvailable() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    // WHEN
    importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeData(true, config, nodeIds, TRUE).getAbsolutePath(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true).getAbsolutePath());
    // THEN
    verifyData();
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 13 with Configuration

use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.

the class ImportToolTest method shouldImportMultipleInputsWithAddedLabelsAndDefaultRelationshipType.

@Test
public void shouldImportMultipleInputsWithAddedLabelsAndDefaultRelationshipType() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    final String[] firstLabels = { "AddedOne", "AddedTwo" };
    final String[] secondLabels = { "AddedThree" };
    final String firstType = "TYPE_1";
    final String secondType = "TYPE_2";
    // WHEN
    importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes:" + join(firstLabels, ":"), nodeData(true, config, nodeIds, lines(0, NODE_COUNT / 2)).getAbsolutePath(), "--nodes:" + join(secondLabels, ":"), nodeData(true, config, nodeIds, lines(NODE_COUNT / 2, NODE_COUNT)).getAbsolutePath(), "--relationships:" + firstType, relationshipData(true, config, nodeIds, lines(0, RELATIONSHIP_COUNT / 2), false).getAbsolutePath(), "--relationships:" + secondType, relationshipData(true, config, nodeIds, lines(RELATIONSHIP_COUNT / 2, RELATIONSHIP_COUNT), false).getAbsolutePath());
    // THEN
    verifyData(node -> {
        if (node.getId() < NODE_COUNT / 2) {
            assertNodeHasLabels(node, firstLabels);
        } else {
            assertNodeHasLabels(node, secondLabels);
        }
    }, relationship -> {
        if (relationship.getId() < RELATIONSHIP_COUNT / 2) {
            assertEquals(firstType, relationship.getType().name());
        } else {
            assertEquals(secondType, relationship.getType().name());
        }
    });
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 14 with Configuration

use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.

the class ImportToolTest method shouldImportFromInputDataEncodedWithSpecificCharset.

@Test
public void shouldImportFromInputDataEncodedWithSpecificCharset() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    Charset charset = Charset.forName("UTF-16");
    // WHEN
    importTool("--into", dbRule.getStoreDirAbsolutePath(), "--input-encoding", charset.name(), "--nodes", nodeData(true, config, nodeIds, TRUE, charset).getAbsolutePath(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true, charset).getAbsolutePath());
    // THEN
    verifyData();
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) Charset(java.nio.charset.Charset) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 15 with Configuration

use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.

the class ImportToolTest method shouldReportBadDelimiterConfiguration.

@Test
public void shouldReportBadDelimiterConfiguration() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.TABS;
    // WHEN
    try {
        importTool("--into", dbRule.getStoreDirAbsolutePath(), "--delimiter", "\\bogus", "--array-delimiter", String.valueOf(config.arrayDelimiter()), "--nodes", nodeData(true, config, nodeIds, TRUE).getAbsolutePath(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true).getAbsolutePath());
        fail("Should have failed");
    } catch (IllegalArgumentException e) {
        // THEN
        assertThat(e.getMessage(), containsString("bogus"));
    }
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

Configuration (org.neo4j.unsafe.impl.batchimport.input.csv.Configuration)27 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)22 Test (org.junit.Test)22 File (java.io.File)7 InputException (org.neo4j.unsafe.impl.batchimport.input.InputException)7 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 IllegalMultilineFieldException (org.neo4j.csv.reader.IllegalMultilineFieldException)5 DuplicateInputIdException (org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.DuplicateInputIdException)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)4 Node (org.neo4j.graphdb.Node)4 Transaction (org.neo4j.graphdb.Transaction)4 DynamicLabel (org.neo4j.graphdb.DynamicLabel)2 Label (org.neo4j.graphdb.Label)2 Charset (java.nio.charset.Charset)1 Extractors (org.neo4j.csv.reader.Extractors)1 Args (org.neo4j.helpers.Args)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 SimpleLogService (org.neo4j.kernel.impl.logging.SimpleLogService)1