Search in sources :

Example 61 with CaseInsensitiveString

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

the class MaterialUpdateStatusNotifierTest method shouldBeAbleToUnregisterAListenerDuringACallback.

@Test
public void shouldBeAbleToUnregisterAListenerDuringACallback() throws Exception {
    final PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("config"), new MaterialConfigs());
    Material material = new HgMaterial("url", null);
    pipelineConfig.addMaterialConfig(material.config());
    MaterialUpdateStatusListener statusListener = new MaterialUpdateStatusListener() {

        public void onMaterialUpdate(MaterialUpdateCompletedMessage message) {
            materialUpdateStatusNotifier.removeListenerFor(pipelineConfig);
        }

        public boolean isListeningFor(Material material) {
            return true;
        }
    };
    materialUpdateStatusNotifier.registerListenerFor(pipelineConfig, statusListener);
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(material, 123));
    assertThat(materialUpdateStatusNotifier.hasListenerFor(pipelineConfig), is(false));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 62 with CaseInsensitiveString

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

the class MaterialUpdateStatusNotifierTest method shouldNotifyListenerWhenItsMaterialIsUpdatedEvenIfAnotherListenerThrowsAnException.

@Test
public void shouldNotifyListenerWhenItsMaterialIsUpdatedEvenIfAnotherListenerThrowsAnException() throws Exception {
    Material sharedMaterial = new HgMaterial("url", null);
    PipelineConfig pipelineConfig1 = new PipelineConfig(new CaseInsensitiveString("config"), new MaterialConfigs());
    pipelineConfig1.addMaterialConfig(sharedMaterial.config());
    PipelineConfig pipelineConfig2 = new PipelineConfig(new CaseInsensitiveString("another-config"), new MaterialConfigs());
    pipelineConfig2.addMaterialConfig(sharedMaterial.config());
    MaterialUpdateStatusListener badListener = Mockito.mock(MaterialUpdateStatusListener.class);
    Mockito.doThrow(new RuntimeException("foo")).when(badListener).onMaterialUpdate(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
    MaterialUpdateStatusListener goodListener = Mockito.mock(MaterialUpdateStatusListener.class);
    when(badListener.isListeningFor(sharedMaterial)).thenReturn(true);
    when(goodListener.isListeningFor(sharedMaterial)).thenReturn(true);
    materialUpdateStatusNotifier.registerListenerFor(pipelineConfig1, badListener);
    materialUpdateStatusNotifier.registerListenerFor(pipelineConfig2, goodListener);
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
    Mockito.verify(badListener).onMaterialUpdate(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
    Mockito.verify(goodListener).onMaterialUpdate(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 63 with CaseInsensitiveString

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

the class SpecificMaterialRevisionFactoryTest method shouldCreateDependencyMaterialForAPipeline.

@Test
public void shouldCreateDependencyMaterialForAPipeline() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream"), new CaseInsensitiveString("blah-stage"));
    MaterialConfig dependencyMaterialConfig = dependencyMaterial.config();
    MaterialRevision expected = new MaterialRevision(dependencyMaterial, new Modification(new Date(), "upstream/4/blah-stage/2", "MOCK_LABEL-12", null));
    String upstreamFingerprint = "234fa4";
    when(mockGoConfigService.findMaterial(new CaseInsensitiveString("blahPipeline"), upstreamFingerprint)).thenReturn(dependencyMaterialConfig);
    when(materialConfigConverter.toMaterial(dependencyMaterialConfig)).thenReturn(dependencyMaterial);
    when(mockMaterialChecker.findSpecificRevision(dependencyMaterial, "upstream/4/blah-stage/2")).thenReturn(expected);
    MaterialRevisions materialRevisions = specificMaterialRevisionFactory.create("blahPipeline", Collections.singletonMap(upstreamFingerprint, "upstream/4/blah-stage/2"));
    assertThat(materialRevisions, is(new MaterialRevisions(expected)));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) Test(org.junit.Test)

Example 64 with CaseInsensitiveString

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

the class SpecificMaterialRevisionFactoryTest method shouldThrowExceptionWhenSpecifiedMaterialDoesNotExist.

@Test
public void shouldThrowExceptionWhenSpecifiedMaterialDoesNotExist() throws Exception {
    when(mockGoConfigService.findMaterial(new CaseInsensitiveString("blahPipeline"), "not-exist")).thenReturn(null);
    try {
        specificMaterialRevisionFactory.create("blahPipeline", Collections.singletonMap("not-exist", "upstream/500/blah-stage/2"));
        fail("Should not be able to find material");
    } catch (Exception expected) {
        assertThat(expected.getMessage(), is("Material with fingerprint [not-exist] for pipeline [blahPipeline] does not exist"));
    }
}
Also used : CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 65 with CaseInsensitiveString

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

the class GoDashboardServiceTest method shouldUpdateCacheForPipelineGivenItsConfig.

@Test
public void shouldUpdateCacheForPipelineGivenItsConfig() throws Exception {
    PipelineConfig pipelineConfig = configMother.addPipelineWithGroup(config, "group1", "pipeline1", "stage1", "job1");
    PipelineConfigs groupConfig = config.findGroup("group1");
    GoDashboardPipeline pipeline = pipeline("pipeline1");
    when(goConfigService.findGroupByPipeline(new CaseInsensitiveString("pipeline1"))).thenReturn(groupConfig);
    when(dashboardCurrentStateLoader.pipelineFor(pipelineConfig, groupConfig)).thenReturn(pipeline);
    service.updateCacheForPipeline(pipelineConfig);
    verify(cache).put(pipeline);
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) PipelineConfigs(com.thoughtworks.go.config.PipelineConfigs) 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