diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-07-14 19:32:45 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-07-14 19:32:45 +0200 |
commit | 86706f9bae9c427f729484cd98b425cd25ae653e (patch) | |
tree | bdfb312769448b7adce876a37bf87bff3f5127a8 /sonar-server | |
parent | 28588545174b1c764b018daf943d65f6b3617b47 (diff) | |
download | sonarqube-86706f9bae9c427f729484cd98b425cd25ae653e.tar.gz sonarqube-86706f9bae9c427f729484cd98b425cd25ae653e.zip |
Update Center improvements
* SONAR-3661 API: new component org.sonar.api.utils.UriReader
* SONAR-3660 The property sonar.updatecenter.url must support local files
* SONAR-3659 Availability of Update Center with non-RELEASE versions of Sonar
* SONAR-2008 Enable updates from SNAPSHOT versions for plugins
Diffstat (limited to 'sonar-server')
8 files changed, 175 insertions, 160 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index 287f8e2f541..b3295221436 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -36,6 +36,7 @@ import org.sonar.api.rules.XMLRuleParser; import org.sonar.api.utils.HttpDownloader; import org.sonar.api.utils.IocContainer; import org.sonar.api.utils.TimeProfiler; +import org.sonar.api.utils.UriReader; import org.sonar.api.workflow.internal.DefaultWorkflow; import org.sonar.core.PicoUtils; import org.sonar.core.config.Logback; @@ -193,6 +194,7 @@ public final class Platform { servicesContainer.addSingleton(WorkflowEngine.class); servicesContainer.addSingleton(HttpDownloader.class); + servicesContainer.addSingleton(UriReader.class); servicesContainer.addSingleton(UpdateCenterClient.class); servicesContainer.addSingleton(UpdateCenterMatrixFactory.class); servicesContainer.addSingleton(PluginDownloader.class); diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java b/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java index 191c0e88cbd..7d461004756 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java @@ -19,6 +19,7 @@ */ package org.sonar.server.plugins; +import com.google.common.annotations.VisibleForTesting; import org.apache.commons.io.IOUtils; import org.slf4j.LoggerFactory; import org.sonar.api.Properties; @@ -26,8 +27,7 @@ import org.sonar.api.Property; import org.sonar.api.PropertyType; import org.sonar.api.ServerComponent; import org.sonar.api.config.Settings; -import org.sonar.api.utils.HttpDownloader; -import org.sonar.api.utils.Logs; +import org.sonar.api.utils.UriReader; import org.sonar.updatecenter.common.UpdateCenter; import org.sonar.updatecenter.common.UpdateCenterDeserializer; @@ -67,19 +67,17 @@ public class UpdateCenterClient implements ServerComponent { private URI uri; private UpdateCenter center = null; private long lastRefreshDate = 0; - private HttpDownloader downloader; + private UriReader uriReader; - /** - * for unit tests - */ - UpdateCenterClient(HttpDownloader downloader, URI uri) { - this.downloader = downloader; + @VisibleForTesting + UpdateCenterClient(UriReader uriReader, URI uri) { + this.uriReader = uriReader; this.uri = uri; - Logs.INFO.info("Update center: " + uri + " (" + downloader.getProxySynthesis(uri) + ")"); + LoggerFactory.getLogger(getClass()).info("Update center: " + uriReader.description(uri)); } - public UpdateCenterClient(HttpDownloader downloader, Settings configuration) throws URISyntaxException { - this(downloader, new URI(configuration.getString(URL_PROPERTY))); + public UpdateCenterClient(UriReader uriReader, Settings settings) throws URISyntaxException { + this(uriReader, new URI(settings.getString(URL_PROPERTY))); } public UpdateCenter getCenter() { @@ -88,7 +86,7 @@ public class UpdateCenterClient implements ServerComponent { public UpdateCenter getCenter(boolean forceRefresh) { if (center == null || forceRefresh || needsRefresh()) { - center = download(); + center = init(); lastRefreshDate = System.currentTimeMillis(); } return center; @@ -102,10 +100,10 @@ public class UpdateCenterClient implements ServerComponent { return lastRefreshDate + PERIOD_IN_MILLISECONDS < System.currentTimeMillis(); } - private UpdateCenter download() { + private UpdateCenter init() { InputStream input = null; try { - input = downloader.openStream(uri); + input = uriReader.openStream(uri); if (input != null) { java.util.Properties properties = new java.util.Properties(); properties.load(input); @@ -113,7 +111,7 @@ public class UpdateCenterClient implements ServerComponent { } } catch (Exception e) { - LoggerFactory.getLogger(getClass()).error("Fail to download data from update center", e); + LoggerFactory.getLogger(getClass()).error("Fail to connect to update center", e); } finally { IOUtils.closeQuietly(input); diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterMatrix.java b/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterMatrix.java index e3f6e48decb..b7caf70ca76 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterMatrix.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterMatrix.java @@ -41,18 +41,6 @@ public final class UpdateCenterMatrix { this.installedSonarVersion = installedSonarVersion; } - public UpdateCenterMatrix(UpdateCenter center, String installedSonarVersion) { - this(center, Version.create(installedSonarVersion)); - } - - public UpdateCenter getCenter() { - return center; - } - - public Version getInstalledSonarVersion() { - return installedSonarVersion; - } - public UpdateCenterMatrix registerInstalledPlugin(String pluginKey, Version pluginVersion) { Plugin plugin = center.getPlugin(pluginKey); if (plugin != null) { @@ -61,21 +49,30 @@ public final class UpdateCenterMatrix { return this; } + /** + * Used by ruby webapp + */ + public UpdateCenter getCenter() { + return center; + } + public UpdateCenterMatrix registerPendingPluginsByFilename(String filename) { pendingPluginFilenames.add(filename); return this; } public List<PluginUpdate> findAvailablePlugins() { + Version adjustedSonarVersion = getAdjustedSonarVersion(); + List<PluginUpdate> availables = Lists.newArrayList(); for (Plugin plugin : center.getPlugins()) { if (!installedPlugins.containsKey(plugin) && !isAlreadyDownloaded(plugin)) { - Release release = plugin.getLastCompatibleRelease(installedSonarVersion); + Release release = plugin.getLastCompatibleRelease(adjustedSonarVersion); if (release != null) { availables.add(PluginUpdate.createWithStatus(release, PluginUpdate.Status.COMPATIBLE)); } else { - release = plugin.getLastCompatibleReleaseIfUpgrade(installedSonarVersion); + release = plugin.getLastCompatibleReleaseIfUpgrade(adjustedSonarVersion); if (release != null) { availables.add(PluginUpdate.createWithStatus(release, PluginUpdate.Status.REQUIRE_SONAR_UPGRADE)); } @@ -96,13 +93,15 @@ public final class UpdateCenterMatrix { } public List<PluginUpdate> findPluginUpdates() { + Version adjustedSonarVersion = getAdjustedSonarVersion(); + List<PluginUpdate> updates = Lists.newArrayList(); for (Map.Entry<Plugin, Version> entry : installedPlugins.entrySet()) { Plugin plugin = entry.getKey(); if (!isAlreadyDownloaded(plugin)) { Version pluginVersion = entry.getValue(); for (Release release : plugin.getReleasesGreaterThan(pluginVersion)) { - updates.add(PluginUpdate.createForPluginRelease(release, installedSonarVersion)); + updates.add(PluginUpdate.createForPluginRelease(release, adjustedSonarVersion)); } } } @@ -156,4 +155,13 @@ public final class UpdateCenterMatrix { this.date = d; return this; } + + /** + * Update center declares RELEASE versions of Sonar, for instance 3.2 but not 3.2-SNAPSHOT. + * We assume that SNAPSHOT, milestones and release candidates of Sonar support the + * same plugins than related RELEASE. + */ + private Version getAdjustedSonarVersion() { + return Version.createRelease(installedSonarVersion.toString()); + } } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/available.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/available.html.erb index d96b398f17a..0f5defd15af 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/available.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/available.html.erb @@ -1,7 +1,7 @@ <script> function installPlugin(key) { /* check terms & conditions */ - var tc=$('tc-' + key) + var tc=$('tc-' + key); if (tc!=null && !tc.checked) { alert('Please accept the Terms and Conditions'); return false; @@ -14,7 +14,8 @@ function installPlugin(key) { return false; } </script> - <%= render :partial => 'updatecenter/tabs', :locals => {:tab => 'available'} -%> +<h1 class="marginbottom10"><%= message('update_center.page') -%></h1> +<%= render :partial => 'updatecenter/tabs', :locals => {:tab => 'available'} -%> <div class="tabs-panel"> <%= render :partial => 'updatecenter/operations' -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/system_updates.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/system_updates.html.erb index a52a6d89968..a4f707b32f5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/system_updates.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/system_updates.html.erb @@ -1,102 +1,113 @@ - <style> - ol.bulletpoints li { - list-style-type: decimal; - list-style-position: inside; - } - </style> - <script> - function submitForm(elt) { - elt.submit(); - elt.disable(); - return false; -} +<style> + ol.bulletpoints li { + list-style-type: decimal; + list-style-position: inside; + } +</style> +<script> + function submitForm(elt) { + elt.submit(); + elt.disable(); + return false; + } </script> - <%= render :partial => 'updatecenter/tabs', :locals => {:tab => 'system_updates'} -%> +<h1 class="marginbottom10"><%= message('update_center.page') -%></h1> +<%= render :partial => 'updatecenter/tabs', :locals => {:tab => 'system_updates'} -%> - <div class="tabs-panel"> +<div class="tabs-panel"> - <%= render :partial => 'updatecenter/operations' -%> + <%= render :partial => 'updatecenter/operations' -%> - <% if @center %> - <% if @sonar_updates.empty? %> - <table class="data width100 marginbottom10"> - <thead> - <tr> - <td> </td> - </tr> - </thead> - <tbody> - <tr> - <td>System is up to date</td> - </tr> - </tbody> - </table> - <% else %> + <% if @center %> + <% if @sonar_updates.empty? %> + <table class="data width100 marginbottom10"> + <thead> + <tr> + <td></td> + </tr> + </thead> + <tbody> + <tr> + <td>System is up to date</td> + </tr> + </tbody> + </table> + <% else %> - <% @sonar_updates.to_a.reverse.each do |update| + <% @sonar_updates.to_a.reverse.each do |update| release=update.getRelease() - %> - <table class="data width100" id="sonar-<%= release.getVersion() -%>"> - <thead> + %> + <table class="data width100" id="sonar-<%= release.getVersion() -%>"> + <thead> <tr> <th><h2>Sonar <%= release.getVersion() -%></h2></th> </tr> - </thead> - <tbody> + </thead> + <tbody> <tr class="even"> <td> <table class="width100 spaced"> <tr> <td class="thin nowrap"><b>Date: </b></td> - <td class="sep"> </td> + <td class="sep"></td> <td><%= release_date(release.getDate()) if release.getDate() -%></td> </tr> <tr> - <td class="thin nowrap"><b><%= link_to_if release.getChangelogUrl(), 'Release Notes', release.getChangelogUrl(), :class => 'external' %>: </b></td> - <td class="sep"> </td> + <td class="thin nowrap"> + <b><%= link_to_if release.getChangelogUrl(), 'Release Notes', release.getChangelogUrl(), :class => 'external' %> + : </b></td> + <td class="sep"></td> <td><%= release.getDescription() -%></td> </tr> <tr> <td class="thin nowrap" valign="top"><b>How to upgrade: </b></td> - <td class="sep"> </td> + <td class="sep"></td> <td> <% if update.hasWarnings() %> - Follow those steps to upgrade Sonar from version <%= sonar_version -%> to version <%= release.getVersion() -%> : - <ol class="bulletpoints"> - <% update.getIncompatiblePlugins().each do |incompatible_plugin| %> - <li> - <form method="post" action="<%= ApplicationController.root_context -%>/updatecenter/uninstall?key=<%= incompatible_plugin.getKey() -%>&from=system_updates" style="display: inline-block"> - <%= image_tag 'warning.png' -%> <input type="submit" value="Uninstall" class="red-button" onClick="return submitForm(this);"/> the plugin <%= incompatible_plugin.getName() -%> which is not compatible with Sonar <%= release.getVersion() -%>. - </form> - </li> - <% end %> - <% update.getPluginsToUpgrade().each do |plugin_to_upgrade| %> - <li> - <form method="post" id="upgrade-form-<%= plugin_to_upgrade.getArtifact().getKey() -%>" action="<%= ApplicationController.root_context -%>/updatecenter/install?key=<%= plugin_to_upgrade.getArtifact().getKey() -%>&version=<%= plugin_to_upgrade.getVersion() -%>&from=system_updates" style="display: inline-block"> - <input type="submit" id="upgrade-submit-<%= plugin_to_upgrade.getArtifact().getKey() -%>" value="Upgrade" onClick="return submitForm(this);"/> - the plugin <%= plugin_to_upgrade.getArtifact().getName() -%> to version <%= plugin_to_upgrade.getVersion() -%> - </form> - </li> - <% end %> - <li>Stop Sonar</li> - <li><%= link_to 'Download', release.getDownloadUrl(), :class => 'external' -%> and install Sonar <%= release.getVersion() -%> after having carefully read the upgrade guide.</li> - <li>Start Sonar</li> - </ol> + Follow those steps to upgrade Sonar from version <%= sonar_version -%> to + version <%= release.getVersion() -%> : + <ol class="bulletpoints"> + <% update.getIncompatiblePlugins().each do |incompatible_plugin| %> + <li> + <form method="post" action="<%= ApplicationController.root_context -%>/updatecenter/uninstall?key=<%= incompatible_plugin.getKey() -%>&from=system_updates" style="display: inline-block"> + <%= image_tag 'warning.png' -%> + <input type="submit" value="Uninstall" class="red-button" onClick="return submitForm(this);"/> + the plugin <%= incompatible_plugin.getName() -%> which is not compatible with + Sonar <%= release.getVersion() -%>. + </form> + </li> + <% end %> + <% update.getPluginsToUpgrade().each do |plugin_to_upgrade| %> + <li> + <form method="post" id="upgrade-form-<%= plugin_to_upgrade.getArtifact().getKey() -%>" action="<%= ApplicationController.root_context -%>/updatecenter/install?key=<%= plugin_to_upgrade.getArtifact().getKey() -%>&version=<%= plugin_to_upgrade.getVersion() -%>&from=system_updates" style="display: inline-block"> + <input type="submit" id="upgrade-submit-<%= plugin_to_upgrade.getArtifact().getKey() -%>" value="Upgrade" onClick="return submitForm(this);"/> + the plugin <%= plugin_to_upgrade.getArtifact().getName() -%> to + version <%= plugin_to_upgrade.getVersion() -%> + </form> + </li> + <% end %> + <li>Stop Sonar</li> + <li><%= link_to 'Download', release.getDownloadUrl(), :class => 'external' -%> and install + Sonar <%= release.getVersion() -%> after having carefully read the upgrade guide. + </li> + <li>Start Sonar</li> + </ol> <% else %> - <%= link_to 'Download', release.getDownloadUrl(), :class => 'external' -%> and install Sonar <%= release.getVersion() -%> after having carefully read the upgrade guide. + <%= link_to 'Download', release.getDownloadUrl(), :class => 'external' -%> and install + Sonar <%= release.getVersion() -%> after having carefully read the upgrade guide. <% end %> </td> </tr> </table> </td> </tr> - </tbody> - </table> - <div class="break30"> </div> - <% end - end - end %> + </tbody> + </table> + <div class="break30"></div> + <% end + end + end %> - <%= render :partial => 'updatecenter/status', :locals => {:action => 'system_updates' } %> - </div> + <%= render :partial => 'updatecenter/status', :locals => {:action => 'system_updates'} %> +</div> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/updates.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/updates.html.erb index 1966fd95241..d313e675353 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/updates.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/updates.html.erb @@ -7,8 +7,8 @@ function upgradePlugin(key) { return false; } </script> - - <%= render :partial => 'updatecenter/tabs', :locals => {:tab => 'updates'} -%> +<h1 class="marginbottom10"><%= message('update_center.page') -%></h1> +<%= render :partial => 'updatecenter/tabs', :locals => {:tab => 'updates'} -%> <div class="tabs-panel"> diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java index d170dbbe935..339659b709a 100644 --- a/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java +++ b/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java @@ -22,64 +22,61 @@ package org.sonar.server.plugins; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; -import org.sonar.api.utils.HttpDownloader; import org.sonar.api.utils.SonarException; +import org.sonar.api.utils.UriReader; import org.sonar.updatecenter.common.UpdateCenter; import org.sonar.updatecenter.common.Version; import java.net.URI; import java.net.URISyntaxException; -import static junit.framework.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.internal.matchers.IsCollectionContaining.hasItems; -import static org.mockito.Matchers.anyObject; +import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.*; public class UpdateCenterClientTest { private UpdateCenterClient client; - private HttpDownloader downloader; + private UriReader reader; private static final String BASE_URL = "http://update.sonarsource.org"; @Before public void startServer() throws Exception { - downloader = mock(HttpDownloader.class); - client = new UpdateCenterClient(downloader, new URI(BASE_URL)); + reader = mock(UriReader.class); + client = new UpdateCenterClient(reader, new URI(BASE_URL)); } @Test public void downloadUpdateCenter() throws URISyntaxException { - when(downloader.openStream(new URI(BASE_URL))).thenReturn(IOUtils.toInputStream("sonar.versions=2.2,2.3")); + when(reader.openStream(new URI(BASE_URL))).thenReturn(IOUtils.toInputStream("sonar.versions=2.2,2.3")); UpdateCenter center = client.getCenter(); - verify(downloader, times(1)).openStream(new URI(BASE_URL)); - assertThat(center.getSonar().getVersions(), hasItems(Version.create("2.2"), Version.create("2.3"))); + verify(reader, times(1)).openStream(new URI(BASE_URL)); + assertThat(center.getSonar().getVersions()).containsOnly(Version.create("2.2"), Version.create("2.3")); } @Test - public void ignoreWhenServerIsDown() { - when(downloader.download((URI) anyObject())).thenThrow(new SonarException()); - assertNull(client.getCenter()); + public void ignore_connection_errors() { + when(reader.openStream(any(URI.class))).thenThrow(new SonarException()); + assertThat(client.getCenter()).isNull(); } @Test - public void cacheData() throws URISyntaxException { - when(downloader.openStream(new URI(BASE_URL))).thenReturn(IOUtils.toInputStream("sonar.versions=2.2,2.3")); + public void cache_data() throws Exception { + when(reader.openStream(new URI(BASE_URL))).thenReturn(IOUtils.toInputStream("sonar.versions=2.2,2.3")); client.getCenter(); client.getCenter(); - verify(downloader, times(1)).openStream(new URI(BASE_URL)); + verify(reader, times(1)).openStream(new URI(BASE_URL)); } @Test - public void forceRefresh() throws URISyntaxException { - when(downloader.openStream(new URI(BASE_URL))).thenReturn(IOUtils.toInputStream("sonar.versions=2.2,2.3")); + public void forceRefresh() throws Exception { + when(reader.openStream(new URI(BASE_URL))).thenReturn(IOUtils.toInputStream("sonar.versions=2.2,2.3")); client.getCenter(); client.getCenter(true); - verify(downloader, times(2)).openStream(new URI(BASE_URL)); + verify(reader, times(2)).openStream(new URI(BASE_URL)); } }
\ No newline at end of file diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterMatrixTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterMatrixTest.java index 3a07a915cca..d6b287b7d62 100644 --- a/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterMatrixTest.java +++ b/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterMatrixTest.java @@ -28,9 +28,7 @@ import org.sonar.updatecenter.common.Version; import java.util.List; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.fest.assertions.Assertions.assertThat; public class UpdateCenterMatrixTest { private UpdateCenter center; @@ -66,29 +64,29 @@ public class UpdateCenterMatrixTest { @Test public void findPluginUpdates() { - UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, "2.1"); + UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, Version.create("2.1")); matrix.registerInstalledPlugin("foo", Version.create("1.0")); List<PluginUpdate> updates = matrix.findPluginUpdates(); - assertThat(updates.size(), is(2)); + assertThat(updates).hasSize(2); - assertThat(updates.get(0).getRelease(), is(foo11)); - assertThat(updates.get(0).isCompatible(), is(true)); + assertThat(updates.get(0).getRelease()).isEqualTo(foo11); + assertThat(updates.get(0).isCompatible()).isTrue(); - assertThat(updates.get(1).getRelease(), is(foo12)); - assertThat(updates.get(1).isCompatible(), is(false)); - assertThat(updates.get(1).requiresSonarUpgrade(), is(true)); + assertThat(updates.get(1).getRelease()).isEqualTo(foo12); + assertThat(updates.get(1).isCompatible()).isFalse(); + assertThat(updates.get(1).requiresSonarUpgrade()).isTrue(); } @Test public void noPluginUpdatesIfLastReleaseIsInstalled() { - UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, "2.3"); + UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, Version.create("2.3")); matrix.registerInstalledPlugin("foo", Version.create("1.2")); - assertTrue(matrix.findPluginUpdates().isEmpty()); + assertThat(matrix.findPluginUpdates()).isEmpty(); } @Test public void availablePluginsAreOnlyTheBestReleases() { - UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, "2.2"); + UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, Version.create("2.2")); matrix.registerInstalledPlugin("foo", Version.create("1.0")); List<PluginUpdate> availables = matrix.findAvailablePlugins(); @@ -96,14 +94,14 @@ public class UpdateCenterMatrixTest { // bar 1.0 is compatible with the installed sonar // bar 1.1 requires sonar to be upgraded to 2.2.2 or 2.3 // => available plugin to install is bar 1.0 - assertThat(availables.size(), is(1)); - assertThat(availables.get(0).getRelease(), is(bar10)); - assertThat(availables.get(0).isCompatible(), is(true)); + assertThat(availables.size()).isEqualTo(1); + assertThat(availables.get(0).getRelease()).isEqualTo(bar10); + assertThat(availables.get(0).isCompatible()).isTrue(); } @Test public void availablePluginsRequireSonarUpgrade() { - UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, "2.2.1"); + UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, Version.create("2.2.1")); matrix.registerInstalledPlugin("foo", Version.create("1.0")); List<PluginUpdate> availables = matrix.findAvailablePlugins(); @@ -111,9 +109,9 @@ public class UpdateCenterMatrixTest { // bar 1.0 is not compatible with the installed sonar // bar 1.1 requires sonar to be upgraded to 2.2.2 or 2.3 // => available plugin to install is bar 1.1 - assertThat(availables.size(), is(1)); - assertThat(availables.get(0).getRelease(), is(bar11)); - assertThat(availables.get(0).requiresSonarUpgrade(), is(true)); + assertThat(availables.size()).isEqualTo(1); + assertThat(availables.get(0).getRelease()).isEqualTo(bar11); + assertThat(availables.get(0).requiresSonarUpgrade()).isTrue(); } @Test @@ -121,13 +119,13 @@ public class UpdateCenterMatrixTest { center.getSonar().addRelease(Version.create("2.3")); center.getSonar().addRelease(Version.create("2.4")); - UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, "2.2"); + UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, Version.create("2.2")); List<SonarUpdate> updates = matrix.findSonarUpdates(); // no plugins are installed, so both sonar versions are compatible - assertThat(updates.size(), is(2)); - assertThat(updates.get(0).hasWarnings(), is(false)); - assertThat(updates.get(1).hasWarnings(), is(false)); + assertThat(updates).hasSize(2); + assertThat(updates.get(0).hasWarnings()).isFalse(); + assertThat(updates.get(1).hasWarnings()).isFalse(); } @Test @@ -135,40 +133,40 @@ public class UpdateCenterMatrixTest { center.getSonar().addRelease(Version.create("2.3")); center.getSonar().addRelease(Version.create("2.4")); - UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, "2.2"); + UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, Version.create("2.2")); matrix.registerInstalledPlugin("foo", Version.create("1.0")); matrix.registerInstalledPlugin("bar", Version.create("1.0")); List<SonarUpdate> updates = matrix.findSonarUpdates(); - assertThat(updates.size(), is(2)); + assertThat(updates).hasSize(2); // sonar 2.3 supports foo 1.1/1.2 and bar 1.1 // => 2 plugin upgrades are required - assertThat(updates.get(0).hasWarnings(), is(true)); - assertThat(updates.get(0).requiresPluginUpgrades(), is(true)); - assertThat(updates.get(0).getPluginsToUpgrade().size(), is(2)); + assertThat(updates.get(0).hasWarnings()).isTrue(); + assertThat(updates.get(0).requiresPluginUpgrades()).isTrue(); + assertThat(updates.get(0).getPluginsToUpgrade()).hasSize(2); // sonar 2.4 supports no plugins - assertThat(updates.get(1).hasWarnings(), is(true)); - assertThat(updates.get(1).isIncompatible(), is(true)); - assertThat(updates.get(1).getIncompatiblePlugins().size(), is(2)); + assertThat(updates.get(1).hasWarnings()).isTrue(); + assertThat(updates.get(1).isIncompatible()).isTrue(); + assertThat(updates.get(1).getIncompatiblePlugins()).hasSize(2); } @Test public void excludePendingDownloadsFromPluginUpdates() { - UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, "2.1"); + UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, Version.create("2.1")); matrix.registerInstalledPlugin("foo", Version.create("1.0")); matrix.registerPendingPluginsByFilename("foo-1.0.jar"); List<PluginUpdate> updates = matrix.findPluginUpdates(); - assertThat(updates.size(), is(0)); + assertThat(updates.size()).isEqualTo(0); } @Test public void excludePendingDownloadsFromAvailablePlugins() { - UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, "2.1"); + UpdateCenterMatrix matrix = new UpdateCenterMatrix(center, Version.create("2.1")); matrix.registerPendingPluginsByFilename("foo-1.0.jar"); matrix.registerPendingPluginsByFilename("bar-1.1.jar"); List<PluginUpdate> updates = matrix.findAvailablePlugins(); - assertThat(updates.size(), is(0)); + assertThat(updates.size()).isEqualTo(0); } } |