package com.marklogic.hector.examples;

import com.google.common.annotations.VisibleForTesting;
import com.marklogic.hector.ImportDelimitedFileJob;
import com.marklogic.junit.Fragment;
import com.marklogic.spring.batch.test.AbstractJobRunnerTest;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration(classes = { ImportDelimitedFileJob.class })
public class ImportNycBabiesTest extends AbstractJobRunnerTest {

    private JobParametersBuilder jpb = new JobParametersBuilder();

    @Before
    public void initJobParameters() {
        jpb.addString("input_file_path", ".\\src\\test\\resources\\baby-names.csv");
        jpb.addString("delimited_root_name", "baby-name");
        jpb.addString("output_collections", "baby-name");
        jpb.addString("output_transform", "com.marklogic.hector.examples.babies.BabyNameColumnMapSerializer");
    }

    @Test
    public void ingestDelimitedBabyNamesDefaultThreadAndChunkSizeTest() throws Exception {
        JobExecution jobExecution = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
        getClientTestHelper().assertCollectionSize("Expecting 199 files in baby-name collection", "baby-name", 199);
    }

    @Test
    public void ingestDelimitedBabyNamesWithUriTransformTest() throws Exception {
        jpb.addString("uri_transform", "com.marklogic.hector.examples.babies.BabyNameUriGenerator");
        JobExecution jobExecution = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
        getClientTestHelper().assertCollectionSize("Expecting 199 files in baby-name collection", "baby-name", 199);
        getClientTestHelper().parseUri("2011-HAZEL.xml", "baby-name");
    }

    @Test
    public void ingestBabyNamesToJsonTest() throws Exception {
        jpb.addString("document_type", "json");
        JobExecution jobExecution = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
        getClientTestHelper().assertCollectionSize("Expecting 199 files in baby-name collection", "baby-name", 199);

    }

    @Test
    public void ingestBabyNamesWithDefaultDelimitedRootNameTest() throws Exception {
        JobParametersBuilder jpb = new JobParametersBuilder();
        jpb.addString("input_file_path", ".\\src\\test\\resources\\baby-names.csv");
        jpb.addString("output_collections", "baby-name");
        jpb.addString("uri_transform", "com.marklogic.hector.examples.babies.BabyNameUriGenerator");
        JobExecution jobExecution = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
        getClientTestHelper().assertCollectionSize("Expecting 199 files in baby-name collection", "baby-name", 199);
        Fragment f = getClientTestHelper().parseUri("2011-HAZEL.xml", "baby-name");
        f.assertElementExists("Expecting default delimited root name", "/record");


    }



    @Test
    public void ingestBabyNamesWithUriIdTest() throws Exception {
        jpb.addString("input_file_path", ".\\src\\test\\resources\\Most_Popular_Baby_Names_NYC.csv");
        jpb.addString("delimited_root_name", "baby-name");
        jpb.addString("document_type", "xml");
        jpb.addString("output_collections", "baby-name");
        jpb.addString("uri_id", "NM");
        JobExecution jobExecution = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
        getClientTestHelper().assertCollectionSize("Expecting 2811 files in baby-name collection", "baby-name", 2811);
        getClientTestHelper().parseUri("ALEC", "baby-name");
    }

}



@@ -37,64 +37,8 @@
 s;%0A%0A
-import com.google.common.annotations.VisibleForTesting;%0A
 impo
@@ -288,61 +288,8 @@
 on;%0A
-import org.springframework.batch.core.JobParameters;%0A
 impo
@@ -863,115 +863,776 @@
 %22);%0A
-        jpb.addString(%22output_transform%22, %22com.marklogic.hector.examples.babies.BabyNameColumnMapSerializer
+%0A    %7D%0A%0A    @Test%0A    public void ingestDelimitedBabyNamesWithOutputTransformTest() throws Exception %7B%0A        jpb.addString(%22uri_transform%22, %22com.marklogic.hector.examples.babies.BabyNameUriGenerator%22);%0A        jpb.addString(%22output_transform%22, %22com.marklogic.hector.examples.babies.BabyNameColumnMapSerializer%22);%0A        JobExecution jobExecution = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());%0A        getClientTestHelper().assertCollectionSize(%22Expecting 199 files in baby-name collection%22, %22baby-name%22, 199);%0A        Fragment f = getClientTestHelper().parseUri(%222011-HAZEL.xml%22, %22baby-name%22);%0A        f.assertElementExists(%22Expecting birth year%22, %22/baby-name/birthYear%22);%0A        f.assertElementExists(%22Expecting birth year%22, %22/baby-name/create_date
 %22);%0A
@@ -3576,18 +3576,16 @@
 %0A    %7D%0A%0A
-%0A%0A
     @Tes
@@ -3656,274 +3656,8 @@
 n %7B%0A
-        jpb.addString(%22input_file_path%22, %22.%5C%5Csrc%5C%5Ctest%5C%5Cresources%5C%5CMost_Popular_Baby_Names_NYC.csv%22);%0A        jpb.addString(%22delimited_root_name%22, %22baby-name%22);%0A        jpb.addString(%22document_type%22, %22xml%22);%0A        jpb.addString(%22output_collections%22, %22baby-name%22);%0A
     
@@ -3899,20 +3899,19 @@
 -name%22, 
-2811
+199
 );%0A     
@@ -3949,12 +3949,13 @@
 ri(%22
-ALEC
+HAZEL
 %22, %22

Add test for output_transform