예제 #1
0
  @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()));
  }
예제 #2
0
 @Before
 public void setup() throws Exception {
   initMocks(this);
   result = new HttpLocalizedOperationResult();
   currentUser = new Username(new CaseInsensitiveString("user"));
   cruiseConfig = new GoConfigMother().defaultCruiseConfig();
   scm =
       new SCM(
           "id",
           new PluginConfiguration("plugin-id", "1"),
           new Configuration(
               new ConfigurationProperty(
                   new ConfigurationKey("key"), new ConfigurationValue("value"))));
   scm.setName("material");
   scms = new SCMs();
   scms.add(scm);
   cruiseConfig.setSCMs(scms);
 }
예제 #3
0
 @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));
 }