use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldLoadAsUser_Filesystem_WithMd5Sum.
@Test
public void shouldLoadAsUser_Filesystem_WithMd5Sum() throws Exception {
GoConfigHolder configHolder = goConfigDao.loadConfigHolder();
String md5 = DigestUtils.md5Hex(FileUtils.readFileToString(dataSource.fileLocation()));
assertThat(configHolder.configForEdit.getMd5(), is(md5));
assertThat(configHolder.config.getMd5(), is(md5));
CruiseConfig forEdit = configHolder.configForEdit;
forEdit.addPipeline("my-awesome-group", PipelineConfigMother.createPipelineConfig("pipeline-foo", "stage-bar", "job-baz"));
FileOutputStream fos = new FileOutputStream(dataSource.fileLocation());
new MagicalGoConfigXmlWriter(configCache, ConfigElementImplementationRegistryMother.withNoPlugins()).write(forEdit, fos, false);
configHolder = dataSource.load();
String xmlText = FileUtils.readFileToString(dataSource.fileLocation());
String secondMd5 = DigestUtils.md5Hex(xmlText);
assertThat(configHolder.configForEdit.getMd5(), is(secondMd5));
assertThat(configHolder.config.getMd5(), is(secondMd5));
assertThat(configHolder.configForEdit.getMd5(), is(not(md5)));
GoConfigRevision commitedVersion = configRepository.getRevision(secondMd5);
assertThat(commitedVersion.getContent(), is(xmlText));
assertThat(commitedVersion.getUsername(), is(GoFileConfigDataSource.FILESYSTEM));
}
use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldUse_UserFromSession_asConfigModifyingUserWhenNoneGiven.
@Test
public void shouldUse_UserFromSession_asConfigModifyingUserWhenNoneGiven() throws GitAPIException, IOException {
SecurityContext context = SecurityContextHolder.getContext();
context.setAuthentication(new UsernamePasswordAuthenticationToken(new User("loser_boozer", "pass", true, true, true, true, new GrantedAuthority[] {}), null));
goConfigDao.updateMailHost(getMailHost("mailhost.local"));
CruiseConfig cruiseConfig = goConfigDao.load();
GoConfigRevision revision = configRepository.getRevision(cruiseConfig.getMd5());
assertThat(revision.getUsername(), is("loser_boozer"));
}
use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldVersionTheCruiseConfigXmlWhenSaved.
@Test
public void shouldVersionTheCruiseConfigXmlWhenSaved() throws Exception {
CachedGoConfig cachedGoConfig = configHelper.getCachedGoConfig();
CruiseConfig configForEdit = cachedGoConfig.loadForEditing();
GoConfigHolder configHolder = new GoConfigHolder(cachedGoConfig.currentConfig(), configForEdit);
Date loserChangedAt = new DateTime().plusDays(2).toDate();
when(timeProvider.currentTime()).thenReturn(loserChangedAt);
GoConfigHolder afterFirstSave = dataSource.writeWithLock(new UserAwarePipelineAddingCommand("foo-pipeline", "loser"), configHolder).getConfigHolder();
Date biggerLoserChangedAt = new DateTime().plusDays(4).toDate();
when(timeProvider.currentTime()).thenReturn(biggerLoserChangedAt);
GoConfigHolder afterSecondSave = dataSource.writeWithLock(new UserAwarePipelineAddingCommand("bar-pipeline", "bigger_loser"), afterFirstSave).getConfigHolder();
String expectedMd5 = afterFirstSave.config.getMd5();
GoConfigRevision firstRev = configRepository.getRevision(expectedMd5);
assertThat(firstRev.getUsername(), is("loser"));
assertThat(firstRev.getGoVersion(), is(CurrentGoCDVersion.getInstance().formatted()));
assertThat(firstRev.getMd5(), is(expectedMd5));
assertThat(firstRev.getTime(), is(loserChangedAt));
assertThat(firstRev.getSchemaVersion(), is(GoConstants.CONFIG_SCHEMA_VERSION));
assertThat(com.thoughtworks.go.config.ConfigMigrator.load(firstRev.getContent()), is(afterFirstSave.configForEdit));
CruiseConfig config = afterSecondSave.config;
assertThat(config.hasPipelineNamed(new CaseInsensitiveString("bar-pipeline")), is(true));
expectedMd5 = config.getMd5();
GoConfigRevision secondRev = configRepository.getRevision(expectedMd5);
assertThat(secondRev.getUsername(), is("bigger_loser"));
assertThat(secondRev.getGoVersion(), is(CurrentGoCDVersion.getInstance().formatted()));
assertThat(secondRev.getMd5(), is(expectedMd5));
assertThat(secondRev.getTime(), is(biggerLoserChangedAt));
assertThat(secondRev.getSchemaVersion(), is(GoConstants.CONFIG_SCHEMA_VERSION));
assertThat(com.thoughtworks.go.config.ConfigMigrator.load(secondRev.getContent()), is(afterSecondSave.configForEdit));
}
use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.
the class GoConfigMigrator method upgradeVersionedConfigFile.
private GoConfigHolder upgradeVersionedConfigFile(Exception originalException) throws Exception {
GoConfigRevision currentConfigRevision = configRepository.getCurrentRevision();
if (currentConfigRevision == null) {
LOGGER.warn("There is no versioned configuration to fallback for migration.");
throw originalException;
}
try {
File backupFile = this.goConfigMigration.revertFileToVersion(fileLocation(), currentConfigRevision);
logException(backupFile.getAbsolutePath(), originalException.getMessage());
return upgradeConfigFile();
} catch (Exception e) {
LOGGER.warn("The versioned config file could be invalid or migrating the versioned config resulted in an invalid configuration");
throw e;
}
}
use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.
the class GoConfigAdministrationControllerTest method shouldLoadSpecificConfigVersionWhenHistoricalVersionIsRequested.
@Test
public void shouldLoadSpecificConfigVersionWhenHistoricalVersionIsRequested() throws Exception {
MockHttpServletResponse response = new MockHttpServletResponse();
String configXml = "config-content";
when(goConfigService.getConfigAtVersion("some-md5")).thenReturn(new GoConfigRevision(configXml, "some-md5", "loser", "100.9.3.1", new TimeProvider()));
controller.getConfigRevision("some-md5", response);
assertThat(response.getContentAsString(), is(configXml));
assertThat(response.getHeader(XmlAction.X_CRUISE_CONFIG_MD5).toString(), is("some-md5"));
}
Aggregations