package org.embulk.parser.joni;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.embulk.EmbulkTestRuntime;
import org.embulk.config.ConfigSource;
import org.embulk.spi.Exec;
import org.embulk.spi.util.Newline;
import org.joda.time.DateTimeZone;
import org.junit.Rule;
import org.junit.Test;

import java.nio.charset.Charset;

import static junit.framework.TestCase.assertEquals;

public class TestJoniParserPlugin
{
    @Rule
    public EmbulkTestRuntime runtime = new EmbulkTestRuntime();

    @Test
    public void checkDefaultValues() {
        ConfigSource config = Exec.newConfigSource()
                .set("columns", ImmutableList.of(
                        ImmutableMap.of(
                                "name", "name",
                                "type", "string")))
                .set("format", "(?<name>a*)");

        JoniParserPlugin.PluginTask task = config.loadConfig(JoniParserPlugin.PluginTask.class);

        assertEquals(Charset.forName("utf-8"), task.getCharset());
        assertEquals(Newline.CRLF, task.getNewline());
        assertEquals(DateTimeZone.UTC, task.getDefaultTimeZone());
        assertEquals("%Y-%m-%d %H:%M:%S.%N %z", task.getDefaultTimestampFormat());
        assertEquals( false, task.getStopOnInvalidRecord());
        //assertEquals( true, task.getDefaultTypecast());

    }

}

@@ -158,16 +158,58 @@
 untime;%0A
+import org.embulk.config.ConfigException;%0A
 import o
@@ -1422,10 +1422,671 @@
 %0A    %7D%0A%0A
+    @Test(expected = ConfigException.class)%0A    public void checkColumnsRequired()%0A    %7B%0A        ConfigSource config = Exec.newConfigSource()%0A                .set(%22format%22, %22(?%3Cname%3Ea*)%22);%0A%0A        config.loadConfig(JoniParserPlugin.PluginTask.class);%0A    %7D%0A%0A    @Test(expected = ConfigException.class)%0A    public void checkFormatRequired()%0A    %7B%0A        ConfigSource config = Exec.newConfigSource()%0A                .set(%22columns%22, ImmutableList.of(%0A                        ImmutableMap.of(%0A                                %22name%22, %22name%22,%0A                                %22type%22, %22string%22)));%0A%0A        config.loadConfig(JoniParserPlugin.PluginTask.class);%0A    %7D%0A
 %7D%0A

Add tests for required config.