Search in sources :

Example 31 with GitMaterialConfig

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

the class ConfigConverterTest method shouldConvertGitMaterialConfigWhenNulls.

@Test
void shouldConvertGitMaterialConfigWhenNulls() {
    GitMaterialConfig gitMaterialConfig = git();
    gitMaterialConfig.setUrl("url");
    CRGitMaterial crGitMaterial = (CRGitMaterial) configConverter.materialToCRMaterial(gitMaterialConfig);
    assertThat(crGitMaterial.getName()).isNull();
    assertThat(crGitMaterial.getDestination()).isNull();
    assertThat(crGitMaterial.isAutoUpdate()).isTrue();
    assertThat(crGitMaterial.isShallowClone()).isFalse();
    assertThat(crGitMaterial.getUrl()).isEqualTo("url");
    assertThat(crGitMaterial.getBranch()).isEqualTo("master");
}
Also used : GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 32 with GitMaterialConfig

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

the class ConfigRepositoryInitializerTest method shouldNotReInitializeConfigRepositoriesWhenCruiseConfigListenerIsInvokedAgain.

@Test
void shouldNotReInitializeConfigRepositoriesWhenCruiseConfigListenerIsInvokedAgain() {
    GitMaterialConfig gitMaterialConfig = (GitMaterialConfig) repoConfigs.get(0).getRepo();
    Material gitMaterial = new Materials(new MaterialConfigs(gitMaterialConfig)).first();
    TestingMaterialInstance gitMaterialInstance = new TestingMaterialInstance("git-repo", "flyweight");
    File folder = new File("repo-folder");
    MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(gitMaterial, oneModifiedFile("revision1")));
    Modification modification = materialRevisions.firstModifiedMaterialRevision().getLatestModification();
    when(materialRepository.findMaterialInstance(gitMaterialConfig)).thenReturn(gitMaterialInstance);
    when(materialRepository.folderFor(gitMaterial)).thenReturn(folder);
    when(materialRepository.findLatestModification(gitMaterial)).thenReturn(materialRevisions);
    configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
    configRepositoryInitializer.pluginLoaded(yamlPluginDescriptor);
    verify(goConfigRepoConfigDataSource, times(1)).onCheckoutComplete(gitMaterialConfig, folder, modification);
    // config changes..
    configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
    verifyNoMoreInteractions(goConfigRepoConfigDataSource);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) TestingMaterialInstance(com.thoughtworks.go.domain.materials.TestingMaterialInstance) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Material(com.thoughtworks.go.domain.materials.Material) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.oneModifiedFile(com.thoughtworks.go.helper.ModificationsMother.oneModifiedFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 33 with GitMaterialConfig

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

the class ConfigRepositoryInitializerTest method shouldInitializeConfigRepositoryAsAndWhenPluginsAreLoaded.

@Test
void shouldInitializeConfigRepositoryAsAndWhenPluginsAreLoaded() {
    // add another config repo using another plugin id
    ConfigRepoConfig repoConfig2 = new ConfigRepoConfig();
    repoConfig2.setId("repo2");
    repoConfig2.setPluginId(JSON_PLUGIN_ID);
    repoConfig2.setRepo(MaterialConfigsMother.git("git-repo"));
    repoConfigs.add(repoConfig2);
    GitMaterialConfig gitMaterialConfig = (GitMaterialConfig) repoConfigs.get(0).getRepo();
    Material gitMaterial = new Materials(new MaterialConfigs(gitMaterialConfig)).first();
    TestingMaterialInstance gitMaterialInstance = new TestingMaterialInstance("git-repo", "flyweight");
    File folder = new File("repo-folder");
    MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(gitMaterial, oneModifiedFile("revision1")));
    Modification modification = materialRevisions.firstModifiedMaterialRevision().getLatestModification();
    when(materialRepository.findMaterialInstance(gitMaterialConfig)).thenReturn(gitMaterialInstance);
    when(materialRepository.folderFor(gitMaterial)).thenReturn(folder);
    when(materialRepository.findLatestModification(gitMaterial)).thenReturn(materialRevisions);
    // initialize config
    configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
    // load yaml plugin
    configRepositoryInitializer.pluginLoaded(yamlPluginDescriptor);
    // verify the config repo is initialized once all the in use plugins are loaded
    verify(goConfigRepoConfigDataSource, times(1)).onCheckoutComplete(gitMaterialConfig, folder, modification);
    // load json plugin
    configRepositoryInitializer.pluginLoaded(jsonPluginDescriptor);
    // verify the config repo is initialized once all the in use plugins are loaded
    verify(goConfigRepoConfigDataSource, times(2)).onCheckoutComplete(gitMaterialConfig, folder, modification);
    // load groovy plugin
    configRepositoryInitializer.pluginLoaded(groovyPluginDescriptor);
    // verify nothing happens on more plugin load
    verifyNoMoreInteractions(goConfigRepoConfigDataSource);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) TestingMaterialInstance(com.thoughtworks.go.domain.materials.TestingMaterialInstance) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Material(com.thoughtworks.go.domain.materials.Material) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.oneModifiedFile(com.thoughtworks.go.helper.ModificationsMother.oneModifiedFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 34 with GitMaterialConfig

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

the class GoConfigServiceTest method shouldIncludeAllRemotePipelinesWithSpecificFingerprint.

@Test
public void shouldIncludeAllRemotePipelinesWithSpecificFingerprint() throws Exception {
    cruiseConfig = new BasicCruiseConfig();
    expectLoad(cruiseConfig);
    PipelineConfig pipelineConfig = new GoConfigMother().addPipelineWithGroup(cruiseConfig, "group", "pipeline_name", "stage_name", "job_name");
    GitMaterialConfig gitMaterialConfig = git("https://foo");
    MaterialConfigs materialConfigs = new MaterialConfigs(gitMaterialConfig);
    pipelineConfig.setMaterialConfigs(materialConfigs);
    pipelineConfig.setOrigin(new RepoConfigOrigin());
    List<CaseInsensitiveString> pipelineNames = goConfigService.pipelinesWithMaterial(gitMaterialConfig.getFingerprint());
    assertThat(pipelineNames, contains(new CaseInsensitiveString("pipeline_name")));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 35 with GitMaterialConfig

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

the class MaterialRepresenter method toJSON.

public static void toJSON(OutputWriter jsonWriter, MaterialConfig materialConfig) {
    if (!materialConfig.errors().isEmpty()) {
        jsonWriter.addChild("errors", errorWriter -> {
            HashMap<String, String> errorMapping = new HashMap<>();
            errorMapping.put("materialName", "name");
            errorMapping.put("folder", "destination");
            errorMapping.put("autoUpdate", "auto_update");
            errorMapping.put("filterAsString", "filter");
            errorMapping.put("checkexternals", "check_externals");
            errorMapping.put("serverAndPort", "port");
            errorMapping.put("useTickets", "use_tickets");
            errorMapping.put("pipelineName", "pipeline");
            errorMapping.put("stageName", "stage");
            errorMapping.put("pipelineStageName", "pipeline");
            errorMapping.put("packageId", "ref");
            errorMapping.put("scmId", "ref");
            errorMapping.put("encryptedPassword", "encrypted_password");
            new ErrorGetter(errorMapping).toJSON(errorWriter, materialConfig);
        });
    }
    jsonWriter.add("type", classToTypeMap.get(materialConfig.getClass()));
    switch(classToTypeMap.get(materialConfig.getClass())) {
        case "git":
            jsonWriter.addChild("attributes", attributeWriter -> GitMaterialRepresenter.toJSON(attributeWriter, (GitMaterialConfig) materialConfig));
            break;
        case "hg":
            jsonWriter.addChild("attributes", attributeWriter -> HgMaterialRepresenter.toJSON(attributeWriter, (HgMaterialConfig) materialConfig));
            break;
        case "svn":
            jsonWriter.addChild("attributes", attributeWriter -> SvnMaterialRepresenter.toJSON(attributeWriter, (SvnMaterialConfig) materialConfig));
            break;
        case "p4":
            jsonWriter.addChild("attributes", attributeWriter -> PerforceMaterialRepresenter.toJSON(attributeWriter, (P4MaterialConfig) materialConfig));
            break;
        case "tfs":
            jsonWriter.addChild("attributes", attributeWriter -> TfsMaterialRepresenter.toJSON(attributeWriter, (TfsMaterialConfig) materialConfig));
            break;
        case "dependency":
            jsonWriter.addChild("attributes", attributeWriter -> DependencyMaterialRepresenter.toJSON(attributeWriter, (DependencyMaterialConfig) materialConfig));
            break;
        case "package":
            jsonWriter.addChild("attributes", attributeWriter -> PackageMaterialRepresenter.toJSON(attributeWriter, (PackageMaterialConfig) materialConfig));
            break;
        case "plugin":
            jsonWriter.addChild("attributes", attributeWriter -> PluggableScmMaterialRepresenter.toJSON(attributeWriter, (PluggableSCMMaterialConfig) materialConfig));
            break;
    }
}
Also used : PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) HashMap(java.util.HashMap) 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) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)

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