Search in sources :

Example 1 with RealOutsideWorld

use of org.neo4j.commandline.admin.RealOutsideWorld in project neo4j by neo4j.

the class CsvImporterTest method writesReportToSpecifiedReportFile.

@Test
public void writesReportToSpecifiedReportFile() throws Exception {
    File dbDir = testDir.directory("db");
    File logDir = testDir.directory("logs");
    File reportLocation = testDir.file("the_report");
    File inputFile = testDir.file("foobar.csv");
    List<String> lines = Arrays.asList("foo,bar,baz");
    Files.write(inputFile.toPath(), lines, Charset.defaultCharset());
    try (RealOutsideWorld outsideWorld = new RealOutsideWorld()) {
        Config config = Config.defaults().with(additionalConfig()).with(stringMap(DatabaseManagementSystemSettings.database_path.name(), dbDir.getAbsolutePath(), GraphDatabaseSettings.logs_directory.name(), logDir.getAbsolutePath()));
        CsvImporter csvImporter = new CsvImporter(Args.parse(String.format("--report-file=%s", reportLocation.getAbsolutePath()), String.format("--nodes=%s", inputFile.getAbsolutePath())), config, outsideWorld);
        csvImporter.doImport();
    }
    assertTrue(reportLocation.exists());
}
Also used : RealOutsideWorld(org.neo4j.commandline.admin.RealOutsideWorld) Config(org.neo4j.kernel.configuration.Config) File(java.io.File) Test(org.junit.Test)

Example 2 with RealOutsideWorld

use of org.neo4j.commandline.admin.RealOutsideWorld in project neo4j by neo4j.

the class ImportCommandTest method defaultsToCsvWhenModeNotSpecified.

@Test
public void defaultsToCsvWhenModeNotSpecified() throws Exception {
    File homeDir = testDir.directory("home");
    ImporterFactory mockImporterFactory = mock(ImporterFactory.class);
    when(mockImporterFactory.getImporterForMode(eq("csv"), any(Args.class), any(Config.class), any(OutsideWorld.class))).thenReturn(mock(Importer.class));
    try (RealOutsideWorld outsideWorld = new RealOutsideWorld()) {
        ImportCommand importCommand = new ImportCommand(homeDir.toPath(), testDir.directory("conf").toPath(), outsideWorld, mockImporterFactory);
        String[] arguments = { "--database=foo", "--from=bar" };
        importCommand.execute(arguments);
        verify(mockImporterFactory).getImporterForMode(eq("csv"), any(Args.class), any(Config.class), any(OutsideWorld.class));
    }
}
Also used : Args(org.neo4j.helpers.Args) NullOutsideWorld(org.neo4j.commandline.admin.NullOutsideWorld) OutsideWorld(org.neo4j.commandline.admin.OutsideWorld) RealOutsideWorld(org.neo4j.commandline.admin.RealOutsideWorld) RealOutsideWorld(org.neo4j.commandline.admin.RealOutsideWorld) Config(org.neo4j.kernel.configuration.Config) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)2 Test (org.junit.Test)2 RealOutsideWorld (org.neo4j.commandline.admin.RealOutsideWorld)2 Config (org.neo4j.kernel.configuration.Config)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 NullOutsideWorld (org.neo4j.commandline.admin.NullOutsideWorld)1 OutsideWorld (org.neo4j.commandline.admin.OutsideWorld)1 Args (org.neo4j.helpers.Args)1