package be.raildelays.batch;

import com.excilys.ebi.spring.dbunit.config.DBOperation;
import com.excilys.ebi.spring.dbunit.test.DataSet;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.batch.test.MetaDataInstanceFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

@DirtiesContext
// Because of issue [SPR-8849] (https://jira.springsource.org/browse/SPR-8849)
@ContextConfiguration(locations = {"/jobs/handle-max-months-job-context.xml"})
public class HandleDelayMoreThanOneHourIT extends AbstractContextIT {

    /**
     * SUT.
     */
    @Autowired
    private JobLauncherTestUtils jobLauncherTestUtils;

    @Test
    public void testCompleted() throws Exception {
        final Map<String, JobParameter> parameters = new HashMap<>();

        parameters.put("input.file.path", new JobParameter("train-list.properties"));
        parameters.put("date", new JobParameter(new SimpleDateFormat("dd/MM/yyyy").parse("01/01/2000")));
        parameters.put("station.a.name", new JobParameter("Liège-Guillemins"));
        parameters.put("station.b.name", new JobParameter("Brussels (Bruxelles)-Central"));
        parameters.put("excel.output.path", new JobParameter("./output.xls"));
        parameters.put("excel.input.template", new JobParameter(new ClassPathResource("template.xls").getFile().getAbsolutePath()));
        parameters.put("mail.account.username", new JobParameter("alexis.soumagne@gmail.com"));
        parameters.put("mail.account.password", new JobParameter("BRU338 tcpqriow"));
        parameters.put("mail.account.address", new JobParameter("alexis.soumagne@gmail.com"));
        parameters.put("mail.server.host", new JobParameter("smtp.gmail.com"));
        parameters.put("mail.server.port", new JobParameter("465"));
        parameters.put("lang", new JobParameter("en"));

        JobExecution jobExecution = getJobLauncherTestUtils().launchJob(new JobParameters(parameters));

        Assert.assertFalse(jobExecution.getStatus().isUnsuccessful());
    }

}

@@ -1481,18 +1481,20 @@
 ut(%22
-input.file
+excel.output
 .pat
@@ -1519,28 +1519,19 @@
 er(%22
-train-list.propertie
+./output.xl
 s%22))
@@ -1560,928 +1560,274 @@
 ut(%22
-date%22, new JobParameter(new SimpleDateFormat(%22dd/MM/yyyy%22).parse(%2201/01/2000%22)));%0A        parameters.put(%22station.a.name%22, new JobParameter(%22Li%C3%A8ge-Guillemins%22));%0A        parameters.put(%22station.b.name%22, new JobParameter(%22Brussels (Bruxelles)-Central%22));%0A        parameters.put(%22excel.output.path%22, new JobParameter(%22./output.xls%22));%0A        parameters.put(%22excel.input.template%22, new JobParameter(new ClassPathResource(%22template.xls%22).getFile().getAbsolutePath()));%0A        parameters.put(%22mail.account.username%22, new JobParameter(%22alexis.soumagne@gmail.com%22));%0A        parameters.put(%22mail.account.password%22, new JobParameter(%22BRU338 tcpqriow%22));%0A        parameters.put(%22mail.account.address%22, new JobParameter(%22alexis.soumagne@gmail.com%22));%0A        parameters.put(%22mail.server.host%22, new JobParameter(%22smtp.gmail.com%22));%0A        parameters.put(%22mail.server.port%22, new JobParameter(%22465%22));%0A        parameters.put(%22lang
+excel.archive.path%22, new JobParameter(%22./#%7Bjava.time.LocalDate.now().toString()%7D/retard_sncb.xls%22));%0A        parameters.put(%22excel.input.template%22, new JobParameter(new ClassPathResource(%22template.xls%22).getFile().getAbsolutePath()));%0A        parameters.put(%22language
 %22, n

Split before / split after a threshold date