Search in sources :

Example 46 with GitMaterialConfig

use of com.thoughtworks.go.config.materials.git.GitMaterialConfig in project gocd by gocd.

the class MaterialServiceTest method findMatchingMods_shouldCallDaoToFetchLatestMatchingMods.

@Test
public void findMatchingMods_shouldCallDaoToFetchLatestMatchingMods() {
    GitMaterialConfig config = git("http://test.com");
    GitMaterialInstance instance = new GitMaterialInstance("http://test.com", null, null, null, "flyweight");
    Modifications modifications = new Modifications();
    modifications.add(new Modification("user", "comment 1", "email", new DateTime().minusHours(1).toDate(), "revision"));
    modifications.add(new Modification("user", "comment 2", "email", new DateTime().minusHours(2).toDate(), "revision"));
    modifications.add(new Modification("user", "comment 3", "email", new DateTime().minusHours(3).toDate(), "revision"));
    when(materialRepository.findMaterialInstance(config)).thenReturn(instance);
    when(materialRepository.findMatchingModifications(anyLong(), anyString(), any(FeedModifier.class), anyLong(), anyInt())).thenReturn(modifications);
    List<Modification> result = materialService.getModificationsFor(config, "comment", 0, 0, 10);
    verify(materialRepository).findMatchingModifications(eq(instance.getId()), eq("comment"), eq(FeedModifier.Latest), eq(0L), eq(10));
    assertThat(result, is(modifications));
}
Also used : GitMaterialInstance(com.thoughtworks.go.domain.materials.git.GitMaterialInstance) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) FeedModifier(com.thoughtworks.go.server.dao.FeedModifier) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with GitMaterialConfig

use of com.thoughtworks.go.config.materials.git.GitMaterialConfig in project gocd by gocd.

the class ConfigConverter method toScmMaterialConfig.

private ScmMaterialConfig toScmMaterialConfig(CRScmMaterial crScmMaterial) {
    String materialName = crScmMaterial.getName();
    if (crScmMaterial instanceof CRGitMaterial) {
        CRGitMaterial git = (CRGitMaterial) crScmMaterial;
        String gitBranch = git.getBranch();
        if (StringUtils.isBlank(gitBranch))
            gitBranch = GitMaterialConfig.DEFAULT_BRANCH;
        GitMaterialConfig gitConfig = new GitMaterialConfig();
        gitConfig.setUrl(git.getUrl());
        gitConfig.setBranch(gitBranch);
        gitConfig.setShallowClone(git.isShallowClone());
        setCommonMaterialMembers(gitConfig, crScmMaterial);
        setCommonScmMaterialMembers(gitConfig, git);
        return gitConfig;
    } else if (crScmMaterial instanceof CRHgMaterial) {
        CRHgMaterial hg = (CRHgMaterial) crScmMaterial;
        HgMaterialConfig hgConfig = new HgMaterialConfig();
        hgConfig.setUrl(hg.getUrl());
        hgConfig.setUserName(hg.getUsername());
        hgConfig.setPassword(hg.getPassword());
        hgConfig.setBranchAttribute(hg.getBranch());
        hgConfig.setAutoUpdate(hg.isAutoUpdate());
        hgConfig.setFilter(toFilter(crScmMaterial));
        hgConfig.setInvertFilter(false);
        hgConfig.setFolder(hg.getDestination());
        hgConfig.setName(toMaterialName(materialName));
        setCommonMaterialMembers(hgConfig, crScmMaterial);
        setCommonScmMaterialMembers(hgConfig, hg);
        return hgConfig;
    } else if (crScmMaterial instanceof CRP4Material) {
        CRP4Material crp4Material = (CRP4Material) crScmMaterial;
        P4MaterialConfig p4MaterialConfig = new P4MaterialConfig();
        p4MaterialConfig.setServerAndPort(crp4Material.getPort());
        p4MaterialConfig.setView(crp4Material.getView());
        p4MaterialConfig.setUseTickets(crp4Material.isUseTickets());
        setCommonMaterialMembers(p4MaterialConfig, crScmMaterial);
        setCommonScmMaterialMembers(p4MaterialConfig, crp4Material);
        return p4MaterialConfig;
    } else if (crScmMaterial instanceof CRSvnMaterial) {
        CRSvnMaterial crSvnMaterial = (CRSvnMaterial) crScmMaterial;
        SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig();
        svnMaterialConfig.setUrl(crSvnMaterial.getUrl());
        svnMaterialConfig.setUserName(crSvnMaterial.getUsername());
        svnMaterialConfig.setCheckExternals(crSvnMaterial.isCheckExternals());
        setCommonMaterialMembers(svnMaterialConfig, crScmMaterial);
        setCommonScmMaterialMembers(svnMaterialConfig, crSvnMaterial);
        return svnMaterialConfig;
    } else if (crScmMaterial instanceof CRTfsMaterial) {
        CRTfsMaterial crTfsMaterial = (CRTfsMaterial) crScmMaterial;
        TfsMaterialConfig tfsMaterialConfig = new TfsMaterialConfig();
        tfsMaterialConfig.setUrl(crTfsMaterial.getUrl());
        tfsMaterialConfig.setUserName(crTfsMaterial.getUsername());
        tfsMaterialConfig.setDomain(crTfsMaterial.getDomain());
        tfsMaterialConfig.setProjectPath(crTfsMaterial.getProject());
        setCommonMaterialMembers(tfsMaterialConfig, crTfsMaterial);
        setCommonScmMaterialMembers(tfsMaterialConfig, crTfsMaterial);
        return tfsMaterialConfig;
    } else
        throw new ConfigConvertionException(String.format("unknown scm material type '%s'", crScmMaterial));
}
Also used : GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)

