private List<String> getStdOut() { List<String> lines = suppress.getOutputVoice().lines(); // Remove empty lines return lines.stream().filter( line -> !line.equals( "" ) ).collect( Collectors.toList() ); }
@Test public void shouldNotThrowNullPointerExceptionIfConfigurationValidationFails() throws Exception { // given ServerBootstrapper serverBootstrapper = new ServerBootstrapper() { @Override protected GraphFactory createGraphFactory( Config config ) { return new CommunityGraphFactory(); } @Override protected NeoServer createNeoServer( GraphFactory graphFactory, Config config, GraphDatabaseDependencies dependencies ) { return mock( NeoServer.class ); } }; File dir = Files.createTempDirectory( "test-server-bootstrapper" ).toFile(); dir.deleteOnExit(); // when serverBootstrapper.start( dir, Optional.empty(), MapUtil.stringMap( database_path.name(), homeDir.absolutePath().getAbsolutePath() ) ); // then no exceptions are thrown and assertThat( suppress.getOutputVoice().lines(), not( empty() ) ); } }
@Test public void usageMessageIncludeExample() throws Exception { SuppressOutput.Voice outputVoice = suppressOutput.getOutputVoice(); importTool( "?" ); assertTrue( "Usage message should include example section, but was:" + outputVoice, outputVoice.containsMessage( "Example:" ) ); }
@Test public void usageMessagePrintedOnEmptyInputParameters() throws Exception { SuppressOutput.Voice outputVoice = suppressOutput.getOutputVoice(); importTool(); assertTrue( "Output should include usage section, but was:" + outputVoice, outputVoice.containsMessage( "Example:" ) ); }
@Test void shouldUseArgumentsFoundInside_f_Argument() throws FileNotFoundException, CommandFailed, IncorrectUsage { // given File report = testDir.file( "report" ); ImportCommand importCommand = new ImportCommand( testDir.directory( "home" ).toPath(), testDir.directory( "conf" ).toPath(), new RealOutsideWorld( System.out, System.err, new ByteArrayInputStream( new byte[0] ) ) ); File nodesFile = createTextFile( "nodes.csv", ":ID", "1", "2" ); String pathWithEscapedSpaces = escapeSpaces( nodesFile.getAbsolutePath() ); String reportEscapedPath = escapeSpaces( report.getAbsolutePath() ); File argFile = createTextFile( "args.txt", "--database=foo", "--nodes=" + pathWithEscapedSpaces, "--report-file=" + reportEscapedPath ); String[] arguments = {"-f", argFile.getAbsolutePath()}; // when importCommand.execute( arguments ); // then assertTrue( suppressOutput.getOutputVoice().containsMessage( "IMPORT DONE" ) ); assertTrue( suppressOutput.getErrorVoice().containsMessage( nodesFile.getAbsolutePath() ) ); assertTrue( suppressOutput.getOutputVoice().containsMessage( "2 nodes" ) ); }
@Test void mainPrintsVersion() { // when CommunityEntryPoint.main( new String[]{ "--version" } ); // then assertTrue( suppressOutput.getOutputVoice().containsMessage( "neo4j " + neo4jVersion() ) ); } }
@Test public void shouldImportWithAsManyDefaultsAsAvailable() throws Exception { // GIVEN List<String> nodeIds = nodeIds(); Configuration config = Configuration.COMMAS; // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", nodeData( true, config, nodeIds, TRUE ).getAbsolutePath(), "--relationships", relationshipData( true, config, nodeIds, TRUE, true ).getAbsolutePath() ); // THEN assertTrue( suppressOutput.getOutputVoice().containsMessage( "IMPORT DONE" ) ); verifyData(); }
@Test public void shouldFailIfHeaderHasLessColumnsThanData() throws Exception { // GIVEN List<String> nodeIds = nodeIds(); Configuration config = Configuration.TABS; // WHEN data file contains more columns than header file int extraColumns = 3; try { importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--delimiter", "TAB", "--array-delimiter", String.valueOf( config.arrayDelimiter() ), "--nodes", nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData( false, config, nodeIds, TRUE, Charset.defaultCharset(), extraColumns ) .getAbsolutePath(), "--relationships", relationshipHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + relationshipData( false, config, nodeIds, TRUE, true ).getAbsolutePath() ); fail( "Should have thrown exception" ); } catch ( InputException e ) { // THEN assertTrue( suppressOutput.getOutputVoice().containsMessage( "IMPORT FAILED" ) ); assertFalse( suppressOutput.getErrorVoice().containsMessage( e.getClass().getName() ) ); assertTrue( e.getMessage().contains( "Extra column not present in header on line" ) ); } }
@Test public void shouldLogHelpfulStartupMessages() { CommunityBootstrapper boot = new CommunityBootstrapper(); Map<String,String> propertyPairs = getPropertyPairs(); boot.start( testDir.directory(), Optional.of( new File( "nonexistent-file.conf" ) ), propertyPairs ); URI uri = boot.getServer().baseUri(); boot.stop(); List<String> captured = suppressOutput.getOutputVoice().lines(); assertThat( captured, containsAtLeastTheseLines( warn( "Config file \\[nonexistent-file.conf\\] does not exist." ), info( NEO4J_IS_STARTING_MESSAGE ), info( "Starting..." ), info( "Started." ), info( "Remote interface available at " + uri.toString() ), info( "Stopping..." ), info( "Stopped." ) ) ); }