public void setSrcfile(String srcfile) { fetchTask.setSrcfile(srcfile); }
@Test public void shouldReturnSrcFileWhenSrcFileIsNotEmpty() throws Exception { FetchTask fetchTask = new FetchTask(); fetchTask.setSrcfile("a.jar"); assertThat(fetchTask.getSrc(), is("a.jar")); }
@Test public void shouldIndicateSourceIsAFileBasedOnValuePopulated() { FetchTask fetchTask = new FetchTask(); fetchTask.setSrcfile("a.txt"); assertThat(fetchTask.isSourceAFile(), is(true)); FetchTask fetchTaskWithDir = new FetchTask(); fetchTaskWithDir.setSrcdir("/a/b"); assertThat(fetchTaskWithDir.isSourceAFile(), is(false)); }
private void validateAndAssertIncorrectPath(String source, boolean isSourceDir, String destination, String propertyName) { StageConfig stage = upstream.getFirstStageConfig(); JobConfig job = stage.getJobs().get(0); FetchTask task = new FetchTask(upstream.name(), stage.name(), job.name(), null, destination); if (isSourceDir) { task.setSrcdir(source); } else { task.setSrcfile(source); } task.validate(ConfigSaveValidationContext.forChain(config, new BasicPipelineConfigs(), upstream, stage, job)); assertThat(task.errors().isEmpty(), is(false)); String path = propertyName.equals(FetchTask.SRC) ? source : destination; String message = String.format("Task of job '%s' in stage '%s' of pipeline '%s' has %s path '%s' which is outside the working directory.", job.name(), stage.name(), upstream.name(), propertyName, path); assertThat(task.errors().on(propertyName), is(message)); }
public FetchTask toFetchTask(CRFetchArtifactTask crTask) { FetchTask fetchTask = new FetchTask( new CaseInsensitiveString(crTask.getPipelineName() == null ? "" : crTask.getPipelineName()), new CaseInsensitiveString(crTask.getStage()), new CaseInsensitiveString(crTask.getJob()), crTask.getSource(), crTask.getDestination()); if (crTask.sourceIsDirectory()) { fetchTask.setSrcdir(crTask.getSource()); fetchTask.setSrcfile(null); } setCommonTaskMembers(fetchTask, crTask); return fetchTask; }
@Test public void shouldPopulateErrorIfBothSrcFileAndSrcDirAreNotDefined() { FetchTask task = new FetchTask(new CaseInsensitiveString("upstream"), new CaseInsensitiveString("stage"), new CaseInsensitiveString("job"), "src_file", "dest"); task.setSrcfile(null); task.validate(ConfigSaveValidationContext.forChain(config, upstream, upstream.getStage(new CaseInsensitiveString("stage")))); assertThat(task.errors().isEmpty(), is(false)); assertThat(task.errors().on(FetchTask.SRC), is("Should provide either srcdir or srcfile")); }
@Test public void shouldPopulateErrorOnSrcFileOrSrcDirOrDestIfIsNotAValidFilePathPattern() { FetchTask task = new FetchTask(new CaseInsensitiveString("upstream"), new CaseInsensitiveString("stage"), new CaseInsensitiveString("job"), "..", ".."); StageConfig stage = upstream.getStage(new CaseInsensitiveString("stage")); ValidationContext context = ConfigSaveValidationContext.forChain(config, new BasicPipelineConfigs(), upstream, stage, stage.getJobs().first()); task.validate(context); assertThat(task.errors().isEmpty(), is(false)); assertThat(task.errors().on(FetchTask.SRC), is("Task of job 'job' in stage 'stage' of pipeline 'upstream' has src path '..' which is outside the working directory.")); assertThat(task.errors().on(FetchTask.DEST), is("Task of job 'job' in stage 'stage' of pipeline 'upstream' has dest path '..' which is outside the working directory.")); task.setSrcfile(null); task.setSrcdir(".."); task.validate(context); assertThat(task.errors().on(FetchTask.SRC), is("Task of job 'job' in stage 'stage' of pipeline 'upstream' has src path '..' which is outside the working directory.")); }