Search in sources :

Example 46 with Material

use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.

the class MaterialUpdateServiceTest method setUp.

@Before
public void setUp() throws Exception {
    queue = mock(MaterialUpdateQueue.class);
    configQueue = mock(ConfigMaterialUpdateQueue.class);
    watchList = mock(GoConfigWatchList.class);
    completed = mock(MaterialUpdateCompletedTopic.class);
    goConfigService = mock(GoConfigService.class);
    postCommitHookMaterialType = mock(PostCommitHookMaterialTypeResolver.class);
    serverHealthService = mock(ServerHealthService.class);
    systemEnvironment = new SystemEnvironment();
    scmMaterialSource = mock(SCMMaterialSource.class);
    dependencyMaterialUpdateNotifier = mock(DependencyMaterialUpdateNotifier.class);
    materialConfigConverter = mock(MaterialConfigConverter.class);
    MDUPerformanceLogger mduPerformanceLogger = mock(MDUPerformanceLogger.class);
    dependencyMaterialUpdateQueue = mock(DependencyMaterialUpdateQueue.class);
    service = new MaterialUpdateService(queue, configQueue, completed, watchList, goConfigService, systemEnvironment, serverHealthService, postCommitHookMaterialType, mduPerformanceLogger, materialConfigConverter, dependencyMaterialUpdateQueue);
    service.registerMaterialSources(scmMaterialSource);
    service.registerMaterialUpdateCompleteListener(scmMaterialSource);
    service.registerMaterialUpdateCompleteListener(dependencyMaterialUpdateNotifier);
    HashSet<MaterialConfig> materialConfigs = new HashSet(Collections.singleton(MATERIAL_CONFIG));
    HashSet<Material> materials = new HashSet(Collections.singleton(svnMaterial));
    when(goConfigService.getSchedulableMaterials()).thenReturn(materialConfigs);
    when(materialConfigConverter.toMaterials(materialConfigs)).thenReturn(materials);
    username = new Username(new CaseInsensitiveString("loser"));
    result = new HttpLocalizedOperationResult();
    validMaterialType = mock(PostCommitHookMaterialType.class);
    when(validMaterialType.isKnown()).thenReturn(true);
    when(validMaterialType.isValid(anyString())).thenReturn(true);
    invalidMaterialType = mock(PostCommitHookMaterialType.class);
    when(invalidMaterialType.isKnown()).thenReturn(false);
    when(invalidMaterialType.isValid(anyString())).thenReturn(false);
}
Also used : MDUPerformanceLogger(com.thoughtworks.go.server.perf.MDUPerformanceLogger) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) MaterialConfigConverter(com.thoughtworks.go.server.service.MaterialConfigConverter) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) PostCommitHookMaterialTypeResolver(com.thoughtworks.go.server.materials.postcommit.PostCommitHookMaterialTypeResolver) PostCommitHookMaterialType(com.thoughtworks.go.server.materials.postcommit.PostCommitHookMaterialType) Before(org.junit.Before)

Example 47 with Material

use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.

the class MaterialUpdateServiceTest method shouldNotUpdateServerHealthMessageWhenIdleTimeLessThanConfigured.

@Test
public void shouldNotUpdateServerHealthMessageWhenIdleTimeLessThanConfigured() {
    // given
    service = spy(service);
    systemEnvironment.set(SystemEnvironment.MATERIAL_UPDATE_INACTIVE_TIMEOUT, 2);
    ProcessManager processManager = mock(ProcessManager.class);
    Material material = mock(Material.class);
    service.updateMaterial(material);
    when(service.getProcessManager()).thenReturn(processManager);
    when(material.getFingerprint()).thenReturn("fingerprint");
    when(processManager.getIdleTimeFor("fingerprint")).thenReturn(60010L);
    // when
    service.updateMaterial(material);
    // then
    verify(serverHealthService, never()).removeByScope(HealthStateScope.forMaterialUpdate(material));
    verify(serverHealthService, never()).update(Matchers.<ServerHealthState>any());
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) ProcessManager(com.thoughtworks.go.util.ProcessManager) Test(org.junit.Test)

Example 48 with Material

use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.

the class MaterialUpdateStatusNotifierTest method shouldNotifyListenerWhenItsMaterialIsUpdated.

