@Test
  public void shouldUpdateSubjectWhenUpdateCalledOnCommand() throws Exception {
    Username username = new Username(new CaseInsensitiveString("user"));
    PackageRepository packageRepository = new PackageRepository();

    UpdateConfigFromUI updateCommand =
        service.getPackageRepositoryUpdateCommand(packageRepository, username);

    CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
    updateCommand.update(cruiseConfig);
    verify(cruiseConfig).savePackageRepository(packageRepository);
  }
  @Test
  public void shouldCheckIfUserCanAccessAdminPagesWhileUpdatingPackageRepository()
      throws Exception {
    Username username = new Username(new CaseInsensitiveString("user"));
    when(securityService.canViewAdminPage(username)).thenReturn(false);

    UpdateConfigFromUI updateCommand =
        service.getPackageRepositoryUpdateCommand(new PackageRepository(), username);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    updateCommand.checkPermission(GoConfigMother.configWithPipelines("sample"), result);

    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(401));
    verify(securityService).canViewAdminPage(username);
  }
  @Test
  public void shouldValidateUpdateCommandForPackageRepository() throws Exception {
    Username username = new Username(new CaseInsensitiveString("user"));
    Validatable packageRepository = new PackageRepository();
    ((PackageRepository) packageRepository).setId("id");

    Validatable cruiseConfig = GoConfigMother.configWithPipelines("sample");
    ((CruiseConfig) cruiseConfig)
        .getPackageRepositories()
        .add((PackageRepository) packageRepository);

    UpdateConfigFromUI updateCommand =
        service.getPackageRepositoryUpdateCommand((PackageRepository) packageRepository, username);

    assertThat(updateCommand.node((CruiseConfig) cruiseConfig), is(cruiseConfig));
    assertThat(updateCommand.updatedNode((CruiseConfig) cruiseConfig), is(cruiseConfig));
    assertThat(updateCommand.subject(cruiseConfig), is(packageRepository));
    assertThat(updateCommand.updatedSubject(cruiseConfig), is(packageRepository));
  }