use of com.thoughtworks.go.domain.materials.Material 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() {
@Override
public void onMaterialUpdate(MaterialUpdateCompletedMessage message) {
materialUpdateStatusNotifier.removeListenerFor(pipelineConfig);
}
@Override
public boolean isListeningFor(Material material) {
return true;
}
};
materialUpdateStatusNotifier.registerListenerFor(pipelineConfig, statusListener);
materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(material, 123));
assertThat(materialUpdateStatusNotifier.hasListenerFor(pipelineConfig), is(false));
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class MercurialPostCommitHookImplementerTest method shouldPruneMercurialMaterialsWhichMatchIncomingURL.
@Test
public void shouldPruneMercurialMaterialsWhichMatchIncomingURL() throws Exception {
HgMaterial material1 = mock(HgMaterial.class);
when(material1.getUrlArgument()).thenReturn(new UrlArgument("http://repo1.something.local"));
HgMaterial material2 = mock(HgMaterial.class);
when(material2.getUrlArgument()).thenReturn(new UrlArgument("http://repo1.something.local"));
HgMaterial material3 = mock(HgMaterial.class);
when(material3.getUrlArgument()).thenReturn(new UrlArgument("ssh://repo1.something.local"));
GitMaterial material4 = mock(GitMaterial.class);
when(material4.getUrlArgument()).thenReturn(new UrlArgument("http://repo1.something.local"));
Set<Material> materials = new HashSet<>(Arrays.asList(material1, material2, material3, material4));
Map params = new HashMap();
params.put(MercurialPostCommitHookImplementer.REPO_URL_PARAM_KEY, "http://repo1.something.local");
Set<Material> actual = implementer.prune(materials, params);
assertThat(actual.size(), is(2));
assertThat(actual, hasItem(material1));
assertThat(actual, hasItem(material2));
verify(material1).getUrlArgument();
verify(material2).getUrlArgument();
verify(material3).getUrlArgument();
verify(material4, times(0)).getUrlArgument();
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class SvnPostCommitHookImplementerTest method shouldPruneListToGiveOutOnlySvnMaterials.
@Test
void shouldPruneListToGiveOutOnlySvnMaterials() {
final Material svnMaterial1 = mock(SvnMaterial.class);
final Material svnMaterial2 = mock(SvnMaterial.class);
final Material svnMaterial3 = mock(SvnMaterial.class);
final Material hgMaterial = mock(HgMaterial.class);
final Material gitMaterial = mock(GitMaterial.class);
final Material p4Material = mock(P4Material.class);
final Material tfsMaterial = mock(TfsMaterial.class);
final Material dependencyMaterial = mock(DependencyMaterial.class);
final HashSet<Material> allMaterials = new HashSet<>(Arrays.asList(svnMaterial1, svnMaterial2, svnMaterial3, gitMaterial, hgMaterial, p4Material, tfsMaterial, dependencyMaterial));
final SvnPostCommitHookImplementer spy = spy(implementer);
doAnswer(invocation -> Boolean.TRUE).when(spy).isQualified(anyString(), any(SvnMaterial.class), any(HashMap.class));
doAnswer(invocation -> new HashMap()).when(spy).createUrlToRemoteUUIDMap(allMaterials);
final HashMap params = new HashMap();
params.put(SvnPostCommitHookImplementer.UUID, "some uuid");
final Set<Material> prunedList = spy.prune(allMaterials, params);
assertThat(prunedList.size()).isEqualTo(3);
assertThat(prunedList).contains(svnMaterial1, svnMaterial2, svnMaterial3);
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class SvnPostCommitHookImplementerTest method shouldPruneListToGiveOutOnlySvnMaterialsWhichMatchTheRepositoryUrl.
@Test
void shouldPruneListToGiveOutOnlySvnMaterialsWhichMatchTheRepositoryUrl() {
SvnMaterial svnMaterial1 = new SvnMaterial("http://user:pass@example.com/svn1", "user", "pass", true);
SvnMaterial svnMaterial2 = new SvnMaterial("http://admin@example.com/svn2", "admin", "discreetbluewhale", true);
GitMaterial gitMaterial = new GitMaterial("http://admin@example.com/svn2");
final HashSet<Material> allMaterials = new HashSet<>(Arrays.asList(svnMaterial1, svnMaterial2, gitMaterial));
final HashMap<Object, Object> params = new HashMap<>();
final SvnPostCommitHookImplementer svnPostCommitHookImplementer = new SvnPostCommitHookImplementer();
params.put(SvnPostCommitHookImplementer.REPO_URL_PARAM_KEY, "http://example.com/svn1");
Set<Material> prunedList = svnPostCommitHookImplementer.prune(allMaterials, params);
assertThat(prunedList).contains(svnMaterial1);
assertThat(prunedList).hasSize(1);
params.put(SvnPostCommitHookImplementer.REPO_URL_PARAM_KEY, "http://admin@example.com/svn2");
prunedList = svnPostCommitHookImplementer.prune(allMaterials, params);
assertThat(prunedList).contains(svnMaterial2);
assertThat(prunedList).hasSize(1);
params.put(SvnPostCommitHookImplementer.REPO_URL_PARAM_KEY, "http://example.com/svn42");
prunedList = svnPostCommitHookImplementer.prune(allMaterials, params);
assertThat(prunedList).isEmpty();
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class MaterialUpdateServiceTest method shouldUpdateServerHealthMessageWhenHung.
@Test
void shouldUpdateServerHealthMessageWhenHung() {
// given
service = spy(service);
systemEnvironment.set(SystemEnvironment.MATERIAL_UPDATE_INACTIVE_TIMEOUT, 1);
ProcessManager processManager = mock(ProcessManager.class);
Material material = mock(Material.class);
service.updateMaterial(material);
when(service.getProcessManager()).thenReturn(processManager);
when(material.getFingerprint()).thenReturn("fingerprint");
when(material.getUriForDisplay()).thenReturn("uri");
when(material.getLongDescription()).thenReturn("details to uniquely identify a material");
when(material.isAutoUpdate()).thenReturn(true);
when(processManager.getIdleTimeFor(new MaterialFingerprintTag("fingerprint"))).thenReturn(60010L);
// when
service.updateMaterial(material);
// then
verify(serverHealthService).removeByScope(HealthStateScope.forMaterialUpdate(material));
ArgumentCaptor<ServerHealthState> argumentCaptor = ArgumentCaptor.forClass(ServerHealthState.class);
verify(serverHealthService).update(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().getMessage()).isEqualTo("Material update for uri hung:");
assertThat(argumentCaptor.getValue().getDescription()).isEqualTo("Material update is currently running but has not shown any activity in the last 1 minute(s). This may be hung. Details - details to uniquely identify a material");
assertThat(argumentCaptor.getValue().getType()).isEqualTo(HealthStateType.general(HealthStateScope.forMaterialUpdate(material)));
}
Aggregations