package de.tblsoft.solr.pipeline.pipeline;

import de.tblsoft.solr.pipeline.PipelineExecuter;
import de.tblsoft.solr.pipeline.test.AbstractPipelineTest;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;

/**
 * Created by tblsoft on 11.05.16.
 */
public class CsvWriterTest extends AbstractPipelineTest {

    @Test
    public void writeCsv() throws Exception {
        PipelineExecuter executer = new PipelineExecuter("examples/unittest/csv-writer-pipeline.yaml");
        executer.execute();

        String actual = FileUtils.readFileToString(new File("examples/unittest/output.csv"));
        String expected = FileUtils.readFileToString(new File("examples/unittest/expected.csv"));



        System.out.println(getHex(actual));
        System.out.println("---------------");
        System.out.println(getHex(expected));

        Assert.assertEquals(expected, actual);

        FileUtils.deleteQuietly(new File("examples/unittest/output.csv"));

    }

    String getHex(String value ) throws Exception {
        String hexString = Hex.encodeHexString(value.getBytes("UTF-8"));
        return hexString;


    }
}

@@ -150,52 +150,8 @@
 st;%0A
-import org.apache.commons.codec.binary.Hex;%0A
 impo
@@ -255,16 +255,39 @@
 io.File;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -579,22 +579,28 @@
         
+List%3C
 String
+%3E
  actual 
@@ -611,36 +611,29 @@
 leUtils.read
-FileToString
+Lines
 (new File(%22e
@@ -672,22 +672,28 @@
         
+List%3C
 String
+%3E
  expecte
@@ -714,20 +714,13 @@
 read
-FileToString
+Lines
 (new
@@ -766,430 +766,130 @@
 );%0A%0A
-%0A%0A        System.out.println(getHex(actual));%0A        System.out.println(%22---------------%22);%0A        System.out.println(getHex(expected));%0A%0A        Assert.assertEquals(expected, actual);%0A%0A        FileUtils.deleteQuietly(new File(%22examples/unittest/output.csv%22));%0A%0A    %7D%0A%0A    String getHex(String value ) throws Exception %7B%0A        String hexString = Hex.encodeHexString(value.getBytes(%22UTF-8%22));%0A        return hexString;%0A
+        Assert.assertEquals(expected, actual);%0A%0A        FileUtils.deleteQuietly(new File(%22examples/unittest/output.csv%22));
 %0A%0A  

add test for csv writer and implement some bugfixes