use of org.neo4j.csv.reader.CharReadable in project neo4j by neo4j.
the class DataFactoriesTest method shouldParseHeaderFromFirstLineOfFirstInputFile.
@Test
public void shouldParseHeaderFromFirstLineOfFirstInputFile() throws Exception {
// GIVEN
final CharReadable firstSource = wrap("id:ID\tname:String\tbirth_date:long");
final CharReadable secondSource = wrap("0\tThe node\t123456789");
DataFactory dataFactory = DataFactories.data(value -> value, () -> new MultiReadable(Readables.iterator(IOFunctions.identity(), firstSource, secondSource)));
Header.Factory headerFactory = defaultFormatNodeFileHeader();
Extractors extractors = new Extractors(';');
// WHEN
CharSeeker seeker = CharSeekers.charSeeker(new MultiReadable(dataFactory.create(TABS).stream()), TABS, false);
Header header = headerFactory.create(seeker, TABS, IdType.ACTUAL, groups);
// THEN
assertArrayEquals(array(entry("id", Type.ID, extractors.long_()), entry("name", Type.PROPERTY, extractors.string()), entry("birth_date", Type.PROPERTY, extractors.long_())), header.entries());
seeker.close();
}
use of org.neo4j.csv.reader.CharReadable in project neo4j by neo4j.
the class CsvInputTest method shouldReportDuplicateSourceFileUsedAsBothNodeAndRelationshipSourceFile.
@Test
public void shouldReportDuplicateSourceFileUsedAsBothNodeAndRelationshipSourceFile() {
// given
String sourceDescription = "The single data source";
Supplier<CharReadable> nodeHeaderSource = () -> wrap(dataWithSourceDescription(":ID", "node source"), 3);
Supplier<CharReadable> relationshipHeaderSource = () -> wrap(dataWithSourceDescription(":START_ID,:END_ID,:TYPE", "relationship source"), 10);
Supplier<CharReadable> source = () -> wrap(dataWithSourceDescription("1,2,3", sourceDescription), 6);
Iterable<DataFactory> nodeData = datas(config -> new Data() {
@Override
public RawIterator<CharReadable, IOException> stream() {
return asRawIterator(iterator(nodeHeaderSource.get(), source.get()));
}
@Override
public Decorator decorator() {
return NO_DECORATOR;
}
});
Iterable<DataFactory> relationshipData = datas(config -> new Data() {
@Override
public RawIterator<CharReadable, IOException> stream() {
return asRawIterator(iterator(relationshipHeaderSource.get(), source.get()));
}
@Override
public Decorator decorator() {
return NO_DECORATOR;
}
});
CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
// when
new CsvInput(nodeData, defaultFormatNodeFileHeader(), relationshipData, defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
// then
verify(monitor).duplicateSourceFile(sourceDescription);
}
use of org.neo4j.csv.reader.CharReadable in project neo4j by neo4j.
the class CsvInputTest method shouldReportDuplicateNodeSourceFiles.
@Test
public void shouldReportDuplicateNodeSourceFiles() {
// given
String sourceDescription = "The single data source";
Supplier<CharReadable> source = () -> wrap(dataWithSourceDescription(":ID", sourceDescription), 3);
Iterable<DataFactory> data = datas(config -> new Data() {
@Override
public RawIterator<CharReadable, IOException> stream() {
// Contains two of the same file
return asRawIterator(iterator(source.get(), source.get()));
}
@Override
public Decorator decorator() {
return NO_DECORATOR;
}
});
CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
// when
new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
// then
verify(monitor).duplicateSourceFile(sourceDescription);
}
use of org.neo4j.csv.reader.CharReadable in project neo4j by neo4j.
the class CsvInputTest method shouldReportNoNodeLabels.
@Test
public void shouldReportNoNodeLabels() {
// given
String sourceDescription = "source";
Supplier<CharReadable> headerSource = () -> wrap(dataWithSourceDescription(":ID", sourceDescription), 3);
Iterable<DataFactory> data = datas(config -> new Data() {
@Override
public RawIterator<CharReadable, IOException> stream() {
return asRawIterator(iterator(headerSource.get()));
}
@Override
public Decorator decorator() {
return NO_DECORATOR;
}
});
CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
// when
new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
// then
verify(monitor).noNodeLabelsSpecified(sourceDescription);
}
use of org.neo4j.csv.reader.CharReadable in project neo4j by neo4j.
the class CsvInputTest method shouldReportDuplicateRelationshipSourceFiles.
@Test
public void shouldReportDuplicateRelationshipSourceFiles() {
// given
String sourceDescription = "The single data source";
Supplier<CharReadable> source = () -> wrap(dataWithSourceDescription(":START_ID,:END_ID,:TYPE", sourceDescription), 3);
Iterable<DataFactory> data = datas(config -> new Data() {
@Override
public RawIterator<CharReadable, IOException> stream() {
// Contains two of the same file
return asRawIterator(iterator(source.get(), source.get()));
}
@Override
public Decorator decorator() {
return NO_DECORATOR;
}
});
CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
// when
new CsvInput(datas(), defaultFormatNodeFileHeader(), data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
// then
verify(monitor).duplicateSourceFile(sourceDescription);
}
Aggregations