public static String[] parseFileArgumentList( File file ) throws IOException { List<String> arguments = new ArrayList<>(); readTextFile( file, line -> arguments.addAll( asList( tokenizeStringWithQuotes( line, true, true, false ) ) ) ); return arguments.toArray( new String[arguments.size()] ); }
private ThrowingSupplier<String, IOException> fileContentSupplier( final File file ) { return () -> readTextFile( file, StandardCharsets.UTF_8 ); }
public void add( File fixturePath ) { try { if ( fixturePath.isDirectory() ) { for ( File file : fixturePath.listFiles( cypherFileOrDirectoryFilter ) ) { add( file ); } return; } add( FileUtils.readTextFile( fixturePath, StandardCharsets.UTF_8 ) ); } catch ( IOException e ) { throw new RuntimeException( "Unable to read fixture file '" + fixturePath.getAbsolutePath() + "': " + e.getMessage(), e ); } }
@Test public void shouldWarnIfHeaderHasLessColumnsThanDataWhenToldTo() throws Exception { // GIVEN List<String> nodeIds = nodeIds(); Configuration config = Configuration.TABS; File bad = badFile(); // WHEN data file contains more columns than header file int extraColumns = 3; importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--bad", bad.getAbsolutePath(), "--bad-tolerance", Integer.toString( nodeIds.size() * extraColumns ), "--ignore-extra-columns", "--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() ); // THEN String badContents = FileUtils.readTextFile( bad, Charset.defaultCharset() ); assertTrue( badContents.contains( "Extra column not present in header on line" ) ); }
@Test public void shouldTreatRelationshipWithMissingStartOrEndIdOrTypeAsBadRelationship() throws Exception { // GIVEN List<String> nodeIds = asList( "a", "b", "c" ); Configuration config = Configuration.COMMAS; File nodeData = nodeData( true, config, nodeIds, TRUE ); List<RelationshipDataLine> relationships = Arrays.asList( relationship( "a", null, "TYPE" ), relationship( null, "b", "TYPE" ), relationship( "a", "b", null ) ); File relationshipData = relationshipData( true, config, relationships.iterator(), TRUE, true ); File bad = badFile(); // WHEN importing data where some relationships refer to missing nodes importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", nodeData.getAbsolutePath(), "--bad", bad.getAbsolutePath(), "--skip-bad-relationships", "true", "--relationships", relationshipData.getAbsolutePath() ); String badContents = FileUtils.readTextFile( bad, Charset.defaultCharset() ); assertEquals( badContents, 3, occurencesOf( badContents, "is missing data" ) ); }
String badContents = FileUtils.readTextFile( bad, Charset.defaultCharset() ); assertTrue( "Didn't contain first bad relationship", badContents.contains( "bogus" ) ); assertTrue( "Didn't contain second bad relationship", badContents.contains( "missing" ) );
public static String[] parseFileArgumentList( File file ) throws IOException { List<String> arguments = new ArrayList<>(); readTextFile( file, line -> arguments.addAll( asList( tokenizeStringWithQuotes( line, true, true, false ) ) ) ); return arguments.toArray( new String[arguments.size()] ); }
public void add( File fixturePath ) { try { if ( fixturePath.isDirectory() ) { for ( File file : fixturePath.listFiles( cypherFileOrDirectoryFilter ) ) { add( file ); } return; } add( FileUtils.readTextFile( fixturePath, StandardCharsets.UTF_8 ) ); } catch ( IOException e ) { throw new RuntimeException( "Unable to read fixture file '" + fixturePath.getAbsolutePath() + "': " + e.getMessage(), e ); } }