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