Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ProjectCleanerTest.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.ce.task.projectanalysis.purge;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import org.sonar.api.CoreProperties;
  24. import org.sonar.api.config.PropertyDefinitions;
  25. import org.sonar.api.impl.config.MapSettings;
  26. import org.sonar.core.config.PurgeConstants;
  27. import org.sonar.core.config.PurgeProperties;
  28. import org.sonar.db.DbSession;
  29. import org.sonar.db.purge.PurgeDao;
  30. import org.sonar.db.purge.PurgeListener;
  31. import org.sonar.db.purge.PurgeProfiler;
  32. import org.sonar.db.purge.period.DefaultPeriodCleaner;
  33. import static java.util.Collections.emptySet;
  34. import static org.mockito.ArgumentMatchers.any;
  35. import static org.mockito.ArgumentMatchers.anyLong;
  36. import static org.mockito.Mockito.mock;
  37. import static org.mockito.Mockito.never;
  38. import static org.mockito.Mockito.verify;
  39. public class ProjectCleanerTest {
  40. private ProjectCleaner underTest;
  41. private PurgeDao dao = mock(PurgeDao.class);
  42. private PurgeProfiler profiler = mock(PurgeProfiler.class);
  43. private DefaultPeriodCleaner periodCleaner = mock(DefaultPeriodCleaner.class);
  44. private PurgeListener purgeListener = mock(PurgeListener.class);
  45. private MapSettings settings = new MapSettings(new PropertyDefinitions(PurgeProperties.all()));
  46. @Before
  47. public void before() {
  48. this.underTest = new ProjectCleaner(dao, periodCleaner, profiler, purgeListener);
  49. }
  50. @Test
  51. public void no_profiling_when_property_is_false() {
  52. settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, false);
  53. underTest.purge(mock(DbSession.class), "root", "project", settings.asConfig(), emptySet());
  54. verify(profiler, never()).dump(anyLong(), any());
  55. }
  56. @Test
  57. public void profiling_when_property_is_true() {
  58. settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, true);
  59. underTest.purge(mock(DbSession.class), "root", "project", settings.asConfig(), emptySet());
  60. verify(profiler).dump(anyLong(), any());
  61. }
  62. @Test
  63. public void call_period_cleaner_index_client_and_purge_dao() {
  64. settings.setProperty(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES, 5);
  65. underTest.purge(mock(DbSession.class), "root", "project", settings.asConfig(), emptySet());
  66. verify(periodCleaner).clean(any(), any(), any());
  67. verify(dao).purge(any(), any(), any(), any());
  68. }
  69. }