コード例 #1
0
  @Test
  public void shouldNotContinueWithConfigSaveIfObjectNotFound() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(false);

    SCM updatedScm =
        new SCM(
            "non-existent-id",
            new PluginConfiguration("plugin-id", "1"),
            new Configuration(
                new ConfigurationProperty(
                    new ConfigurationKey("key1"), new ConfigurationValue("value1"))));
    UpdateSCMConfigCommand command =
        new UpdateSCMConfigCommand(
            updatedScm,
            pluggableScmService,
            goConfigService,
            currentUser,
            result,
            "md5",
            entityHashingService);

    thrown.expect(NullPointerException.class);
    thrown.expectMessage("The pluggable scm material with id 'non-existent-id' is not found.");
    assertThat(command.canContinue(cruiseConfig), is(false));
  }
コード例 #2
0
  @Test
  public void shouldNotContinueWithConfigSaveIfUserIsUnauthorized() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
    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"))));
    UpdateSCMConfigCommand command =
        new UpdateSCMConfigCommand(
            updatedScm,
            pluggableScmService,
            goConfigService,
            currentUser,
            result,
            "md5",
            entityHashingService);

    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("UNAUTHORIZED_TO_EDIT"));
  }
コード例 #3
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()));
  }
コード例 #4
0
 @Test
 public void shouldThrowAnExceptionIfSCMIsNotFound() throws Exception {
   SCM updatedScm =
       new SCM(
           "non-existent-id",
           new PluginConfiguration("non-existent-plugin-id", "1"),
           new Configuration(
               new ConfigurationProperty(
                   new ConfigurationKey("key1"), new ConfigurationValue("value1"))));
   UpdateSCMConfigCommand command =
       new UpdateSCMConfigCommand(
           updatedScm,
           pluggableScmService,
           goConfigService,
           currentUser,
           result,
           "md5",
           entityHashingService);
   thrown.expect(NullPointerException.class);
   thrown.expectMessage("The pluggable scm material with id 'non-existent-id' is not found.");
   command.update(cruiseConfig);
 }
コード例 #5
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));
 }