diff options
Diffstat (limited to 'sonar-scanner-engine/src/test')
39 files changed, 265 insertions, 1815 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/WsTestUtil.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/WsTestUtil.java new file mode 100644 index 00000000000..ffe7e82fc26 --- /dev/null +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/WsTestUtil.java @@ -0,0 +1,96 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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; + +import org.apache.commons.lang.StringUtils; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.sonar.batch.bootstrap.BatchWsClient; +import org.sonarqube.ws.client.WsRequest; +import org.sonarqube.ws.client.WsResponse; + +import java.io.InputStream; +import java.io.Reader; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.argThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class WsTestUtil { + public static void mockStream(BatchWsClient mock, String path, InputStream is) { + WsResponse response = mock(WsResponse.class); + when(response.contentStream()).thenReturn(is); + when(mock.call(argThat(new RequestMatcher(path)))).thenReturn(response); + } + + public static void mockStream(BatchWsClient mock, InputStream is) { + WsResponse response = mock(WsResponse.class); + when(response.contentStream()).thenReturn(is); + when(mock.call(any(WsRequest.class))).thenReturn(response); + } + + public static void mockReader(BatchWsClient mock, Reader reader) { + WsResponse response = mock(WsResponse.class); + when(response.contentReader()).thenReturn(reader); + when(mock.call(any(WsRequest.class))).thenReturn(response); + } + + public static void mockReader(BatchWsClient mock, String path, Reader reader) { + WsResponse response = mock(WsResponse.class); + when(response.contentReader()).thenReturn(reader); + when(mock.call(argThat(new RequestMatcher(path)))).thenReturn(response); + } + + public static void mockException(BatchWsClient mock, Exception e) { + when(mock.call(any(WsRequest.class))).thenThrow(e); + } + + public static void mockException(BatchWsClient mock, String path, Exception e) { + when(mock.call(argThat(new RequestMatcher(path)))).thenThrow(e); + } + + public static void verifyCall(BatchWsClient mock, String path) { + verify(mock).call(argThat(new RequestMatcher(path))); + } + + private static class RequestMatcher extends BaseMatcher<WsRequest> { + private String path; + + public RequestMatcher(String path) { + this.path = path; + } + + @Override + public boolean matches(Object item) { + if (item == null) { + return false; + } + WsRequest request = (WsRequest) item; + return StringUtils.equals(request.getPath(), path); + } + + @Override + public void describeTo(Description description) { + description.appendText("request path (\"" + path + "\")"); + } + } +} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java deleted file mode 100644 index 66ab296a063..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.analysis; - -import com.google.common.collect.ImmutableMap; -import org.assertj.core.util.Maps; -import org.junit.Test; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.batch.bootstrap.BatchWsClient; -import org.sonar.batch.cache.WSLoader; -import org.sonar.batch.cache.WSLoader.LoadStrategy; -import org.sonar.home.cache.PersistentCache; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class AnalysisWSLoaderProviderTest { - - PersistentCache cache = mock(PersistentCache.class); - BatchWsClient wsClient = mock(BatchWsClient.class); - AnalysisMode mode = mock(AnalysisMode.class); - - AnalysisWSLoaderProvider underTest = new AnalysisWSLoaderProvider(); - - @Test - public void testDefault() { - WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(Maps.<String, String>newHashMap())); - assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY); - } - - @Test - public void no_cache_by_default_in_issues_mode() { - when(mode.isIssues()).thenReturn(true); - WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(Maps.<String, String>newHashMap())); - assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY); - } - - @Test - public void enable_cache_in_issues_mode() { - when(mode.isIssues()).thenReturn(true); - WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(ImmutableMap.of(AnalysisWSLoaderProvider.SONAR_USE_WS_CACHE, "true"))); - assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.CACHE_ONLY); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java index 95e17ca849a..4c2deee6ebb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java @@ -20,20 +20,21 @@ package org.sonar.batch.bootstrap; import java.io.File; +import java.io.StringReader; import java.util.List; + +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.batch.cache.WSLoader; -import org.sonar.batch.cache.WSLoaderResult; +import org.sonar.batch.WsTestUtil; import org.sonar.core.platform.RemotePlugin; import org.sonar.home.cache.FileCache; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -45,16 +46,19 @@ public class BatchPluginInstallerTest { @Rule public ExpectedException thrown = ExpectedException.none(); - FileCache fileCache = mock(FileCache.class); - BatchWsClient wsClient = mock(BatchWsClient.class); - BatchPluginPredicate pluginPredicate = mock(BatchPluginPredicate.class); + private FileCache fileCache = mock(FileCache.class); + private BatchWsClient wsClient; + private BatchPluginPredicate pluginPredicate = mock(BatchPluginPredicate.class); + + @Before + public void setUp() { + wsClient = mock(BatchWsClient.class); + } @Test public void listRemotePlugins() { - - WSLoader wsLoader = mock(WSLoader.class); - when(wsLoader.loadString("/deploy/plugins/index.txt")).thenReturn(new WSLoaderResult<>("checkstyle\nsqale", true)); - BatchPluginInstaller underTest = new BatchPluginInstaller(wsLoader, wsClient, fileCache, pluginPredicate); + WsTestUtil.mockReader(wsClient, "/deploy/plugins/index.txt", new StringReader("checkstyle\nsqale")); + BatchPluginInstaller underTest = new BatchPluginInstaller(wsClient, fileCache, pluginPredicate); List<RemotePlugin> remotePlugins = underTest.listRemotePlugins(); assertThat(remotePlugins).extracting("key").containsOnly("checkstyle", "sqale"); @@ -65,8 +69,7 @@ public class BatchPluginInstallerTest { File pluginJar = temp.newFile(); when(fileCache.get(eq("checkstyle-plugin.jar"), eq("fakemd5_1"), any(FileCache.Downloader.class))).thenReturn(pluginJar); - WSLoader wsLoader = mock(WSLoader.class); - BatchPluginInstaller underTest = new BatchPluginInstaller(wsLoader, wsClient, fileCache, pluginPredicate); + BatchPluginInstaller underTest = new BatchPluginInstaller(wsClient, fileCache, pluginPredicate); RemotePlugin remote = new RemotePlugin("checkstyle").setFile("checkstyle-plugin.jar", "fakemd5_1"); File file = underTest.download(remote); @@ -76,11 +79,9 @@ public class BatchPluginInstallerTest { @Test public void should_fail_to_get_plugin_index() { + WsTestUtil.mockException(wsClient, "/deploy/plugins/index.txt", new IllegalStateException()); thrown.expect(IllegalStateException.class); - WSLoader wsLoader = mock(WSLoader.class); - doThrow(new IllegalStateException()).when(wsLoader).loadString("/deploy/plugins/index.txt"); - - new BatchPluginInstaller(wsLoader, wsClient, fileCache, pluginPredicate).installRemotes(); + new BatchPluginInstaller(wsClient, fileCache, pluginPredicate).installRemotes(); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java index 41152b3ccb5..0019d8adc18 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java @@ -42,7 +42,7 @@ public class GlobalContainerTest { Map<String, String> props = ImmutableMap.of(CoreProperties.WORKING_DIRECTORY, temp.getRoot().getAbsolutePath(), CoreProperties.GLOBAL_WORKING_DIRECTORY, temp.getRoot().getAbsolutePath()); - GlobalContainer container = GlobalContainer.create(props, extensions, false); + GlobalContainer container = GlobalContainer.create(props, extensions); container.doBeforeStart(); return container; } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java deleted file mode 100644 index c8f105de443..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.cache; - -import com.google.common.io.Files; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Date; -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.PersistentCache; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class DefaultProjectCacheStatusTest { - @Rule - public TemporaryFolder tmp = new TemporaryFolder(); - - @Rule - public ExpectedException exception = ExpectedException.none(); - - ProjectCacheStatus cacheStatus; - PersistentCache cache = mock(PersistentCache.class); - - @Before - public void setUp() { - when(cache.getDirectory()).thenReturn(tmp.getRoot().toPath()); - cacheStatus = new DefaultProjectCacheStatus(cache); - } - - @Test - public void errorSave() throws IOException { - when(cache.getDirectory()).thenReturn(tmp.getRoot().toPath().resolve("unexistent_folder")); - cacheStatus = new DefaultProjectCacheStatus(cache); - - exception.expect(IllegalStateException.class); - exception.expectMessage("Failed to write cache sync status"); - cacheStatus.save(); - } - - @Test - public void errorStatus() throws IOException { - Files.write("trash".getBytes(StandardCharsets.UTF_8), new File(tmp.getRoot(), "cache-sync-status")); - cacheStatus = new DefaultProjectCacheStatus(cache); - - exception.expect(IllegalStateException.class); - exception.expectMessage("Failed to read cache sync status"); - cacheStatus.getSyncStatus(); - } - - @Test - public void testSave() { - cacheStatus.save(); - assertThat(cacheStatus.getSyncStatus()).isNotNull(); - assertThat(age(cacheStatus.getSyncStatus())).isLessThan(2000); - } - - @Test - public void testDelete() { - cacheStatus.save(); - cacheStatus.delete(); - assertThat(cacheStatus.getSyncStatus()).isNull(); - } - - private long age(Date date) { - return (new Date().getTime()) - date.getTime(); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java deleted file mode 100644 index 3f019caae02..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.cache; - -import org.sonar.home.cache.PersistentCache; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; - -import static org.junit.Assert.*; -import static org.assertj.core.api.Assertions.assertThat; -import org.sonar.batch.bootstrap.GlobalProperties; -import org.junit.Before; -import org.junit.Test; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; - -public class GlobalPersistentCacheProviderTest { - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - private GlobalPersistentCacheProvider provider; - private GlobalProperties globalProperties; - - @Before - public void setUp() { - HashMap<String, String> map = new HashMap<>(); - map.put("sonar.userHome", temp.getRoot().getAbsolutePath()); - globalProperties = new GlobalProperties(map); - provider = new GlobalPersistentCacheProvider(); - } - - @Test - public void test_path() { - PersistentCache cache = provider.provide(globalProperties); - assertThat(cache.getDirectory()).isEqualTo(temp.getRoot().toPath() - .resolve("ws_cache") - .resolve("http%3A%2F%2Flocalhost%3A9000") - .resolve("global")); - } - - @Test - public void test_singleton() { - assertTrue(provider.provide(globalProperties) == provider.provide(globalProperties)); - } - - @Test - public void test_without_sonar_home() { - globalProperties = new GlobalProperties(new HashMap<String, String>()); - PersistentCache cache = provider.provide(globalProperties); - assertThat(cache.getDirectory().toAbsolutePath().toString()).startsWith(findHome().toAbsolutePath().toString()); - - } - - private static Path findHome() { - String home = System.getenv("SONAR_USER_HOME"); - - if (home != null) { - return Paths.get(home); - } - - home = System.getProperty("user.home"); - return Paths.get(home, ".sonar"); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java deleted file mode 100644 index c06bb94ca08..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.cache; - -import com.google.common.collect.ImmutableList; -import java.util.Date; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.sonar.batch.repository.QualityProfileLoader; -import org.sonar.batch.rule.ActiveRulesLoader; -import org.sonar.batch.rule.LoadedActiveRule; -import org.sonar.batch.rule.RulesLoader; -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; - -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -public class NonAssociatedCacheSynchronizerTest { - private NonAssociatedCacheSynchronizer synchronizer; - - @Mock - private RulesLoader rulesLoader; - @Mock - private QualityProfileLoader qualityProfileLoader; - @Mock - private ActiveRulesLoader activeRulesLoader; - @Mock - private ProjectCacheStatus cacheStatus; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - - QualityProfile pf = QualityProfile.newBuilder().setKey("profile").setName("profile").setLanguage("lang").build(); - LoadedActiveRule ar = new LoadedActiveRule(); - - when(qualityProfileLoader.loadDefault(null, null)).thenReturn(ImmutableList.of(pf)); - when(activeRulesLoader.load("profile", null)).thenReturn(ImmutableList.of(ar)); - - synchronizer = new NonAssociatedCacheSynchronizer(rulesLoader, qualityProfileLoader, activeRulesLoader, cacheStatus); - } - - @Test - public void dont_sync_if_exists() { - when(cacheStatus.getSyncStatus()).thenReturn(new Date()); - synchronizer.execute(false); - verifyZeroInteractions(rulesLoader, qualityProfileLoader, activeRulesLoader); - } - - @Test - public void always_sync_if_force() { - when(cacheStatus.getSyncStatus()).thenReturn(new Date()); - synchronizer.execute(true); - checkSync(); - } - - @Test - public void sync_if_doesnt_exist() { - synchronizer.execute(false); - checkSync(); - } - - private void checkSync() { - verify(cacheStatus).getSyncStatus(); - verify(cacheStatus).save(); - verify(rulesLoader).load(null); - verify(qualityProfileLoader).loadDefault(null, null); - verify(activeRulesLoader).load("profile", null); - - verifyNoMoreInteractions(qualityProfileLoader, activeRulesLoader); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java deleted file mode 100644 index 52df42e035d..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.cache; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; -import java.io.IOException; -import java.util.Date; -import java.util.HashMap; -import org.apache.commons.lang.mutable.MutableBoolean; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.batch.analysis.AnalysisProperties; -import org.sonar.batch.analysis.DefaultAnalysisMode; -import org.sonar.batch.repository.DefaultProjectRepositoriesLoader; -import org.sonar.batch.repository.DefaultQualityProfileLoader; -import org.sonar.batch.repository.DefaultServerIssuesLoader; -import org.sonar.batch.repository.ProjectRepositories; -import org.sonar.batch.repository.ProjectRepositoriesLoader; -import org.sonar.batch.repository.QualityProfileLoader; -import org.sonar.batch.repository.ServerIssuesLoader; -import org.sonar.batch.repository.user.UserRepositoryLoader; -import org.sonar.batch.rule.ActiveRulesLoader; -import org.sonar.batch.rule.DefaultActiveRulesLoader; -import org.sonar.batch.rule.LoadedActiveRule; -import org.sonar.batch.rule.RulesLoader; -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class ProjectCacheSynchronizerTest { - private static final String PROJECT_KEY = "org.codehaus.sonar-plugins:sonar-scm-git-plugin"; - - @Rule - public ExpectedException exception = ExpectedException.none(); - - @Mock - private ProjectDefinition project; - @Mock - private ProjectCacheStatus cacheStatus; - @Mock - private DefaultAnalysisMode analysisMode; - @Mock - private AnalysisProperties properties; - @Mock - private RulesLoader rulesLoader; - - private ServerIssuesLoader issuesLoader; - private UserRepositoryLoader userRepositoryLoader; - private QualityProfileLoader qualityProfileLoader; - private ActiveRulesLoader activeRulesLoader; - private ProjectRepositoriesLoader projectRepositoriesLoader; - - @Before - public void setUp() throws IOException { - MockitoAnnotations.initMocks(this); - - when(analysisMode.isIssues()).thenReturn(true); - when(properties.properties()).thenReturn(new HashMap<String, String>()); - } - - private ProjectCacheSynchronizer createMockedLoaders(boolean projectExists, Date lastAnalysisDate) { - issuesLoader = mock(DefaultServerIssuesLoader.class); - userRepositoryLoader = mock(UserRepositoryLoader.class); - qualityProfileLoader = mock(DefaultQualityProfileLoader.class); - activeRulesLoader = mock(DefaultActiveRulesLoader.class); - projectRepositoriesLoader = mock(DefaultProjectRepositoriesLoader.class); - - QualityProfile pf = QualityProfile.newBuilder().setKey("profile").setName("profile").setLanguage("lang").build(); - LoadedActiveRule ar = new LoadedActiveRule(); - ProjectRepositories repo = mock(ProjectRepositories.class); - - when(qualityProfileLoader.load(PROJECT_KEY, null, null)).thenReturn(ImmutableList.of(pf)); - when(qualityProfileLoader.loadDefault(null, null)).thenReturn(ImmutableList.of(pf)); - when(activeRulesLoader.load("profile", null)).thenReturn(ImmutableList.of(ar)); - when(repo.lastAnalysisDate()).thenReturn(lastAnalysisDate); - when(repo.exists()).thenReturn(projectExists); - when(projectRepositoriesLoader.load(anyString(), anyBoolean(), any(MutableBoolean.class))).thenReturn(repo); - - return new ProjectCacheSynchronizer(rulesLoader, qualityProfileLoader, projectRepositoriesLoader, activeRulesLoader, issuesLoader, userRepositoryLoader, cacheStatus); - } - - @Test - public void testLoadersUsage() { - ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date()); - synchronizer.load(PROJECT_KEY, false); - - verify(issuesLoader).load(eq(PROJECT_KEY), any(Function.class)); - verify(rulesLoader).load(null); - verify(qualityProfileLoader).load(PROJECT_KEY, null, null); - verify(activeRulesLoader).load("profile", null); - verify(projectRepositoriesLoader).load(eq(PROJECT_KEY), eq(true), any(MutableBoolean.class)); - - verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader); - } - - @Test - public void testLoadersUsage_NoLastAnalysis() { - ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, null); - synchronizer.load(PROJECT_KEY, false); - - verify(projectRepositoriesLoader).load(eq(PROJECT_KEY), eq(true), any(MutableBoolean.class)); - verify(qualityProfileLoader).load(PROJECT_KEY, null, null); - verify(activeRulesLoader).load("profile", null); - - verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader); - } - - @Test - public void testLoadersUsage_ProjectDoesntExist() { - ProjectCacheSynchronizer synchronizer = createMockedLoaders(false, null); - synchronizer.load(PROJECT_KEY, false); - - verify(projectRepositoriesLoader).load(eq(PROJECT_KEY), eq(true), any(MutableBoolean.class)); - verify(qualityProfileLoader).loadDefault(null, null); - verify(activeRulesLoader).load("profile", null); - - verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader); - } - - @Test - public void testLastAnalysisToday() { - ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date()); - - when(cacheStatus.getSyncStatus()).thenReturn(new Date()); - synchronizer.load(PROJECT_KEY, false); - - verify(cacheStatus).getSyncStatus(); - verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader, cacheStatus); - } - - @Test - public void testLastAnalysisYesterday() { - ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date()); - - Date d = new Date(new Date().getTime() - 60 * 60 * 24 * 1000); - when(cacheStatus.getSyncStatus()).thenReturn(d); - synchronizer.load(PROJECT_KEY, false); - - verify(cacheStatus).save(); - verify(cacheStatus).getSyncStatus(); - } - - @Test - public void testDontFailOnError() { - ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date()); - - Date d = new Date(new Date().getTime() - 60 * 60 * 24 * 1000); - when(cacheStatus.getSyncStatus()).thenReturn(d); - - when(projectRepositoriesLoader.load(anyString(), anyBoolean(), any(MutableBoolean.class))).thenThrow(IllegalStateException.class); - synchronizer.load(PROJECT_KEY, false); - - verify(cacheStatus).getSyncStatus(); - verifyNoMoreInteractions(cacheStatus); - } - - @Test - public void testForce() { - ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date()); - - when(cacheStatus.getSyncStatus()).thenReturn(new Date()); - synchronizer.load(PROJECT_KEY, true); - - verify(cacheStatus).save(); - verify(cacheStatus).getSyncStatus(); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java deleted file mode 100644 index 69c142556ae..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.cache; - -import org.sonar.api.batch.bootstrap.ProjectKey; - -import org.sonar.batch.util.BatchUtils; -import org.sonar.batch.analysis.DefaultAnalysisMode; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; -import org.sonar.batch.bootstrap.GlobalProperties; -import org.sonar.batch.cache.ProjectPersistentCacheProvider; - -import java.io.File; -import java.nio.file.Path; -import java.util.Collections; - -import static org.mockito.Mockito.mock; -import org.junit.Before; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; - -public class ProjectPersistentCacheProviderTest { - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - private ProjectPersistentCacheProvider provider = null; - private GlobalProperties props = null; - private DefaultAnalysisMode mode = null; - private ProjectKey key = null; - - @Before - public void prepare() { - key = new ProjectKeySupplier("proj"); - props = new GlobalProperties(Collections.<String, String>emptyMap()); - mode = mock(DefaultAnalysisMode.class); - provider = new ProjectPersistentCacheProvider(); - } - - @Test - public void test_singleton() { - assertThat(provider.provide(props, mode, key)).isEqualTo(provider.provide(props, mode, key)); - } - - @Test - public void test_cache_dir() { - assertThat(provider.provide(props, mode, key).getDirectory().toFile()).exists().isDirectory(); - } - - @Test - public void test_home() { - File f = temp.getRoot(); - props.properties().put("sonar.userHome", f.getAbsolutePath()); - Path expected = f.toPath() - .resolve("ws_cache") - .resolve("http%3A%2F%2Flocalhost%3A9000") - .resolve( BatchUtils.getServerVersion()) - .resolve("projects") - .resolve("proj"); - - assertThat(provider.provide(props, mode, key).getDirectory()).isEqualTo(expected); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java deleted file mode 100644 index 948f888cd68..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.cache; - -import java.util.HashMap; -import org.junit.Test; -import org.sonar.batch.bootstrap.GlobalProperties; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.home.cache.PersistentCache; -import org.sonar.scanner.protocol.input.ProjectRepositories; -import org.sonarqube.ws.client.WsClient; - -import static org.mockito.Mockito.mock; - -public class ProjectSyncContainerTest { - private ComponentContainer createParentContainer() { - PersistentCache cache = mock(PersistentCache.class); - WsClient server = mock(WsClient.class); - - GlobalProperties globalProps = new GlobalProperties(new HashMap<String, String>()); - ComponentContainer parent = new ComponentContainer(); - parent.add(cache); - parent.add(server); - parent.add(globalProps); - return parent; - } - - @Test - public void testProjectRepository() { - ProjectSyncContainer container = new ProjectSyncContainer(createParentContainer(), "my:project", true); - container.doBeforeStart(); - container.getPicoContainer().start(); - container.getComponentByType(ProjectRepositories.class); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java deleted file mode 100644 index ce9d88a037c..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.cache; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.sonar.batch.bootstrap.BatchWsClient; -import org.sonar.batch.cache.WSLoader.LoadStrategy; -import org.sonar.home.cache.PersistentCache; - -import static org.assertj.core.api.Assertions.assertThat; - -public class StrategyWSLoaderProviderTest { - @Mock - private PersistentCache cache; - - @Mock - private BatchWsClient client; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testStrategy() { - StrategyWSLoaderProvider provider = new StrategyWSLoaderProvider(LoadStrategy.CACHE_FIRST); - WSLoader wsLoader = provider.provide(cache, client); - - assertThat(wsLoader.getDefaultStrategy()).isEqualTo(LoadStrategy.CACHE_FIRST); - } - - @Test - public void testSingleton() { - StrategyWSLoaderProvider provider = new StrategyWSLoaderProvider(LoadStrategy.CACHE_FIRST); - WSLoader wsLoader = provider.provide(cache, client); - - assertThat(provider.provide(null, null)).isEqualTo(wsLoader); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/WSLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/WSLoaderTest.java deleted file mode 100644 index ad7bb763d67..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/WSLoaderTest.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.cache; - -import java.io.IOException; -import java.io.InputStream; -import org.apache.commons.io.IOUtils; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.InOrder; -import org.mockito.Mockito; -import org.sonar.batch.bootstrap.BatchWsClient; -import org.sonar.batch.cache.WSLoader.LoadStrategy; -import org.sonar.home.cache.PersistentCache; -import org.sonarqube.ws.client.HttpException; -import org.sonarqube.ws.client.MockWsResponse; -import org.sonarqube.ws.client.WsRequest; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class WSLoaderTest { - private final static String ID = "dummy"; - private final static String cacheValue = "cache"; - private final static String serverValue = "server"; - - @Rule - public ExpectedException exception = ExpectedException.none(); - - BatchWsClient ws = mock(BatchWsClient.class, Mockito.RETURNS_DEEP_STUBS); - PersistentCache cache = mock(PersistentCache.class); - - @Test - public void dont_retry_server_offline() throws IOException { - turnServerOffline(); - when(cache.getString(ID)).thenReturn(cacheValue); - WSLoader underTest = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws); - - assertResult(underTest.loadString(ID), cacheValue, true); - assertResult(underTest.loadString(ID), cacheValue, true); - - assertUsedServer(1); - assertUsedCache(2); - } - - @Test - public void get_stream_from_cache() throws IOException { - InputStream is = IOUtils.toInputStream("is"); - when(cache.getStream(ID)).thenReturn(is); - - WSLoader loader = new WSLoader(LoadStrategy.CACHE_FIRST, cache, ws); - WSLoaderResult<InputStream> result = loader.loadStream(ID); - - assertThat(result.get()).isEqualTo(is); - verify(cache).getStream(ID); - verifyNoMoreInteractions(cache, ws); - } - - @Test - public void put_stream_in_cache() throws IOException { - InputStream input = IOUtils.toInputStream("is"); - - when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(input)); - when(cache.getStream(ID)).thenReturn(input); - - // SERVER_FIRST -> load from server then put to cache - WSLoader underTest = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws); - WSLoaderResult<InputStream> result = underTest.loadStream(ID); - assertThat(result.get()).isEqualTo(input); - - InOrder inOrder = inOrder(ws, cache); - inOrder.verify(ws).call(any(WsRequest.class)); - inOrder.verify(cache).put(eq(ID), any(InputStream.class)); - inOrder.verify(cache).getStream(ID); - verifyNoMoreInteractions(cache, ws); - } - - @Test - public void test_cache_strategy_fallback() throws IOException { - turnCacheEmpty(); - when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue)); - WSLoader loader = new WSLoader(LoadStrategy.CACHE_FIRST, cache, ws); - - assertResult(loader.loadString(ID), serverValue, false); - - InOrder inOrder = inOrder(ws, cache); - inOrder.verify(cache).getString(ID); - inOrder.verify(ws).call(any(WsRequest.class)); - } - - @Test - public void test_server_strategy_fallback() throws IOException { - turnServerOffline(); - when(cache.getString(ID)).thenReturn(cacheValue); - WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws); - - assertResult(loader.loadString(ID), cacheValue, true); - - InOrder inOrder = inOrder(ws, cache); - inOrder.verify(ws).call(any(WsRequest.class)); - inOrder.verify(cache).getString(ID); - } - - @Test - public void test_put_cache() throws IOException { - when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue)); - WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws); - loader.loadString(ID); - verify(cache).put(ID, serverValue.getBytes()); - } - - @Test - public void test_throw_cache_exception_fallback() throws IOException { - turnServerOffline(); - - when(cache.getString(ID)).thenThrow(new NullPointerException()); - WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws); - - try { - loader.loadString(ID); - fail("NPE expected"); - } catch (NullPointerException e) { - assertUsedServer(1); - assertUsedCache(1); - } - } - - @Test - public void test_throw_cache_exception() throws IOException { - when(cache.getString(ID)).thenThrow(new IllegalStateException()); - - WSLoader loader = new WSLoader(LoadStrategy.CACHE_FIRST, cache, ws); - - try { - loader.loadString(ID); - fail("IllegalStateException expected"); - } catch (IllegalStateException e) { - assertUsedServer(0); - assertUsedCache(1); - } - } - - @Test - public void test_throw_http_exceptions() { - when(ws.call(any(WsRequest.class))).thenThrow(new HttpException("url", 500)); - - WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws); - - try { - loader.loadString(ID); - fail("IllegalStateException expected"); - } catch (HttpException e) { - // cache should not be used - verifyNoMoreInteractions(cache); - } - } - - @Test - public void test_server_only_not_available() { - turnServerOffline(); - - exception.expect(IllegalStateException.class); - exception.expectMessage("Server is not available"); - - WSLoader loader = new WSLoader(LoadStrategy.SERVER_ONLY, cache, ws); - loader.loadString(ID); - } - - @Test - public void test_server_cache_not_available() throws IOException { - turnServerOffline(); - turnCacheEmpty(); - - exception.expect(IllegalStateException.class); - exception.expectMessage("Server is not accessible and data is not cached"); - - WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws); - loader.loadString(ID); - } - - @Test - public void test_cache_only_available() throws IOException { - turnCacheEmpty(); - - exception.expect(IllegalStateException.class); - exception.expectMessage("Data is not cached"); - - WSLoader loader = new WSLoader(LoadStrategy.CACHE_ONLY, cache, ws); - loader.loadString(ID); - } - - @Test - public void test_server_strategy() throws IOException { - when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue)); - WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws); - assertResult(loader.loadString(ID), serverValue, false); - - // should not fetch from cache - verify(cache).put(ID, serverValue.getBytes()); - verifyNoMoreInteractions(cache); - } - - @Test(expected = IllegalStateException.class) - public void test_server_only() throws IOException { - turnServerOffline(); - WSLoader loader = new WSLoader(LoadStrategy.SERVER_ONLY, cache, ws); - loader.loadString(ID); - } - - @Test - public void test_string() { - when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue)); - WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws); - assertResult(loader.loadString(ID), serverValue, false); - } - - private void assertUsedCache(int times) throws IOException { - verify(cache, times(times)).getString(ID); - } - - private void assertUsedServer(int times) { - verify(ws, times(times)).call(any(WsRequest.class)); - } - - private void assertResult(WSLoaderResult<String> result, String expected, boolean fromCache) { - assertThat(result).isNotNull(); - assertThat(result.get()).isEqualTo(expected); - assertThat(result.isFromCache()).isEqualTo(fromCache); - } - - private void turnServerOffline() { - when(ws.call(any(WsRequest.class))).thenThrow(new IllegalStateException()); - } - - private void turnCacheEmpty() throws IOException { - when(cache.getString(ID)).thenReturn(null); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java index 7d8ab1d2319..38102f6a5dc 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java @@ -19,71 +19,59 @@ */ package org.sonar.batch.issue.tracking; -import org.sonar.batch.cache.WSLoader.LoadStrategy; -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.batch.cache.WSLoader; -import org.apache.commons.lang.mutable.MutableBoolean; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.utils.HttpDownloader; +import org.sonar.batch.WsTestUtil; +import org.sonar.batch.bootstrap.BatchWsClient; +import java.io.StringReader; import java.net.URI; import java.net.URISyntaxException; -import static org.mockito.Matchers.any; - import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; public class DefaultServerLineHashesLoaderTest { + private BatchWsClient wsClient; @Rule public ExpectedException thrown = ExpectedException.none(); @Before public void before() { + wsClient = mock(BatchWsClient.class); } @Test public void should_download_source_from_ws_if_preview_mode() { - WSLoader wsLoader = mock(WSLoader.class); - when(wsLoader.loadString(anyString(), any(LoadStrategy.class))).thenReturn(new WSLoaderResult<>("ae12\n\n43fb", true)); - - ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(wsLoader); + WsTestUtil.mockReader(wsClient, new StringReader("ae12\n\n43fb")); + ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(wsClient); - String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Bar.c", null); + String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Bar.c"); assertThat(hashes).containsOnly("ae12", "", "43fb"); - verify(wsLoader).loadString("/api/sources/hash?key=myproject%3Aorg%2Ffoo%2FBar.c", LoadStrategy.CACHE_FIRST); + WsTestUtil.verifyCall(wsClient, "/api/sources/hash?key=myproject%3Aorg%2Ffoo%2FBar.c"); } @Test public void should_download_source_with_space_from_ws_if_preview_mode() { - WSLoader server = mock(WSLoader.class); - when(server.loadString(anyString(), any(LoadStrategy.class))).thenReturn(new WSLoaderResult<>("ae12\n\n43fb", true)); + WsTestUtil.mockReader(wsClient, new StringReader("ae12\n\n43fb")); + ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(wsClient); - ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(server); - - MutableBoolean fromCache = new MutableBoolean(); - String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Foo Bar.c", fromCache); - assertThat(fromCache.booleanValue()).isTrue(); + String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Foo Bar.c"); assertThat(hashes).containsOnly("ae12", "", "43fb"); - verify(server).loadString("/api/sources/hash?key=myproject%3Aorg%2Ffoo%2FFoo+Bar.c", LoadStrategy.CACHE_FIRST); + WsTestUtil.verifyCall(wsClient, "/api/sources/hash?key=myproject%3Aorg%2Ffoo%2FFoo+Bar.c"); } @Test public void should_fail_to_download_source_from_ws() throws URISyntaxException { - WSLoader server = mock(WSLoader.class); - when(server.loadString(anyString(), any(LoadStrategy.class))).thenThrow(new HttpDownloader.HttpException(new URI(""), 500)); - - ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(server); + WsTestUtil.mockException(wsClient, new HttpDownloader.HttpException(new URI(""), 500)); + ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(wsClient); thrown.expect(HttpDownloader.HttpException.class); - lastSnapshots.getLineHashes("foo", null); + lastSnapshots.getLineHashes("foo"); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java index 9acf02b3577..d49cb46c9d7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java @@ -83,10 +83,10 @@ public class SourceHashHolderTest { FileUtils.write(ioFile, source, StandardCharsets.UTF_8); when(file.key()).thenReturn(key); when(file.status()).thenReturn(InputFile.Status.CHANGED); - when(lastSnapshots.getLineHashes(key, null)).thenReturn(new String[] {md5Hex(source)}); + when(lastSnapshots.getLineHashes(key)).thenReturn(new String[] {md5Hex(source)}); assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); - verify(lastSnapshots).getLineHashes(key, null); + verify(lastSnapshots).getLineHashes(key); assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); Mockito.verifyNoMoreInteractions(lastSnapshots); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java index f405eea8785..8055f7baae6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java @@ -31,7 +31,6 @@ import org.sonar.batch.rule.ActiveRulesLoader; import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; import org.sonar.batch.repository.QualityProfileLoader; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.mutable.MutableBoolean; import javax.annotation.Nullable; @@ -43,8 +42,6 @@ import org.sonar.batch.rule.RulesLoader; import org.sonar.scanner.protocol.input.GlobalRepositories; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; import com.google.common.base.Function; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.Table; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -59,35 +56,19 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; -import javax.annotation.Nullable; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.mutable.MutableBoolean; import org.sonar.api.CoreProperties; import org.sonar.api.Plugin; import org.sonar.api.batch.debt.internal.DefaultDebtModel; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.server.rule.RulesDefinition; -import org.sonar.api.server.rule.RulesDefinition.Repository; -import org.sonar.api.utils.DateUtils; import org.sonar.batch.bootstrapper.Batch; import org.sonar.batch.bootstrapper.EnvironmentInformation; -import org.sonar.batch.bootstrapper.IssueListener; import org.sonar.batch.bootstrapper.LogOutput; import org.sonar.batch.issue.tracking.ServerLineHashesLoader; import org.sonar.batch.report.ReportPublisher; -import org.sonar.batch.repository.FileData; import org.sonar.batch.repository.GlobalRepositoriesLoader; -import org.sonar.batch.repository.ProjectRepositories; import org.sonar.batch.repository.ProjectRepositoriesLoader; -import org.sonar.batch.repository.QualityProfileLoader; import org.sonar.batch.repository.ServerIssuesLoader; -import org.sonar.batch.rule.ActiveRulesLoader; -import org.sonar.batch.rule.LoadedActiveRule; -import org.sonar.batch.rule.RulesLoader; -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; -import org.sonarqube.ws.Rules.ListResponse.Rule; /** * Main utility class for writing batch medium tests. @@ -381,7 +362,7 @@ public class BatchMediumTester { } @Override - public List<Rule> load(@Nullable MutableBoolean fromCache) { + public List<Rule> load() { return rules; } } @@ -394,7 +375,7 @@ public class BatchMediumTester { } @Override - public List<LoadedActiveRule> load(String qualityProfileKey, MutableBoolean fromCache) { + public List<LoadedActiveRule> load(String qualityProfileKey) { return activeRules; } } @@ -406,7 +387,7 @@ public class BatchMediumTester { private GlobalRepositories ref = new GlobalRepositories(); @Override - public GlobalRepositories load(@Nullable MutableBoolean fromCache) { + public GlobalRepositories load() { return ref; } @@ -439,7 +420,7 @@ public class BatchMediumTester { private Date lastAnalysisDate; @Override - public ProjectRepositories load(String projectKey, boolean isIssuesMode, @Nullable MutableBoolean fromCache) { + public ProjectRepositories load(String projectKey, boolean isIssuesMode) { Table<String, String, String> settings = HashBasedTable.create(); return new ProjectRepositories(settings, fileDataTable, lastAnalysisDate); } @@ -470,12 +451,12 @@ public class BatchMediumTester { } @Override - public List<QualityProfile> load(String projectKey, String profileName, MutableBoolean fromCache) { + public List<QualityProfile> load(String projectKey, String profileName) { return qualityProfiles; } @Override - public List<QualityProfile> loadDefault(String profileName, MutableBoolean fromCache) { + public List<QualityProfile> loadDefault(String profileName) { return qualityProfiles; } } @@ -489,11 +470,10 @@ public class BatchMediumTester { } @Override - public boolean load(String componentKey, Function<ServerIssue, Void> consumer) { + public void load(String componentKey, Function<ServerIssue, Void> consumer) { for (ServerIssue serverIssue : serverIssues) { consumer.apply(serverIssue); } - return true; } } @@ -501,7 +481,7 @@ public class BatchMediumTester { private Map<String, String[]> byKey = new HashMap<>(); @Override - public String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache) { + public String[] getLineHashes(String fileKey) { if (byKey.containsKey(fileKey)) { return byKey.get(fileKey); } else { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java deleted file mode 100644 index 4ebf5eb1fa6..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.mediumtest.cache; - -import org.junit.rules.TemporaryFolder; - -import org.sonar.batch.mediumtest.TaskResult; -import org.sonar.batch.mediumtest.BatchMediumTester.TaskBuilder; -import org.sonar.batch.mediumtest.LogOutputRecorder; -import org.sonar.batch.repository.FileData; -import com.google.common.collect.ImmutableMap; - -import java.util.Date; - -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.CoreProperties; -import org.sonar.batch.mediumtest.BatchMediumTester; -import org.sonar.xoo.XooPlugin; -import org.sonar.xoo.rule.XooRulesDefinition; - -public class CacheSyncTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - private BatchMediumTester tester; - - @After - public void stop() { - if (tester != null) { - tester.stop(); - tester = null; - } - } - - @Test - public void testExecuteTask() { - LogOutputRecorder logOutput = new LogOutputRecorder(); - - tester = BatchMediumTester.builder() - .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES, - "sonar.verbose", "true")) - .registerPlugin("xoo", new XooPlugin()) - .addRules(new XooRulesDefinition()) - .addQProfile("lang", "name") - .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo") - .setPreviousAnalysisDate(new Date()) - .addFileData("test-project", "file1", new FileData("hash", "123456789")) - .setLogOutput(logOutput) - .build(); - - tester.start(); - executeTask(tester.newTask()); - assertThat(logOutput.getAsString()).contains("Cache for project [key] not found, synchronizing"); - } - - @Test - public void testSyncFirstTime() { - LogOutputRecorder logOutput = new LogOutputRecorder(); - - tester = BatchMediumTester.builder() - .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES, - "sonar.verbose", "true")) - .registerPlugin("xoo", new XooPlugin()) - .addRules(new XooRulesDefinition()) - .addQProfile("lang", "name") - .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo") - .setPreviousAnalysisDate(new Date()) - .addFileData("test-project", "file1", new FileData("hash", "123456789")) - .setLogOutput(logOutput) - .build(); - - tester.start(); - tester.syncProject("test-project"); - assertThat(logOutput.getAsString()).contains("Cache for project [test-project] not found"); - } - - @Test - public void testSyncTwice() { - LogOutputRecorder logOutput = new LogOutputRecorder(); - - tester = BatchMediumTester.builder() - .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES, - "sonar.verbose", "true")) - .registerPlugin("xoo", new XooPlugin()) - .addRules(new XooRulesDefinition()) - .addQProfile("lang", "name") - .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo") - .setPreviousAnalysisDate(new Date()) - .addFileData("test-project", "file1", new FileData("hash", "123456789")) - .setLogOutput(logOutput) - .build(); - - tester.start(); - tester.syncProject("test-project"); - tester.syncProject("test-project"); - assertThat(logOutput.getAsString()).contains("-- Found project [test-project]"); - assertThat(logOutput.getAsString()).contains("not found, synchronizing data"); - assertThat(logOutput.getAsString()).contains("], synchronizing data (forced).."); - } - - @Test - public void testNonAssociated() { - LogOutputRecorder logOutput = new LogOutputRecorder(); - - tester = BatchMediumTester.builder() - .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)) - .registerPlugin("xoo", new XooPlugin()) - .addRules(new XooRulesDefinition()) - .addQProfile("lang", "name") - .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo") - .setPreviousAnalysisDate(new Date()) - .addFileData("test-project", "file1", new FileData("hash", "123456789")) - .setLogOutput(logOutput) - .build(); - - tester.start(); - tester.syncProject(null); - - assertThat(logOutput.getAsString()).contains("Cache not found, synchronizing data"); - } - - private TaskResult executeTask(TaskBuilder builder) { - builder.property("sonar.projectKey", "key"); - builder.property("sonar.projectVersion", "1.0"); - builder.property("sonar.projectName", "key"); - builder.property("sonar.projectBaseDir", temp.getRoot().getAbsolutePath()); - builder.property("sonar.sources", temp.getRoot().getAbsolutePath()); - return builder.start(); - } - -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issuesmode/NonAssociatedProject.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issuesmode/NonAssociatedProject.java deleted file mode 100644 index 32c66f2689f..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issuesmode/NonAssociatedProject.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.mediumtest.issuesmode; - -import com.google.common.collect.ImmutableMap; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.filefilter.FileFilterUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.CoreProperties; -import org.sonar.api.utils.log.LogTester; -import org.sonar.batch.mediumtest.BatchMediumTester; -import org.sonar.batch.mediumtest.TaskResult; -import org.sonar.xoo.XooPlugin; -import org.sonar.xoo.rule.XooRulesDefinition; - -import java.io.File; -import java.io.IOException; - -public class NonAssociatedProject { - @org.junit.Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @org.junit.Rule - public LogTester logTester = new LogTester(); - - public BatchMediumTester tester; - - @Before - public void prepare() throws IOException { - tester = BatchMediumTester.builder() - .bootstrapProperties(ImmutableMap.of( - CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES, - CoreProperties.GLOBAL_WORKING_DIRECTORY, temp.newFolder().getAbsolutePath())) - .registerPlugin("xoo", new XooPlugin()) - .addQProfile("xoo", "Sonar Way") - .addRules(new XooRulesDefinition()) - .addRule("manual:MyManualIssue", "manual", "MyManualIssue", "My manual issue") - .addRule("manual:MyManualIssueDup", "manual", "MyManualIssue", "My manual issue") - .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", null, "xoo") - .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo") - .addActiveRule("xoo", "OneIssuePerModule", null, "OneIssuePerModule", "MAJOR", null, "xoo") - .addActiveRule("manual", "MyManualIssue", null, "My manual issue", "MAJOR", null, null) - .setAssociated(false) - .build(); - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } - - private File copyProject(String path) throws Exception { - File projectDir = temp.newFolder(); - File originalProjectDir = new File(IssueModeAndReportsMediumTest.class.getResource(path).toURI()); - FileUtils.copyDirectory(originalProjectDir, projectDir, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".sonar"))); - return projectDir; - } - - @Test - public void testNonAssociated() throws Exception { - File projectDir = copyProject("/mediumtest/xoo/multi-modules-sample-not-associated"); - - TaskResult result = tester - .newScanTask(new File(projectDir, "sonar-project.properties")) - .start(); - - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java index db1a2dcd30e..2e2d8ea4c47 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java @@ -27,7 +27,6 @@ import org.hamcrest.TypeSafeMatcher; import org.junit.BeforeClass; import org.sonar.batch.bootstrapper.EnvironmentInformation; import org.sonar.api.utils.MessageException; -import org.apache.commons.lang.mutable.MutableBoolean; import org.sonar.batch.repository.GlobalRepositoriesLoader; import org.sonar.scanner.protocol.input.GlobalRepositories; import org.sonar.batch.bootstrapper.Batch; @@ -104,7 +103,7 @@ public class ExceptionHandlingMediumTest { boolean withCause = false; @Override - public GlobalRepositories load(MutableBoolean fromCache) { + public GlobalRepositories load() { if (withCause) { IllegalStateException cause = new IllegalStateException("Code 401"); throw MessageException.of("Error loading repository", cause); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java index cb3781e5103..c902ee3658a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java @@ -19,60 +19,31 @@ */ package org.sonar.batch.repository; -import org.apache.commons.lang.mutable.MutableBoolean; import org.junit.Before; -import org.junit.Test; -import org.sonar.batch.cache.WSLoader; -import org.sonar.batch.cache.WSLoaderResult; +import org.sonar.batch.WsTestUtil; +import org.sonar.batch.bootstrap.BatchWsClient; import org.sonar.scanner.protocol.input.GlobalRepositories; -import static org.assertj.core.api.Assertions.assertThat; +import java.io.StringReader; + import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; public class DefaultGlobalRepositoriesLoaderTest { private static final String BATCH_GLOBAL_URL = "/batch/global"; - private WSLoader wsLoader; - private WSLoaderResult<String> result; + private BatchWsClient wsClient; private DefaultGlobalRepositoriesLoader globalRepositoryLoader; @Before public void setUp() { - wsLoader = mock(WSLoader.class); - result = new WSLoaderResult<>(new GlobalRepositories().toJson(), true); - when(wsLoader.loadString(BATCH_GLOBAL_URL)).thenReturn(result); - - globalRepositoryLoader = new DefaultGlobalRepositoriesLoader(wsLoader); + wsClient = mock(BatchWsClient.class); + WsTestUtil.mockReader(wsClient, BATCH_GLOBAL_URL, new StringReader(new GlobalRepositories().toJson())); + globalRepositoryLoader = new DefaultGlobalRepositoriesLoader(wsClient); } - @Test public void test() { - MutableBoolean fromCache = new MutableBoolean(); - globalRepositoryLoader.load(fromCache); - - assertThat(fromCache.booleanValue()).isTrue(); - verify(wsLoader).loadString(BATCH_GLOBAL_URL); - verifyNoMoreInteractions(wsLoader); - } - - @Test - public void testFromServer() { - result = new WSLoaderResult<>(new GlobalRepositories().toJson(), false); - when(wsLoader.loadString(BATCH_GLOBAL_URL)).thenReturn(result); - MutableBoolean fromCache = new MutableBoolean(); - globalRepositoryLoader.load(fromCache); - - assertThat(fromCache.booleanValue()).isFalse(); - verify(wsLoader).loadString(BATCH_GLOBAL_URL); - verifyNoMoreInteractions(wsLoader); - } - - public void testWithoutArg() { - globalRepositoryLoader.load(null); - - verify(wsLoader).loadString(BATCH_GLOBAL_URL); - verifyNoMoreInteractions(wsLoader); + globalRepositoryLoader.load(); + WsTestUtil.verifyCall(wsClient, BATCH_GLOBAL_URL); + verifyNoMoreInteractions(wsClient); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java index d633820ca83..b92301c2647 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java @@ -24,21 +24,20 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import org.apache.commons.lang.mutable.MutableBoolean; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.utils.MessageException; -import org.sonar.batch.cache.WSLoader; -import org.sonar.batch.cache.WSLoaderResult; +import org.sonar.batch.WsTestUtil; +import org.sonar.batch.bootstrap.BatchWsClient; import org.sonarqube.ws.WsBatch.WsProjectResponse; import org.sonarqube.ws.client.HttpException; +import org.sonarqube.ws.client.WsRequest; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; public class DefaultProjectRepositoriesLoaderTest { @@ -47,20 +46,20 @@ public class DefaultProjectRepositoriesLoaderTest { public ExpectedException thrown = ExpectedException.none(); private DefaultProjectRepositoriesLoader loader; - private WSLoader wsLoader; + private BatchWsClient wsClient; @Before public void prepare() throws IOException { - wsLoader = mock(WSLoader.class); + wsClient = mock(BatchWsClient.class); InputStream is = mockData(); - when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true)); - loader = new DefaultProjectRepositoriesLoader(wsLoader); + WsTestUtil.mockStream(wsClient, "/batch/project.protobuf?key=foo%3F", is); + loader = new DefaultProjectRepositoriesLoader(wsClient); } @Test public void continueOnError() { - when(wsLoader.loadStream(anyString())).thenThrow(IllegalStateException.class); - ProjectRepositories proj = loader.load(PROJECT_KEY, false, null); + when(wsClient.call(any(WsRequest.class))).thenThrow(IllegalStateException.class); + ProjectRepositories proj = loader.load(PROJECT_KEY, false); assertThat(proj.exists()).isEqualTo(false); } @@ -68,50 +67,47 @@ public class DefaultProjectRepositoriesLoaderTest { public void parsingError() throws IOException { InputStream is = mock(InputStream.class); when(is.read()).thenThrow(IOException.class); - - when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false)); - loader.load(PROJECT_KEY, false, null); + WsTestUtil.mockStream(wsClient, "/batch/project.protobuf?key=foo%3F", is); + loader.load(PROJECT_KEY, false); } @Test(expected = IllegalStateException.class) public void failFastHttpError() { HttpException http = new HttpException("url", 403); IllegalStateException e = new IllegalStateException("http error", http); - when(wsLoader.loadStream(anyString())).thenThrow(e); - loader.load(PROJECT_KEY, false, null); + WsTestUtil.mockException(wsClient, e); + loader.load(PROJECT_KEY, false); } - + @Test public void failFastHttpErrorMessageException() { thrown.expect(MessageException.class); thrown.expectMessage("http error"); - + HttpException http = new HttpException("uri", 403); MessageException e = MessageException.of("http error", http); - when(wsLoader.loadStream(anyString())).thenThrow(e); - loader.load(PROJECT_KEY, false, null); + WsTestUtil.mockException(wsClient, e); + loader.load(PROJECT_KEY, false); } @Test public void passIssuesModeParameter() { - loader.load(PROJECT_KEY, false, null); - verify(wsLoader).loadStream("/batch/project.protobuf?key=foo%3F"); + loader.load(PROJECT_KEY, false); + WsTestUtil.verifyCall(wsClient, "/batch/project.protobuf?key=foo%3F"); - loader.load(PROJECT_KEY, true, null); - verify(wsLoader).loadStream("/batch/project.protobuf?key=foo%3F&issues_mode=true"); + loader.load(PROJECT_KEY, true); + WsTestUtil.verifyCall(wsClient, "/batch/project.protobuf?key=foo%3F&issues_mode=true"); } @Test public void deserializeResponse() throws IOException { - MutableBoolean fromCache = new MutableBoolean(); - loader.load(PROJECT_KEY, false, fromCache); - assertThat(fromCache.booleanValue()).isTrue(); + loader.load(PROJECT_KEY, false); } @Test public void passAndEncodeProjectKeyParameter() { - loader.load(PROJECT_KEY, false, null); - verify(wsLoader).loadStream("/batch/project.protobuf?key=foo%3F"); + loader.load(PROJECT_KEY, false); + WsTestUtil.verifyCall(wsClient, "/batch/project.protobuf?key=foo%3F"); } private InputStream mockData() throws IOException { @@ -126,9 +122,9 @@ public class DefaultProjectRepositoriesLoaderTest { @Test public void readRealResponse() throws IOException { InputStream is = getTestResource("project.protobuf"); - when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true)); + WsTestUtil.mockStream(wsClient, "/batch/project.protobuf?key=org.sonarsource.github%3Asonar-github-plugin&issues_mode=true", is); - ProjectRepositories proj = loader.load("org.sonarsource.github:sonar-github-plugin", true, null); + ProjectRepositories proj = loader.load("org.sonarsource.github:sonar-github-plugin", true); FileData fd = proj.fileData("org.sonarsource.github:sonar-github-plugin", "src/test/java/org/sonar/plugins/github/PullRequestIssuePostJobTest.java"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java index d3b4ce6b87d..8110c2a273f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java @@ -24,8 +24,8 @@ import org.sonar.api.utils.MessageException; import org.sonarqube.ws.QualityProfiles; import com.google.common.io.Resources; import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.batch.cache.WSLoader; +import org.sonar.batch.WsTestUtil; +import org.sonar.batch.bootstrap.BatchWsClient; import org.junit.Rule; import org.junit.rules.ExpectedException; import org.junit.Before; @@ -38,9 +38,7 @@ import java.io.InputStream; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -49,50 +47,49 @@ public class DefaultQualityProfileLoaderTest { public ExpectedException exception = ExpectedException.none(); private DefaultQualityProfileLoader qpLoader; - private WSLoader ws; + private BatchWsClient wsClient; private InputStream is; @Before public void setUp() throws IOException { - ws = mock(WSLoader.class); + wsClient = mock(BatchWsClient.class); is = mock(InputStream.class); when(is.read()).thenReturn(-1); - WSLoaderResult<InputStream> result = new WSLoaderResult<>(is, false); - when(ws.loadStream(anyString())).thenReturn(result); - qpLoader = new DefaultQualityProfileLoader(ws); + WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232", is); + qpLoader = new DefaultQualityProfileLoader(wsClient); } @Test public void testEncoding() throws IOException { - WSLoaderResult<InputStream> result = new WSLoaderResult<>(createEncodedQP("qp"), false); - when(ws.loadStream(anyString())).thenReturn(result); + InputStream is = createEncodedQP("qp"); + WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232", is); - List<QualityProfile> loaded = qpLoader.load("foo#2", "my-profile#2", null); - verify(ws).loadStream("/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232"); - verifyNoMoreInteractions(ws); + List<QualityProfile> loaded = qpLoader.load("foo#2", "my-profile#2"); + WsTestUtil.verifyCall(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232"); + verifyNoMoreInteractions(wsClient); assertThat(loaded).hasSize(1); } @Test public void testNoProfile() throws IOException { InputStream is = createEncodedQP(); - when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false)); + WsTestUtil.mockStream(wsClient, is); exception.expect(MessageException.class); exception.expectMessage("No quality profiles"); - qpLoader.load("project", null, null); - verifyNoMoreInteractions(ws); + qpLoader.load("project", null); + verifyNoMoreInteractions(wsClient); } @Test public void use_real_response() throws IOException { InputStream is = getTestResource("quality_profile_search_default"); - when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false)); + WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true", is); - List<QualityProfile> loaded = qpLoader.loadDefault(null, null); - verify(ws).loadStream("/api/qualityprofiles/search.protobuf?defaults=true"); - verifyNoMoreInteractions(ws); + List<QualityProfile> loaded = qpLoader.loadDefault(null); + WsTestUtil.verifyCall(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true"); + verifyNoMoreInteractions(wsClient); assertThat(loaded).hasSize(1); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java index 22416368f3f..a2e978b3b4d 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java @@ -19,10 +19,10 @@ */ package org.sonar.batch.repository; -import org.sonar.batch.cache.WSLoaderResult; +import org.sonar.batch.WsTestUtil; +import org.sonar.batch.bootstrap.BatchWsClient; import org.sonar.scanner.protocol.input.ScannerInput; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; -import org.sonar.batch.cache.WSLoader; import com.google.common.base.Function; import org.junit.Before; import org.junit.Test; @@ -39,12 +39,12 @@ import static org.mockito.Mockito.when; public class DefaultServerIssuesLoaderTest { private DefaultServerIssuesLoader loader; - private WSLoader wsLoader; + private BatchWsClient wsClient; @Before public void prepare() { - wsLoader = mock(WSLoader.class); - loader = new DefaultServerIssuesLoader(wsLoader); + wsClient = mock(BatchWsClient.class); + loader = new DefaultServerIssuesLoader(wsClient); } @Test @@ -57,7 +57,7 @@ public class DefaultServerIssuesLoaderTest { .writeDelimitedTo(bos); InputStream is = new ByteArrayInputStream(bos.toByteArray()); - when(wsLoader.loadStream("/batch/issues.protobuf?key=foo")).thenReturn(new WSLoaderResult<>(is, true)); + WsTestUtil.mockStream(wsClient, "/batch/issues.protobuf?key=foo", is); final List<ServerIssue> result = new ArrayList<>(); loader.load("foo", new Function<ScannerInput.ServerIssue, Void>() { @@ -76,7 +76,7 @@ public class DefaultServerIssuesLoaderTest { public void testError() throws IOException { InputStream is = mock(InputStream.class); when(is.read()).thenThrow(IOException.class); - when(wsLoader.loadStream("/batch/issues.protobuf?key=foo")).thenReturn(new WSLoaderResult<>(is, true)); + WsTestUtil.mockStream(wsClient, "/batch/issues.protobuf?key=foo", is); loader.load("foo", mock(Function.class)); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java index 781b48a2a59..cb0490f79f5 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java @@ -24,7 +24,6 @@ import java.util.Date; import org.sonar.batch.repository.FileData; import com.google.common.collect.Table; import com.google.common.collect.HashBasedTable; -import org.apache.commons.lang.mutable.MutableBoolean; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -32,7 +31,6 @@ import org.mockito.MockitoAnnotations; import org.sonar.api.batch.bootstrap.ProjectKey; import org.sonar.batch.analysis.DefaultAnalysisMode; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -64,52 +62,26 @@ public class ProjectRepositoriesProviderTest { } @Test - public void testNonAssociated() { - when(mode.isNotAssociated()).thenReturn(true); - ProjectRepositories repo = provider.provide(loader, projectKey, mode); - - assertThat(repo.exists()).isEqualTo(false); - verify(mode).isNotAssociated(); - verifyNoMoreInteractions(loader, projectKey, mode); - } - - @Test - public void singleton() { - when(mode.isNotAssociated()).thenReturn(true); - ProjectRepositories repo = provider.provide(loader, projectKey, mode); - - assertThat(repo.exists()).isEqualTo(false); - verify(mode).isNotAssociated(); - verifyNoMoreInteractions(loader, projectKey, mode); - - repo = provider.provide(loader, projectKey, mode); - verifyNoMoreInteractions(loader, projectKey, mode); - } - - @Test public void testValidation() { - when(mode.isNotAssociated()).thenReturn(false); when(mode.isIssues()).thenReturn(true); - when(loader.load(eq("key"), eq(true), any(MutableBoolean.class))).thenReturn(project); + when(loader.load(eq("key"), eq(true))).thenReturn(project); provider.provide(loader, projectKey, mode); } @Test public void testAssociated() { - when(mode.isNotAssociated()).thenReturn(false); when(mode.isIssues()).thenReturn(false); - when(loader.load(eq("key"), eq(false), any(MutableBoolean.class))).thenReturn(project); + when(loader.load(eq("key"), eq(false))).thenReturn(project); ProjectRepositories repo = provider.provide(loader, projectKey, mode); assertThat(repo.exists()).isEqualTo(true); assertThat(repo.lastAnalysisDate()).isNotNull(); - verify(mode).isNotAssociated(); verify(mode, times(2)).isIssues(); verify(projectKey).get(); - verify(loader).load(eq("key"), eq(false), any(MutableBoolean.class)); + verify(loader).load(eq("key"), eq(false)); verifyNoMoreInteractions(loader, projectKey, mode); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java index 0cd1683b9c9..bdbdb0ea703 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java @@ -22,7 +22,6 @@ package org.sonar.batch.repository; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang.mutable.MutableBoolean; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -37,7 +36,6 @@ import org.sonar.batch.rule.ModuleQProfiles; import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; 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.Matchers.isNull; @@ -79,49 +77,35 @@ public class QualityProfileProviderTest { @Test public void testProvide() { - when(mode.isNotAssociated()).thenReturn(false); - when(loader.load(eq("project"), isNull(String.class), any(MutableBoolean.class))).thenReturn(response); + when(loader.load(eq("project"), isNull(String.class))).thenReturn(response); ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode); assertResponse(qps); - verify(loader).load(eq("project"), isNull(String.class), any(MutableBoolean.class)); - verifyNoMoreInteractions(loader); - } - - @Test - public void testNonAssociated() { - when(mode.isNotAssociated()).thenReturn(true); - when(loader.loadDefault(anyString(), any(MutableBoolean.class))).thenReturn(response); - ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode); - assertResponse(qps); - - verify(loader).loadDefault(anyString(), any(MutableBoolean.class)); + verify(loader).load(eq("project"), isNull(String.class)); verifyNoMoreInteractions(loader); } @Test public void testProjectDoesntExist() { - when(mode.isNotAssociated()).thenReturn(false); when(projectRepo.exists()).thenReturn(false); - when(loader.loadDefault(anyString(), any(MutableBoolean.class))).thenReturn(response); + when(loader.loadDefault(anyString())).thenReturn(response); ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode); assertResponse(qps); - verify(loader).loadDefault(anyString(), any(MutableBoolean.class)); + verify(loader).loadDefault(anyString()); verifyNoMoreInteractions(loader); } @Test public void testProfileProp() { - when(mode.isNotAssociated()).thenReturn(false); - when(loader.load(eq("project"), eq("custom"), any(MutableBoolean.class))).thenReturn(response); + when(loader.load(eq("project"), eq("custom"))).thenReturn(response); when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom"); when(props.properties()).thenReturn(ImmutableMap.of(ModuleQProfiles.SONAR_PROFILE_PROP, "custom")); ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode); assertResponse(qps); - verify(loader).load(eq("project"), eq("custom"), any(MutableBoolean.class)); + verify(loader).load(eq("project"), eq("custom")); verifyNoMoreInteractions(loader); assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server."); @@ -129,29 +113,28 @@ public class QualityProfileProviderTest { @Test public void testIgnoreSonarProfileIssuesMode() { - when(mode.isNotAssociated()).thenReturn(false); when(mode.isIssues()).thenReturn(true); - when(loader.load(eq("project"), (String) eq(null), any(MutableBoolean.class))).thenReturn(response); + when(loader.load(eq("project"), (String) eq(null))).thenReturn(response); when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom"); ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode); assertResponse(qps); - verify(loader).load(eq("project"), (String) eq(null), any(MutableBoolean.class)); + verify(loader).load(eq("project"), (String) eq(null)); verifyNoMoreInteractions(loader); } @Test public void testProfilePropDefault() { - when(mode.isNotAssociated()).thenReturn(true); - when(loader.loadDefault(eq("custom"), any(MutableBoolean.class))).thenReturn(response); + when(projectRepo.exists()).thenReturn(false); + when(loader.loadDefault(eq("custom"))).thenReturn(response); when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom"); when(props.properties()).thenReturn(ImmutableMap.of(ModuleQProfiles.SONAR_PROFILE_PROP, "custom")); ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode); assertResponse(qps); - verify(loader).loadDefault(eq("custom"), any(MutableBoolean.class)); + verify(loader).loadDefault(eq("custom")); verifyNoMoreInteractions(loader); assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server."); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java index 870afd5737e..4b8982a8e74 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java @@ -21,12 +21,10 @@ package org.sonar.batch.repository.user; import org.assertj.core.util.Lists; -import org.sonar.batch.cache.WSLoaderResult; import org.sonar.scanner.protocol.input.ScannerInput; -import org.sonar.batch.cache.WSLoader; +import org.sonar.batch.WsTestUtil; +import org.sonar.batch.bootstrap.BatchWsClient; import org.junit.Before; -import com.google.common.collect.ImmutableList; -import org.apache.commons.lang.mutable.MutableBoolean; import com.google.common.collect.ImmutableMap; import org.junit.rules.ExpectedException; import org.junit.Rule; @@ -39,23 +37,21 @@ import java.io.InputStream; import java.util.Arrays; import java.util.Map; -import static org.mockito.Matchers.anyString; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class UserRepositoryLoaderTest { @Rule public final ExpectedException exception = ExpectedException.none(); - private WSLoader wsLoader; + private BatchWsClient wsClient; private UserRepositoryLoader userRepo; @Before public void setUp() { - wsLoader = mock(WSLoader.class); - userRepo = new UserRepositoryLoader(wsLoader); + wsClient = mock(BatchWsClient.class); + userRepo = new UserRepositoryLoader(wsClient); } @Test @@ -66,30 +62,15 @@ public class UserRepositoryLoaderTest { @Test public void testLoad() throws IOException { Map<String, String> userMap = ImmutableMap.of("fmallet", "Freddy Mallet", "sbrandhof", "Simon"); - WSLoaderResult<InputStream> res = new WSLoaderResult<>(createUsersMock(userMap), true); - when(wsLoader.loadStream("/batch/users?logins=fmallet,sbrandhof")).thenReturn(res); - + InputStream is = createUsersMock(userMap); + WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet,sbrandhof", is); assertThat(userRepo.load(Arrays.asList("fmallet", "sbrandhof"))).extracting("login", "name").containsOnly(tuple("fmallet", "Freddy Mallet"), tuple("sbrandhof", "Simon")); } @Test - public void testFromCache() throws IOException { - WSLoaderResult<InputStream> res = new WSLoaderResult<>(createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")), true); - when(wsLoader.loadStream(anyString())).thenReturn(res); - MutableBoolean fromCache = new MutableBoolean(); - userRepo.load("", fromCache); - assertThat(fromCache.booleanValue()).isTrue(); - - fromCache.setValue(false); - userRepo.load(ImmutableList.of("user"), fromCache); - assertThat(fromCache.booleanValue()).isTrue(); - } - - @Test public void testLoadSingleUser() throws IOException { - WSLoaderResult<InputStream> res = new WSLoaderResult<>(createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")), true); - when(wsLoader.loadStream("/batch/users?logins=fmallet")).thenReturn(res); - + InputStream is = createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")); + WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet", is); assertThat(userRepo.load("fmallet").getName()).isEqualTo("Freddy Mallet"); } @@ -107,9 +88,7 @@ public class UserRepositoryLoaderTest { public void testInputStreamError() throws IOException { InputStream is = mock(InputStream.class); Mockito.doThrow(IOException.class).when(is).read(); - WSLoaderResult<InputStream> res = new WSLoaderResult<>(is, true); - - when(wsLoader.loadStream("/batch/users?logins=fmallet,sbrandhof")).thenReturn(res); + WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet,sbrandhof", is); exception.expect(IllegalStateException.class); exception.expectMessage("Unable to get user details from server"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java index 1e1b1f0fc3c..9e1c3b70504 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java @@ -60,9 +60,9 @@ public class ActiveRulesProviderTest { List<LoadedActiveRule> qp2Rules = ImmutableList.of(r2, r3); List<LoadedActiveRule> qp3Rules = ImmutableList.of(r1, r3); - when(loader.load(eq("qp1"), any(MutableBoolean.class))).thenReturn(qp1Rules); - when(loader.load(eq("qp2"), any(MutableBoolean.class))).thenReturn(qp2Rules); - when(loader.load(eq("qp3"), any(MutableBoolean.class))).thenReturn(qp3Rules); + when(loader.load(eq("qp1"))).thenReturn(qp1Rules); + when(loader.load(eq("qp2"))).thenReturn(qp2Rules); + when(loader.load(eq("qp3"))).thenReturn(qp3Rules); ModuleQProfiles profiles = mockProfiles("qp1", "qp2", "qp3"); ActiveRules activeRules = provider.provide(loader, profiles); @@ -71,9 +71,9 @@ public class ActiveRulesProviderTest { assertThat(activeRules.findAll()).extracting("ruleKey").containsOnly( RuleKey.of("rule1", "rule1"), RuleKey.of("rule2", "rule2"), RuleKey.of("rule3", "rule3")); - verify(loader).load(eq("qp1"), any(MutableBoolean.class)); - verify(loader).load(eq("qp2"), any(MutableBoolean.class)); - verify(loader).load(eq("qp3"), any(MutableBoolean.class)); + verify(loader).load(eq("qp1")); + verify(loader).load(eq("qp2")); + verify(loader).load(eq("qp3")); verifyNoMoreInteractions(loader); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java index 434c84dda93..40f2c462dd2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java @@ -20,8 +20,8 @@ package org.sonar.batch.rule; import org.sonar.api.rule.RuleKey; -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.batch.cache.WSLoader; +import org.sonar.batch.WsTestUtil; +import org.sonar.batch.bootstrap.BatchWsClient; import com.google.common.io.Resources; import org.junit.Test; @@ -29,21 +29,19 @@ import java.io.IOException; import java.io.InputStream; import java.util.Collection; -import static org.mockito.Mockito.verify; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; import org.junit.Before; public class DefaultActiveRulesLoaderTest { private DefaultActiveRulesLoader loader; - private WSLoader ws; + private BatchWsClient wsClient; @Before public void setUp() { - ws = mock(WSLoader.class); - loader = new DefaultActiveRulesLoader(ws); + wsClient = mock(BatchWsClient.class); + loader = new DefaultActiveRulesLoader(wsClient); } @Test @@ -53,18 +51,19 @@ public class DefaultActiveRulesLoaderTest { String req1 = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true&qprofile=c%2B-test_c%2B-values-17445&p=1&ps=500"; String req2 = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true&qprofile=c%2B-test_c%2B-values-17445&p=2&ps=500"; - when(ws.loadStream(req1)).thenReturn(new WSLoaderResult<>(response1, false)); - when(ws.loadStream(req2)).thenReturn(new WSLoaderResult<>(response2, false)); + WsTestUtil.mockStream(wsClient, req1, response1); + WsTestUtil.mockStream(wsClient, req2, response2); - Collection<LoadedActiveRule> activeRules = loader.load("c+-test_c+-values-17445", null); + Collection<LoadedActiveRule> activeRules = loader.load("c+-test_c+-values-17445"); assertThat(activeRules).hasSize(226); assertActiveRule(activeRules); - - verify(ws).loadStream(req1); - verify(ws).loadStream(req2); - verifyNoMoreInteractions(ws); + + WsTestUtil.verifyCall(wsClient, req1); + WsTestUtil.verifyCall(wsClient, req2); + + verifyNoMoreInteractions(wsClient); } - + private static void assertActiveRule(Collection<LoadedActiveRule> activeRules) { RuleKey key = RuleKey.of("squid", "S3008"); for (LoadedActiveRule r : activeRules) { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java index a5a461c4e9f..ceaa22a494b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java @@ -20,11 +20,9 @@ package org.sonar.batch.rule; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import org.junit.rules.ExpectedException; -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.batch.cache.WSLoader; -import org.apache.commons.lang.mutable.MutableBoolean; +import org.sonar.batch.WsTestUtil; +import org.sonar.batch.bootstrap.BatchWsClient; import org.sonarqube.ws.Rules.ListResponse.Rule; import com.google.common.io.ByteSource; import com.google.common.io.Resources; @@ -33,7 +31,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; -import static org.mockito.Matchers.anyString; import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; @@ -43,37 +40,24 @@ public class DefaultRulesLoaderTest { @Test public void testParseServerResponse() throws IOException { - WSLoader wsLoader = mock(WSLoader.class); + BatchWsClient wsClient = mock(BatchWsClient.class); InputStream is = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoader/response.protobuf")).openBufferedStream(); - when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true)); - DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader); - List<Rule> ruleList = loader.load(null); + WsTestUtil.mockStream(wsClient, is); + DefaultRulesLoader loader = new DefaultRulesLoader(wsClient); + List<Rule> ruleList = loader.load(); assertThat(ruleList).hasSize(318); } @Test - public void testLoadedFromCache() throws IOException { - WSLoader wsLoader = mock(WSLoader.class); - InputStream is = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoader/response.protobuf")).openBufferedStream(); - when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true)); - DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader); - MutableBoolean fromCache = new MutableBoolean(); - loader.load(fromCache); - - assertThat(fromCache.booleanValue()).isTrue(); - } - - @Test public void testError() throws IOException { - WSLoader wsLoader = mock(WSLoader.class); + BatchWsClient wsClient = mock(BatchWsClient.class); InputStream is = ByteSource.wrap(new String("trash").getBytes()).openBufferedStream(); - when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true)); - DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader); + WsTestUtil.mockStream(wsClient, is); + DefaultRulesLoader loader = new DefaultRulesLoader(wsClient); exception.expect(IllegalStateException.class); exception.expectMessage("Unable to get rules"); - loader.load(null); + loader.load(); } - } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/RulesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/RulesProviderTest.java index 2df29eaa61a..fcf2133be83 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/RulesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/RulesProviderTest.java @@ -19,10 +19,6 @@ */ package org.sonar.batch.rule; -import static org.mockito.Matchers.any; - -import org.apache.commons.lang.mutable.MutableBoolean; - import com.google.common.collect.Lists; import org.sonar.api.batch.rule.Rules; import static org.assertj.core.api.Assertions.assertThat; @@ -35,7 +31,7 @@ public class RulesProviderTest { @Test public void testRuleTranslation() { RulesLoader loader = mock(RulesLoader.class); - when(loader.load(any(MutableBoolean.class))).thenReturn(Lists.newArrayList(getTestRule())); + when(loader.load()).thenReturn(Lists.newArrayList(getTestRule())); RulesProvider provider = new RulesProvider(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java index c550bb3ba39..c10bb04dd8b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java @@ -30,11 +30,9 @@ import java.util.Map; import java.util.Properties; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.utils.MessageException; @@ -43,8 +41,6 @@ import org.sonar.api.utils.log.LoggerLevel; import org.sonar.batch.analysis.AnalysisProperties; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class ProjectReactorBuilderTest { @@ -54,13 +50,6 @@ public class ProjectReactorBuilderTest { @Rule public LogTester logTester = new LogTester(); - private AnalysisMode mode; - - @Before - public void setUp() { - mode = mock(AnalysisMode.class); - } - @Test public void shouldDefineSimpleProject() { ProjectDefinition projectDefinition = loadProjectDefinition("simple-project"); @@ -332,7 +321,7 @@ public class ProjectReactorBuilderTest { AnalysisProperties taskProperties = new AnalysisProperties(props, null); assertThat(taskProperties.property("module1.module11.property")).isEqualTo("My module11 property"); - new ProjectReactorBuilder(taskProperties, mode).execute(); + new ProjectReactorBuilder(taskProperties).execute(); assertThat(taskProperties.property("module1.module11.property")).isNull(); } @@ -415,7 +404,7 @@ public class ProjectReactorBuilderTest { @Test public void shouldInitRootWorkDir() { - ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(Maps.<String, String>newHashMap(), null), mode); + ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(Maps.<String, String>newHashMap(), null)); File baseDir = new File("target/tmp/baseDir"); File workDir = builder.initRootProjectWorkDir(baseDir, Maps.<String, String>newHashMap()); @@ -424,18 +413,10 @@ public class ProjectReactorBuilderTest { } @Test - public void nonAssociatedMode() { - when(mode.isIssues()).thenReturn(true); - ProjectDefinition project = loadProjectDefinition("multi-module-with-basedir-not-associated"); - - assertThat(project.getKey()).isEqualTo("project"); - } - - @Test public void shouldInitWorkDirWithCustomRelativeFolder() { Map<String, String> props = Maps.<String, String>newHashMap(); props.put("sonar.working.directory", ".foo"); - ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null), mode); + ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null)); File baseDir = new File("target/tmp/baseDir"); File workDir = builder.initRootProjectWorkDir(baseDir, props); @@ -447,7 +428,7 @@ public class ProjectReactorBuilderTest { public void shouldInitRootWorkDirWithCustomAbsoluteFolder() { Map<String, String> props = Maps.<String, String>newHashMap(); props.put("sonar.working.directory", new File("src").getAbsolutePath()); - ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null), mode); + ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null)); File baseDir = new File("target/tmp/baseDir"); File workDir = builder.initRootProjectWorkDir(baseDir, props); @@ -499,7 +480,7 @@ public class ProjectReactorBuilderTest { private ProjectDefinition loadProjectDefinition(String projectFolder) { Map<String, String> props = loadProps(projectFolder); AnalysisProperties bootstrapProps = new AnalysisProperties(props, null); - ProjectReactor projectReactor = new ProjectReactorBuilder(bootstrapProps, mode).execute(); + ProjectReactor projectReactor = new ProjectReactorBuilder(bootstrapProps).execute(); return projectReactor.getRoot(); } @@ -638,7 +619,7 @@ public class ProjectReactorBuilderTest { Map<String, String> props = loadProps("simple-project"); props.put("sonar.qualitygate", "somevalue"); AnalysisProperties bootstrapProps = new AnalysisProperties(props, null); - new ProjectReactorBuilder(bootstrapProps, mode).execute(); + new ProjectReactorBuilder(bootstrapProps).execute(); assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Property 'sonar.qualitygate' is not supported any more. It will be ignored."); } diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo deleted file mode 100644 index 74d29a4fa08..00000000000 --- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo +++ /dev/null @@ -1,16 +0,0 @@ -package com.sonar.it.samples.modules.a1; - -public class HelloA1 { - private int i; - private HelloA1() { - - } - - public void hello() { - System.out.println("hello" + " xoo"); - } - - protected String getHello() { - return "hello"; - } -}
\ No newline at end of file diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo deleted file mode 100644 index 42039538a92..00000000000 --- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo +++ /dev/null @@ -1,12 +0,0 @@ -package com.sonar.it.samples.modules.a2; - -public class HelloA2 { - private int i; - private HelloA2() { - - } - - public void hello() { - System.out.println("hello" + " xoo"); - } -}
\ No newline at end of file diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo deleted file mode 100644 index b83c3af128c..00000000000 --- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo +++ /dev/null @@ -1,12 +0,0 @@ -package com.sonar.it.samples.modules.b1; - -public class HelloB1 { - private int i; - private HelloB1() { - - } - - public void hello() { - System.out.println("hello" + " world"); - } -}
\ No newline at end of file diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo deleted file mode 100644 index 20b8bb3876a..00000000000 --- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo +++ /dev/null @@ -1,12 +0,0 @@ -package com.sonar.it.samples.modules.b2; - -public class HelloB2 { - private int i; - private HelloB2() { - - } - - public void hello() { - System.out.println("hello" + " world"); - } -}
\ No newline at end of file diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/sonar-project.properties b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/sonar-project.properties deleted file mode 100644 index c2b00ede37c..00000000000 --- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/sonar-project.properties +++ /dev/null @@ -1,31 +0,0 @@ -# Root project information -#sonar.projectKey=com.sonarsource.it.samples:multi-modules-sample -sonar.projectName=Sonar :: Integration Tests :: Multi-modules Sample -sonar.projectVersion=1.0-SNAPSHOT - -sonar.language=xoo - -# Some properties that will be inherited by the modules -sonar.sources=src/main/xoo - -# List of the module identifiers -sonar.modules=module_a,module_b - -module_a.sonar.projectKey=module_a -module_a.sonar.projectName=Module A - -module_a.sonar.modules=module_a1,module_a2 - -module_a.module_a1.sonar.projectName=Sub-module A1 - -module_a.module_a2.sonar.projectName=Sub-module A2 - - -module_b.sonar.projectKey=module_b -module_b.sonar.projectName=Module B - -module_b.sonar.modules=module_b1,module_b2 - -module_b.module_b1.sonar.projectName=Sub-module B1 - -module_b.module_b2.sonar.projectName=Sub-module B2 diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobuf b/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobuf Binary files differdeleted file mode 100644 index 1d417ce2880..00000000000 --- a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobuf +++ /dev/null diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf b/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf Binary files differdeleted file mode 100644 index 8b610d8f73c..00000000000 --- a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf +++ /dev/null diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json b/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json deleted file mode 100644 index 2887ce18d10..00000000000 --- a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json +++ /dev/null @@ -1,164 +0,0 @@ -{ - "timestamp": 0, - "qprofilesByLanguage": { - "java": { - "key": "java-sonar-way-72608", - "name": "Sonar way", - "language": "java", - "rulesUpdatedAt": "2015-08-10T12:06:53+0200" - } - }, - "activeRules": [ - { - "repositoryKey": "common-java", - "ruleKey": "DuplicatedBlocks", - "name": "Source files should not have any duplicated blocks", - "severity": "MAJOR", - "language": "java", - "params": {} - }, - { - "repositoryKey": "common-java", - "ruleKey": "InsufficientBranchCoverage", - "name": "Branches should have sufficient coverage by unit tests", - "severity": "MAJOR", - "language": "java", - "params": { - "minimumBranchCoverageRatio": "65.0" - } - }, - { - "repositoryKey": "squid", - "ruleKey": "RightCurlyBraceStartLineCheck", - "name": "A close curly brace should be located at the beginning of a line", - "severity": "MINOR", - "internalKey": "RightCurlyBraceStartLineCheck", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "UselessParenthesesCheck", - "name": "Useless parentheses around expressions should be removed to prevent any misunderstanding", - "severity": "MAJOR", - "internalKey": "UselessParenthesesCheck", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "ObjectFinalizeCheck", - "name": "The Object.finalize() method should not be called", - "severity": "CRITICAL", - "internalKey": "ObjectFinalizeCheck", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "ObjectFinalizeOverridenCheck", - "name": "The Object.finalize() method should not be overriden", - "severity": "CRITICAL", - "internalKey": "ObjectFinalizeOverridenCheck", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "ObjectFinalizeOverridenCallsSuperFinalizeCheck", - "name": "super.finalize() should be called at the end of Object.finalize() implementations", - "severity": "BLOCKER", - "internalKey": "ObjectFinalizeOverridenCallsSuperFinalizeCheck", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "ClassVariableVisibilityCheck", - "name": "Class variable fields should not have public accessibility", - "severity": "MAJOR", - "internalKey": "ClassVariableVisibilityCheck", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "S2188", - "name": "JUnit test cases should call super methods", - "severity": "CRITICAL", - "internalKey": "S2188", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "S2186", - "name": "JUnit assertions should not be used in \"run\" methods", - "severity": "CRITICAL", - "internalKey": "S2186", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "S2187", - "name": "TestCases should contain tests", - "severity": "MAJOR", - "internalKey": "S2187", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "S2391", - "name": "JUnit framework methods should be declared properly", - "severity": "CRITICAL", - "internalKey": "S2391", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "S2325", - "name": "\"private\" methods that don\u0027t access instance data should be \"static\"", - "severity": "MINOR", - "internalKey": "S2325", - "language": "java", - "params": {} - }, - { - "repositoryKey": "squid", - "ruleKey": "S1166", - "name": "Exception handlers should preserve the original exception", - "severity": "CRITICAL", - "internalKey": "S1166", - "language": "java", - "params": { - "exceptions": "java.lang.InterruptedException, java.lang.NumberFormatException, java.text.ParseException, java.net.MalformedURLException" - } - }, - { - "repositoryKey": "squid", - "ruleKey": "S2970", - "name": "Assertions should be complete", - "severity": "CRITICAL", - "internalKey": "S2970", - "language": "java", - "params": {} - } - - ], - "settingsByModule": {}, - "fileDataByModuleAndPath": { - "org.codehaus.sonar-plugins:sonar-scm-git-plugin": { - "src/test/java/org/sonar/plugins/scm/git/JGitBlameCommandTest.java": { - "needBlame": true - }, - "src/main/java/org/sonar/plugins/scm/git/GitScmProvider.java": { - "hash": "90082117d0dc0f1189ab7e4990a20667", - "needBlame": true - } - } - }, - "lastAnalysisDate": "2015-08-10T13:20:09+0200" -}
\ No newline at end of file diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_users.protobuf b/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_users.protobuf deleted file mode 100644 index e69de29bb2d..00000000000 --- a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_users.protobuf +++ /dev/null |