aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-dbcleaner-plugin/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-01-27 16:48:54 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-01-27 16:48:54 +0100
commitf5ff50a3a00fac3e9d7237b653771b812b01aa3e (patch)
tree1c2197c342d51351b6991982159a0be8773fa0e2 /plugins/sonar-dbcleaner-plugin/src/test
parent0a77863d625d55d3ae67f21aa6dce53903cd83d2 (diff)
downloadsonarqube-f5ff50a3a00fac3e9d7237b653771b812b01aa3e.tar.gz
sonarqube-f5ff50a3a00fac3e9d7237b653771b812b01aa3e.zip
SONAR-2757 extract purge task into a dedicated component
Diffstat (limited to 'plugins/sonar-dbcleaner-plugin/src/test')
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerPluginTest.java3
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java (renamed from plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJobTest.java)32
2 files changed, 12 insertions, 23 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerPluginTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerPluginTest.java
index e46d3bb44bb..30476ece23f 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerPluginTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerPluginTest.java
@@ -23,12 +23,11 @@ import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
public class DbCleanerPluginTest {
@Test
public void shouldGetExtensions() {
- assertThat(new DbCleanerPlugin().getExtensions().size(), is(2));
+ assertThat(new DbCleanerPlugin().getExtensions().size(), is(3));
}
}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJobTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java
index ffc6cdf4c5d..f40c61b5fb2 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJobTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java
@@ -23,10 +23,8 @@ import org.apache.commons.lang.ArrayUtils;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.Test;
-import org.sonar.api.batch.SensorContext;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Project;
import org.sonar.core.purge.PurgeDao;
import org.sonar.core.purge.PurgeSnapshotQuery;
import org.sonar.plugins.dbcleaner.api.DbCleanerConstants;
@@ -34,14 +32,14 @@ import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner;
import static org.mockito.Mockito.*;
-public class ProjectPurgePostJobTest {
+public class DefaultPurgeTaskTest {
@Test
public void shouldNotDeleteHistoricalDataOfDirectoriesByDefault() {
PurgeDao purgeDao = mock(PurgeDao.class);
- Settings settings = new Settings(new PropertyDefinitions(ProjectPurgePostJob.class));
- ProjectPurgePostJob job = new ProjectPurgePostJob(purgeDao, settings, mock(DefaultPeriodCleaner.class));
+ Settings settings = new Settings(new PropertyDefinitions(DefaultPurgeTask.class));
+ DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class));
- job.executeOn(newProject(), mock(SensorContext.class));
+ task.purgeProject(1L);
verify(purgeDao, never()).deleteSnapshots(argThat(newDirectoryQueryMatcher()));
}
@@ -49,11 +47,11 @@ public class ProjectPurgePostJobTest {
@Test
public void shouldDeleteHistoricalDataOfDirectories() {
PurgeDao purgeDao = mock(PurgeDao.class);
- Settings settings = new Settings(new PropertyDefinitions(ProjectPurgePostJob.class));
+ Settings settings = new Settings(new PropertyDefinitions(DefaultPurgeTask.class));
settings.setProperty(DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY, "true");
- ProjectPurgePostJob job = new ProjectPurgePostJob(purgeDao, settings, mock(DefaultPeriodCleaner.class));
+ DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class));
- job.executeOn(newProject(), mock(SensorContext.class));
+ task.purgeProject(1L);
verify(purgeDao, times(1)).deleteSnapshots(argThat(newDirectoryQueryMatcher()));
}
@@ -61,13 +59,12 @@ public class ProjectPurgePostJobTest {
@Test
public void shouldNotFailOnErrors() {
PurgeDao purgeDao = mock(PurgeDao.class);
- when(purgeDao.purgeProject(anyInt())).thenThrow(new RuntimeException());
-
- ProjectPurgePostJob job = new ProjectPurgePostJob(purgeDao, new Settings(), mock(DefaultPeriodCleaner.class));
+ when(purgeDao.purgeProject(anyLong())).thenThrow(new RuntimeException());
+ DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, new Settings(), mock(DefaultPeriodCleaner.class));
- job.executeOn(newProject(), mock(SensorContext.class));
+ task.purgeProject(1L);
- verify(purgeDao).purgeProject(anyInt());
+ verify(purgeDao).purgeProject(anyLong());
}
private BaseMatcher<PurgeSnapshotQuery> newDirectoryQueryMatcher() {
@@ -81,11 +78,4 @@ public class ProjectPurgePostJobTest {
}
};
}
-
- private Project newProject() {
- Project project = new Project("foo");
- project.setId(1);
- return project;
- }
-
}