Example 48 with GitMaterialConfig

use of com.thoughtworks.go.config.materials.git.GitMaterialConfig in project gocd by gocd.

the class SCMMaterialSourceTest method shouldRefreshMaterialCacheOnPackageRepositoryChange.

@Test
public void shouldRefreshMaterialCacheOnPackageRepositoryChange() {
    GitMaterialConfig gitMaterial = new GitMaterialConfig();
    gitMaterial.setUrl("http://github.com/gocd/gocd");
    ArgumentCaptor<EntityConfigChangedListener> captor = ArgumentCaptor.forClass(EntityConfigChangedListener.class);
    doNothing().when(goConfigService).register(captor.capture());
    when(goConfigService.getSchedulableSCMMaterials()).thenReturn(emptySet()).thenReturn(singleton(gitMaterial));
    source = new SCMMaterialSource(goConfigService, systemEnvironment, new MaterialConfigConverter(), materialUpdateService);
    source.initialize();
    EntityConfigChangedListener entityConfigChangedListener = captor.getAllValues().get(1);
    assertTrue(entityConfigChangedListener.shouldCareAbout(new PackageRepository()));
    assertThat(source.materialsForUpdate().size(), is(0));
    entityConfigChangedListener.onEntityConfigChange(new PackageRepository());
    Set<Material> materials = source.materialsForUpdate();
    assertThat(materials.size(), is(1));
    assertThat(materials.iterator().next().getFingerprint(), is(gitMaterial.getFingerprint()));
}
Also used : GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Material(com.thoughtworks.go.domain.materials.Material) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) MaterialConfigConverter(com.thoughtworks.go.server.service.MaterialConfigConverter) Test(org.junit.jupiter.api.Test)

Example 49 with GitMaterialConfig

use of com.thoughtworks.go.config.materials.git.GitMaterialConfig in project gocd by gocd.

the class CruiseConfigTestBase method shouldCheckCyclicDependency.

@Test
public void shouldCheckCyclicDependency() throws Exception {
    PipelineConfig p1 = createPipelineConfig("p1", "s1", "j1");
    PipelineConfig p2 = createPipelineConfig("p2", "s2", "j1");
    p2.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p1"), new CaseInsensitiveString("s1")));
    PipelineConfig p3 = createPipelineConfig("p3", "s3", "j1");
    p3.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p2"), new CaseInsensitiveString("s2")));
    p1.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p3"), new CaseInsensitiveString("s3")));
    pipelines.addAll(Arrays.asList(p1, p2, p3));
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    ConfigReposConfig reposConfig = new ConfigReposConfig();
    GitMaterialConfig configRepo = git("http://git");
    reposConfig.add(ConfigRepoConfig.createConfigRepoConfig(configRepo, "myplug", "id"));
    mainCruiseConfig.setConfigRepos(reposConfig);
    PartialConfig partialConfig = PartialConfigMother.withPipeline("pipe2");
    cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, partialConfig);
    cruiseConfig.validate(mock(ValidationContext.class));
    List<ConfigErrors> allErrors = cruiseConfig.getAllErrors();
    assertThat((allErrors.get(0).on("base")), is("Circular dependency: p1 <- p2 <- p3 <- p1"));
}
Also used : GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.jupiter.api.Test)

