Search in sources :

Example 6 with SqlMapClientTemplate

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

the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldNotCacheWhenTheStageIsNull.

@Test
public void findStageWithIdentifier_shouldNotCacheWhenTheStageIsNull() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    stageDao.setSqlMapClientTemplate(mockTemplate);
    when(mockTemplate.queryForObject(eq("findStageWithJobsByIdentifier"), any())).thenReturn(null);
    Stage actual = stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
    assertThat(actual, is(new NullStage("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 7 with SqlMapClientTemplate

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

the class JobInstanceSqlMapDaoTest method shouldCacheJobIdentifierForGivenAttributes.

@Test
public void shouldCacheJobIdentifierForGivenAttributes() throws Exception {
    SqlMapClientTemplate template = mock(SqlMapClientTemplate.class);
    jobInstanceDao.setSqlMapClientTemplate(template);
    Map attrs = m("pipelineName", PIPELINE_NAME, "pipelineCounter", null, "pipelineLabel", savedPipeline.getLabel(), "stageName", STAGE_NAME, "stageCounter", counter, "jobName", JOB_NAME_IN_DIFFERENT_CASE);
    JobIdentifier jobIdentifier = new JobIdentifier(PIPELINE_NAME, savedPipeline.getCounter(), savedPipeline.getLabel(), STAGE_NAME, String.valueOf(counter), JOB_NAME);
    when(template.queryForObject("findJobId", attrs)).thenReturn(jobIdentifier);
    assertThat(jobInstanceDao.findOriginalJobIdentifier(new StageIdentifier(PIPELINE_NAME, null, savedPipeline.getLabel(), STAGE_NAME, String.valueOf(counter)), JOB_NAME_IN_DIFFERENT_CASE), is(jobIdentifier));
    verify(template).queryForObject("findJobId", attrs);
    assertThat(jobInstanceDao.findOriginalJobIdentifier(new StageIdentifier(PIPELINE_NAME, null, savedPipeline.getLabel(), STAGE_NAME, String.valueOf(counter)), JOB_NAME_IN_DIFFERENT_CASE), not(sameInstance(jobIdentifier)));
    assertThat(jobInstanceDao.findOriginalJobIdentifier(new StageIdentifier(PIPELINE_NAME, null, savedPipeline.getLabel(), STAGE_NAME, String.valueOf(counter)), JOB_NAME), is(jobIdentifier));
    verifyNoMoreInteractions(template);
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Example 8 with SqlMapClientTemplate

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

the class PipelineSqlMapDaoIntegrationTest method loadHistoryByIds_shouldLoadHistoryByIdWhenOnlyASingleIdIsNeedeSoThatItUsesTheExistingCacheForEnvironmentsPage.

@Test
public void loadHistoryByIds_shouldLoadHistoryByIdWhenOnlyASingleIdIsNeedeSoThatItUsesTheExistingCacheForEnvironmentsPage() throws Exception {
    SqlMapClientTemplate origTemplate = pipelineDao.getSqlMapClientTemplate();
    try {
        SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
        when(mockTemplate.queryForList(eq("getPipelineRange"), any())).thenReturn(Arrays.asList(2L));
        pipelineDao.setSqlMapClientTemplate(mockTemplate);
        PipelineInstanceModels pipelineHistories = pipelineDao.loadHistory("pipelineName", 1, 0);
        verify(mockTemplate, never()).queryForList(eq("getPipelineHistoryByName"), any());
        verify(mockTemplate, times(1)).queryForList(eq("getPipelineRange"), any());
    } finally {
        pipelineDao.setSqlMapClientTemplate(origTemplate);
    }
}
Also used : PipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels) SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Example 9 with SqlMapClientTemplate

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

the class StageSqlMapDaoIntegrationTest method isStageActive_shouldMakeIsActiveFalseWhenTheStageCompletes.

@Test
public void isStageActive_shouldMakeIsActiveFalseWhenTheStageCompletes() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    stageDao.setSqlMapClientTemplate(mockTemplate);
    when(mockTemplate.queryForObject(eq("isStageActive"), any())).thenReturn(1).thenReturn(0);
    boolean stageActive = stageDao.isStageActive(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name()));
    assertThat(stageActive, is(true));
    Stage stage = StageMother.completedFailedStageInstance(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name()), "job");
    //The cached 'true' should now be removed
    stageDao.stageStatusChanged(stage);
    assertThat(stageDao.isStageActive(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name())), is(false));
    verify(mockTemplate, times(2)).queryForObject(eq("isStageActive"), any());
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Example 10 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.SqlMapClientTemplate 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(stageList);
    StageHistoryPage stageHistoryPage = stageDao.findStageHistoryPage(stage, 10);
    StageHistoryPage stageHistoryPageInNextQuery = stageDao.findStageHistoryPage(stage, 10);
    assertThat(stageHistoryPage.getStages(), is(stageList));
    assertThat(stageHistoryPage.getPagination(), is(Pagination.pageFor(10, 20, 10)));
    assertThat(stageHistoryPageInNextQuery.getStages(), is(stageList));
    assertThat(stageHistoryPageInNextQuery.getPagination(), is(Pagination.pageFor(10, 20, 10)));
    stageHistoryPage.getStages().get(0).setState(StageState.Failing);
    assertThat(stageHistoryPageInNextQuery.getStages().get(0).getState(), is(StageState.Passed));
    verify(mockTemplate, times(1)).queryForList(eq("findStageHistoryPage"), any());
}
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)

Aggregations

SqlMapClientTemplate (org.springframework.orm.ibatis.SqlMapClientTemplate)35 Test (org.junit.Test)34 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)8 Method (java.lang.reflect.Method)8 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 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)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