private JobConfigs toJobConfigs(Collection<CRJob> jobs) { JobConfigs jobConfigs = new JobConfigs(); for (CRJob crJob : jobs) { jobConfigs.add(toJobConfig(crJob)); } return jobConfigs; }
private static void setJobs(JsonReader jsonReader, StageConfig stageConfig) { JobConfigs allJobs = new JobConfigs(); jsonReader.readArrayIfPresent("jobs", jobs -> { jobs.forEach(job -> { allJobs.add(JobRepresenter.fromJSON(new JsonReader(job.getAsJsonObject()))); }); }); stageConfig.setJobs(allJobs); } }
private static void setJobs(JsonReader jsonReader, StageConfig stageConfig) { JobConfigs allJobs = new JobConfigs(); jsonReader.readArrayIfPresent("jobs", jobs -> { jobs.forEach(job -> { allJobs.add(JobRepresenter.fromJSON(new JsonReader(job.getAsJsonObject()))); }); }); stageConfig.setJobs(allJobs); } }
private static JobConfigs defaultBuildPlans(String... planNames) { JobConfigs plans = new JobConfigs(); for (String name : planNames) { plans.add(defaultBuildPlan(name)); } return plans; }
@Test public void shouldBombIfABuildPlanWithSameNameIsAdded() throws Exception { JobConfigs jobConfigs = new JobConfigs(); jobConfigs.add(jobConfig("Test")); try { jobConfigs.add(jobConfig("Test")); fail("Should not be able to add build plan with the same name again"); } catch (RuntimeException ignored) { } }
@Test public void shouldBombIfABuildPlanWithSameNameWithDifferentCaseIsAdded() throws Exception { JobConfigs jobConfigs = new JobConfigs(); jobConfigs.add(jobConfig("Test")); try { jobConfigs.add(jobConfig("test")); fail("Should not be able to add build plan with the same name again"); } catch (RuntimeException ignored) { } }
public static StageConfig stageConfigWithParams(String stageName, String paramName) { StageConfig stageConfig = StageConfigMother.stageConfig(stageName); ArrayList<EnvironmentVariableConfig> environmentVariableConfigs = new ArrayList<>(); environmentVariableConfigs.add(new EnvironmentVariableConfig("env1", "#{" + paramName + "}")); stageConfig.setVariables(new EnvironmentVariablesConfig(environmentVariableConfigs)); stageConfig.getJobs().add(JobConfigMother.jobConfig()); return stageConfig; }
@Test public void shouldGetJobConfigByJobName() { JobConfigs configs = new JobConfigs(); JobConfig expected = new JobConfig("job-1"); configs.add(expected); configs.add(new JobConfig("job-2")); JobConfig actual = configs.getJob(new CaseInsensitiveString("job-1")); assertThat(actual, is(expected)); assertThat(configs.getJob(new CaseInsensitiveString("some-junk")), is(nullValue())); } }
@Test public void shouldFindBuildPlanByName() { JobConfigs jobConfigs = new JobConfigs(); jobConfigs.add(jobConfig("Test")); assertThat(jobConfigs.containsName(new CaseInsensitiveString("Poo")), is(false)); }
public static PipelineConfig pipelineWithElasticJob(String... elasticProfileIds) { PipelineConfig pipelineConfig = pipelineConfig(UUID.randomUUID().toString()); pipelineConfig.first().getJobs().clear(); for (String elasticProfileId : elasticProfileIds) { pipelineConfig.first().getJobs().add(JobConfigMother.elasticJob(elasticProfileId)); } return pipelineConfig; }
@Test public void shouldFindCorrectJobIfJobIsOnAllAgents() throws Exception { JobConfig allAgentsJob = new JobConfig("job-for-all-agents"); allAgentsJob.setRunOnAllAgents(true); JobConfigs jobs = new JobConfigs(); jobs.add(allAgentsJob); jobs.add(new JobConfig("job")); StageConfig stage = new StageConfig(new CaseInsensitiveString("stage-name"), jobs); JobConfig found = stage.jobConfigByInstanceName("job-for-all-agents-" + RunOnAllAgentsJobTypeConfig.MARKER + "-1", true); assertThat(found, is(allAgentsJob)); }
@Test public void shouldClearExistingJobsWhenNullGivenAsAttributeMap() throws Exception{ JobConfigs jobs = new JobConfigs(); jobs.add(new JobConfig("quux")); jobs.setConfigAttributes(null); assertThat(jobs.size(), is(0)); }
@Test public void shouldFindCorrectJobIfJobIsOnAllAgentsAndAmbiguousName() throws Exception { JobConfig allAgentsJob = new JobConfig("job-for-all-agents"); JobConfig ambiguousJob = new JobConfig("job-for-all"); allAgentsJob.setRunOnAllAgents(true); ambiguousJob.setRunOnAllAgents(true); JobConfigs jobs = new JobConfigs(); jobs.add(ambiguousJob); jobs.add(allAgentsJob); StageConfig stage = new StageConfig(new CaseInsensitiveString("stage-name"), jobs); JobConfig found = stage.jobConfigByInstanceName(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("job-for-all-agents", 1), true); assertThat(found, is(allAgentsJob)); }
private StageConfig completedStage() { JobConfigs plans = new JobConfigs(); plans.add(new JobConfig("completed")); return new StageConfig(new CaseInsensitiveString("completed stage"), plans); }
@Test public void shouldNotBombIfABuildPlanWithSameNameIsSetAgain() throws Exception { JobConfigs jobConfigs = new JobConfigs(); jobConfigs.add(jobConfig("Test")); jobConfigs.set(0, jobConfig("Test")); }
public static StageConfig stageConfigWithEnvironmentVariable(String stageName) { StageConfig stageConfig = StageConfigMother.stageConfig(stageName); stageConfig.setVariables(EnvironmentVariablesConfigMother.environmentVariables()); stageConfig.getJobs().add(JobConfigMother.jobConfig()); return stageConfig; }
private CruiseConfig cruiseConfigWithProperties(ArtifactPropertyConfig... artifactPropertyConfigs) throws Exception { CruiseConfig cruiseConfig = loader.loadConfigHolder(ONE_PIPELINE).configForEdit; JobConfig jobConfig = BuildPlanMother.withArtifactPropertiesGenerator(artifactPropertyConfigs); cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1")).first().allBuildPlans().add(jobConfig); return cruiseConfig; }
@Test public void shouldAddJobsGivenInTheAttributesMapAfterClearingExistingJobs() throws Exception{ JobConfigs jobs = new JobConfigs(); jobs.add(new JobConfig("quux")); jobs.setConfigAttributes(a(m(JobConfig.NAME, "foo"), m(JobConfig.NAME, "bar"))); assertThat(jobs.get(0).name(), is(new CaseInsensitiveString("foo"))); assertThat(jobs.get(1).name(), is(new CaseInsensitiveString("bar"))); assertThat(jobs.size(), is(2)); }
public static JobConfigs jobConfigs(String... buildNames) { JobConfigs jobConfigs = new JobConfigs(); for (String buildName : buildNames) { jobConfigs.add(new JobConfig(new CaseInsensitiveString(buildName), new ResourceConfigs(), new ArtifactConfigs())); } return jobConfigs; }
public static JobConfigs withBuildPlans(String... jobConfigNames) { JobConfigs jobConfigs = new JobConfigs(); for (String planName : jobConfigNames) { jobConfigs.add(new JobConfig(new CaseInsensitiveString(planName), new ResourceConfigs(), new ArtifactConfigs())); } return jobConfigs; }