use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class BuildCauseProducerServiceTest method manualTrigger_shouldRequestUpdateOfNewMaterials_WhenPipelineConfigInConfigRepo.
@Test
public void manualTrigger_shouldRequestUpdateOfNewMaterials_WhenPipelineConfigInConfigRepo() {
HgMaterial material1 = new HgMaterial("url", null);
HgMaterial material2 = new HgMaterial("url2", null);
HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
HgMaterialConfig materialConfig2 = new HgMaterialConfig("url2", null);
pipelineConfig.addMaterialConfig(materialConfig1);
pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig1, "plug"), "revision1"));
when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
when(materialConfigConverter.toMaterial(materialConfig2)).thenReturn(material2);
buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
// updated pipeline config
PipelineConfig updatedPipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs());
updatedPipelineConfig.addMaterialConfig(materialConfig1);
updatedPipelineConfig.addMaterialConfig(materialConfig2);
when(goConfigService.pipelineConfigNamed(pipelineConfig.name())).thenReturn(updatedPipelineConfig);
when(goConfigService.hasPipelineNamed(pipelineConfig.name())).thenReturn(true);
Materials materials = new Materials(material1, material2);
when(materialConfigConverter.toMaterials(updatedPipelineConfig.materialConfigs())).thenReturn(materials);
when(materialExpansionService.expandMaterialConfigsForScheduling(updatedPipelineConfig.materialConfigs())).thenReturn(updatedPipelineConfig.materialConfigs());
when(pipelineScheduleQueue.mostRecentScheduled(updatedPipelineConfig.name().toString())).thenReturn(BuildCause.createNeverRun());
when(materialChecker.findLatestRevisions(any(), eq(materials))).thenReturn(new MaterialRevisions());
MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
verify(goConfigService, times(2)).pipelineConfigNamed(pipelineConfig.name());
verify(mockMaterialUpdateService, times(1)).updateMaterial(material1);
verify(mockMaterialUpdateService, times(1)).updateMaterial(material2);
statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material2, 0));
verify(mockMaterialUpdateStatusNotifier).removeListenerFor(updatedPipelineConfig);
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class BuildCauseProducerServiceTest method manualTrigger_shouldUpdatePipelineConfigWhenMaterialIsConfigRepo.
@Test
public void manualTrigger_shouldUpdatePipelineConfigWhenMaterialIsConfigRepo() {
HgMaterial material1 = new HgMaterial("url", null);
HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
pipelineConfig.addMaterialConfig(materialConfig1);
pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig1, "plug"), "revision1"));
when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
when(goConfigService.hasPipelineNamed(pipelineConfig.name())).thenReturn(true);
buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
verify(mockMaterialUpdateStatusNotifier).removeListenerFor(pipelineConfig);
verify(goConfigService, times(2)).pipelineConfigNamed(pipelineConfig.name());
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class GoConfigServiceTest method pipelineEditableViaUI_shouldReturnFalseWhenPipelineIsRemote.
@Test
public void pipelineEditableViaUI_shouldReturnFalseWhenPipelineIsRemote() throws Exception {
PipelineConfigs group = new BasicPipelineConfigs();
PipelineConfig pipelineConfig = createPipelineConfig("pipeline", "name", "plan");
pipelineConfig.setOrigin(new RepoConfigOrigin());
group.add(pipelineConfig);
expectLoad(new BasicCruiseConfig(group));
assertThat(goConfigService.isPipelineEditable("pipeline"), is(false));
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class EnvironmentConfigServiceTest method getAllRemotePipelinesForUserInEnvironment_shouldReturnOnlyRemotelyAssignedPipelinesWhichUserHasPermsToView.
@Test
public void getAllRemotePipelinesForUserInEnvironment_shouldReturnOnlyRemotelyAssignedPipelinesWhichUserHasPermsToView() throws NoSuchEnvironmentException {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Username user = new Username(new CaseInsensitiveString("user"));
when(mockGoConfigService.getAllPipelineConfigs()).thenReturn(asList(pipelineConfig("foo"), pipelineConfig("bar"), pipelineConfig("baz")));
when(securityService.hasViewPermissionForPipeline(user, "foo")).thenReturn(true);
when(securityService.hasViewPermissionForPipeline(user, "bar")).thenReturn(true);
when(securityService.hasViewPermissionForPipeline(user, "baz")).thenReturn(false);
EnvironmentsConfig environmentConfigs = environmentsConfig("foo-env", "foo");
EnvironmentConfig fooEnv = environmentConfigs.named(new CaseInsensitiveString("foo-env"));
fooEnv.setOrigins(new RepoConfigOrigin());
environmentConfigService.sync(environmentConfigs);
List<EnvironmentPipelineModel> pipelines = environmentConfigService.getAllRemotePipelinesForUserInEnvironment(user, fooEnv);
assertThat(pipelines.size(), is(1));
assertThat(pipelines, is(asList(new EnvironmentPipelineModel("foo", "foo-env"))));
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class PipelineConfig method isConfigOriginSameAsOneOfMaterials.
public boolean isConfigOriginSameAsOneOfMaterials() {
if (!(isConfigDefinedRemotely()))
return false;
RepoConfigOrigin repoConfigOrigin = (RepoConfigOrigin) this.origin;
MaterialConfig configMaterial = repoConfigOrigin.getMaterial();
for (MaterialConfig material : this.materialConfigs()) {
if (material.getFingerprint().equals(configMaterial.getFingerprint()))
return true;
}
return false;
}
Aggregations