@Override public Properties getProperties(JobParameters params) { return PropertiesConverter.stringToProperties("a=b"); } });
@Test public void testEscapedColon() throws Exception { Properties props = new Properties(); props.setProperty("test", "C:/test"); String str = PropertiesConverter.propertiesToString(props); props = PropertiesConverter.stringToProperties(str); assertEquals("C:/test", props.getProperty("test")); }
if (!contains(stringToParse, "\n")) { stringToParse = StringUtils.arrayToDelimitedString( StringUtils.commaDelimitedListToStringArray(stringToParse), "\n");
@Override public String getParameters(long executionId) throws NoSuchJobExecutionException { JobExecution jobExecution = findExecutionById(executionId); return PropertiesConverter.propertiesToString(jobParametersConverter.getProperties(jobExecution .getJobParameters())); }
/** * Null or empty properties should be converted to empty String */ @Test public void testPropertiesToStringNull() { string = PropertiesConverter.propertiesToString(null); assertEquals("", string); string = PropertiesConverter.propertiesToString(new Properties()); assertEquals("", string); }
/** * Create a {@link JobExecution} with the parameters provided. * * @param jobName the name of the job * @param instanceId the Id of the {@link JobInstance} * @param executionId the id for the {@link JobExecution} * @param jobParameters comma or new line separated name=value pairs * @return a {@link JobExecution} */ public static JobExecution createJobExecution(String jobName, Long instanceId, Long executionId, String jobParameters) { JobParameters params = new DefaultJobParametersConverter().getJobParameters(PropertiesConverter .stringToProperties(jobParameters)); return createJobExecution(jobName, instanceId, executionId, params); }
/** * Check that Properties can be converted to String and back correctly. */ @Test public void testTwoWayRegularConversion() { Properties storedProps = new Properties(); storedProps.setProperty("key1", "value1"); storedProps.setProperty("key2", "value2"); props = PropertiesConverter.stringToProperties(PropertiesConverter.propertiesToString(storedProps)); assertEquals(storedProps, props); }
/** * Check that Properties can be comma delimited with extra whitespace. */ @Test public void testShortConversionWithCommas() { Properties storedProps = new Properties(); storedProps.setProperty("key1", "value1"); storedProps.setProperty("key2", "value2"); String value = PropertiesConverter.propertiesToString(storedProps); assertTrue("Wrong value: "+value, value.contains("key1=value1")); assertTrue("Wrong value: "+value, value.contains("key2=value2")); assertEquals(1, StringUtils.countOccurrencesOf(value, ",")); }
if (!contains(stringToParse, "\n")) { stringToParse = StringUtils.arrayToDelimitedString( StringUtils.commaDelimitedListToStringArray(stringToParse), "\n");
/** * Check that Properties can be newline delimited. */ @Test public void testRegularConversionWithCommaAndNewline() { Properties storedProps = new Properties(); storedProps.setProperty("key1", "value1"); storedProps.setProperty("key2", "value2"); props = PropertiesConverter.stringToProperties("key1=value1\n key2=value2"); assertEquals(storedProps, props); }
/** * @param oldParameters the latest job parameters * @return a String representation for rendering the job parameters from the last * instance */ private String fromJobParameters(JobParameters oldParameters) { String properties = PropertiesConverter.propertiesToString(converter.getProperties(oldParameters)); if (properties.startsWith("#")) { properties = properties.substring(properties.indexOf(LINE_SEPARATOR) + LINE_SEPARATOR.length()); } properties = properties.replace("\\:", ":"); return properties; }
/** * Check that Properties can be comma delimited with extra whitespace. */ @Test public void testRegularConversionWithCommaAndWhitespace() { Properties storedProps = new Properties(); storedProps.setProperty("key1", "value1"); storedProps.setProperty("key2", "value2"); props = PropertiesConverter.stringToProperties("key1=value1, key2=value2"); assertEquals(storedProps, props); }
/** * @param oldParameters the latest job parameters * @return a String representation for rendering the job parameters from the last * instance */ private String fromJobParameters(JobParameters oldParameters) { String properties = PropertiesConverter.propertiesToString(converter.getProperties(oldParameters)); if (properties.startsWith("#")) { properties = properties.substring(properties.indexOf(LINE_SEPARATOR) + LINE_SEPARATOR.length()); } properties = properties.replace("\\:", ":"); return properties; }
/** * Check that Properties can be comma delimited. */ @Test public void testRegularConversionWithComma() { Properties storedProps = new Properties(); storedProps.setProperty("key1", "value1"); storedProps.setProperty("key2", "value2"); props = PropertiesConverter.stringToProperties("key1=value1,key2=value2"); assertEquals(storedProps, props); }
/** * @param oldParameters the latest job parameters * @return a String representation for rendering the job parameters from the * last instance */ public String fromJobParameters(JobParameters oldParameters) { String properties = PropertiesConverter.propertiesToString(converter.getProperties(oldParameters)); if (properties.startsWith("#")) { properties = properties.substring(properties.indexOf(LINE_SEPARATOR) + LINE_SEPARATOR.length()); } properties = properties.replace("\\:", ":"); return properties; }
@Override public Long start(String jobName, String parameters) throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException { logger.info("Checking status of job with name=" + jobName); JobParameters jobParameters = jobParametersConverter.getJobParameters(PropertiesConverter .stringToProperties(parameters)); if (jobRepository.isJobInstanceExists(jobName, jobParameters)) { throw new JobInstanceAlreadyExistsException(String.format( "Cannot start a job instance that already exists with name=%s and parameters=%s", jobName, parameters)); } Job job = jobRegistry.getJob(jobName); logger.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, parameters)); try { return jobLauncher.run(job, jobParameters).getId(); } catch (JobExecutionAlreadyRunningException e) { throw new UnexpectedJobExecutionException(String.format(ILLEGAL_STATE_MSG, "job execution already running", jobName, parameters), e); } catch (JobRestartException e) { throw new UnexpectedJobExecutionException(String.format(ILLEGAL_STATE_MSG, "job not restartable", jobName, parameters), e); } catch (JobInstanceAlreadyCompleteException e) { throw new UnexpectedJobExecutionException(String.format(ILLEGAL_STATE_MSG, "job already complete", jobName, parameters), e); } }
/** * @param oldParameters the latest job parameters * @return a String representation for rendering the job parameters from the last * instance */ private String fromJobParameters(JobParameters oldParameters) { String properties = PropertiesConverter.propertiesToString(converter.getProperties(oldParameters)); if (properties.startsWith("#")) { properties = properties.substring(properties.indexOf(LINE_SEPARATOR) + LINE_SEPARATOR.length()); } properties = properties.replace("\\:", ":"); return properties; }
/** * Null String should be converted to empty Properties */ @Test public void testStringToPropertiesNull() { props = PropertiesConverter.stringToProperties(null); assertNotNull(props); assertEquals("properties are empty", 0, props.size()); }
/** * @param oldParameters the latest job parameters * @return a String representation for rendering the job parameters from the * last instance */ public String fromJobParameters(JobParameters oldParameters) { String properties = PropertiesConverter.propertiesToString(converter.getProperties(oldParameters)); if (properties.startsWith("#")) { properties = properties.substring(properties.indexOf(LINE_SEPARATOR) + LINE_SEPARATOR.length()); } properties = properties.replace("\\:", ":"); return properties; }
private JobExecution runJobForRestartTest() throws Exception { return jobLauncherTestUtils .launchJob(new DefaultJobParametersConverter() .getJobParameters(PropertiesConverter .stringToProperties("run.id(long)=1,parameter=true,run.date=20070122,input.file=classpath:data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt"))); } }