Search in sources :

Example 91 with SvnMaterialConfig

use of com.thoughtworks.go.config.materials.svn.SvnMaterialConfig in project gocd by gocd.

the class ScheduledPipelineLoaderIntegrationTest method shouldSetAServerHealthMessageWhenMaterialForPipelineWithBuildCauseIsNotFound.

@Test
public void shouldSetAServerHealthMessageWhenMaterialForPipelineWithBuildCauseIsNotFound() throws IllegalArtifactLocationException, IOException {
    JobConfig jobConfig = new JobConfig("job-one");
    jobConfig.addTask(new AntTask());
    PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("last", new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(jobConfig)));
    pipelineConfig.materialConfigs().clear();
    SvnMaterialConfig onDirOne = MaterialConfigsMother.svnMaterialConfig("google.com", "dirOne", "loser", "boozer", false, "**/*.html");
    final P4MaterialConfig onDirTwo = MaterialConfigsMother.p4MaterialConfig("host:987654321", "zoozer", "secret", "through-the-window", true);
    onDirTwo.setConfigAttributes(Collections.singletonMap(ScmMaterialConfig.FOLDER, "dirTwo"));
    pipelineConfig.addMaterialConfig(onDirOne);
    pipelineConfig.addMaterialConfig(onDirTwo);
    configHelper.addPipeline(pipelineConfig);
    Pipeline building = PipelineMother.building(pipelineConfig);
    final Pipeline pipeline = dbHelper.savePipelineWithMaterials(building);
    CruiseConfig cruiseConfig = configHelper.currentConfig();
    PipelineConfig cfg = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("last"));
    cfg.removeMaterialConfig(cfg.materialConfigs().get(1));
    configHelper.writeConfigFile(cruiseConfig);
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPipeline("last")).size(), is(0));
    final long jobId = pipeline.getStages().get(0).getJobInstances().get(0).getId();
    Date currentTime = new Date(System.currentTimeMillis() - 1);
    Pipeline loadedPipeline = null;
    try {
        loadedPipeline = loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
        fail("should not have loaded pipeline with build-cause as one of the necessary materials was not found");
    } catch (Exception e) {
        assertThat(e, is(instanceOf(StaleMaterialsOnBuildCause.class)));
        assertThat(e.getMessage(), is("Cannot load job 'last/" + pipeline.getCounter() + "/stage/1/job-one' because material " + onDirTwo + " was not found in config."));
    }
    assertThat(loadedPipeline, is(nullValue()));
    JobInstance reloadedJobInstance = jobInstanceService.buildById(jobId);
    assertThat(reloadedJobInstance.getState(), is(JobState.Completed));
    assertThat(reloadedJobInstance.getResult(), is(JobResult.Failed));
    HealthStateScope scope = HealthStateScope.forJob("last", "stage", "job-one");
    assertThat(serverHealthService.filterByScope(scope).size(), is(1));
    ServerHealthState error = serverHealthService.filterByScope(HealthStateScope.forJob("last", "stage", "job-one")).get(0);
    assertThat(error, is(ServerHealthState.error("Cannot load job 'last/" + pipeline.getCounter() + "/stage/1/job-one' because material " + onDirTwo + " was not found in config.", "Job for pipeline 'last/" + pipeline.getCounter() + "/stage/1/job-one' has been failed as one or more material configurations were either changed or removed.", HealthStateType.general(HealthStateScope.forJob("last", "stage", "job-one")))));
    DateTime expiryTime = (DateTime) ReflectionUtil.getField(error, "expiryTime");
    assertThat(expiryTime.toDate().after(currentTime), is(true));
    assertThat(expiryTime.toDate().before(new Date(System.currentTimeMillis() + 5 * 60 * 1000 + 1)), is(true));
    String logText = FileUtils.readFileToString(consoleService.consoleLogArtifact(reloadedJobInstance.getIdentifier()), UTF_8);
    assertThat(logText, containsString("Cannot load job 'last/" + pipeline.getCounter() + "/stage/1/job-one' because material " + onDirTwo + " was not found in config."));
    assertThat(logText, containsString("Job for pipeline 'last/" + pipeline.getCounter() + "/stage/1/job-one' has been failed as one or more material configurations were either changed or removed."));
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) StaleMaterialsOnBuildCause(com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause) Date(java.util.Date) IllegalArtifactLocationException(com.thoughtworks.go.domain.exception.IllegalArtifactLocationException) IOException(java.io.IOException) DateTime(org.joda.time.DateTime) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 92 with SvnMaterialConfig

use of com.thoughtworks.go.config.materials.svn.SvnMaterialConfig in project gocd by gocd.

the class PipelineHistoryServiceIntegrationTest method shouldCreateEmptyPipelineIfThePipelineHasNeverBeenRun.

@Test
public void shouldCreateEmptyPipelineIfThePipelineHasNeverBeenRun() throws Exception {
    SvnMaterialConfig svnMaterial = svn("https://some-url", "new-user", "new-pass", false);
    configHelper.addPipeline("new-pipeline", "new-stage", svnMaterial, "first-job");
    configHelper.addAuthorizedUserForPipelineGroup("username", BasicPipelineConfigs.DEFAULT_GROUP);
    PipelineInstanceModels instanceModels = pipelineHistoryService.loadWithEmptyAsDefault("new-pipeline", Pagination.ONE_ITEM, "username");
    PipelineInstanceModel instanceModel = instanceModels.get(0);
    assertThat(instanceModel.getMaterials(), is(new MaterialConfigs(svnMaterial)));
    assertThat(instanceModel.getCurrentRevision(svnMaterial).getRevision(), is("No historical data"));
    assertThat(instanceModel.getLatestRevision(svnMaterial).getRevision(), is("No historical data"));
    assertThat(instanceModel.getStageHistory().size(), is(1));
    assertThat(instanceModel.getStageHistory().get(0).getName(), is("new-stage"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)92 Test (org.junit.jupiter.api.Test)60 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)25 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)15 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)12 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)11 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)11 GoCipher (com.thoughtworks.go.security.GoCipher)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)9 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)9 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)8 Test (org.junit.Test)8 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)7 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)6 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)5 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)4 SvnCommand (com.thoughtworks.go.domain.materials.svn.SvnCommand)4 SCMs (com.thoughtworks.go.domain.scm.SCMs)3 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 SvnTestRepo (com.thoughtworks.go.helper.SvnTestRepo)3