@Test public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() { when(goConfigService.isUserAdmin(currentUser)).thenReturn(true); when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(false); SCM updatedScm = new SCM( "id", new PluginConfiguration("plugin-id", "1"), new Configuration( new ConfigurationProperty( new ConfigurationKey("key1"), new ConfigurationValue("value1")))); updatedScm.setName("material"); when(entityHashingService.md5ForEntity(cruiseConfig.getSCMs().find("id"), "material")) .thenReturn("another-md5"); UpdateSCMConfigCommand command = new UpdateSCMConfigCommand( updatedScm, pluggableScmService, goConfigService, currentUser, result, "md5", entityHashingService); assertThat(command.canContinue(cruiseConfig), is(false)); assertThat(result.toString(), containsString("STALE_RESOURCE_CONFIG")); assertThat(result.toString(), containsString(updatedScm.getName())); }
@Test public void shouldUpdateAnExistingSCMWithNewValues() throws Exception { SCM updatedScm = new SCM( "id", new PluginConfiguration("plugin-id", "1"), new Configuration( new ConfigurationProperty( new ConfigurationKey("key1"), new ConfigurationValue("value1")))); updatedScm.setName("material"); UpdateSCMConfigCommand command = new UpdateSCMConfigCommand( updatedScm, pluggableScmService, goConfigService, currentUser, result, "md5", entityHashingService); assertThat(cruiseConfig.getSCMs().contains(scm), is(true)); command.update(cruiseConfig); assertThat(cruiseConfig.getSCMs().contains(updatedScm), is(true)); }