Search in sources :

Example 26 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method findStageHistoryPage_shouldReturnStageHistoryEntryWithConfigVersion.

@Test
public void findStageHistoryPage_shouldReturnStageHistoryEntryWithConfigVersion() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    Stage stage = StageMother.passedStageInstance("dev", "java", "pipeline-name");
    stage.setApprovedBy("admin");
    stage.setConfigVersion("md5-test");
    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(stageList);
    StageHistoryPage stageHistoryPage = stageDao.findStageHistoryPage(stage, 10);
    assertThat(stageHistoryPage.getStages().get(0).getConfigVersion(), is("md5-test"));
}
Also used : StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.Test)

Example 27 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldClearCacheWhenJobStateChanges.

@Test
public void findStageWithIdentifier_shouldClearCacheWhenJobStateChanges() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    Stage stage = StageMother.passedStageInstance("pipeline", "stage", "job", new Date());
    stageDao.setSqlMapClientTemplate(mockTemplate);
    when(mockTemplate.queryForObject(eq("findStageWithJobsByIdentifier"), any())).thenReturn(stage);
    assertEquals(stage, stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1")));
    stageDao.jobStatusChanged(stage.getFirstJob());
    assertEquals(stage, stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1")));
    verify(mockTemplate, times(2)).queryForObject(eq("findStageWithJobsByIdentifier"), any());
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Example 28 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldCacheTheStage.

@Test
public void findStageWithIdentifier_shouldCacheTheStage() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    Stage stage = StageMother.passedStageInstance("pipeline", "stage", "job", new Date());
    stageDao.setSqlMapClientTemplate(mockTemplate);
    when(mockTemplate.queryForObject(eq("findStageWithJobsByIdentifier"), any())).thenReturn(stage);
    Stage actual = stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
    assertEquals(stage, actual);
    stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
    verify(mockTemplate, times(1)).queryForObject(eq("findStageWithJobsByIdentifier"), any());
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Example 29 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method shouldInvalidateCachedAllStagesForAPipelineInstanceWhenTheStatusOfAStageOfThisPipelineInstanceIsChanged.

@Test
public void shouldInvalidateCachedAllStagesForAPipelineInstanceWhenTheStatusOfAStageOfThisPipelineInstanceIsChanged() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    stageDao.setSqlMapClientTemplate(mockTemplate);
    Stage stage1 = StageMother.passedStageInstance("first", "job", "pipeline");
    Stage stage2 = StageMother.passedStageInstance("second", "job", "pipeline");
    List<Stage> stages = asList(stage1, stage2);
    when(mockTemplate.queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap())).thenReturn(stages);
    Stages actual = stageDao.findAllStagesFor("pipeline", 1);
    assertThat(actual, is(new Stages(stages)));
    // Should invalidate the cached stages
    stageDao.stageStatusChanged(StageMother.scheduledStage("pipeline", 1, "first", 2, "job"));
    actual = stageDao.findAllStagesFor("pipeline", 1);
    assertThat(actual, is(new Stages(stages)));
    verify(mockTemplate, times(2)).queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap());
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Example 30 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method getAllRunsOfStageForPipelineInstance_shouldClearCacheOnJobStateChange.

@Test
public void getAllRunsOfStageForPipelineInstance_shouldClearCacheOnJobStateChange() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    Stage first = StageMother.passedStageInstance("pipeline", "stage", 1, "job", new Date());
    Stage second = StageMother.passedStageInstance("pipeline", "stage", 2, "job", new Date());
    Stage third = StageMother.passedStageInstance("pipeline", "stage", 3, "job", new Date());
    List<Stage> expected = asList(third, second, first);
    stageDao.setSqlMapClientTemplate(mockTemplate);
    when(mockTemplate.queryForList(eq("getAllRunsOfStageForPipelineInstance"), any())).thenReturn(expected);
    assertThat(stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage"), is(expected));
    stageDao.jobStatusChanged(first.getFirstJob());
    assertThat(stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage"), is(expected));
    stageDao.jobStatusChanged(second.getFirstJob());
    assertThat(stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage"), is(expected));
    verify(mockTemplate, times(3)).queryForList(eq("getAllRunsOfStageForPipelineInstance"), any());
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Aggregations

SqlMapClientTemplate (org.springframework.orm.ibatis.SqlMapClientTemplate)36 Test (org.junit.Test)35 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)8 Method (java.lang.reflect.Method)8 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)2 StageHistoryEntry (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)2 StageHistoryPage (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage)2 TransactionManager (com.ibatis.sqlmap.engine.transaction.TransactionManager)1 Cache (com.opensymphony.oscache.base.Cache)1 Cloner (com.rits.cloning.Cloner)1 FeedEntry (com.thoughtworks.go.domain.feed.FeedEntry)1 StageFeedEntry (com.thoughtworks.go.domain.feed.stage.StageFeedEntry)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1 StubGoCache (com.thoughtworks.go.server.service.StubGoCache)1 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)1 Before (org.junit.Before)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1