2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2008-2012 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * Sonar 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 * Sonar 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
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.plugins.dbcleaner.period;
22 import org.apache.commons.configuration.PropertiesConfiguration;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.sonar.api.resources.Project;
26 import org.sonar.jpa.test.AbstractDbUnitTestCase;
28 import java.util.Date;
29 import java.util.GregorianCalendar;
31 public class DefaultPeriodCleanerTest extends AbstractDbUnitTestCase {
33 DefaultPeriodCleaner cleaner;
40 cleaner = new DefaultPeriodCleaner(getSession());
42 project = new Project("myproject");
43 project.setConfiguration(new PropertiesConfiguration());
45 GregorianCalendar calendar = new GregorianCalendar(2010, 10, 1);
46 Date dateToStartKeepingOneSnapshotByWeek = calendar.getTime();
47 calendar.set(2010, 7, 1);
48 Date dateToStartKeepingOneSnapshotByMonth = calendar.getTime();
49 calendar.set(2010, 2, 1);
50 Date dateToStartDeletingAllSnapshots = calendar.getTime();
51 periods = new Periods(dateToStartKeepingOneSnapshotByWeek, dateToStartKeepingOneSnapshotByMonth, dateToStartDeletingAllSnapshots);
55 public void integrationTests() {
56 setupData("dbContent");
57 cleaner.purge(project, 1010, periods);
58 checkTables("dbContent", "snapshots");
63 // After a first run, no more snapshot should be deleted
64 setupData("dbContent-result");
65 cleaner.purge(project, 1010, periods);
66 checkTables("dbContent");