Search in sources :

Example 86 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class PipelineConfigsServiceTest method shouldReturnXmlForGivenGroup_onGetXml.

@Test
public void shouldReturnXmlForGivenGroup_onGetXml() {
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    String groupName = "group_name";
    new GoConfigMother().addPipelineWithGroup(cruiseConfig, groupName, "pipeline_name", "stage_name", "job_name");
    when(goConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
    when(securityService.isUserAdminOfGroup(validUser.getUsername(), groupName)).thenReturn(true);
    String actualXml = service.getXml(groupName, validUser, result);
    String expectedXml = "<pipelines group=\"group_name\">\n  <pipeline name=\"pipeline_name\">\n    <materials>\n      <svn url=\"file:///tmp/foo\" />\n    </materials>\n    <stage name=\"stage_name\">\n      <jobs>\n        <job name=\"job_name\">\n          <tasks>\n            <ant />\n          </tasks>\n        </job>\n      </jobs>\n    </stage>\n  </pipeline>\n</pipelines>";
    assertThat(actualXml, is(expectedXml));
    assertThat(result.isSuccessful(), is(true));
    verify(goConfigService, times(1)).getConfigForEditing();
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 87 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class MaterialUpdateServiceIntegrationTest method configWithMaterial.

private CruiseConfig configWithMaterial(SvnMaterialConfig goodMaterial) {
    CruiseConfig config = new BasicCruiseConfig();
    new GoConfigMother().addPipeline(config, "good-pipeline", "first-stage", new MaterialConfigs(goodMaterial));
    return config;
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother)

Example 88 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class ConfigMaterialUpdateListenerIntegrationTest method shouldCheckoutNewMaterial.

@Test
public void shouldCheckoutNewMaterial() throws Exception {
    GoConfigMother mother = new GoConfigMother();
    PipelineConfig pipelineConfig = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0);
    configTestRepo.addPipelineToRepositoryAndPush("pipe1.gocd.xml", pipelineConfig);
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    File flyweightDir = materialRepository.folderFor(material);
    assertThat(flyweightDir.exists(), is(true));
    assertThat(new File(flyweightDir, "pipe1.gocd.xml").exists(), is(true));
}
Also used : File(java.io.File) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 89 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class ConfigMaterialUpdateListenerIntegrationTest method shouldParseAndLoadValidPartialConfig.

@Test
public void shouldParseAndLoadValidPartialConfig() throws Exception {
    String fileName = "pipe1.gocd.xml";
    GoConfigMother mother = new GoConfigMother();
    PipelineConfig pipelineConfig = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0);
    configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    PartialConfig partial = goConfigRepoConfigDataSource.latestPartialConfigForMaterial(materialConfig);
    assertNotNull(partial);
    assertThat(partial.getGroups().get(0).size(), is(1));
    assertThat(partial.getGroups().get(0).get(0), is(pipelineConfig));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 90 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class ConfigMaterialUpdateListenerIntegrationTest method shouldNotMergeFromInvalidConfigRepository_AndShouldKeepLastValidPart.

@Test
public void shouldNotMergeFromInvalidConfigRepository_AndShouldKeepLastValidPart() throws Exception {
    String fileName = "pipe1.gocd.xml";
    GoConfigMother mother = new GoConfigMother();
    PipelineConfig pipelineConfig = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0);
    configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    cachedGoConfig.forceReload();
    assertThat(goConfigService.hasPipelineNamed(pipelineConfig.name()), is(true));
    assertThat(goConfigService.pipelineConfigNamed(pipelineConfig.name()), is(pipelineConfig));
    configTestRepo.addCodeToRepositoryAndPush("badPipe.gocd.xml", "added bad config file", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<cruise xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"cruise-config.xsd\" schemaVersion=\"38\">\n" + "<pipelines group=\"changed\">\n" + "  <pipeline name=\"badPipe\">\n" + "    <materials>\n" + "      <svn url=\"file:///tmp/foo\" />\n" + "      <svn url=\"file:///tmp/foo\" />\n" + "    </materials>\n" + "  </pipeline>\n" + "</pipelines>" + "</cruise>");
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    cachedGoConfig.forceReload();
    // but we still have the old part
    assertThat(goConfigService.hasPipelineNamed(pipelineConfig.name()), is(true));
    assertThat(goConfigService.pipelineConfigNamed(pipelineConfig.name()), is(pipelineConfig));
    // and no trace of badPipe
    assertThat(goConfigService.hasPipelineNamed(new CaseInsensitiveString("badPipe")), is(false));
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Aggregations

GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)102 Test (org.junit.jupiter.api.Test)64 Username (com.thoughtworks.go.server.domain.Username)30 BeforeEach (org.junit.jupiter.api.BeforeEach)19 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)13 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)12 File (java.io.File)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)8 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 SCM (com.thoughtworks.go.domain.scm.SCM)4 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)3 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)3 Configuration (com.thoughtworks.go.domain.config.Configuration)3 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)3