@Override public void addPipeline(CaseInsensitiveString pipelineName) { this.getFirstEditablePart().addPipeline(pipelineName); }
public void addPipelinesToEnvironment(String environmentName, String ... pipelineNames) { EnvironmentConfig environment = getOrCreateEnvironment(environmentName); for (String pipelineName : pipelineNames) { environment.addPipeline(new CaseInsensitiveString(pipelineName)); } }
@Test public void shouldUpdatePipelines() { environmentConfig.addPipeline(new CaseInsensitiveString("baz")); environmentConfig.setConfigAttributes(Collections.singletonMap(BasicEnvironmentConfig.PIPELINES_FIELD, Arrays.asList(Collections.singletonMap("name", "foo"), Collections.singletonMap("name", "bar")))); assertThat(environmentConfig.getPipelineNames(), is(Arrays.asList(new CaseInsensitiveString("foo"), new CaseInsensitiveString("bar")))); }
@Test public void shouldReturnPipelineNamesContainedInIt() throws Exception { environmentConfig.addPipeline(new CaseInsensitiveString("deployment")); environmentConfig.addPipeline(new CaseInsensitiveString("testing")); List<CaseInsensitiveString> pipelineNames = environmentConfig.getPipelineNames(); assertThat(pipelineNames.size(), is(2)); assertThat(pipelineNames, hasItem(new CaseInsensitiveString("deployment"))); assertThat(pipelineNames, hasItem(new CaseInsensitiveString("testing"))); }
@Test public void shouldReturnFalseThatNotEmptyWhenHasPipeline() { environmentConfig.addPipeline(new CaseInsensitiveString("pipe")); assertThat(environmentConfig.isEnvironmentEmpty(), is(false)); } @Test
@Test public void shouldReturnPipelineNamesFrom2Parts() throws Exception { pairEnvironmentConfig.get(0).addPipeline(new CaseInsensitiveString("deployment")); pairEnvironmentConfig.get(1).addPipeline(new CaseInsensitiveString("testing")); List<CaseInsensitiveString> pipelineNames = pairEnvironmentConfig.getPipelineNames(); assertThat(pipelineNames.size(), is(2)); assertThat(pipelineNames, hasItem(new CaseInsensitiveString("deployment"))); assertThat(pipelineNames, hasItem(new CaseInsensitiveString("testing"))); }
@Test public void shouldNotRepeatPipelineNamesFrom2Parts() throws Exception { pairEnvironmentConfig.get(0).addPipeline(new CaseInsensitiveString("deployment")); pairEnvironmentConfig.get(1).addPipeline(new CaseInsensitiveString("deployment")); List<CaseInsensitiveString> pipelineNames = pairEnvironmentConfig.getPipelineNames(); assertThat(pipelineNames, hasItem(new CaseInsensitiveString("deployment"))); }
@Test public void shouldReturnEmptyForRemotePipelinesWhenIsLocal() { environmentConfig.addPipeline(new CaseInsensitiveString("pipe")); assertThat(environmentConfig.getRemotePipelines().isEmpty(), is(true)); }
@Test public void getRemotePipelines_shouldReturnEmptyWhenOnlyLocalPartHasPipelines() { uatLocalPart2.addPipeline(new CaseInsensitiveString("pipe")); assertThat(pairEnvironmentConfig.getRemotePipelines().isEmpty(), is(true)); }
@Test public void shouldDeduplicateRepeatedPipelinesFrom2Parts() throws Exception { pairEnvironmentConfig.get(0).addPipeline(new CaseInsensitiveString("deployment")); pairEnvironmentConfig.get(1).addPipeline(new CaseInsensitiveString("deployment")); List<CaseInsensitiveString> pipelineNames = pairEnvironmentConfig.getPipelineNames(); assertThat(pipelineNames.size(), is(1)); assertTrue(pairEnvironmentConfig.containsPipeline(new CaseInsensitiveString("deployment"))); }
@Test public void hasSamePipelinesAs_shouldReturnTrueWhenAnyPipelineNameIsEqualToOther(){ pairEnvironmentConfig.get(0).addPipeline(new CaseInsensitiveString("pipe1")); pairEnvironmentConfig.get(1).addPipeline(new CaseInsensitiveString("pipe2")); BasicEnvironmentConfig config = new BasicEnvironmentConfig(); config.addPipeline(new CaseInsensitiveString("pipe2")); assertThat(pairEnvironmentConfig.hasSamePipelinesAs(config),is(true)); }
@Test public void hasSamePipelinesAs_shouldReturnFalseWhenNoneOfOtherPipelinesIsEqualToOther(){ pairEnvironmentConfig.get(0).addPipeline(new CaseInsensitiveString("pipe1")); pairEnvironmentConfig.get(1).addPipeline(new CaseInsensitiveString("pipe2")); BasicEnvironmentConfig config = new BasicEnvironmentConfig(); config.addPipeline(new CaseInsensitiveString("pipe3")); assertThat(pairEnvironmentConfig.hasSamePipelinesAs(config),is(false)); }
@Test public void shouldCreateMatcherWhenPipelinesGiven() throws Exception { environmentConfig.addPipeline(new CaseInsensitiveString("pipeline")); environmentConfig.addAgent(AGENT_UUID); EnvironmentPipelineMatcher pipelineMatcher = environmentConfig.createMatcher(); assertThat(pipelineMatcher.match("pipeline", AGENT_UUID), is(true)); }
@Test public void shouldNotLockAPipelineWhenItIsAddedToAnEnvironment() throws Exception { CruiseConfig config = GoConfigMother.configWithPipelines("pipeline-1"); EnvironmentConfig env = config.addEnvironment("environment"); env.addPipeline(new CaseInsensitiveString("pipeline-1")); assertThat(config.isPipelineLockable("pipeline-1"), is(false)); }
@Test public void shouldValidateDuplicatePipelines() throws Exception { pairEnvironmentConfig.get(0).addPipeline(new CaseInsensitiveString("up42")); pairEnvironmentConfig.get(1).addPipeline(new CaseInsensitiveString("up42")); pairEnvironmentConfig.validate(ConfigSaveValidationContext.forChain(pairEnvironmentConfig)); assertThat(pairEnvironmentConfig.errors().isEmpty(), is(false)); assertThat(pairEnvironmentConfig.errors().firstError(), Matchers.is("Environment pipeline 'up42' is defined more than once.")); }
@Test public void shouldReturnAllPipelinesForRemotePipelinesWhenIsRemote() { environmentConfig.setOrigins(new RepoConfigOrigin()); environmentConfig.addPipeline(new CaseInsensitiveString("pipe")); assertThat(environmentConfig.getRemotePipelines().isEmpty(), is(false)); }
@Override public void update(CruiseConfig configForEdit) throws Exception { EnvironmentConfig environmentConfig = configForEdit.getEnvironments().named(this.environmentConfig.name()); for (String uuid : agentsToAdd) { environmentConfig.addAgent(uuid); } for (String uuid : agentsToRemove) { environmentConfig.removeAgent(uuid); } for (String pipelineName : pipelinesToAdd) { environmentConfig.addPipeline(new CaseInsensitiveString(pipelineName)); } for (String pipelineName : pipelinesToRemove) { environmentConfig.removePipeline(new CaseInsensitiveString(pipelineName)); } for (EnvironmentVariableConfig variableConfig : envVarsToAdd) { environmentConfig.addEnvironmentVariable(variableConfig); } for (String variableName : envVarsToRemove) { environmentConfig.getVariables().removeIfExists(variableName); } }