@Override public EnvironmentPipelineMatcher createMatcher() { return new EnvironmentPipelineMatcher(name, agents.getUuids(), pipelines); }
public boolean match(String pipelineName, String uuid) { return hasPipeline(pipelineName) && hasAgent(uuid); }
public boolean equals(Object that) { if (this == that) { return true; } if (that == null) { return false; } if (getClass() != that.getClass()) { return false; } return equals((EnvironmentPipelineMatcher) that); }
public String envForPipeline(String pipelineName) { for (EnvironmentPipelineMatcher matcher : matchers) { if (matcher.hasPipeline(pipelineName)) { return CaseInsensitiveString.str(matcher.name()); } } return null; }
@Test public void shouldMatchPipelineNameIgnoringCase() { EnvironmentPipelineMatcher matcher = new EnvironmentPipelineMatcher(new CaseInsensitiveString("env"), Arrays.asList("uuid1", "uuid2"), new EnvironmentPipelinesConfig() {{ add(new EnvironmentPipelineConfig(new CaseInsensitiveString("pipeline1"))); add(new EnvironmentPipelineConfig(new CaseInsensitiveString("pipeline2"))); }}); assertThat(matcher.hasPipeline(jobPlan("PipeLine1").getPipelineName()), is(true)); assertThat(matcher.hasPipeline(jobPlan("PIPELINE1").getPipelineName()), is(true)); assertThat(matcher.hasPipeline(jobPlan("PIPELine1").getPipelineName()), is(true)); assertThat(matcher.hasPipeline(jobPlan("PipeLine2").getPipelineName()), is(true)); }
private boolean pipelineReferenced(String pipelineName) { for(EnvironmentPipelineMatcher matcher : this) { if (matcher.hasPipeline(pipelineName)) { return true; } } return false; } }
public boolean match(String pipelineName, String uuid) { for(EnvironmentPipelineMatcher matcher : this) { if (matcher.match(pipelineName, uuid)) { return true; } } return !pipelineReferenced(pipelineName) && !agentReferenced(uuid); }
private boolean agentReferenced(String uuid) { for(EnvironmentPipelineMatcher matcher : this) { if (matcher.hasAgent(uuid)) { return true; } } return false; }
@Test public void shouldCreateMatcherWhenNoPipelines() throws Exception { EnvironmentPipelineMatcher pipelineMatcher = environmentConfig.createMatcher(); assertThat(pipelineMatcher.match("pipeline", AGENT_UUID), is(false)); }
@Override public EnvironmentPipelineMatcher createMatcher() { return new EnvironmentPipelineMatcher(this.name(), this.getAgents().getUuids(), this.getPipelines()); }
@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 shouldLoadConfigWithPipelinesMatchingUpWithPipelineDefinitionCaseInsensitively() throws Exception { String content = configWithEnvironments( "<environments>" + " <environment name='uat'>" + " <pipelines>" + " <pipeline name='piPeline1'/>" + " </pipelines>" + " </environment>" + "</environments>"); EnvironmentsConfig environmentsConfig = ConfigMigrator.loadWithMigration(content).config.getEnvironments(); EnvironmentPipelineMatcher matcher = environmentsConfig.matchersForPipeline("pipeline1"); assertThat(matcher, is(new EnvironmentPipelineMatcher(new CaseInsensitiveString("uat"), new ArrayList<>(), new EnvironmentPipelinesConfig(new CaseInsensitiveString("piPeline1"))))); }
}}; assertThat(matchers, hasItem(new EnvironmentPipelineMatcher(new CaseInsensitiveString("uat"), uat_uuids, new EnvironmentPipelinesConfig()))); assertThat(matchers, hasItem(new EnvironmentPipelineMatcher(new CaseInsensitiveString("prod"), prod_uuids, new EnvironmentPipelinesConfig())));
}}; assertThat(matchers, hasItem(new EnvironmentPipelineMatcher(new CaseInsensitiveString("uat"), uat_uuids, new EnvironmentPipelinesConfig()))); assertThat(matchers, hasItem(new EnvironmentPipelineMatcher(new CaseInsensitiveString("prod"), prod_uuids, new EnvironmentPipelinesConfig())));