3 * Copyright (C) 2009-2019 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.ce.task.projectanalysis.purge;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.sonar.api.CoreProperties;
25 import org.sonar.api.config.PropertyDefinitions;
26 import org.sonar.api.config.internal.MapSettings;
27 import org.sonar.core.config.PurgeConstants;
28 import org.sonar.core.config.PurgeProperties;
29 import org.sonar.db.DbSession;
30 import org.sonar.db.purge.PurgeDao;
31 import org.sonar.db.purge.PurgeListener;
32 import org.sonar.db.purge.PurgeProfiler;
33 import org.sonar.db.purge.period.DefaultPeriodCleaner;
35 import static java.util.Collections.emptyList;
36 import static org.mockito.ArgumentMatchers.any;
37 import static org.mockito.ArgumentMatchers.anyLong;
38 import static org.mockito.Mockito.mock;
39 import static org.mockito.Mockito.never;
40 import static org.mockito.Mockito.verify;
42 public class ProjectCleanerTest {
44 private ProjectCleaner underTest;
45 private PurgeDao dao = mock(PurgeDao.class);
46 private PurgeProfiler profiler = mock(PurgeProfiler.class);
47 private DefaultPeriodCleaner periodCleaner = mock(DefaultPeriodCleaner.class);
48 private PurgeListener purgeListener = mock(PurgeListener.class);
49 private MapSettings settings = new MapSettings(new PropertyDefinitions(PurgeProperties.all()));
52 public void before() {
53 this.underTest = new ProjectCleaner(dao, periodCleaner, profiler, purgeListener);
57 public void no_profiling_when_property_is_false() {
58 settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, false);
60 underTest.purge(mock(DbSession.class), "root", "project", settings.asConfig(), emptyList());
62 verify(profiler, never()).dump(anyLong(), any());
66 public void profiling_when_property_is_true() {
67 settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, true);
69 underTest.purge(mock(DbSession.class), "root", "project", settings.asConfig(), emptyList());
71 verify(profiler).dump(anyLong(), any());
75 public void call_period_cleaner_index_client_and_purge_dao() {
76 settings.setProperty(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES, 5);
78 underTest.purge(mock(DbSession.class), "root", "project", settings.asConfig(), emptyList());
80 verify(periodCleaner).clean(any(), any(), any());
81 verify(dao).purge(any(), any(), any(), any());