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);
}
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());
}
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));
}
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));
}
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));
}
Aggregations