@Test public void testWorkingDirectory() throws Exception { File notExistingFile = new File("not-existing-path"); Assert.state(!notExistingFile.exists(), "not-existing-path does actually exist"); try { tasklet.setWorkingDirectory(notExistingFile.getCanonicalPath()); fail(); } catch (IllegalArgumentException e) { // expected } File notDirectory = File.createTempFile(this.getClass().getName(), null); Assert.state(notDirectory.exists(), "The file does not exist"); Assert.state(!notDirectory.isDirectory(), "The file is actually a directory"); try { tasklet.setWorkingDirectory(notDirectory.getCanonicalPath()); fail(); } catch (IllegalArgumentException e) { // expected } File directory = notDirectory.getParentFile(); Assert.state(directory.exists(), "The directory does not exist"); Assert.state(directory.isDirectory(), "The directory is not a directory"); // no error expected now tasklet.setWorkingDirectory(directory.getCanonicalPath()); }
private void initializeTasklet() { tasklet = new SystemCommandTasklet(); tasklet.setEnvironmentParams(null); // inherit from parent process tasklet.setWorkingDirectory(null); // inherit from parent process tasklet.setSystemProcessExitCodeMapper(new SimpleSystemProcessExitCodeMapper()); tasklet.setTimeout(5000); // long enough timeout tasklet.setTerminationCheckInterval(500); tasklet.setCommand("invalid command, change value for successful execution"); tasklet.setInterruptOnCancel(true); tasklet.setTaskExecutor(new SimpleAsyncTaskExecutor()); }