/**
 * Copyright (C) 2011 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.util.csv;

import static org.testng.AssertJUnit.assertEquals;

import java.util.List;

import org.fudgemsg.FudgeContext;
import org.fudgemsg.FudgeMsg;
import org.fudgemsg.MutableFudgeMsg;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.google.common.collect.Lists;
import com.opengamma.util.fudgemsg.OpenGammaFudgeContext;

@Test
public class CSVDocumentReaderTest {
  
  private static final FudgeContext s_fudgeContext = OpenGammaFudgeContext.getInstance();
  private List<FudgeMsg> _expectedRows;
  
  @BeforeMethod
  public void setUp() {
    
    _expectedRows = Lists.newArrayList();
    
    MutableFudgeMsg row = s_fudgeContext.newMessage();
    row.add("Name", "Kirk");
    row.add("JobTitle", "CEO");
    _expectedRows.add(row);
    
    row = s_fudgeContext.newMessage();
    row.add("Name", "Jim");
    row.add("JobTitle", "CTO");
    _expectedRows.add(row);
    
    row = s_fudgeContext.newMessage();
    row.add("Name", "Elaine");
    row.add("JobTitle", "CQO");
    _expectedRows.add(row);
    
    row = s_fudgeContext.newMessage();
    row.add("Name", "Andrew");
    row.add("JobTitle", "Engineer");
    _expectedRows.add(row);
    
    row = s_fudgeContext.newMessage();
    row.add("Name", "Alan");
    _expectedRows.add(row);
    
  }
  
  public void csvReader() {
    List<FudgeMsg> actualRows = Lists.newArrayList();
    
    CSVDocumentReader reader = new CSVDocumentReader(CSVDocumentReaderTest.class.getResource("test_csv_document_read.csv"));
    for (FudgeMsg row : reader) {
      actualRows.add(row);
    }
    assertEquals(_expectedRows, actualRows);        
  }

}

@@ -697,16 +697,51 @@
 edRows;%0A
+  CSVDocumentReader _csvDocReader;%0A
   %0A  @Be
@@ -1490,123 +1490,18 @@
  %0A  
-%7D%0A  %0A  public void csvReader() %7B%0A    List%3CFudgeMsg%3E actualRows = Lists.newArrayList();%0A    %0A    CSVDocumentReader r
+  _csvDocR
 eade
@@ -1598,16 +1598,105 @@
 csv%22));%0A
+    %0A  %7D%0A  %0A  public void read() %7B%0A    List%3CFudgeMsg%3E actualRows = Lists.newArrayList();%0A
     for 
@@ -1711,17 +1711,24 @@
 g row : 
-r
+_csvDocR
 eader) %7B
@@ -1817,12 +1817,75 @@
     %0A  %7D
+%0A  %0A  public void multipleReads() %7B%0A    read();%0A    read();%0A  %7D
 %0A%0A%7D%0A

add test for multiple reads