@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 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 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 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" ) ); } }
List<String> errorLines = suppressOutput.getErrorVoice().lines(); assertContains( errorLines, "Starting a database on these store files will likely fail or observe inconsistent records" );
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 ); } } }