Search in sources :

Example 1 with StageHistoryEntry

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

the class StageSqlMapDaoIntegrationTest method findStageHistoryPage_shouldCacheStageHistoryPage.

@Test
public void findStageHistoryPage_shouldCacheStageHistoryPage() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    Stage stage = StageMother.passedStageInstance("dev", "java", "pipeline-name");
    stage.setApprovedBy("admin");
    stageDao.setSqlMapClientTemplate(mockTemplate);
    when(mockTemplate.queryForObject(eq("getStageHistoryCount"), any())).thenReturn(20);
    when(mockTemplate.queryForObject(eq("findOffsetForStage"), any())).thenReturn(10);
    List<StageHistoryEntry> stageList = asList(new StageHistoryEntry(stage, 1, 10));
    when(mockTemplate.queryForList(eq("findStageHistoryPage"), any())).thenReturn((List) stageList);
    StageHistoryPage stageHistoryPage = stageDao.findStageHistoryPage(stage, 10);
    StageHistoryPage stageHistoryPageInNextQuery = stageDao.findStageHistoryPage(stage, 10);
    assertThat(stageHistoryPage.getStages()).isEqualTo(stageList);
    assertThat(stageHistoryPage.getPagination()).isEqualTo(Pagination.pageFor(10, 20, 10));
    assertThat(stageHistoryPageInNextQuery.getStages()).isEqualTo(stageList);
    assertThat(stageHistoryPageInNextQuery.getPagination()).isEqualTo(Pagination.pageFor(10, 20, 10));
    stageHistoryPage.getStages().get(0).setState(StageState.Failing);
    assertThat(stageHistoryPageInNextQuery.getStages().get(0).getState()).isEqualTo(StageState.Passed);
    verify(mockTemplate, times(1)).queryForList(eq("findStageHistoryPage"), any());
}
Also used : StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) SqlMapClientTemplate(com.thoughtworks.go.server.transaction.SqlMapClientTemplate) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.jupiter.api.Test)

Example 2 with StageHistoryEntry

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

the class StageSqlMapDaoIntegrationTest method shouldReturnNullStageHistoryEntryWhenGettingHistoryForPage1.

@Test
public void shouldReturnNullStageHistoryEntryWhenGettingHistoryForPage1() throws Exception {
    HgMaterial hg = new HgMaterial("url", null);
    String[] hg_revs = { "h1" };
    scheduleUtil.checkinInOrder(hg, hg_revs);
    String pipelineName = "p1";
    String stageName = "stage_name";
    ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
    for (int i = 0; i < 10; i++) {
        scheduleUtil.runAndPass(p1, "h1");
    }
    StageHistoryPage historyPage = stageDao.findStageHistoryPage(pipelineName, stageName, new Supplier<Pagination>() {

        @Override
        public Pagination get() {
            return Pagination.pageByNumber(1, 1, 10);
        }
    });
    StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
    StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
    assertThat(bottomOfFirstPage).isNull();
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.jupiter.api.Test)

Example 3 with StageHistoryEntry

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

the class StageSqlMapDaoIntegrationTest method shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntryEvenThoughOtherStageInstanceAreInBetween.

@Test
public void shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntryEvenThoughOtherStageInstanceAreInBetween() throws Exception {
    HgMaterial hg = new HgMaterial("url", null);
    String[] hg_revs = { "h1" };
    scheduleUtil.checkinInOrder(hg, hg_revs);
    String pipelineName = "p1";
    String anotherPipeline = "p2";
    String stageName = "stage_name";
    String anotherStage = "another_stage_name";
    ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
    ScheduleTestUtil.AddedPipeline p2 = scheduleUtil.saveConfigWith(anotherPipeline, anotherStage, scheduleUtil.m(hg));
    for (int i = 0; i < 11; i++) {
        scheduleUtil.runAndPass(p1, "h1");
        scheduleUtil.runAndPass(p2, "h1");
    }
    StageHistoryPage historyPage = stageDao.findStageHistoryPage(pipelineName, stageName, new Supplier<Pagination>() {

        @Override
        public Pagination get() {
            return Pagination.pageByNumber(2, 2, 10);
        }
    });
    StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
    StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
    assertThat(bottomOfFirstPage.getId()).isEqualTo(topOfSecondPage.getId() + 2);
    assertThat(bottomOfFirstPage.getIdentifier().getPipelineName()).isEqualTo(pipelineName);
    assertThat(bottomOfFirstPage.getIdentifier().getStageName()).isEqualTo(stageName);
    assertThat(bottomOfFirstPage.getIdentifier().getPipelineCounter()).isEqualTo(2);
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.jupiter.api.Test)

