Search in sources :

Example 61 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoConfigServiceTest method shouldReturnNullIfNoSecretConfigExistBySecretConfigId.

@Test
public void shouldReturnNullIfNoSecretConfigExistBySecretConfigId() throws Exception {
    GoConfigMother configMother = new GoConfigMother();
    BasicCruiseConfig config = GoConfigMother.defaultCruiseConfig();
    configMother.addPipelineWithGroup(config, "group1", "pipeline1", "stage1", "job1");
    expectLoad(config);
    assertThat(goConfigService.getSecretConfigById("invalid"), is(nullValue()));
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 62 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoConfigServiceTest method shouldRegisterBaseUrlChangeListener.

@Test
public void shouldRegisterBaseUrlChangeListener() throws Exception {
    CruiseConfig cruiseConfig = new GoConfigMother().cruiseConfigWithOnePipelineGroup();
    when(goConfigDao.load()).thenReturn(cruiseConfig);
    goConfigService.initialize();
    verify(goConfigDao).registerListener(any(BaseUrlChangeListener.class));
}
Also used : BaseUrlChangeListener(com.thoughtworks.go.listener.BaseUrlChangeListener) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 63 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoConfigServiceTest method shouldIgnoreXmlEntitiesAndReplaceThemWithEmptyString_DuringPipelineGroupPartialSave.

@Test
public void shouldIgnoreXmlEntitiesAndReplaceThemWithEmptyString_DuringPipelineGroupPartialSave() throws Exception {
    ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
    File targetFile = TempFiles.createUniqueFile("somefile");
    FileUtils.writeStringToFile(targetFile, "CONTENTS_OF_FILE", StandardCharsets.UTF_8);
    cruiseConfig = new BasicCruiseConfig();
    expectLoad(cruiseConfig);
    new GoConfigMother().addPipelineWithGroup(cruiseConfig, "group_name", "pipeline1", "stage_name", "job_name");
    expectLoadForEditing(cruiseConfig);
    when(goConfigDao.md5OfConfigFile()).thenReturn("md5");
    when(goConfigDao.updateFullConfig(commandArgumentCaptor.capture())).thenReturn(null);
    GoConfigService.XmlPartialSaver partialSaver = goConfigService.groupSaver("group_name");
    GoConfigValidity validity = partialSaver.saveXml(groupXmlWithEntity(targetFile.getAbsolutePath()), "md5");
    PipelineConfigs group = commandArgumentCaptor.getValue().configForEdit().findGroup("group_name");
    PipelineConfig pipeline = group.findBy(new CaseInsensitiveString("pipeline1"));
    assertThat(validity.isValid(), Matchers.is(true));
    String entityValue = pipeline.getParams().getParamNamed("foo").getValue();
    assertThat(entityValue, not(containsString("CONTENTS_OF_FILE")));
    assertThat(entityValue, isEmptyString());
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) File(java.io.File) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.jupiter.api.Test)

Example 64 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoConfigServiceTest method shouldReturnAllPipelinesForASuperAdmin.

@Test
public void shouldReturnAllPipelinesForASuperAdmin() throws Exception {
    GoConfigMother configMother = new GoConfigMother();
    BasicCruiseConfig config = GoConfigMother.defaultCruiseConfig();
    GoConfigMother.enableSecurityWithPasswordFilePlugin(config);
    GoConfigMother.addUserAsSuperAdmin(config, "superadmin");
    PipelineConfig pipelineConfig = configMother.addPipelineWithGroup(config, "group1", "p1", "s1", "j1");
    when(goConfigDao.loadForEditing()).thenReturn(config);
    expectLoad(config);
    List<PipelineConfig> pipelines = goConfigService.getAllPipelineConfigsForEditForUser(new Username("superadmin"));
    assertThat(pipelines, contains(pipelineConfig));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 65 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoDashboardServiceTest method shouldRemoveExistingPipelineEntryInCacheWhenPipelineConfigIsRemoved.

@Test
public void shouldRemoveExistingPipelineEntryInCacheWhenPipelineConfigIsRemoved() {
    BasicCruiseConfig config = GoConfigMother.defaultCruiseConfig();
    PipelineConfig pipelineConfig = new GoConfigMother().addPipeline(config, "pipeline1", "stage1", "job1");
    config.findGroupOfPipeline(pipelineConfig).remove(pipelineConfig);
    when(goConfigService.findGroupByPipeline(any())).thenReturn(null);
    // simulate the event
    service.updateCacheForPipeline(pipelineConfig);
    verify(cache).remove(pipelineConfig.getName());
    verify(dashboardCurrentStateLoader).clearEntryFor(pipelineConfig.getName());
    verifyNoMoreInteractions(dashboardCurrentStateLoader);
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Aggregations

GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)102 Test (org.junit.jupiter.api.Test)64 Username (com.thoughtworks.go.server.domain.Username)30 BeforeEach (org.junit.jupiter.api.BeforeEach)19 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)13 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)12 File (java.io.File)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)8 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 SCM (com.thoughtworks.go.domain.scm.SCM)4 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)3 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)3 Configuration (com.thoughtworks.go.domain.config.Configuration)3 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)3