aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-10-27 00:51:27 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-10-27 00:51:27 +0200
commitb37cc878ad2e5952807aef46e966f7d790f52a2d (patch)
treec03ce76e28795e52053ee7f9c74b3908b7e87494 /sonar-batch
parentf7a628ba80b14f5ae3a61853b7a04eca7178755f (diff)
downloadsonarqube-b37cc878ad2e5952807aef46e966f7d790f52a2d.tar.gz
sonarqube-b37cc878ad2e5952807aef46e966f7d790f52a2d.zip
Add PluginDownloaderTest
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/PluginDownloaderTest.java75
1 files changed, 75 insertions, 0 deletions
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<RemotePlugin> 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<File> 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);
+ }
+}