Search in sources :

Example 1 with Environment

use of com.thoughtworks.go.presentation.pipelinehistory.Environment in project gocd by gocd.

the class EnvironmentService method addEnvironmentFor.

void addEnvironmentFor(CaseInsensitiveString environmentName, Username username, ArrayList<Environment> environments) throws NoSuchEnvironmentException {
    List<CaseInsensitiveString> pipelines = environmentConfigService.pipelinesFor(environmentName);
    if (pipelines.isEmpty()) {
        environments.add(new Environment(CaseInsensitiveString.str(environmentName), new ArrayList<>()));
        return;
    }
    List<PipelineModel> pipelineInstanceModels = getPipelinesInstanceForEnvironment(pipelines, username);
    if (!pipelineInstanceModels.isEmpty()) {
        environments.add(new Environment(CaseInsensitiveString.str(environmentName), pipelineInstanceModels));
    }
}
Also used : ArrayList(java.util.ArrayList) Environment(com.thoughtworks.go.presentation.pipelinehistory.Environment) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PipelineModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineModel)

Example 2 with Environment

use of com.thoughtworks.go.presentation.pipelinehistory.Environment in project gocd by gocd.

the class EnvironmentServiceTest method shouldReturnAllTheEnvironments.

@Test
public void shouldReturnAllTheEnvironments() throws Exception {
    when(environmentConfigService.environmentNames()).thenReturn(Arrays.asList(new CaseInsensitiveString("uat"), new CaseInsensitiveString("preprod")));
    when(environmentConfigService.pipelinesFor(new CaseInsensitiveString("uat"))).thenReturn(Arrays.asList(new CaseInsensitiveString("uat-pipeline"), new CaseInsensitiveString("staging-pipeline")));
    when(environmentConfigService.pipelinesFor(new CaseInsensitiveString("preprod"))).thenReturn(Arrays.asList(new CaseInsensitiveString("preprod-pipeline")));
    stubPipelineHistoryServiceToReturnPipelines("uat-pipeline", "preprod-pipeline", "staging-pipeline");
    List<Environment> environments = environmentService.getEnvironments(USER_FOO);
    assertThat(environments.size(), is(2));
    assertThat(environments.get(0).getPipelineModels().size(), is(2));
    assertThat(environments.get(1).getPipelineModels().size(), is(1));
}
Also used : Environment(com.thoughtworks.go.presentation.pipelinehistory.Environment) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 3 with Environment

use of com.thoughtworks.go.presentation.pipelinehistory.Environment in project gocd by gocd.

the class EnvironmentServiceTest method shouldAddEnvironmentsThatHaveNoPipelinesConfigured.

@Test
public void shouldAddEnvironmentsThatHaveNoPipelinesConfigured() throws Exception {
    when(environmentConfigService.environmentNames()).thenReturn(Arrays.asList(new CaseInsensitiveString("uat"), new CaseInsensitiveString("preprod")));
    when(environmentConfigService.pipelinesFor(new CaseInsensitiveString("uat"))).thenReturn(new ArrayList<>());
    when(environmentConfigService.pipelinesFor(new CaseInsensitiveString("preprod"))).thenReturn(Arrays.asList(new CaseInsensitiveString("preprod-pipeline")));
    stubPipelineHistoryServiceToReturnPipelines("preprod-pipeline");
    List<Environment> environments = environmentService.getEnvironments(USER_FOO);
    assertThat(environments.size(), is(2));
    assertThat(environments.get(0).getPipelineModels().size(), is(0));
    assertThat(environments.get(1).getPipelineModels().size(), is(1));
}
Also used : Environment(com.thoughtworks.go.presentation.pipelinehistory.Environment) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 4 with Environment

use of com.thoughtworks.go.presentation.pipelinehistory.Environment in project gocd by gocd.

the class EnvironmentServiceTest method shouldReturnPipelineHistoryForPipelinesInAnEnvironment.

@Test
public void shouldReturnPipelineHistoryForPipelinesInAnEnvironment() throws Exception {
    Username username = new Username(new CaseInsensitiveString("Foo"));
    when(environmentConfigService.pipelinesFor(new CaseInsensitiveString("uat"))).thenReturn(Arrays.asList(new CaseInsensitiveString("uat-pipeline"), new CaseInsensitiveString("staging-pipeline")));
    PipelineInstanceModel uatInstance = stubPipelineHistoryServiceToReturnPipelines("uat-pipeline");
    PipelineInstanceModel stagingInstance = stubPipelineHistoryServiceToReturnPipelines("staging-pipeline");
    ArrayList<Environment> environments = new ArrayList<>();
    environmentService.addEnvironmentFor(new CaseInsensitiveString("uat"), username, environments);
    assertThat(environments.size(), is(1));
    Environment environment = environments.get(0);
    assertThat(environment.getName(), is("uat"));
    List<PipelineModel> models = environment.getPipelineModels();
    assertThat(models.size(), is(2));
    PipelineModel model1 = new PipelineModel(uatInstance.getName(), true, true, PipelinePauseInfo.notPaused());
    model1.addPipelineInstance(uatInstance);
    assertThat(models, hasItem(model1));
    PipelineModel model2 = new PipelineModel(stagingInstance.getName(), true, true, PipelinePauseInfo.notPaused());
    model2.addPipelineInstance(stagingInstance);
    assertThat(models, hasItem(model2));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) ArrayList(java.util.ArrayList) Environment(com.thoughtworks.go.presentation.pipelinehistory.Environment) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PipelineModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineModel) Test(org.junit.Test)

Example 5 with Environment

use of com.thoughtworks.go.presentation.pipelinehistory.Environment in project gocd by gocd.

the class EnvironmentServiceTest method shouldOmitEnvironmentsHavePipelinesConfiguredButHaveNoPermissionsOnThePipelines.

@Test
public void shouldOmitEnvironmentsHavePipelinesConfiguredButHaveNoPermissionsOnThePipelines() throws Exception {
    when(environmentConfigService.environmentNames()).thenReturn(Arrays.asList(new CaseInsensitiveString("uat"), new CaseInsensitiveString("preprod")));
    when(environmentConfigService.pipelinesFor(new CaseInsensitiveString("uat"))).thenReturn(Arrays.asList(new CaseInsensitiveString("staging-pipeline")));
    when(environmentConfigService.pipelinesFor(new CaseInsensitiveString("preprod"))).thenReturn(Arrays.asList(new CaseInsensitiveString("preprod-pipeline")));
    stubPipelineHistoryServiceToReturnPipelines("preprod-pipeline");
    when(pipelineHistoryService.latest("staging-pipeline", USER_FOO)).thenReturn(null);
    List<Environment> environments = environmentService.getEnvironments(USER_FOO);
    assertThat(environments.size(), is(1));
    assertThat(environments.get(0).getPipelineModels().size(), is(1));
}
Also used : Environment(com.thoughtworks.go.presentation.pipelinehistory.Environment) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)6 Environment (com.thoughtworks.go.presentation.pipelinehistory.Environment)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 PipelineModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineModel)2 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)1 Username (com.thoughtworks.go.server.domain.Username)1