Example 4 with StageHistoryEntry

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

the class StageSqlMapDaoIntegrationTest method shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry.

@Test
public void shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry() throws Exception {
    HgMaterial hg = new HgMaterial("url", null);
    String[] hg_revs = { "h1" };
    scheduleUtil.checkinInOrder(hg, hg_revs);
    String pipelineName = "p1";
    String stageName = "stage_name";
    ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
    for (int i = 0; i < 11; i++) {
        scheduleUtil.runAndPass(p1, "h1");
    }
    StageHistoryPage historyPage = stageDao.findStageHistoryPage(pipelineName, stageName, new Supplier<Pagination>() {

        @Override
        public Pagination get() {
            return Pagination.pageByNumber(2, 2, 10);
        }
    });
    StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
    StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
    assertThat(bottomOfFirstPage.getId()).isEqualTo(topOfSecondPage.getId() + 1);
    assertThat(bottomOfFirstPage.getIdentifier().getPipelineName()).isEqualTo(pipelineName);
    assertThat(bottomOfFirstPage.getIdentifier().getStageName()).isEqualTo(stageName);
    assertThat(bottomOfFirstPage.getIdentifier().getPipelineCounter()).isEqualTo(2);
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.jupiter.api.Test)

Example 5 with StageHistoryEntry

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

the class StageSqlMapDaoTest method shouldLoadStageHistoryEntryForAStageRunAfterTheLatestRunThatIsRetrievedForStageHistory.

@Test
void shouldLoadStageHistoryEntryForAStageRunAfterTheLatestRunThatIsRetrievedForStageHistory() {
    String pipelineName = "some_pipeline_name";
    String stageName = "some_stage_name";
    Supplier function = mock(Supplier.class);
    Pagination pagination = mock(Pagination.class);
    when(pagination.getCurrentPage()).thenReturn(3);
    when(pagination.getPageSize()).thenReturn(10);
    when(function.get()).thenReturn(pagination);
    StageSqlMapDao spy = spy(stageSqlMapDao);
    List<StageHistoryEntry> expectedStageHistoryEntriesList = mock(ArrayList.class);
    StageHistoryEntry topOfThisPage = mock(StageHistoryEntry.class);
    when(expectedStageHistoryEntriesList.get(0)).thenReturn(topOfThisPage);
    StageHistoryEntry bottomOfLastPage = mock(StageHistoryEntry.class);
    doReturn(expectedStageHistoryEntriesList).when(spy).findStages(pagination, pipelineName, stageName);
    doReturn(bottomOfLastPage).when(spy).findImmediateChronologicallyForwardStageHistoryEntry(topOfThisPage);
    StageHistoryPage stageHistoryPage = spy.findStageHistoryPage(pipelineName, stageName, function);
    assertThat(stageHistoryPage.getStages(), is(expectedStageHistoryEntriesList));
    assertThat(stageHistoryPage.getImmediateChronologicallyForwardStageHistoryEntry(), is(bottomOfLastPage));
    verify(spy, times(1)).findStages(pagination, pipelineName, stageName);
    verify(spy, times(1)).findImmediateChronologicallyForwardStageHistoryEntry(expectedStageHistoryEntriesList.get(0));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) Supplier(java.util.function.Supplier) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.jupiter.api.Test)

Aggregations

StageHistoryEntry (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)17 Test (org.junit.jupiter.api.Test)14 StageHistoryPage (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage)11 Pagination (com.thoughtworks.go.server.util.Pagination)6 Username (com.thoughtworks.go.server.domain.Username)4 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)3 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)3 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 SqlMapClientTemplate (com.thoughtworks.go.server.transaction.SqlMapClientTemplate)2 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)1 TimeProvider (com.thoughtworks.go.util.TimeProvider)1 HashMap (java.util.HashMap)1 Supplier (java.util.function.Supplier)1