diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-07-02 20:13:22 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-07-02 21:29:42 +0200 |
commit | 29ae9b385a7bf720ae89637582c862df43b7fd0d (patch) | |
tree | c42098461a73b77d0fa8f2d91b09dac10250efdc /sonar-batch/src/test/java/org | |
parent | 25ff4124dbb2e2e5455fe94a4726c8b4d841f860 (diff) | |
download | sonarqube-29ae9b385a7bf720ae89637582c862df43b7fd0d.tar.gz sonarqube-29ae9b385a7bf720ae89637582c862df43b7fd0d.zip |
SONAR-6588 drop db connection from batch
Diffstat (limited to 'sonar-batch/src/test/java/org')
21 files changed, 25 insertions, 1377 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactoryTest.java deleted file mode 100644 index 7106ac25ff7..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactoryTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.junit.Test; -import org.sonar.api.database.DatabaseSession; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -public class BatchDatabaseSessionFactoryTest { - @Test - public void getSession() { - DatabaseSession session = mock(DatabaseSession.class); - BatchDatabaseSessionFactory factory = new BatchDatabaseSessionFactory(session); - - assertThat(factory.getSession()).isSameAs(session); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java deleted file mode 100644 index ed3d0dc1f06..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.junit.Test; -import org.sonar.api.config.Settings; - -import java.util.Properties; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -public class BatchDatabaseTest { - @Test - public void should_init_at_least_two_connections() { - BatchDatabase db = new BatchDatabase(new Settings(), mock(JdbcDriverHolder.class)); - Properties props = new Properties(); - - db.doCompleteProperties(props); - - assertThat(Integer.parseInt(props.getProperty("sonar.jdbc.initialSize"))).isGreaterThanOrEqualTo(2); - assertThat(Integer.parseInt(props.getProperty("sonar.jdbc.maxActive"))).isGreaterThanOrEqualTo(2); - } - -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java deleted file mode 100644 index e0ea0d6a440..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.CoreProperties; -import org.sonar.api.config.Settings; -import org.sonar.api.database.DatabaseProperties; -import org.sonar.api.utils.MessageException; -import org.sonar.core.persistence.DatabaseVersion; -import org.sonar.core.properties.PropertiesDao; -import org.sonar.core.properties.PropertyDto; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class DatabaseCompatibilityTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - DatabaseVersion databaseVersion; - ServerClient server; - Settings settings; - PropertiesDao propertiesDao; - - private DefaultAnalysisMode mode; - - @Before - public void init() { - server = mock(ServerClient.class); - when(server.getURL()).thenReturn("http://localhost:9000"); - when(server.request("/api/server")).thenReturn("{\"id\":\"123456\",\"version\":\"3.1\",\"status\":\"UP\"}"); - - settings = new Settings(); - settings.setProperty(DatabaseProperties.PROP_URL, "jdbc:postgresql://localhost/foo"); - settings.setProperty(DatabaseProperties.PROP_USER, "bar"); - - propertiesDao = mock(PropertiesDao.class); - when(propertiesDao.selectGlobalProperty(CoreProperties.SERVER_ID)).thenReturn(new PropertyDto().setValue("123456")); - - mode = mock(DefaultAnalysisMode.class); - - databaseVersion = mock(DatabaseVersion.class); - } - - @Test - public void shouldFailIfRequiresDowngrade() { - when(databaseVersion.getStatus()).thenReturn(DatabaseVersion.Status.REQUIRES_DOWNGRADE); - - thrown.expect(MessageException.class); - thrown.expectMessage("Database relates to a more recent version of SonarQube. Please check your settings (JDBC settings, version of Maven plugin)"); - - new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start(); - } - - @Test - public void shouldFailIfRequiresUpgrade() { - when(databaseVersion.getStatus()).thenReturn(DatabaseVersion.Status.REQUIRES_UPGRADE); - - thrown.expect(MessageException.class); - thrown.expectMessage("Database must be upgraded."); - - new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start(); - } - - @Test - public void shouldFailIfNotSameServerId() { - when(propertiesDao.selectGlobalProperty(CoreProperties.SERVER_ID)).thenReturn(new PropertyDto().setValue("11111111")); - - thrown.expect(MessageException.class); - thrown.expectMessage("The current batch process and the configured remote server do not share the same DB configuration."); - thrown.expectMessage("- Batch side: jdbc:postgresql://localhost/foo (bar / *****)"); - thrown.expectMessage("- Server side: check the configuration at http://localhost:9000/system"); - - new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start(); - } - - @Test - public void shouldUseDefaultUserNameWhenFaillingIfNotSameServerIdAndNoUserNameFound() { - when(propertiesDao.selectGlobalProperty(CoreProperties.SERVER_ID)).thenReturn(new PropertyDto().setValue("11111111")); - - settings.removeProperty(DatabaseProperties.PROP_USER); - - thrown.expect(MessageException.class); - thrown.expectMessage("- Batch side: jdbc:postgresql://localhost/foo (sonar / *****)"); - - new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start(); - } - - @Test - public void shouldFailIfCantGetServerId() { - when(server.request("/api/server")).thenThrow(new IllegalStateException()); - - thrown.expect(IllegalStateException.class); - - new DatabaseCompatibility(mock(DatabaseVersion.class), server, settings, propertiesDao, mode).start(); - } - - @Test - public void shouldDoNothingIfUpToDate() { - when(databaseVersion.getStatus()).thenReturn(DatabaseVersion.Status.UP_TO_DATE); - new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start(); - // no error - } - - @Test - public void should_not_verify_compatibility_if_preview() { - settings.setProperty(CoreProperties.SERVER_ID, "11111111"); - when(mode.isPreview()).thenReturn(true); - - new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start(); - - // no failure - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java index 5118c2426f4..39fc0210624 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java @@ -22,10 +22,9 @@ package org.sonar.batch.bootstrap; import org.junit.Test; import org.sonar.api.BatchComponent; import org.sonar.api.batch.BatchSide; -import org.sonar.api.server.ServerSide; import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.batch.RequiresDB; import org.sonar.api.batch.SupportedEnvironment; +import org.sonar.api.server.ServerSide; import org.sonar.batch.bootstrapper.EnvironmentInformation; import static org.assertj.core.api.Assertions.assertThat; @@ -81,14 +80,6 @@ public class ExtensionUtilsTest { assertThat(ExtensionUtils.isMavenExtensionOnly(new BuildToolService())).isFalse(); } - @Test - public void shouldRequiresDB() { - assertThat(ExtensionUtils.requiresDB(BatchService.class)).isFalse(); - assertThat(ExtensionUtils.requiresDB(new BatchService())).isFalse(); - assertThat(ExtensionUtils.requiresDB(PersistentService.class)).isTrue(); - assertThat(ExtensionUtils.requiresDB(new PersistentService())).isTrue(); - } - @BatchSide @InstantiationStrategy(InstantiationStrategy.PER_BATCH) public static class BatchService { @@ -126,10 +117,4 @@ public class ExtensionUtilsTest { public static class BuildToolService { } - - @BatchSide - @RequiresDB - public static class PersistentService { - - } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java deleted file mode 100644 index 17c2096ba29..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import com.google.common.io.Resources; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.sonar.home.cache.FileCache; - -import java.io.File; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -public class JdbcDriverHolderTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - ClassLoader initialThreadClassloader; - private DefaultAnalysisMode mode; - - @Before - public void before() { - initialThreadClassloader = Thread.currentThread().getContextClassLoader(); - mode = mock(DefaultAnalysisMode.class); - } - - @After - public void after() { - Thread.currentThread().setContextClassLoader(initialThreadClassloader); - } - - @Test - public void extend_classloader_with_jdbc_driver() { - FileCache cache = mock(FileCache.class); - - File fakeDriver = new File(Resources.getResource(JdbcDriverHolderTest.class, "JdbcDriverHolderTest/jdbc-driver.jar").getFile()); - when(cache.get(eq("ojdbc14.jar"), eq("fakemd5"), any(FileCache.Downloader.class))).thenReturn(fakeDriver); - - /* jdbc-driver.jar has just one file /foo/foo.txt */ - assertThat(Thread.currentThread().getContextClassLoader().getResource("foo/foo.txt")).isNull(); - - ServerClient server = mock(ServerClient.class); - when(server.request("/deploy/jdbc-driver.txt")).thenReturn("ojdbc14.jar|fakemd5"); - when(server.request("/deploy/ojdbc14.jar")).thenReturn("fakecontent"); - - JdbcDriverHolder holder = new JdbcDriverHolder(cache, mode, server); - holder.start(); - - assertThat(holder.getClassLoader().getResource("foo/foo.txt")).isNotNull(); - assertThat(Thread.currentThread().getContextClassLoader()).isSameAs(holder.getClassLoader()); - assertThat(holder.getClassLoader().getParent()).isSameAs(getClass().getClassLoader()); - - holder.stop(); - assertThat(Thread.currentThread().getContextClassLoader()).isSameAs(getClass().getClassLoader()); - assertThat(holder.getClassLoader()).isNull(); - } - - @Test - public void do_nothing_when_jdbc_driver_file_is_empty() { - FileCache cache = mock(FileCache.class); - - ServerClient server = mock(ServerClient.class); - when(server.request("/deploy/jdbc-driver.txt")).thenReturn(""); - - JdbcDriverHolder holder = new JdbcDriverHolder(cache, mode, server); - holder.start(); - - verify(server, never()).download(anyString(), any(File.class)); - verifyZeroInteractions(cache); - assertThat(holder.getClassLoader()).isNull(); - } - - @Test - public void be_disabled_if_preview() { - FileCache cache = mock(FileCache.class); - when(mode.isPreview()).thenReturn(true); - ServerClient server = mock(ServerClient.class); - JdbcDriverHolder holder = new JdbcDriverHolder(cache, mode, server); - - holder.start(); - - assertThat(holder.getClassLoader()).isNull(); - verifyZeroInteractions(server); - - // no error during stop - holder.stop(); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java deleted file mode 100644 index 60d8a465971..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.components; - -import org.junit.Test; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.measures.Metric; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -import java.util.Arrays; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; - -public class PastMeasuresLoaderTest extends AbstractDbUnitTestCase { - - private static final int PROJECT_SNAPSHOT_ID = 1000; - private static final String PROJECT_KEY = "project"; - private static final String FILE_KEY = "project:org.foo.Bar"; - - @Test - public void shouldGetPastResourceMeasures() { - setupData("shared"); - - List<Metric> metrics = selectMetrics(); - Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", PROJECT_SNAPSHOT_ID); - - PastMeasuresLoader loader = new PastMeasuresLoader(getSession(), metrics); - List<Object[]> measures = loader.getPastMeasures(FILE_KEY, projectSnapshot); - assertThat(measures.size(), is(2)); - - Object[] pastMeasure = measures.get(0); - assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(1)); - assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue()); - assertThat(PastMeasuresLoader.getPersonId(pastMeasure), nullValue()); - assertThat(PastMeasuresLoader.getValue(pastMeasure), is(5.0)); - - pastMeasure = measures.get(1); - assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(2)); - assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue()); - assertThat(PastMeasuresLoader.getPersonId(pastMeasure), nullValue()); - assertThat(PastMeasuresLoader.getValue(pastMeasure), is(60.0)); - } - - @Test - public void shouldGetPastProjectMeasures() { - setupData("shared"); - - List<Metric> metrics = selectMetrics(); - Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", PROJECT_SNAPSHOT_ID); - - PastMeasuresLoader loader = new PastMeasuresLoader(getSession(), metrics); - List<Object[]> measures = loader.getPastMeasures(PROJECT_KEY, projectSnapshot); - assertThat(measures.size(), is(2)); - - Object[] pastMeasure = measures.get(0); - assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(1)); - assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue()); - assertThat(PastMeasuresLoader.getPersonId(pastMeasure), nullValue()); - assertThat(PastMeasuresLoader.getValue(pastMeasure), is(60.0)); - - pastMeasure = measures.get(1); - assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(2)); - assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue()); - assertThat(PastMeasuresLoader.getPersonId(pastMeasure), nullValue()); - assertThat(PastMeasuresLoader.getValue(pastMeasure), is(80.0)); - } - - @Test - public void shouldKeepOnlyNumericalMetrics() { - Metric ncloc = new Metric("ncloc", Metric.ValueType.INT); - ncloc.setId(1); - Metric complexity = new Metric("complexity", Metric.ValueType.INT); - complexity.setId(2); - Metric data = new Metric("data", Metric.ValueType.DATA); - data.setId(3); - List<Metric> metrics = Arrays.asList(ncloc, complexity, data); - - PastMeasuresLoader loader = new PastMeasuresLoader(getSession(), metrics); - - assertThat(loader.getMetrics().size(), is(2)); - assertThat(loader.getMetrics(), hasItems(ncloc, complexity)); - } - - private List<Metric> selectMetrics() { - return getSession().getResults(Metric.class); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java deleted file mode 100644 index 8d8506a063a..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.components; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentMatcher; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.sonar.api.CoreProperties; -import org.sonar.api.config.Settings; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.utils.DateUtils; -import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate; -import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays; -import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis; -import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion; -import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import static junit.framework.Assert.assertNull; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class PastSnapshotFinderTest { - - @Mock - private PastSnapshotFinderByDays finderByDays; - @Mock - private PastSnapshotFinderByDate finderByDate; - @Mock - private PastSnapshotFinderByVersion finderByVersion; - @Mock - private PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis; - @Mock - private PastSnapshotFinderByPreviousVersion finderByPreviousVersion; - - private PastSnapshotFinder finder; - - @Before - public void initFinders() { - MockitoAnnotations.initMocks(this); - - finder = new PastSnapshotFinder(finderByDays, finderByVersion, finderByDate, finderByPreviousAnalysis, finderByPreviousVersion); - } - - @Test - public void should_find() { - Settings settings = new Settings().setProperty("sonar.timemachine.period5", "1.2"); - - when(finderByVersion.findByVersion(null, "1.2")).thenReturn(new PastSnapshot("version", new Date(), new Snapshot())); - - PastSnapshot variationSnapshot = finder.find(null, null, settings, 5); - - verify(finderByVersion).findByVersion(null, "1.2"); - assertThat(variationSnapshot.getIndex(), is(5)); - assertThat(variationSnapshot.getMode(), is("version")); - assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); - } - - @Test - public void should_find_with_qualifier_suffix() { - Settings settings = new Settings().setProperty("sonar.timemachine.period5.TRK", "1.2"); - - when(finderByVersion.findByVersion(null, "1.2")).thenReturn(new PastSnapshot("version", new Date(), new Snapshot())); - - PastSnapshot variationSnapshot = finder.find(null, "TRK", settings, 5); - - verify(finderByVersion).findByVersion(null, "1.2"); - assertThat(variationSnapshot.getIndex(), is(5)); - assertThat(variationSnapshot.getMode(), is("version")); - assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); - } - - @Test - public void should_find_by_number_of_days() { - when(finderByDays.findFromDays(null, 30)).thenReturn(new PastSnapshot("days", null).setModeParameter("30")); - - PastSnapshot variationSnapshot = finder.find(null, 1, "30"); - - verify(finderByDays).findFromDays(null, 30); - assertNotNull(variationSnapshot); - assertThat(variationSnapshot.getIndex(), is(1)); - assertThat(variationSnapshot.getMode(), is("days")); - assertThat(variationSnapshot.getModeParameter(), is("30")); - } - - @Test - public void should_not_find_by_number_of_days() { - PastSnapshot variationSnapshot = finder.find(null, 1, "30"); - - verify(finderByDays).findFromDays(null, 30); - assertNull(variationSnapshot); - } - - @Test - public void should_find_by_date() throws ParseException { - final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - final Date date = format.parse("2010-05-18"); - when(finderByDate.findByDate((Snapshot) null, date)).thenReturn(new PastSnapshot("date", date, new Snapshot())); - - PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18"); - - verify(finderByDate).findByDate(any(Snapshot.class), argThat(new ArgumentMatcher<Date>() { - @Override - public boolean matches(Object o) { - return o.equals(date); - } - })); - assertThat(variationSnapshot.getIndex(), is(2)); - assertThat(variationSnapshot.getMode(), is("date")); - assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); - } - - @Test - public void should_not_find_by_date() { - when(finderByDate.findByDate(any(Snapshot.class), any(Date.class))).thenReturn(null); - - PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18"); - - verify(finderByDate).findByDate(any(Snapshot.class), any(Date.class)); - assertNull(variationSnapshot); - } - - @Test - public void should_find_by_previous_analysis() { - final Date date = DateUtils.parseDate("2010-05-18"); - Snapshot snapshot = new Snapshot(); - snapshot.setCreatedAtMs(date.getTime()); - when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, date, snapshot)); - - PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - - verify(finderByPreviousAnalysis).findByPreviousAnalysis(null); - assertThat(variationSnapshot.getIndex(), is(2)); - assertThat(variationSnapshot.getMode(), is(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS)); - assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); - } - - @Test - public void should_not_find_previous_analysis() { - when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(null); - - PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - - verify(finderByPreviousAnalysis).findByPreviousAnalysis(null); - - assertNull(variationSnapshot); - } - - @Test - public void should_find_by_previous_version() throws ParseException { - final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - final Date date = format.parse("2010-05-18"); - Snapshot snapshot = new Snapshot(); - snapshot.setCreatedAtMs(date.getTime()); - when(finderByPreviousVersion.findByPreviousVersion(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, date, snapshot)); - - PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); - - verify(finderByPreviousVersion).findByPreviousVersion(null); - assertThat(variationSnapshot.getIndex(), is(2)); - assertThat(variationSnapshot.getMode(), is(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION)); - assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); - } - - @Test - public void should_find_by_version() { - when(finderByVersion.findByVersion(null, "1.2")).thenReturn(new PastSnapshot("version", new Date(), new Snapshot())); - - PastSnapshot variationSnapshot = finder.find(null, 2, "1.2"); - - verify(finderByVersion).findByVersion(null, "1.2"); - assertThat(variationSnapshot.getIndex(), is(2)); - assertThat(variationSnapshot.getMode(), is("version")); - assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); - } - - @Test - public void should_not_find_version() { - when(finderByVersion.findByVersion(null, "1.2")).thenReturn(null); - - PastSnapshot variationSnapshot = finder.find(null, 2, "1.2"); - - verify(finderByVersion).findByVersion(null, "1.2"); - assertNull(variationSnapshot); - } - - @Test - public void should_not_fail_if_unknown_format() { - // should not be called - when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot())); - - assertNull(finder.find(null, 2, "foooo")); - } - - @Test - public void should_get_property_value() { - Settings settings = new Settings().setProperty("sonar.timemachine.period1", "5"); - - assertThat(PastSnapshotFinder.getPropertyValue("FIL", settings, 1), is("5")); - assertThat(PastSnapshotFinder.getPropertyValue("FIL", settings, 999), nullValue()); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java deleted file mode 100644 index 3d38431f780..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.components; - -import org.junit.Test; -import org.sonar.api.CoreProperties; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.resources.Qualifiers; - -import java.util.Date; - -import static org.assertj.core.api.Assertions.assertThat; - -public class PastSnapshotTest { - - @Test - public void test_some_setters_and_getters() { - Snapshot snapshot = new Snapshot().setQualifier(Qualifiers.FILE).setCreatedAtMs(System.currentTimeMillis()); - snapshot.setId(10); - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), - snapshot) - .setModeParameter("2.3") - .setIndex(1); - - assertThat(pastSnapshot.getModeParameter()).isEqualTo("2.3"); - assertThat(pastSnapshot.getIndex()).isEqualTo(1); - assertThat(pastSnapshot.getQualifier()).isEqualTo(Qualifiers.FILE); - assertThat(pastSnapshot.getDate()).isNotNull(); - assertThat(pastSnapshot.getProjectSnapshotId()).isEqualTo(10); - } - - @Test - public void test_some_setters_and_getters_with_empty_snapshot() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION); - - assertThat(pastSnapshot.getQualifier()).isNull(); - assertThat(pastSnapshot.getDate()).isNull(); - assertThat(pastSnapshot.getProjectSnapshotId()).isNull(); - } - - @Test - public void testToStringForVersion() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())).setModeParameter("2.3"); - assertThat(pastSnapshot.toString()).startsWith("Compare to version 2.3"); - } - - @Test - public void testToStringForVersionWithoutDate() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION).setModeParameter("2.3"); - assertThat(pastSnapshot.toString()).isEqualTo("Compare to version 2.3"); - } - - @Test - public void testToStringForNumberOfDays() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, new Date()).setModeParameter("30"); - assertThat(pastSnapshot.toString()).startsWith("Compare over 30 days ("); - } - - @Test - public void testToStringForNumberOfDaysWithSnapshot() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())).setModeParameter("30"); - assertThat(pastSnapshot.toString()).startsWith("Compare over 30 days ("); - } - - @Test - public void testToStringForDate() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, new Date()); - assertThat(pastSnapshot.toString()).startsWith("Compare to date "); - } - - @Test - public void testToStringForDateWithSnapshot() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())); - assertThat(pastSnapshot.toString()).startsWith("Compare to date "); - } - - @Test - public void testToStringForPreviousAnalysis() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())); - assertThat(pastSnapshot.toString()).startsWith("Compare to previous analysis "); - } - - @Test - public void testToStringForPreviousAnalysisWithoutDate() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - assertThat(pastSnapshot.toString()).isEqualTo("Compare to previous analysis"); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java deleted file mode 100644 index b4a7daac7d5..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.components; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.database.model.Snapshot; -import org.sonar.batch.deprecated.components.PeriodsDefinition; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -import java.util.Date; - -import static com.google.common.collect.Lists.newArrayList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase { - - private PeriodsDefinition periodsDefinition; - - @Before - public void before() { - setupData("shared"); - periodsDefinition = mock(PeriodsDefinition.class); - } - - @Test - public void get_project_past_snapshot() { - Snapshot projectSnapshot = new Snapshot(); - projectSnapshot.setId(1010); - projectSnapshot.setResourceId(1); - PastSnapshot projectPastSnapshot = new PastSnapshot("mode", new Date(), projectSnapshot); - - when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot)); - - TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition); - assertThat(timeMachineConfiguration.periods()).hasSize(1); - assertThat(timeMachineConfiguration.periods().get(0).getDate()).isNotNull(); - assertThat(timeMachineConfiguration.getProjectPastSnapshots()).hasSize(1); - assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getProjectSnapshot().getId()).isEqualTo(1010); - } - - @Test - public void get_module_past_snapshot() { - Snapshot projectSnapshot = new Snapshot(); - projectSnapshot.setId(1010); - projectSnapshot.setResourceId(2); - PastSnapshot projectPastSnapshot = new PastSnapshot("mode", new Date(), projectSnapshot); - - when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot)); - - TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition); - assertThat(timeMachineConfiguration.periods()).hasSize(1); - assertThat(timeMachineConfiguration.periods().get(0).getDate()).isNotNull(); - assertThat(timeMachineConfiguration.getProjectPastSnapshots()).hasSize(1); - assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getProjectSnapshot().getId()).isEqualTo(1010); - } - - @Test - public void complete_past_snapshot_from_project_past_snapshot() { - Snapshot projectSnapshot = new Snapshot(); - projectSnapshot.setId(1010); - - PastSnapshot projectPastSnapshot = new PastSnapshot("mode", new Date(), projectSnapshot); - projectPastSnapshot.setIndex(1); - projectPastSnapshot.setMode("mode"); - projectPastSnapshot.setModeParameter("modeParam"); - - when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot)); - - TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition); - assertThat(timeMachineConfiguration.getProjectPastSnapshots()).hasSize(1); - assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getProjectSnapshot().getId()).isEqualTo(1010); - assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getIndex()).isEqualTo(1); - assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getMode()).isEqualTo("mode"); - assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getModeParameter()).isEqualTo("modeParam"); - } - - @Test - public void get_no_date_on_new_project() { - Snapshot projectSnapshot = new Snapshot(); - projectSnapshot.setId(1010); - - PastSnapshot projectPastSnapshot = new PastSnapshot("mode", new Date(), projectSnapshot); - - when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot)); - - TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition); - assertThat(timeMachineConfiguration.periods()).hasSize(1); - assertThat(timeMachineConfiguration.periods().get(0).getDate()).isNull(); - } - -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java deleted file mode 100644 index 7ab4b0e76e8..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated.components; - -import org.junit.Test; -import org.sonar.api.database.model.Snapshot; -import org.sonar.batch.components.PastSnapshot; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -public class PastSnapshotFinderByDateTest extends AbstractDbUnitTestCase { - public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); - - @Test - public void shouldFindDate() throws ParseException { - setupData("shared"); - - Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByDate finder = new PastSnapshotFinderByDate(getSession()); - - Date date = DATE_FORMAT.parse("2008-11-22"); - - PastSnapshot pastSnapshot = finder.findByDate(projectSnapshot, date); - assertThat(pastSnapshot.getProjectSnapshotId(), is(1006)); - } - - @Test - public void shouldFindNearestLaterDate() throws ParseException { - setupData("shared"); - - Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByDate finder = new PastSnapshotFinderByDate(getSession()); - - Date date = DATE_FORMAT.parse("2008-11-24"); - - PastSnapshot pastSnapshot = finder.findByDate(projectSnapshot, date); - assertThat(pastSnapshot.getProjectSnapshotId(), is(1009)); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java deleted file mode 100644 index 6117905e446..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated.components; - -import org.hamcrest.core.IsNull; -import org.junit.Test; -import org.sonar.api.database.model.Snapshot; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - -public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase { - - private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - - @Test - public void shouldGetNextSnapshot() { - setupData("shared"); - - Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16 - PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(getSession()); - - assertThat(finder.findFromDays(projectSnapshot, 50).getProjectSnapshotId(), is(1000)); - } - - @Test - public void shouldIgnoreUnprocessedSnapshots() { - setupData("shared"); - - Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16 - PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(getSession()); - - assertThat(finder.findFromDays(projectSnapshot, 7).getProjectSnapshotId(), is(1006)); - } - - @Test - public void shouldNotFindSelf() { - setupData("shouldNotFindSelf"); - - Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16 - PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(getSession()); - - assertThat(finder.findFromDays(projectSnapshot, 1).getProjectSnapshot(), nullValue()); - } - - @Test - public void shouldLocateNearestSnapshotBefore() throws ParseException { - Date current = dateFormat.parse("2010-10-20"); - // distance: 15 => target is 2010-10-05 - - List<Snapshot> snapshots = Arrays.asList( - newSnapshot(1, "2010-09-30"), - newSnapshot(2, "2010-10-03"),// -2 days - newSnapshot(3, "2010-10-08"),// +3 days - newSnapshot(4, "2010-10-12") // + 7 days - ); - assertThat(PastSnapshotFinderByDays.getNearestToTarget(snapshots, current, 15).getId(), is(2)); - } - - @Test - public void shouldLocateNearestSnapshotAfter() throws ParseException { - Date current = dateFormat.parse("2010-10-20"); - // distance: 15 => target is 2010-10-05 - - List<Snapshot> snapshots = Arrays.asList( - newSnapshot(1, "2010-09-30"), - newSnapshot(2, "2010-10-01"),// -4 days - newSnapshot(3, "2010-10-08"),// +3 days - newSnapshot(4, "2010-10-12") // + 7 days - ); - assertThat(PastSnapshotFinderByDays.getNearestToTarget(snapshots, current, 15).getId(), is(3)); - } - - @Test - public void shouldReturnNullIfNoSnapshots() throws ParseException { - Date current = dateFormat.parse("2010-10-20"); - List<Snapshot> snapshots = Collections.emptyList(); - assertThat(PastSnapshotFinderByDays.getNearestToTarget(snapshots, current, 15), IsNull.nullValue()); - } - - private Snapshot newSnapshot(int id, String date) throws ParseException { - Snapshot snapshot = new Snapshot(); - snapshot.setId(id); - snapshot.setCreatedAtMs(dateFormat.parse(date).getTime()); - return snapshot; - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java deleted file mode 100644 index f228d3b8ab8..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated.components; - -import org.junit.Test; -import org.sonar.api.database.model.Snapshot; -import org.sonar.batch.components.PastSnapshot; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsNull.nullValue; -import static org.junit.Assert.assertThat; - -public class PastSnapshotFinderByPreviousAnalysisTest extends AbstractDbUnitTestCase { - - @Test - public void shouldFindPreviousAnalysis() { - setupData("shouldFindPreviousAnalysis"); - - Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(getSession()); - - PastSnapshot pastSnapshot = finder.findByPreviousAnalysis(projectSnapshot); - assertThat(pastSnapshot.getProjectSnapshotId(), is(1009)); - } - - @Test - public void shouldReturnPastSnapshotEvenWhenNoPreviousAnalysis() { - setupData("shouldNotFindPreviousAnalysis"); - - Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(getSession()); - - PastSnapshot pastSnapshot = finder.findByPreviousAnalysis(projectSnapshot); - assertThat(pastSnapshot.isRelatedToSnapshot(), is(false)); - assertThat(pastSnapshot.getProjectSnapshot(), nullValue()); - assertThat(pastSnapshot.getDate(), nullValue()); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java deleted file mode 100644 index bd71b0b4351..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated.components; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.CoreProperties; -import org.sonar.api.database.model.Snapshot; -import org.sonar.batch.components.PastSnapshot; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -import static org.assertj.core.api.Assertions.assertThat; - -public class PastSnapshotFinderByPreviousVersionTest extends AbstractDbUnitTestCase { - - private PastSnapshotFinderByPreviousVersion finder; - - @Before - public void before() { - finder = new PastSnapshotFinderByPreviousVersion(getSession(), getMyBatis()); - } - - @Test - public void shouldFindByPreviousVersion() { - setupData("with-previous-version"); - - Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1003); - PastSnapshot foundSnapshot = finder.findByPreviousVersion(currentProjectSnapshot); - assertThat(foundSnapshot.getProjectSnapshotId()).isEqualTo(1001); - assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); - assertThat(foundSnapshot.getModeParameter()).isEqualTo("1.1"); - } - - @Test - public void shouldFindByPreviousVersionWhenPreviousVersionDeleted() { - setupData("with-previous-version-deleted"); - - Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1003); - PastSnapshot foundSnapshot = finder.findByPreviousVersion(currentProjectSnapshot); - assertThat(foundSnapshot.getProjectSnapshotId()).isEqualTo(1000); - assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); - assertThat(foundSnapshot.getModeParameter()).isEqualTo("1.0"); - } - - @Test - public void testWithNoPreviousVersion() { - setupData("no-previous-version"); - - Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1003); - PastSnapshot foundSnapshot = finder.findByPreviousVersion(currentProjectSnapshot); - assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); - assertThat(foundSnapshot.getProjectSnapshot()).isNull(); - assertThat(foundSnapshot.getModeParameter()).isNull(); - } - -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java deleted file mode 100644 index 85411b26cf7..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated.components; - -import org.junit.Test; -import org.sonar.api.CoreProperties; -import org.sonar.api.database.model.Snapshot; -import org.sonar.batch.components.PastSnapshot; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -import static org.assertj.core.api.Assertions.assertThat; - -public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase { - - @Test - public void shouldFindByVersion() { - setupData("shared"); - - Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(getSession()); - - PastSnapshot foundSnapshot = finder.findByVersion(currentProjectSnapshot, "1.1"); - assertThat(foundSnapshot.getProjectSnapshotId()).isEqualTo(1009); - assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION); - } - - @Test - public void testIfNoVersionFound() { - setupData("shared"); - - Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(getSession()); - - PastSnapshot foundSnapshot = finder.findByVersion(currentProjectSnapshot, "2.1"); - assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION); - assertThat(foundSnapshot.getProjectSnapshot()).isNull(); - assertThat(foundSnapshot.getModeParameter()).isNull(); - } - -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java deleted file mode 100644 index 373398f8edc..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.batch.deprecated.components; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentMatcher; -import org.sonar.api.config.Settings; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.resources.Project; -import org.sonar.batch.DefaultProjectTree; -import org.sonar.batch.components.PastSnapshotFinder; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -public class PeriodsDefinitionTest extends AbstractDbUnitTestCase { - - private Settings settings; - private PastSnapshotFinder pastSnapshotFinder; - - @Before - public void before() { - setupData("shared"); - settings = new Settings(); - pastSnapshotFinder = mock(PastSnapshotFinder.class); - } - - @Test - public void should_init_past_snapshots() { - DefaultProjectTree projectTree = mock(DefaultProjectTree.class); - when(projectTree.getRootProject()).thenReturn(new Project("my:project")); - new PeriodsDefinition(getSession(), projectTree, settings, pastSnapshotFinder); - - verify(pastSnapshotFinder).find(argThat(new ArgumentMatcher<Snapshot>() { - @Override - public boolean matches(Object o) { - return ((Snapshot) o).getResourceId() == 1 /* see database in shared.xml */; - } - }), anyString(), eq(settings), eq(1)); - } - - @Test - public void should_not_init_past_snapshots_if_first_analysis() { - DefaultProjectTree projectTree = mock(DefaultProjectTree.class); - when(projectTree.getRootProject()).thenReturn(new Project("new:project")); - - new PeriodsDefinition(getSession(), projectTree, settings, pastSnapshotFinder); - - verifyZeroInteractions(pastSnapshotFinder); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java index c9f3fa89e73..d859b83ce47 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java @@ -26,7 +26,6 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Directory; import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; @@ -56,33 +55,33 @@ public class ComponentsPublisherTest { Project root = new Project("foo").setName("Root project").setDescription("Root description") .setAnalysisDate(DateUtils.parseDate(("2012-12-12"))); root.setId(1).setUuid("PROJECT_UUID"); - resourceCache.add(root, null).setSnapshot(new Snapshot().setId(11)); + resourceCache.add(root, null); Project module1 = new Project("module1").setName("Module1").setDescription("Module description"); module1.setParent(root); module1.setId(2).setUuid("MODULE_UUID"); - resourceCache.add(module1, root).setSnapshot(new Snapshot().setId(12)); + resourceCache.add(module1, root); rootDef.addSubProject(ProjectDefinition.create().setKey("module1")); Directory dir = Directory.create("src"); dir.setEffectiveKey("module1:src"); dir.setId(3).setUuid("DIR_UUID"); - resourceCache.add(dir, module1).setSnapshot(new Snapshot().setId(13)); + resourceCache.add(dir, module1); org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false); file.setEffectiveKey("module1:src/Foo.java"); file.setId(4).setUuid("FILE_UUID"); - resourceCache.add(file, dir).setSnapshot(new Snapshot().setId(14)).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2)); + resourceCache.add(file, dir).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2)); org.sonar.api.resources.File fileWithoutLang = org.sonar.api.resources.File.create("src/make", null, false); fileWithoutLang.setEffectiveKey("module1:src/make"); fileWithoutLang.setId(5).setUuid("FILE_WITHOUT_LANG_UUID"); - resourceCache.add(fileWithoutLang, dir).setSnapshot(new Snapshot().setId(15)).setInputPath(new DefaultInputFile("module1", "src/make").setLines(10)); + resourceCache.add(fileWithoutLang, dir).setInputPath(new DefaultInputFile("module1", "src/make").setLines(10)); org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", Java.INSTANCE, true); testFile.setEffectiveKey("module1:test/FooTest.java"); testFile.setId(6).setUuid("TEST_FILE_UUID"); - resourceCache.add(testFile, dir).setSnapshot(new Snapshot().setId(16)).setInputPath(new DefaultInputFile("module1", "test/FooTest.java").setLines(4)); + resourceCache.add(testFile, dir).setInputPath(new DefaultInputFile("module1", "test/FooTest.java").setLines(4)); ImmutableProjectReactor reactor = new ImmutableProjectReactor(rootDef); @@ -123,14 +122,14 @@ public class ComponentsPublisherTest { Project root = new Project("foo:my_branch").setName("Root project") .setAnalysisDate(DateUtils.parseDate(("2012-12-12"))); root.setId(1).setUuid("PROJECT_UUID"); - resourceCache.add(root, null).setSnapshot(new Snapshot().setId(11)); + resourceCache.add(root, null); rootDef.properties().put(CoreProperties.LINKS_HOME_PAGE, "http://home"); rootDef.properties().put(CoreProperties.PROJECT_BRANCH_PROPERTY, "my_branch"); Project module1 = new Project("module1:my_branch").setName("Module1"); module1.setParent(root); module1.setId(2).setUuid("MODULE_UUID"); - resourceCache.add(module1, root).setSnapshot(new Snapshot().setId(12)); + resourceCache.add(module1, root); ProjectDefinition moduleDef = ProjectDefinition.create().setKey("module1"); moduleDef.properties().put(CoreProperties.LINKS_CI, "http://ci"); rootDef.addSubProject(moduleDef); @@ -138,12 +137,12 @@ public class ComponentsPublisherTest { Directory dir = Directory.create("src"); dir.setEffectiveKey("module1:my_branch:my_branch:src"); dir.setId(3).setUuid("DIR_UUID"); - resourceCache.add(dir, module1).setSnapshot(new Snapshot().setId(13)); + resourceCache.add(dir, module1); org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false); file.setEffectiveKey("module1:my_branch:my_branch:src/Foo.java"); file.setId(4).setUuid("FILE_UUID"); - resourceCache.add(file, dir).setSnapshot(new Snapshot().setId(14)).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2)); + resourceCache.add(file, dir).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2)); ImmutableProjectReactor reactor = new ImmutableProjectReactor(rootDef); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java index b8e4b7acfb3..c257614fe7c 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java @@ -19,13 +19,17 @@ */ package org.sonar.batch.report; +import java.io.File; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.resources.Project; @@ -36,12 +40,6 @@ import org.sonar.batch.protocol.output.BatchReportReader; import org.sonar.batch.protocol.output.BatchReportWriter; import org.sonar.batch.scan.measure.MeasureCache; -import java.io.File; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; @@ -62,7 +60,7 @@ public class CoveragePublisherTest { Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); BatchComponentCache resourceCache = new BatchComponentCache(); sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); - resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); + resourceCache.add(p, null); resourceCache.add(sampleFile, null).setInputPath(new DefaultInputFile("foo", "src/Foo.php").setLines(5)); measureCache = mock(MeasureCache.class); when(measureCache.byMetric(anyString(), anyString())).thenReturn(Collections.<Measure>emptyList()); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java index a27ce7d2447..3e0f79030bf 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java @@ -28,7 +28,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; import org.sonar.batch.index.BatchComponentCache; @@ -60,7 +59,7 @@ public class IssuesPublisherTest { project = new Project("foo").setAnalysisDate(new Date(1234567L)); BatchComponentCache componentCache = new BatchComponentCache(); org.sonar.api.resources.Resource sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); - componentCache.add(project, null).setSnapshot(new Snapshot().setId(2)); + componentCache.add(project, null); componentCache.add(sampleFile, project); issueCache = mock(IssueCache.class); when(issueCache.byComponent(anyString())).thenReturn(Collections.<DefaultIssue>emptyList()); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java index c4faec31bce..157f1e60f62 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java @@ -20,7 +20,6 @@ package org.sonar.batch.report; import java.io.File; -import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; @@ -28,11 +27,9 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.measures.Metric; -import org.sonar.api.measures.Metric.Level; import org.sonar.api.measures.Metric.ValueType; import org.sonar.api.measures.MetricFinder; import org.sonar.api.resources.Project; @@ -64,7 +61,7 @@ public class MeasuresPublisherTest { Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); BatchComponentCache resourceCache = new BatchComponentCache(); sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); - resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); + resourceCache.add(p, null); resourceCache.add(sampleFile, null); measureCache = mock(MeasureCache.class); when(measureCache.byResource(any(Resource.class))).thenReturn(Collections.<Measure>emptyList()); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/MetadataPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/MetadataPublisherTest.java index 23f9860660a..7e67177a5ec 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/MetadataPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/MetadataPublisherTest.java @@ -31,7 +31,6 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.internal.DefaultActiveRules; import org.sonar.api.batch.rule.internal.NewActiveRule; -import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReport; @@ -58,7 +57,7 @@ public class MetadataPublisherTest { project = new Project("foo").setAnalysisDate(new Date(1234567L)); BatchComponentCache componentCache = new BatchComponentCache(); org.sonar.api.resources.Resource sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); - componentCache.add(project, null).setSnapshot(new Snapshot().setId(2)); + componentCache.add(project, null); componentCache.add(sampleFile, project); underTest = new MetadataPublisher(componentCache, new ImmutableProjectReactor(projectDef), activeRules); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java index 0125a4bb5ba..83f58a78afe 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java @@ -19,23 +19,21 @@ */ package org.sonar.batch.report; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Date; import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; import org.sonar.api.resources.Qualifiers; import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportWriter; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Date; - import static org.assertj.core.api.Assertions.assertThat; public class SourcePublisherTest { @@ -57,7 +55,7 @@ public class SourcePublisherTest { BatchComponentCache resourceCache = new BatchComponentCache(); sampleFile = org.sonar.api.resources.File.create("src/Foo.php"); sampleFile.setEffectiveKey("foo:src/Foo.php"); - resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); + resourceCache.add(p, null); File baseDir = temp.newFolder(); sourceFile = new File(baseDir, "src/Foo.php"); resourceCache.add(sampleFile, null).setInputPath( |