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