Search in sources :

Example 26 with Material

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));
}
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.jupiter.api.Test)

Example 27 with Material

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();
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) Material(com.thoughtworks.go.domain.materials.Material) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Test(org.junit.jupiter.api.Test)

Example 28 with Material

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);
}
Also used : HashMap(java.util.HashMap) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Material(com.thoughtworks.go.domain.materials.Material) P4Material(com.thoughtworks.go.config.materials.perforce.P4Material) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 29 with Material

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();
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) HashMap(java.util.HashMap) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Material(com.thoughtworks.go.domain.materials.Material) P4Material(com.thoughtworks.go.config.materials.perforce.P4Material) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 30 with Material

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)));
}
Also used : MaterialFingerprintTag(com.thoughtworks.go.util.MaterialFingerprintTag) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialsMother.gitMaterial(com.thoughtworks.go.helper.MaterialsMother.gitMaterial) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) ProcessManager(com.thoughtworks.go.util.ProcessManager) Test(org.junit.jupiter.api.Test)

Aggregations

Material (com.thoughtworks.go.domain.materials.Material)122 Test (org.junit.jupiter.api.Test)72 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)49 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)47 Modification (com.thoughtworks.go.domain.materials.Modification)29 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)28 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)24 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)19 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)19 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)19 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)18 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)18 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)16 Materials (com.thoughtworks.go.config.materials.Materials)14 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)13 File (java.io.File)13 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)12 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)12 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)12 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)8