public static CruiseConfig configWith(PipelineConfig... pipelineConfigs) { BasicPipelineConfigs configs = new BasicPipelineConfigs(); configs.setGroup("defaultGroup"); configs.addAll(Arrays.asList(pipelineConfigs)); return new BasicCruiseConfig(configs); }
@Test public void shouldGenerateAMapOfAllPipelinesAndTheirParentDependencies() { /* * -----+ p2 --> p4 * p1 * -----+ p3 * * */ PipelineConfig p1 = createPipelineConfig("p1", "s1", "j1"); PipelineConfig p2 = createPipelineConfig("p2", "s2", "j1"); p2.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p1"), new CaseInsensitiveString("s1"))); PipelineConfig p3 = createPipelineConfig("p3", "s3", "j1"); p3.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p1"), new CaseInsensitiveString("s1"))); PipelineConfig p4 = createPipelineConfig("p4", "s4", "j1"); p4.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p2"), new CaseInsensitiveString("s2"))); pipelines.addAll(asList(p4, p2, p1, p3)); Map<CaseInsensitiveString, List<PipelineConfig>> expectedPipelines = cruiseConfig.generatePipelineVsDownstreamMap(); assertThat(expectedPipelines.size(), is(4)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p1")), hasItems(p2, p3)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p2")), hasItems(p4)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p3")).isEmpty(), is(true)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p4")).isEmpty(), is(true)); }
@Test public void shouldGenerateAMapOfAllPipelinesAndTheirParentDependencies_WhenAllPipelinesInMapAreLocal() { /* * -----+ p2 --> p4 * p1 * -----+ p3 * * */ PipelineConfig p1 = createPipelineConfig("p1", "s1", "j1"); PipelineConfig p2 = createPipelineConfig("p2", "s2", "j1"); p2.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p1"), new CaseInsensitiveString("s1"))); PipelineConfig p3 = createPipelineConfig("p3", "s3", "j1"); p3.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p1"), new CaseInsensitiveString("s1"))); PipelineConfig p4 = createPipelineConfig("p4", "s4", "j1"); p4.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p2"), new CaseInsensitiveString("s2"))); pipelines.addAll(Arrays.asList(p4, p2, p1, p3)); cruiseConfig = new BasicCruiseConfig(new BasicCruiseConfig(pipelines), PartialConfigMother.withPipelineInGroup("remote-pipe-1", "remote_group")); Map<CaseInsensitiveString, List<PipelineConfig>> expectedPipelines = cruiseConfig.generatePipelineVsDownstreamMap(); assertThat(expectedPipelines.size(), is(5)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p1")), hasItems(p2, p3)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p2")), hasItems(p4)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p3")).isEmpty(), is(true)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p4")).isEmpty(), is(true)); assertThat(expectedPipelines.get(new CaseInsensitiveString("remote-pipe-1")).isEmpty(), is(true)); }
@Test public void shouldGenerateAMapOfAllPipelinesAndTheirParentDependencies_WhenThereAreRemotePipelinesInMap() { /* * -----+ p2 --> p4 * p1 * -----+ p3 --> remote-pipe-1 * * */ PipelineConfig p1 = createPipelineConfig("p1", "s1", "j1"); PipelineConfig p2 = createPipelineConfig("p2", "s2", "j1"); p2.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p1"), new CaseInsensitiveString("s1"))); PipelineConfig p3 = createPipelineConfig("p3", "s3", "j1"); p3.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p1"), new CaseInsensitiveString("s1"))); PipelineConfig p4 = createPipelineConfig("p4", "s4", "j1"); p4.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p2"), new CaseInsensitiveString("s2"))); pipelines.addAll(Arrays.asList(p4, p2, p1, p3)); PipelineConfig remotePipe1 = createPipelineConfig("remote-pipe-1", "s5", "j1"); remotePipe1.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p3"), new CaseInsensitiveString("s3"))); PartialConfig part = new PartialConfig(); part.getGroups().addPipeline("remoteGroup", remotePipe1); cruiseConfig = new BasicCruiseConfig(new BasicCruiseConfig(pipelines), part); Map<CaseInsensitiveString, List<PipelineConfig>> expectedPipelines = cruiseConfig.generatePipelineVsDownstreamMap(); assertThat(expectedPipelines.size(), is(5)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p1")), hasItems(p2, p3)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p2")), hasItems(p4)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p3")), hasItems(remotePipe1)); assertThat(expectedPipelines.get(new CaseInsensitiveString("remote-pipe-1")).isEmpty(), is(true)); assertThat(expectedPipelines.get(new CaseInsensitiveString("p4")).isEmpty(), is(true)); }
@Test public void shouldCheckCyclicDependency() throws Exception { PipelineConfig p1 = createPipelineConfig("p1", "s1", "j1"); PipelineConfig p2 = createPipelineConfig("p2", "s2", "j1"); p2.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p1"), new CaseInsensitiveString("s1"))); PipelineConfig p3 = createPipelineConfig("p3", "s3", "j1"); p3.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p2"), new CaseInsensitiveString("s2"))); p1.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p3"), new CaseInsensitiveString("s3"))); pipelines.addAll(Arrays.asList(p1, p2, p3)); BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines); ConfigReposConfig reposConfig = new ConfigReposConfig(); GitMaterialConfig configRepo = new GitMaterialConfig("http://git"); reposConfig.add(new ConfigRepoConfig(configRepo, "myplug")); mainCruiseConfig.setConfigRepos(reposConfig); PartialConfig partialConfig = PartialConfigMother.withPipeline("pipe2"); cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, partialConfig); cruiseConfig.validate(mock(ValidationContext.class)); List<ConfigErrors> allErrors = cruiseConfig.getAllErrors(); assertThat((allErrors.get(0).on("base")), is("Circular dependency: p1 <- p2 <- p3 <- p1")); }