/*
 *
 *  * Copyright 2010-2014 Orient Technologies LTD (info(at)orientechnologies.com)
 *  *
 *  * Licensed under the Apache License, Version 2.0 (the "License");
 *  * you may not use this file except in compliance with the License.
 *  * You may obtain a copy of the License at
 *  *
 *  *      http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS,
 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  * See the License for the specific language governing permissions and
 *  * limitations under the License.
 *
 */

package com.orientechnologies.orient.etl.transformer;

import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.etl.ETLBaseTest;
import org.junit.Test;

import java.util.Date;
import java.util.List;

/**
 * Tests ETL CSV Transformer.
 *
 * @author Luca Garulli
 */
public class OCSVTransformerTest extends ETLBaseTest {

  @Test
  public void testEmpty() {
    String cfgJson = "{source: { content: { value: '' }  }, extractor : { json: {} }, loader: { test: {} } }";
    process(cfgJson);
    assertEquals(0, getResult().size());
  }

  @Test
  public void testOneObject() {
    process("{source: { content: { value: 'name,surname\nJay,Miner' } }, extractor : { row: {} }, transformers: [{ csv: {} }], loader: { test: {} } }");
    assertEquals(1, getResult().size());
    ODocument doc = getResult().get(0);
    assertEquals(2, doc.fields());
    assertEquals("Jay", doc.field("name"));
    assertEquals("Miner", doc.field("surname"));
  }

  @Test
  public void testSmallSet() {
    String content = "name,surname,id";
    for (int i = 0; i < names.length; ++i)
      content += "\n" + names[i] + "," + surnames[i] + "," + i;
    process("{source: { content: { value: '" + content + "' } }, extractor : { row: {} }, transformers: [{ csv: {} }], loader: { test: {} } }");

    assertEquals(getResult().size(), names.length);

    int i = 0;
    for (ODocument doc : getResult()) {
      assertEquals(3, doc.fields());
      assertEquals(names[i], doc.field("name"));
      assertEquals(surnames[i], doc.field("surname"));
      assertEquals(i, doc.field("id"));
      i++;
    }
  }
    @Test
    public void testDateTypeAutodetection(){
        String cfgJson = "{source: { content: { value: 'BirthDay\n2008-04-30' }  }, extractor : { row: {} }, transformers : [{ csv: {} }], loader: { test: {} } }";
        process(cfgJson);
        List<ODocument> res = getResult();
        ODocument doc = res.get(0);
        Date birthday = doc.field("BirthDay");
        assertEquals(2008, birthday.getYear());
        assertEquals(3, birthday.getMonth());
        assertEquals(30, birthday.getDate());
    }
}

@@ -2828,11 +2828,465 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testStringInDblQoutes() throws Exception %7B%0A        String cfgJson = %22%7Bsource: %7B content: %7B value: 'text%5Cn%5C%22Hello, quotes are here!%5C%22' %7D  %7D, extractor : %7B row: %7B%7D %7D, transformers : %5B%7B csv: %7B%7D %7D%5D, loader: %7B test: %7B%7D %7D %7D%22;%0A        process(cfgJson);%0A        List%3CODocument%3E res = getResult();%0A        ODocument doc = res.get(0);%0A        String text = doc.field(%22text%22);%0A        assertEquals(%22Hello, quotes are here!%22, text);%0A    %7D
 %0A%7D%0A

Add testStringInDblQuotes