From: Simon Brandhof Date: Fri, 26 Oct 2012 22:51:27 +0000 (+0200) Subject: Add PluginDownloaderTest X-Git-Tag: 3.4~435 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b37cc878ad2e5952807aef46e966f7d790f52a2d;p=sonarqube.git Add PluginDownloaderTest --- diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/PluginDownloaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/PluginDownloaderTest.java new file mode 100644 index 00000000000..ac5f92af70a --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/PluginDownloaderTest.java @@ -0,0 +1,75 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.batch.bootstrap; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.core.plugins.RemotePlugin; + +import java.io.File; +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class PluginDownloaderTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + @Test + public void should_request_list_of_plugins() { + TempDirectories tempDirs = mock(TempDirectories.class); + ServerClient server = mock(ServerClient.class); + when(server.request("/deploy/plugins/index.txt")).thenReturn("checkstyle,true\nsqale,false"); + PluginDownloader downloader = new PluginDownloader(tempDirs, server); + + List plugins = downloader.downloadPluginIndex(); + assertThat(plugins).hasSize(2); + assertThat(plugins.get(0).getKey()).isEqualTo("checkstyle"); + assertThat(plugins.get(0).isCore()).isTrue(); + assertThat(plugins.get(1).getKey()).isEqualTo("sqale"); + assertThat(plugins.get(1).isCore()).isFalse(); + } + + @Test + public void should_download_plugin() throws Exception { + TempDirectories tempDirs = mock(TempDirectories.class); + File toDir = temp.newFolder(); + when(tempDirs.getDir("plugins/checkstyle")).thenReturn(toDir); + ServerClient server = mock(ServerClient.class); + PluginDownloader downloader = new PluginDownloader(tempDirs, server); + + RemotePlugin plugin = new RemotePlugin("checkstyle", true) + .addFilename("checkstyle-plugin.jar") + .addFilename("checkstyle-extensions.jar"); + List files = downloader.downloadPlugin(plugin); + + File pluginFile = new File(toDir, "checkstyle-plugin.jar"); + File extFile = new File(toDir, "checkstyle-extensions.jar"); + assertThat(files).hasSize(2); + assertThat(files).containsOnly(pluginFile, extFile); + verify(server).download("/deploy/plugins/checkstyle/checkstyle-plugin.jar", pluginFile); + verify(server).download("/deploy/plugins/checkstyle/checkstyle-extensions.jar", extFile); + } +}