Example 50 with GitMaterialConfig

use of com.thoughtworks.go.config.materials.git.GitMaterialConfig in project gocd by gocd.

the class CruiseConfigTestBase method shouldReturnAllUniqueSchedulableScmMaterials.

@Test
public void shouldReturnAllUniqueSchedulableScmMaterials() {
    final MaterialConfig svnMaterialConfig = svn("http://svn_url_1", "username", "password", false);
    svnMaterialConfig.setAutoUpdate(false);
    final MaterialConfig svnMaterialConfigWithAutoUpdate = svn("http://svn_url_2", "username", "password", false);
    svnMaterialConfigWithAutoUpdate.setAutoUpdate(true);
    final MaterialConfig hgMaterialConfig = hg("http://hg_url", null);
    hgMaterialConfig.setAutoUpdate(false);
    final MaterialConfig gitMaterialConfig = git("http://git_url");
    gitMaterialConfig.setAutoUpdate(false);
    final MaterialConfig tfsMaterialConfig = tfs(mock(GoCipher.class), new UrlArgument("http://tfs_url"), "username", "domain", "password", "project_path");
    tfsMaterialConfig.setAutoUpdate(false);
    final MaterialConfig p4MaterialConfig = p4("http://p4_url", "view", "username");
    p4MaterialConfig.setAutoUpdate(false);
    final MaterialConfig dependencyMaterialConfig = MaterialConfigsMother.dependencyMaterialConfig();
    final PluggableSCMMaterialConfig pluggableSCMMaterialConfig = MaterialConfigsMother.pluggableSCMMaterialConfig("scm-id-1", null, null);
    pluggableSCMMaterialConfig.getSCMConfig().setAutoUpdate(false);
    final PipelineConfig p1 = PipelineConfigMother.pipelineConfig("pipeline1", new MaterialConfigs(svnMaterialConfig), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
    final PipelineConfig p2 = PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(svnMaterialConfig, gitMaterialConfig), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
    final PipelineConfig p3 = PipelineConfigMother.pipelineConfig("pipeline3", new MaterialConfigs(hgMaterialConfig, dependencyMaterialConfig), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
    final PipelineConfig p4 = PipelineConfigMother.pipelineConfig("pipeline4", new MaterialConfigs(p4MaterialConfig, pluggableSCMMaterialConfig), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
    final PipelineConfig p5 = PipelineConfigMother.pipelineConfig("pipeline5", new MaterialConfigs(svnMaterialConfigWithAutoUpdate, tfsMaterialConfig), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
    cruiseConfig.getGroups().add(new BasicPipelineConfigs(p1, p2, p3, p4, p5));
    final Set<MaterialConfig> materials = cruiseConfig.getAllUniquePostCommitSchedulableMaterials();
    assertThat(materials.size(), is(6));
    assertThat(materials, hasItems(svnMaterialConfig, hgMaterialConfig, gitMaterialConfig, tfsMaterialConfig, p4MaterialConfig, pluggableSCMMaterialConfig));
    assertThat(materials, not(hasItem(svnMaterialConfigWithAutoUpdate)));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GoCipher(com.thoughtworks.go.security.GoCipher) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) ScmMaterialConfig(com.thoughtworks.go.config.materials.ScmMaterialConfig) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.jupiter.api.Test)

Aggregations

GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)138 Test (org.junit.jupiter.api.Test)73 Test (org.junit.Test)37 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)21 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)21 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)20 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)19 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)17 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)16 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)14 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 GitMaterialInstance (com.thoughtworks.go.domain.materials.git.GitMaterialInstance)11 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)10 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)10 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)9 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)8 Material (com.thoughtworks.go.domain.materials.Material)8 SCMs (com.thoughtworks.go.domain.scm.SCMs)8 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)7