Search in sources :

Example 66 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method hasPipelineEverRunWithMultipleMaterialsInPeggedRevisionsCase.

@Test
public void hasPipelineEverRunWithMultipleMaterialsInPeggedRevisionsCase() {
    HgMaterial firstMaterial = MaterialsMother.hgMaterial("first", "dest");
    MaterialRevision first1 = saveOneScmModification("first1", firstMaterial, "user", "file", "comment");
    MaterialRevision first2 = saveOneScmModification("first2", firstMaterial, "user", "file", "comment");
    HgMaterial secondMaterial = MaterialsMother.hgMaterial("second", "dest");
    MaterialRevision second1 = saveOneScmModification("second1", secondMaterial, "user", "file", "comment");
    MaterialRevision second2 = saveOneScmModification("second2", secondMaterial, "user", "file", "comment");
    MaterialRevisions firstRun = new MaterialRevisions(first1, second2);
    MaterialRevisions secondRun = new MaterialRevisions(first2, second1);
    PipelineConfig config = PipelineMother.createPipelineConfig("mingle", new MaterialConfigs(firstMaterial.config(), secondMaterial.config()), "dev");
    savePipeline(instanceFactory.createPipelineInstance(config, BuildCause.createWithModifications(firstRun, "Pavan"), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()));
    savePipeline(instanceFactory.createPipelineInstance(config, BuildCause.createWithModifications(secondRun, "Shilpa-who-gets-along-well-with-her"), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()));
    assertThat(repo.hasPipelineEverRunWith("mingle", new MaterialRevisions(first2, second2)), is(true));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimeProvider(com.thoughtworks.go.util.TimeProvider) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Test(org.junit.Test)

Example 67 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method hasPipelineEverRunWithIsFalseWhenThereAreNewerModificationsThatHaveNotBeenBuilt.

@Test
public void hasPipelineEverRunWithIsFalseWhenThereAreNewerModificationsThatHaveNotBeenBuilt() {
    HgMaterial hgMaterial = MaterialsMother.hgMaterial("hgUrl", "dest");
    MaterialRevision materialRevision = saveOneScmModification(hgMaterial, "user", "file");
    PipelineConfig pipelineConfig = PipelineMother.createPipelineConfig("mingle", new MaterialConfigs(hgMaterial.config()), "dev");
    MaterialRevisions materialRevisions = new MaterialRevisions(materialRevision);
    Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, BuildCause.createManualForced(materialRevisions, Username.ANONYMOUS), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider());
    pipelineSqlMapDao.save(pipeline);
    MaterialRevision notBuiltRevision = saveOneScmModification(hgMaterial, "user", "file2");
    MaterialRevisions revisions = new MaterialRevisions(new MaterialRevision(hgMaterial, notBuiltRevision.getLatestModification()));
    assertThat(repo.hasPipelineEverRunWith("mingle", revisions), is(false));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimeProvider(com.thoughtworks.go.util.TimeProvider) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Test(org.junit.Test)

Example 68 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class PipelineHistoryServiceIntegrationTest method findMatchingPipelineInstances_shouldShowExpectedNumberOfMatchesWhenThePipelineHasMultipleStagesAndJobs.

@Test
public void findMatchingPipelineInstances_shouldShowExpectedNumberOfMatchesWhenThePipelineHasMultipleStagesAndJobs() {
    final int limit = 2;
    PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipeline_name");
    pipelineConfig.add(StageConfigMother.custom("stage-1", "job-1", "job-2", "job-3", "job-4"));
    goConfigService.addPipeline(pipelineConfig, "pipeline-group");
    pipelineConfig.setLabelTemplate("${COUNT}");
    Pipeline shouldMatch1 = dbHelper.schedulePipeline(pipelineConfig, ModificationsMother.buildCauseForOneModifiedFile(pipelineConfig, "abc-revision-should-match", "comment", "committer"), new TimeProvider());
    dbHelper.cancelStage(shouldMatch1.getStages().get(0));
    Pipeline shouldMatch2 = dbHelper.schedulePipeline(pipelineConfig, ModificationsMother.buildCauseForOneModifiedFile(pipelineConfig, "this-abc-revision-should-match-too", "another comment", "committer"), new TimeProvider());
    dbHelper.cancelStage(shouldMatch2.getStages().get(0));
    PipelineInstanceModels actual = pipelineHistoryService.findMatchingPipelineInstances("pipeline_name", "abc", limit, new Username(new CaseInsensitiveString("user")), new HttpLocalizedOperationResult());
    assertThat("size", actual.size(), is(2));
    assertThat("first counter", actual.get(0).getCounter(), is(shouldMatch2.getCounter()));
    assertThat("second counter", actual.get(1).getCounter(), is(shouldMatch1.getCounter()));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TimeProvider(com.thoughtworks.go.util.TimeProvider) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 69 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class PipelineHistoryServiceIntegrationTest method shouldReturnListOfPipelineInstancesByPageNumber.

@Test
public void shouldReturnListOfPipelineInstancesByPageNumber() {
    final int limit = 1;
    PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("mingle", "stage", "job");
    goConfigService.addPipeline(pipelineConfig, "pipeline-group");
    Pipeline instance1 = dbHelper.schedulePipeline(pipelineConfig, new TimeProvider());
    dbHelper.cancelStage(instance1.getStages().get(0));
    Pipeline instance2 = dbHelper.schedulePipeline(pipelineConfig, new TimeProvider());
    dbHelper.passStage(instance2.getStages().get(0));
    Pipeline instance3 = dbHelper.schedulePipeline(pipelineConfig, new TimeProvider());
    dbHelper.passStage(instance3.getStages().get(0));
    PipelineInstanceModels actual = pipelineHistoryService.findPipelineInstancesByPageNumber(instance2.getName(), 2, limit, "admin");
    assertThat(actual.size(), is(1));
    assertThat(actual.get(0).getCounter(), is(2));
    assertThat(actual.getPagination(), is(Pagination.pageStartingAt(1, 3, limit)));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 70 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class PipelineHistoryServiceIntegrationTest method findMatchingPipelineInstances_shouldMatchLabels.

@Test
public void findMatchingPipelineInstances_shouldMatchLabels() {
    final int limit = 10;
    PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("pipeline_name", "stage", "job");
    goConfigService.addPipeline(pipelineConfig, "pipeline-group");
    pipelineConfig.setLabelTemplate("${COUNT}-blah-1");
    Pipeline instance1 = dbHelper.schedulePipeline(pipelineConfig, new TimeProvider());
    dbHelper.cancelStage(instance1.getStages().get(0));
    pipelineConfig.setLabelTemplate("${COUNT}-blah-2");
    Pipeline instance2 = dbHelper.schedulePipeline(pipelineConfig, new TimeProvider());
    dbHelper.passStage(instance2.getStages().get(0));
    pipelineConfig.setLabelTemplate("${COUNT}-blah-1-1");
    Pipeline instance3 = dbHelper.schedulePipeline(pipelineConfig, new TimeProvider());
    dbHelper.passStage(instance3.getStages().get(0));
    pipelineConfig.setLabelTemplate("${COUNT}-blaH-1-2");
    Pipeline instance4 = dbHelper.schedulePipeline(pipelineConfig, new TimeProvider());
    dbHelper.passStage(instance4.getStages().get(0));
    PipelineInstanceModels actual = pipelineHistoryService.findMatchingPipelineInstances("pipeline_name", "h-1", limit, new Username(new CaseInsensitiveString("user")), new HttpLocalizedOperationResult());
    assertThat(actual.size(), is(3));
    assertThat(actual.get(0).getCounter(), is(4));
    assertThat(actual.get(1).getCounter(), is(3));
    assertThat(actual.get(2).getCounter(), is(1));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TimeProvider(com.thoughtworks.go.util.TimeProvider) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Aggregations

TimeProvider (com.thoughtworks.go.util.TimeProvider)177 Test (org.junit.Test)122 Date (java.util.Date)29 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)28 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)25 DateTime (org.joda.time.DateTime)18 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)16 GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)13 Username (com.thoughtworks.go.server.domain.Username)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 Before (org.junit.Before)13 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)11 Materials (com.thoughtworks.go.config.materials.Materials)10 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 TransactionStatus (org.springframework.transaction.TransactionStatus)9 Material (com.thoughtworks.go.domain.materials.Material)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)6