@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() ) ); } }
public Voice getVoice( Suppressible suppressible ) { for ( Voice voice : voices ) { if ( suppressible.equals( voice.getSuppressible() ) ) { return voice; } } return null; }
voice.restore( failure );
List<String> errorLines = suppressOutput.getErrorVoice().lines(); assertContains( errorLines, "Starting a database on these store files will likely fail or observe inconsistent records" );
@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" ) ); } }
private void shouldPrintReferenceLinkAsPartOfErrorMessage( List<String> nodeIds, Iterator<RelationshipDataLine> relationshipDataLines, String message ) { Configuration config = Configuration.COMMAS; try { // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", nodeData( true, config, nodeIds, TRUE ).getAbsolutePath(), "--skip-bad-relationships", "false", "--relationships", relationshipData( true, config, relationshipDataLines, TRUE, true ).getAbsolutePath() ); fail( " Should fail during import." ); } catch ( Exception e ) { // EXPECT assertTrue( suppressOutput.getErrorVoice().containsMessage( message ) ); } for ( StoreType storeType : StoreType.values() ) { if ( storeType.isRecordStore() ) { dbRule.databaseLayout().file( storeType.getDatabaseFile() ).forEach( File::delete ); } } }
@Test public void shouldPrintStackTraceOnInputExceptionIfToldTo() throws Exception { // GIVEN List<String> nodeIds = nodeIds(); Configuration config = Configuration.COMMAS; // WHEN data file contains more columns than header file int extraColumns = 3; try { importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData( false, config, nodeIds, TRUE, Charset.defaultCharset(), extraColumns ) .getAbsolutePath(), "--stacktrace" ); fail( "Should have thrown exception" ); } catch ( InputException e ) { // THEN assertTrue( suppressOutput.getErrorVoice().containsMessage( e.getClass().getName() ) ); assertTrue( e.getMessage().contains( "Extra column not present in header on line" ) ); } }
@Test public void shouldPrintUserFriendlyMessageAboutUnsupportedMultilineFields() throws Exception { // GIVEN File data = data( ":ID,name", "1,\"one\ntwo\nthree\"", "2,four" ); try { importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", data.getAbsolutePath(), "--multiline-fields", "false" ); fail( "Should have failed" ); } catch ( InputException e ) { // THEN assertTrue( suppressOutput.getErrorVoice().containsMessage( "Detected field which spanned multiple lines" ) ); assertTrue( suppressOutput.getErrorVoice().containsMessage( "multiline-fields" ) ); } }
@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." ) ) ); }
@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 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 usageMessagePrintedOnEmptyInputParameters() throws Exception { SuppressOutput.Voice outputVoice = suppressOutput.getOutputVoice(); importTool(); assertTrue( "Output should include usage section, but was:" + outputVoice, outputVoice.containsMessage( "Example:" ) ); }
@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 void mainPrintsVersion() { // when CommunityEntryPoint.main( new String[]{ "--version" } ); // then assertTrue( suppressOutput.getOutputVoice().containsMessage( "neo4j " + neo4jVersion() ) ); } }
private List<String> getStdOut() { List<String> lines = suppress.getOutputVoice().lines(); // Remove empty lines return lines.stream().filter( line -> !line.equals( "" ) ).collect( Collectors.toList() ); }
/** Get each line written to this voice since it was suppressed */ public List<String> lines() { return asList( toString().split( lineSeparator() ) ); }