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