Search in sources :

Example 91 with GoConfigMother

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

the class GoConfigServiceIntegrationTest method shouldNotThrowUpOnConfigSaveWhenIndependentChangesAreMade_ViaMergeFlow.

@Test
public void shouldNotThrowUpOnConfigSaveWhenIndependentChangesAreMade_ViaMergeFlow() throws Exception {
    // Priming current configuration to add lines simulating the license section before removal
    for (int i = 0; i < 10; i++) {
        configHelper.addRole(new RoleConfig(new CaseInsensitiveString("admin_role_" + i), new RoleUser(new CaseInsensitiveString("admin_user_" + i))));
    }
    // User 1 loads page
    CruiseConfig user1SeeingConfig = goConfigDao.loadForEditing();
    String user1SeeingMd5 = user1SeeingConfig.getMd5();
    // User 2 edits config
    configHelper.addPipelineWithGroup("defaultGroup", "user2_pipeline", "user2_stage", "user2_job");
    CruiseConfig user2SeeingConfig = configHelper.load();
    // User 1 edits old config to make an independent change
    new GoConfigMother().addRole(user1SeeingConfig, new RoleConfig(new CaseInsensitiveString("admin_role"), new RoleUser(new CaseInsensitiveString("admin_user"))));
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    configHelper.getXml(user1SeeingConfig, os);
    // User 1 saves edited config
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
    GoConfigValidity validity = saver.saveXml(os.toString(), user1SeeingMd5);
    assertThat(validity.isValid(), is(true));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.jupiter.api.Test)

Example 92 with GoConfigMother

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

the class GoConfigServiceIntegrationTest method shouldNotThrowUpOnConfigSave_ViaNormalFlow.

@Test
public void shouldNotThrowUpOnConfigSave_ViaNormalFlow() throws Exception {
    // User 1 loads page
    CruiseConfig user1SeeingConfig = goConfigDao.loadForEditing();
    // User 2 edits config
    configHelper.addPipelineWithGroup("defaultGroup", "user2_pipeline", "user2_stage", "user2_job");
    CruiseConfig user2SeeingConfig = configHelper.load();
    String user2SeeingMd5 = user2SeeingConfig.getMd5();
    // User 1 edits new config
    new GoConfigMother().addPipelineWithGroup(user2SeeingConfig, "defaultGroup", "user1_pipeline", "user1_stage", "user1_job");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    configHelper.getXml(user2SeeingConfig, os);
    // User 1 saves edited config
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
    GoConfigValidity validity = saver.saveXml(os.toString(), user2SeeingMd5);
    assertThat(validity.isValid(), is(true));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.jupiter.api.Test)

Example 93 with GoConfigMother

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

the class GoConfigServiceIntegrationTest method shouldThrowUpOnConfigSavePreValidationError_ViaMergeFlow.

@Test
public void shouldThrowUpOnConfigSavePreValidationError_ViaMergeFlow() throws Exception {
    // User 1 loads page
    CruiseConfig user1SeeingConfig = goConfigDao.loadForEditing();
    String user1SeeingMd5 = user1SeeingConfig.getMd5();
    // User 2 edits config
    configHelper.addPipelineWithGroup("defaultGroup", "user2_pipeline", "user2_stage", "user2_job");
    CruiseConfig user2SeeingConfig = configHelper.load();
    // User 1 edits old config
    new GoConfigMother().addPipelineWithGroup(user1SeeingConfig, "defaultGroup", "user1_pipeline", "user1_stage", "user1_job");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    configHelper.getXml(user1SeeingConfig, os);
    // Introduce validation error on xml
    String xml = os.toString();
    xml = xml.replace("user1_pipeline", "user1 pipeline");
    // User 1 saves edited config
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
    GoConfigValidity validity = saver.saveXml(xml, user1SeeingMd5);
    assertThat(validity.isValid(), is(false));
    GoConfigValidity.InvalidGoConfig invalidGoConfig = (GoConfigValidity.InvalidGoConfig) validity;
    // Pre throws VT_CONFLICT as user submitted xml is validated before attempting to save
    assertThat(invalidGoConfig.isType(GoConfigValidity.VT_CONFLICT), is(true));
    assertThat(invalidGoConfig.errorMessage(), containsString("Name is invalid. \"user1 pipeline\""));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.jupiter.api.Test)

Example 94 with GoConfigMother

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

the class GoConfigServiceIntegrationTest method shouldThrowUpOnConfigSaveMergeConflict_ViaMergeFlow.

@Test
public void shouldThrowUpOnConfigSaveMergeConflict_ViaMergeFlow() throws Exception {
    // User 1 loads page
    CruiseConfig user1SeeingConfig = goConfigDao.loadForEditing();
    String user1SeeingMd5 = user1SeeingConfig.getMd5();
    // User 2 edits config
    configHelper.addPipelineWithGroup("defaultGroup", "user2_pipeline", "user2_stage", "user2_job");
    CruiseConfig user2SeeingConfig = configHelper.load();
    // User 1 edits old config
    new GoConfigMother().addPipelineWithGroup(user1SeeingConfig, "defaultGroup", "user1_pipeline", "user1_stage", "user1_job");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    configHelper.getXml(user1SeeingConfig, os);
    // User 1 saves edited config
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
    GoConfigValidity validity = saver.saveXml(os.toString(), user1SeeingMd5);
    assertThat(validity.isValid(), is(false));
    GoConfigValidity.InvalidGoConfig invalidGoConfig = (GoConfigValidity.InvalidGoConfig) validity;
    assertThat(invalidGoConfig.isType(GoConfigValidity.VT_MERGE_OPERATION_ERROR), is(true));
    assertThat(invalidGoConfig.errorMessage(), is("Configuration file has been modified by someone else."));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.jupiter.api.Test)

Example 95 with GoConfigMother

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

the class CcTrayViewAuthorityTest method setUp.

@Before
public void setUp() throws Exception {
    configService = mock(GoConfigService.class);
    service = new CcTrayViewAuthority(configService);
    configMother = new GoConfigMother();
    config = GoConfigMother.defaultCruiseConfig();
}
Also used : GoConfigService(com.thoughtworks.go.server.service.GoConfigService) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Before(org.junit.Before)

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