Package org.apache.commons.csv

Examples of org.apache.commons.csv.CSVRecord


public class CsvToKeyValueMapperTest {

    @Test
    public void testCsvLineParser() throws IOException {
        CsvToKeyValueMapper.CsvLineParser lineParser = new CsvToKeyValueMapper.CsvLineParser(';');
        CSVRecord parsed = lineParser.parse("one;two");

        assertEquals("one", parsed.get(0));
        assertEquals("two", parsed.get(1));
        assertTrue(parsed.isConsistent());
        assertEquals(1, parsed.getRecordNumber());
    }
View Full Code Here


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        ImmutableBytesWritable outputKey = new ImmutableBytesWritable();
        try {
            CSVRecord csvRecord = null;
            try {
                csvRecord = csvLineParser.parse(value.toString());
            } catch (IOException e) {
                context.getCounter(COUNTER_GROUP_NAME, "CSV Parser errors").increment(1L);
            }
View Full Code Here

        verifyNoMoreInteractions(preparedStatement);
    }

    @Test
    public void testExecute_TooFewFields() throws Exception {
        CSVRecord csvRecordWithTooFewFields = createCsvRecord("123,NameValue");
        upsertExecutor.execute(csvRecordWithTooFewFields);

        verify(upsertListener).errorOnRecord(eq(csvRecordWithTooFewFields), anyString());
        verifyNoMoreInteractions(upsertListener);
    }
View Full Code Here

        verifyNoMoreInteractions(upsertListener);
    }

    @Test
    public void testExecute_TooManyFields() throws Exception {
        CSVRecord csvRecordWithTooManyFields = createCsvRecord("123,NameValue,42,1:2:3,Garbage");
        upsertExecutor.execute(csvRecordWithTooManyFields);

        verify(upsertListener).upsertDone(1L);
        verifyNoMoreInteractions(upsertListener);
View Full Code Here

        verifyNoMoreInteractions(preparedStatement);
    }

    @Test
    public void testExecute_InvalidType() throws Exception {
        CSVRecord csvRecordWithInvalidType = createCsvRecord("123,NameValue,ThisIsNotANumber,1:2:3");
        upsertExecutor.execute(csvRecordWithInvalidType);

        verify(upsertListener).errorOnRecord(eq(csvRecordWithInvalidType), anyString());
        verifyNoMoreInteractions(upsertListener);
    }
View Full Code Here

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        ImmutableBytesWritable outputKey = new ImmutableBytesWritable();
        try {
            CSVRecord csvRecord = null;
            try {
                csvRecord = csvLineParser.parse(value.toString());
            } catch (IOException e) {
                context.getCounter(COUNTER_GROUP_NAME, "CSV Parser errors").increment(1L);
            }
View Full Code Here

    @SuppressWarnings("deprecation")
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        ImmutableBytesWritable outputKey = new ImmutableBytesWritable();
        try {
            CSVRecord csvRecord = null;
            try {
                csvRecord = csvLineParser.parse(value.toString());
            } catch (IOException e) {
                context.getCounter(COUNTER_GROUP_NAME, "CSV Parser errors").increment(1L);
            }
View Full Code Here

    @SuppressWarnings("deprecation")
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        ImmutableBytesWritable outputKey = new ImmutableBytesWritable();
        try {
            CSVRecord csvRecord = null;
            try {
                csvRecord = csvLineParser.parse(value.toString());
            } catch (IOException e) {
                context.getCounter(COUNTER_GROUP_NAME, "CSV Parser errors").increment(1L);
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.csv.CSVRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.