Search in sources :

Example 31 with CaseInsensitiveString

use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.

the class DependencyMaterialInstance method toOldMaterial.

@Override
public Material toOldMaterial(String name, String folder, String password) {
    DependencyMaterial dep = new DependencyMaterial(new CaseInsensitiveString(pipelineName), new CaseInsensitiveString(stageName));
    setName(name, dep);
    dep.setId(id);
    return dep;
}
Also used : DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 32 with CaseInsensitiveString

use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.

the class PipelineSqlMapDaoCachingTest method shouldNotInvalidateCacheOfPipelineInstancesTriggeredWithDependencyMaterial_WhenADifferentPipelineInstanceIsCreatedWithDifferentRevision.

@Test
public void shouldNotInvalidateCacheOfPipelineInstancesTriggeredWithDependencyMaterial_WhenADifferentPipelineInstanceIsCreatedWithDifferentRevision() throws Exception {
    String cacheKey = (PipelineSqlMapDao.class + "_cacheKeyForPipelineInstancesWithDependencyMaterial_" + "p1_p_1").intern();
    List<PipelineIdentifier> result = Arrays.asList(new PipelineIdentifier("p1", 1, "1"));
    when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOutOfDependencyMaterial"), anyString())).thenReturn(result);
    List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", new PipelineIdentifier("p", 1));
    assertThat(actual, Matchers.is(result));
    assertThat(goCache.get(cacheKey), is(result));
    MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(new DependencyMaterial(new CaseInsensitiveString("p"), new CaseInsensitiveString("s")), new Modification("u", "comment", "email", new Date(), "p/2/s/1")));
    Pipeline pipeline = new Pipeline("p1", BuildCause.createWithModifications(materialRevisions, ""));
    pipelineDao.save(pipeline);
    assertThat(goCache.get(cacheKey), is(result));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 33 with CaseInsensitiveString

use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.

the class PipelineSqlMapDaoCachingTest method loadActivePipelines_shouldCacheResult.

@Test
public void loadActivePipelines_shouldCacheResult() {
    final String pipelineName = "pipeline";
    CruiseConfig mockCruiseConfig = mock(BasicCruiseConfig.class);
    GoConfigDao mockconfigFileDao = mock(GoConfigDao.class);
    when(mockconfigFileDao.load()).thenReturn(mockCruiseConfig);
    when(mockCruiseConfig.getAllPipelineNames()).thenReturn(Arrays.asList(new CaseInsensitiveString(pipelineName)));
    // need to mock configfileDao for this test
    pipelineDao = new PipelineSqlMapDao(null, repository, goCache, environmentVariableDao, transactionTemplate, null, transactionSynchronizationManager, null, mockconfigFileDao, null, mock(SessionFactory.class));
    pipelineDao.setSqlMapClientTemplate(mockTemplate);
    PipelineInstanceModel pipeline = new PipelineInstanceModel(pipelineName, -2, "label", BuildCause.createManualForced(), new StageInstanceModels());
    PipelineInstanceModels pims = PipelineInstanceModels.createPipelineInstanceModels(pipeline);
    when(mockTemplate.queryForList("allActivePipelines")).thenReturn(pims);
    when(mockTemplate.queryForObject(eq("getPipelineHistoryById"), any())).thenReturn(pipeline);
    PipelineInstanceModels loaded;
    loaded = pipelineDao.loadActivePipelines();
    loaded = pipelineDao.loadActivePipelines();
    assertNotSame(pipeline, loaded);
    assertTrue(ToStringBuilder.reflectionToString(loaded) + " not equal to\n" + ToStringBuilder.reflectionToString(pipeline), EqualsBuilder.reflectionEquals(loaded, pims));
    verify(mockTemplate, times(1)).queryForList("allActivePipelines");
    verify(mockTemplate, times(1)).queryForObject(eq("getPipelineHistoryById"), any());
    verify(mockconfigFileDao, times(2)).load();
    verify(mockCruiseConfig, times(2)).getAllPipelineNames();
}
Also used : CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 34 with CaseInsensitiveString

use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.

the class PipelineSqlMapDaoCachingTest method shouldInvalidateCacheOfPipelineInstancesTriggeredWithDependencyMaterial.

@Test
public void shouldInvalidateCacheOfPipelineInstancesTriggeredWithDependencyMaterial() throws Exception {
    String cacheKey = (PipelineSqlMapDao.class + "_cacheKeyForPipelineInstancesWithDependencyMaterial_" + "p1_p_1").intern();
    List<PipelineIdentifier> result = Arrays.asList(new PipelineIdentifier("p1", 1, "1"));
    when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOutOfDependencyMaterial"), anyString())).thenReturn(new ArrayList());
    List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", new PipelineIdentifier("p", 1));
    assertThat(actual, hasSize(0));
    assertThat((List<PipelineIdentifier>) goCache.get(cacheKey), hasSize(0));
    MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(new DependencyMaterial(new CaseInsensitiveString("p"), new CaseInsensitiveString("s")), new Modification("u", "comment", "email", new Date(), "p/1/s/1")));
    Pipeline pipeline = new Pipeline("p1", BuildCause.createWithModifications(materialRevisions, ""));
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ((TransactionSynchronizationAdapter) invocation.getArguments()[0]).afterCommit();
            return null;
        }
    }).when(transactionSynchronizationManager).registerSynchronization(any(TransactionSynchronization.class));
    when(transactionTemplate.execute(any(TransactionCallback.class))).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ((TransactionCallback) invocation.getArguments()[0]).doInTransaction(new SimpleTransactionStatus());
            return null;
        }
    });
    pipelineDao.save(pipeline);
    assertThat(goCache.get(cacheKey), is(Matchers.nullValue()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) TransactionSynchronization(org.springframework.transaction.support.TransactionSynchronization) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) TransactionCallback(org.springframework.transaction.support.TransactionCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) SimpleTransactionStatus(org.springframework.transaction.support.SimpleTransactionStatus) Test(org.junit.Test)

Example 35 with CaseInsensitiveString

use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.

the class GoDashboardPipelineLockStatusChangeHandlerTest method shouldHandlePipelineLockStatusChangeByRefreshingPipelineInCache.

@Test
public void shouldHandlePipelineLockStatusChangeByRefreshingPipelineInCache() throws Exception {
    handler.call(PipelineLockStatusChangeListener.Event.lock("pipeline1"));
    verify(cacheUpdateService).updateCacheForPipeline(new CaseInsensitiveString("pipeline1"));
}
Also used : CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)392 Test (org.junit.Test)277 Username (com.thoughtworks.go.server.domain.Username)80 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)65 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)65 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)57 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)56 Date (java.util.Date)50 Modification (com.thoughtworks.go.domain.materials.Modification)44 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)30 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)28 Before (org.junit.Before)28 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)27 HashMap (java.util.HashMap)26 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)24 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)24 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)19 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)19 ArrayList (java.util.ArrayList)19 Pipeline (com.thoughtworks.go.domain.Pipeline)18