Converter for JobParameters instances using a simple naming convention for property keys. Key names that are prefixed with a '-' are considered non-identifying and will not contribute to the identity of a JobInstance. Key names ending with "<type>" where type is one of string, date, long are converted to the corresponding type. The default type is string. E.g. schedule.date(date)=2007/12/11 department.id(long)=2345 The literal values are converted to the correct type using the default strategies, augmented if necessary by the custom editors provided. If you need to be able to parse and format local-specific dates and numbers, you can inject formatters (NumberStyles,LongNumberStyles,NumberFormat,DecimalFormat)
Inheritance: IJobParametersConverter
    public void GetJobParametersTest()
    {
        DefaultJobParametersConverter converter = new DefaultJobParametersConverter();
 
        NameValueCollection props2 = new NameValueCollection
        {
            {"+dateDebut(date)", "1970/07/31"},
            {"+everything(long)", "42"},
            {"-balance(double)", "1000.0"},
            {"+name(string)", "thierry"},
            {"-default", "default"},
            {"unmarked", "unmarked"}
        };
        JobParameters jobParameters2 = converter.GetJobParameters(props2);
        Assert.IsNotNull(jobParameters2);
        Assert.AreEqual(6,jobParameters2.GetParameters().Count);
        IDictionary<string, JobParameter> dico = jobParameters2.GetParameters();
        foreach (KeyValuePair<string, JobParameter> entry in dico)
        {
            string key = entry.Key;
            JobParameter value = entry.Value;
            Assert.IsFalse(key.StartsWith("-"));
            if ("dateDebut".Equals(key))
            {
                Assert.AreEqual(JobParameter.ParameterType.Date,value.Type);
                Assert.IsTrue(value.Identifying);
            }
            if ("everything".Equals(key))
            {
                Assert.AreEqual(JobParameter.ParameterType.Long, value.Type);
                Assert.IsTrue(value.Identifying);
            }
            if ("balance".Equals(key))
            {
                Assert.AreEqual(JobParameter.ParameterType.Double, value.Type);
                Assert.IsFalse(value.Identifying);
            }
            if ("name".Equals(key))
            {
                Assert.AreEqual(JobParameter.ParameterType.String, value.Type);
                Assert.IsTrue(value.Identifying);
            }
            if ("default".Equals(key))
            {
                Assert.AreEqual(JobParameter.ParameterType.String, value.Type);
                Assert.IsFalse(value.Identifying);
            }
            if ("unmarked".Equals(key))
            {
                Assert.AreEqual(JobParameter.ParameterType.String, value.Type);
                Assert.IsTrue(value.Identifying);
            }
        }
    }
        public void RunTestSynchronousExecutor()
        {            
            SimpleJobLauncher launcher = new SimpleJobLauncher();
            IJobInstanceDao jobInstanceDao = new MapJobInstanceDao();
            IJobExecutionDao jobExecutionDao = new MapJobExecutionDao();
            IStepExecutionDao stepExecutionDao = new MapStepExecutionDao();
            IExecutionContextDao executionContextDao = new MapExecutionContextDao();

            IJobRepository jobRepository =
                new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao, executionContextDao);
            launcher.JobRepository = jobRepository;

            DefaultJobParametersConverter converter = new DefaultJobParametersConverter();
            NameValueCollection props2 = new NameValueCollection
            {
                {"+dateDebut(date)", "1970/07/31"},
                {"+everything(long)", "42"},
                {"-balance(double)", "1000.0"},
                {"+name(string)", "thierry"},
                {"-default", "default"}
            };
            JobParameters jobParameters = converter.GetJobParameters(props2);

            IJob job = new SimpleJob("myTestJob");
            job.JobParametersValidator = new DummyValidator();
            job.Restartable = false;
            TaskletStep step = new TaskletStep("simpleTS")
            {
                JobRepository = jobRepository,
                Tasklet = new MyDummyTasklet()
            };
            ((SimpleJob)job).AddStep(step);
            ((SimpleJob) job).JobRepository = jobRepository;
            JobExecution jobExecution = launcher.Run(job, jobParameters);
            Assert.IsFalse(jobExecution.Status.IsUnsuccessful());
            Assert.IsFalse(jobExecution.Status.IsRunning()); 
        }
        public void GetPropertiesTest()
        {
            //OrderedDictionary<string, JobParameter> myJobP = new OrderedDictionary<string, JobParameter>
            IDictionary<string, JobParameter> myJobP = new Dictionary<string, JobParameter>
            {
                {"p1", new JobParameter("param1")},
                {"p2", new JobParameter(2)},
                {"p3", new JobParameter(3.0)},
                {"p4", new JobParameter(DateTime.Parse("1970-07-31"))}
            };

            JobParameters jp = new JobParameters(myJobP);
            DefaultJobParametersConverter converter = new DefaultJobParametersConverter();
            NameValueCollection props = converter.GetProperties(jp);
            Assert.IsNotNull(props);
            Assert.AreEqual(4,props.Count);
            foreach (string key in props.Keys)
            {
                string value = props[key];
                Assert.IsNotNull(value);
                if (key.Contains("p1"))
                {
                    Assert.AreEqual("p1", key);
                }
                if (key.Contains("p2"))
                {
                    Assert.AreEqual("p2(long)", key);
                }
                if (key.Contains("p3"))
                {
                    Assert.AreEqual("p3(double)", key);
                }
                if (key.Contains("p4"))
                {
                    Assert.AreEqual("p4(date)", key);
                }
            }
        }
        public void RunTestSystemCommandTasklet()
        {
            SimpleJobLauncher launcher = new SimpleJobLauncher();
            IJobInstanceDao jobInstanceDao = new MapJobInstanceDao();
            IJobExecutionDao jobExecutionDao = new MapJobExecutionDao();
            IStepExecutionDao stepExecutionDao = new MapStepExecutionDao();
            IExecutionContextDao executionContextDao = new MapExecutionContextDao();

            IJobRepository jobRepository =
                new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao, executionContextDao);
            launcher.JobRepository = jobRepository;

            DefaultJobParametersConverter converter = new DefaultJobParametersConverter();
            NameValueCollection props2 = new NameValueCollection
            {
                {"+dateDebut(date)", "1970/07/31"},
                {"+everything(long)", "42"},
                {"-balance(double)", "1000.0"},
                {"+name(string)", "thierry"},
                {"-default", "default"}
            };
            JobParameters jobParameters = converter.GetJobParameters(props2);

            IJob job = new SimpleJob("myTestJob");
            job.JobParametersValidator = new DummyValidator();
            job.Restartable = false;
            TaskletStep step = new TaskletStep("simpleTS") {JobRepository = jobRepository};
            SystemCommandTasklet tasklet = new SystemCommandTasklet
            {
                Command = "DEL MyDummyTasklet2_out_*.txt",
                WorkingDirectory = "C:/temp",
                Timeout = 10000000,
                SystemProcessExitCodeMapper = new SimpleSystemProcessExitCodeMapper()
            };
            step.Tasklet = tasklet;
            step.RegisterStepExecutionListener(tasklet);
            ((SimpleJob)job).AddStep(step);
            ((SimpleJob)job).JobRepository = jobRepository;
            ITaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
            launcher.TaskExecutor = taskExecutor;
            JobExecution jobExecution = launcher.Run(job, jobParameters);
            //wait for execution end (asynchronous)            
            Assert.IsFalse(jobExecution.Status.IsUnsuccessful());
            Assert.IsFalse(jobExecution.Status.IsRunning());
        }