diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-06 14:08:06 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-06 14:08:06 +0000 |
commit | aeadc1f9129274949daaa57738c7c4550bdfbc7b (patch) | |
tree | 08dadf5ef7474fc41d1d48f74648f1ba8b55f34d /sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java | |
download | sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.tar.gz sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.zip |
SONAR-236 remove deprecated code from checkstyle plugin + display default value of rule parameters in Q profile console
Diffstat (limited to 'sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java')
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java b/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java new file mode 100644 index 00000000000..9158839ea1a --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java @@ -0,0 +1,78 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2009 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.batch; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.Purge; +import org.sonar.api.database.model.Snapshot; +import org.sonar.api.resources.Project; +import org.sonar.core.purge.DefaultPurgeContext; +import org.sonar.jpa.test.AbstractDbUnitTestCase; + +import javax.persistence.Query; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class FinalizeSnapshotsJobTest extends AbstractDbUnitTestCase { + + private Purge purgeMock=null; + + @Before + public void before() { + purgeMock = mock(Purge.class); + } + + @Test + public void shouldUnflagPenultimateLastSnapshot() throws Exception { + assertAnalysis(11, "shouldUnflagPenultimateLastSnapshot"); + verify(purgeMock).purge(new DefaultPurgeContext(11, 1)); + } + + @Test + public void doNotFailIfNoPenultimateLast() throws Exception { + assertAnalysis(5, "doNotFailIfNoPenultimateLast"); + verify(purgeMock).purge(new DefaultPurgeContext(5, null)); + } + + @Test + public void lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot() { + assertAnalysis(6, "lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot"); + verify(purgeMock).purge(new DefaultPurgeContext(6, null)); + } + + private void assertAnalysis(int snapshotId, String fixture) { + setupData("sharedFixture", fixture); + + FinalizeSnapshotsJob sensor = new FinalizeSnapshotsJob(mock(ServerMetadata.class), getSession(), new Purge[]{purgeMock}, loadSnapshot(snapshotId)); + sensor.execute(new Project("key"), null); + + getSession().stop(); + checkTables(fixture, "snapshots"); + } + + + private Snapshot loadSnapshot(int id) { + Query query = getSession().createQuery("SELECT s FROM Snapshot s WHERE s.id=:id"); + query.setParameter("id", id); + return (Snapshot) query.getSingleResult(); + } +} |