@Test
public void shouldNotifyListenerWhenItsMaterialIsUpdated() throws Exception {
    PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("config"), new MaterialConfigs());
    Material material = new HgMaterial("url", null);
    pipelineConfig.addMaterialConfig(material.config());
    MaterialUpdateStatusListener mockStatusListener = Mockito.mock(MaterialUpdateStatusListener.class);
    when(mockStatusListener.isListeningFor(material)).thenReturn(true);
    materialUpdateStatusNotifier.registerListenerFor(pipelineConfig, mockStatusListener);
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(material, 123));
    Mockito.verify(mockStatusListener).onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material, 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 49 with Material

use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.

the class SCMMaterialSourceTest method shouldReloadSchedulableMaterialsOnPipelineConfigChange.

@Test
public void shouldReloadSchedulableMaterialsOnPipelineConfigChange() {
    Set<MaterialConfig> schedulableMaterialConfigs = new HashSet<>(Arrays.asList(svnMaterial.config()));
    when(goConfigService.getSchedulableSCMMaterials()).thenReturn(schedulableMaterialConfigs);
    when(materialConfigConverter.toMaterials(schedulableMaterialConfigs)).thenReturn(new HashSet<>(Arrays.asList(svnMaterial)));
    Set<Material> materials = source.materialsForUpdate();
    assertThat(materials.size(), is(1));
    assertTrue(materials.contains(svnMaterial));
    schedulableMaterialConfigs = new HashSet<>(Arrays.asList(svnMaterial.config(), gitMaterial.config()));
    when(goConfigService.getSchedulableSCMMaterials()).thenReturn(schedulableMaterialConfigs);
    when(goConfigService.getCurrentConfig()).thenReturn(mock(CruiseConfig.class));
    when(materialConfigConverter.toMaterials(schedulableMaterialConfigs)).thenReturn(new HashSet<>(Arrays.asList(svnMaterial, gitMaterial)));
    when(serverHealthService.logs()).thenReturn(new ServerHealthStates());
    source.pipelineConfigChangedListener().onEntityConfigChange(mock(PipelineConfig.class));
    materials = source.materialsForUpdate();
    assertThat(materials.size(), is(2));
    assertTrue(materials.contains(svnMaterial));
    assertTrue(materials.contains(gitMaterial));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) ServerHealthStates(com.thoughtworks.go.serverhealth.ServerHealthStates) Material(com.thoughtworks.go.domain.materials.Material) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 50 with Material

use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.

the class SCMMaterialSourceTest method shouldReloadSchedulableMaterialsOnConfigChange.

@Test
public void shouldReloadSchedulableMaterialsOnConfigChange() {
    Set<MaterialConfig> schedulableMaterialConfigs = new HashSet<>(Arrays.asList(svnMaterial.config()));
    when(goConfigService.getSchedulableSCMMaterials()).thenReturn(schedulableMaterialConfigs);
    when(materialConfigConverter.toMaterials(schedulableMaterialConfigs)).thenReturn(new HashSet<>(Arrays.asList(svnMaterial)));
    Set<Material> materials = source.materialsForUpdate();
    assertThat(materials.size(), is(1));
    assertTrue(materials.contains(svnMaterial));
    schedulableMaterialConfigs = new HashSet<>(Arrays.asList(svnMaterial.config(), gitMaterial.config()));
    when(goConfigService.getSchedulableSCMMaterials()).thenReturn(schedulableMaterialConfigs);
    when(materialConfigConverter.toMaterials(schedulableMaterialConfigs)).thenReturn(new HashSet<>(Arrays.asList(svnMaterial, gitMaterial)));
    when(serverHealthService.logs()).thenReturn(new ServerHealthStates());
    source.onConfigChange(mock(CruiseConfig.class));
    materials = source.materialsForUpdate();
    assertThat(materials.size(), is(2));
    assertTrue(materials.contains(svnMaterial));
    assertTrue(materials.contains(gitMaterial));
}
Also used : MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) ServerHealthStates(com.thoughtworks.go.serverhealth.ServerHealthStates) Material(com.thoughtworks.go.domain.materials.Material) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Material (com.thoughtworks.go.domain.materials.Material)95 Test (org.junit.Test)59 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)39 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)39 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)23 Modification (com.thoughtworks.go.domain.materials.Modification)20 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)18 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)16 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)14 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)14 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)14 Materials (com.thoughtworks.go.config.materials.Materials)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)10 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)9 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)9 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)8 Date (java.util.Date)8 HashSet (java.util.HashSet)8 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)7 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)7