aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/test
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-08-11 23:48:48 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-08-11 23:48:48 +0200
commit9cbf7d1d02aaf60f6e36ff259305d4474aa68230 (patch)
tree9fc9f24de417e086d5fbb2f411dd005babb5c866 /sonar-server/src/test
parent3ef437426b9886f519477a288333ba77342d964c (diff)
downloadsonarqube-9cbf7d1d02aaf60f6e36ff259305d4474aa68230.tar.gz
sonarqube-9cbf7d1d02aaf60f6e36ff259305d4474aa68230.zip
SONAR-2692 API: allow plugins to auto-disable on server startup
Diffstat (limited to 'sonar-server/src/test')
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java (renamed from sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java)65
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/GeneratePluginIndexTest.java89
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/plugins/DefaultServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar (renamed from sonar-server/src/test/resources/org/sonar/server/plugins/ServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar)bin7456 -> 7456 bytes
3 files changed, 148 insertions, 6 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java
index dcc85e5b519..7624e422b07 100644
--- a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java
@@ -32,16 +32,18 @@ import java.io.File;
import java.util.Arrays;
import java.util.List;
+import static junit.framework.Assert.assertFalse;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class ServerPluginRepositoryTest {
+public class DefaultServerPluginRepositoryTest {
- private ServerPluginRepository repository;
+ private DefaultServerPluginRepository repository;
@After
public void stop() {
@@ -53,14 +55,14 @@ public class ServerPluginRepositoryTest {
@Test
public void testStart() {
PluginDeployer deployer = mock(PluginDeployer.class);
- File pluginFile = FileUtils.toFile(getClass().getResource("/org/sonar/server/plugins/ServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar"));
+ File pluginFile = FileUtils.toFile(getClass().getResource("/org/sonar/server/plugins/DefaultServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar"));
PluginMetadata plugin = DefaultPluginMetadata.create(pluginFile)
.setKey("artifactsize")
.setMainClass("org.sonar.plugins.artifactsize.ArtifactSizePlugin")
.addDeployedFile(pluginFile);
when(deployer.getMetadata()).thenReturn(Arrays.asList(plugin));
- repository = new ServerPluginRepository(deployer);
+ repository = new DefaultServerPluginRepository(deployer);
repository.start();
assertThat(repository.getPlugins().size(), Is.is(1));
@@ -73,7 +75,7 @@ public class ServerPluginRepositoryTest {
@Test
public void shouldRegisterServerExtensions() {
- ServerPluginRepository repository = new ServerPluginRepository(mock(PluginDeployer.class));
+ DefaultServerPluginRepository repository = new DefaultServerPluginRepository(mock(PluginDeployer.class));
TransientPicoContainer container = new TransientPicoContainer();
repository.registerExtensions(container, Arrays.<Plugin>asList(new FakePlugin(Arrays.<Class>asList(FakeBatchExtension.class, FakeServerExtension.class))));
@@ -85,7 +87,7 @@ public class ServerPluginRepositoryTest {
@Test
public void shouldInvokeServerExtensionProviderss() {
- ServerPluginRepository repository = new ServerPluginRepository(mock(PluginDeployer.class));
+ DefaultServerPluginRepository repository = new DefaultServerPluginRepository(mock(PluginDeployer.class));
TransientPicoContainer container = new TransientPicoContainer();
repository.registerExtensions(container, Arrays.<Plugin>asList(new FakePlugin(Arrays.<Class>asList(FakeExtensionProvider.class))));
@@ -95,6 +97,57 @@ public class ServerPluginRepositoryTest {
assertThat(container.getComponents(FakeBatchExtension.class).size(), is(0));
}
+ @Test
+ public void shouldDisablePlugin() {
+ DefaultServerPluginRepository repository = new DefaultServerPluginRepository(mock(PluginDeployer.class));
+ repository.disable("checkstyle");
+
+ assertTrue(repository.isDisabled("checkstyle"));
+ assertFalse(repository.isDisabled("sqale"));
+ }
+
+ @Test
+ public void shouldDisableDependentPlugins() {
+ PluginDeployer deployer = mock(PluginDeployer.class);
+ List<PluginMetadata> metadata = Arrays.asList(
+ newMetadata("checkstyle", null),
+ newMetadata("checkstyle-extensions", "checkstyle"),
+ newMetadata("sqale", null)
+ );
+ when(deployer.getMetadata()).thenReturn(metadata);
+ DefaultServerPluginRepository repository = new DefaultServerPluginRepository(deployer);
+
+ repository.disable("checkstyle");
+
+ assertTrue(repository.isDisabled("checkstyle"));
+ assertTrue(repository.isDisabled("checkstyle-extensions"));
+ assertFalse(repository.isDisabled("sqale"));
+ }
+
+ @Test
+ public void shouldNotDisableBasePlugin() {
+ PluginDeployer deployer = mock(PluginDeployer.class);
+ List<PluginMetadata> metadata = Arrays.asList(
+ newMetadata("checkstyle", null),
+ newMetadata("checkstyle-extensions", "checkstyle"),
+ newMetadata("sqale", null)
+ );
+ when(deployer.getMetadata()).thenReturn(metadata);
+ DefaultServerPluginRepository repository = new DefaultServerPluginRepository(deployer);
+
+ repository.disable("checkstyle-extensions");
+
+ assertFalse(repository.isDisabled("checkstyle"));
+ assertTrue(repository.isDisabled("checkstyle-extensions"));
+ }
+
+ private PluginMetadata newMetadata(String pluginKey, String basePluginKey) {
+ PluginMetadata plugin = mock(PluginMetadata.class);
+ when(plugin.getKey()).thenReturn(pluginKey);
+ when(plugin.getBasePlugin()).thenReturn(basePluginKey);
+ return plugin;
+ }
+
public static class FakePlugin extends SonarPlugin {
private List<Class> extensions;
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/GeneratePluginIndexTest.java b/sonar-server/src/test/java/org/sonar/server/startup/GeneratePluginIndexTest.java
new file mode 100644
index 00000000000..38c26893317
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/startup/GeneratePluginIndexTest.java
@@ -0,0 +1,89 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 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.server.startup;
+
+import org.apache.commons.io.FileUtils;
+import org.hamcrest.core.Is;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.core.plugins.DefaultPluginMetadata;
+import org.sonar.server.platform.DefaultServerFileSystem;
+import org.sonar.server.plugins.DefaultServerPluginRepository;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.containsString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class GeneratePluginIndexTest {
+
+ private DefaultServerFileSystem fileSystem;
+ private File index;
+
+ @Before
+ public void createIndexFile() {
+ fileSystem = mock(DefaultServerFileSystem.class);
+ index = new File("target/test-tmp/GeneratePluginIndexTest/plugins.txt");
+ when(fileSystem.getPluginIndex()).thenReturn(index);
+ }
+
+ @Test
+ public void shouldWriteIndex() throws IOException {
+ DefaultServerPluginRepository repository = mock(DefaultServerPluginRepository.class);
+ PluginMetadata sqale = newMetadata("sqale");
+ PluginMetadata checkstyle = newMetadata("checkstyle");
+ when(repository.getMetadata()).thenReturn(Arrays.asList(sqale, checkstyle));
+
+ new GeneratePluginIndex(fileSystem, repository).start();
+
+ List<String> lines = FileUtils.readLines(index);
+ assertThat(lines.size(), Is.is(2));
+ assertThat(lines.get(0), containsString("sqale"));
+ assertThat(lines.get(1), containsString("checkstyle"));
+ }
+
+ @Test
+ public void shouldSkipDisabledPlugin() throws IOException {
+ DefaultServerPluginRepository repository = mock(DefaultServerPluginRepository.class);
+ PluginMetadata sqale = newMetadata("sqale");
+ PluginMetadata checkstyle = newMetadata("checkstyle");
+ when(repository.getMetadata()).thenReturn(Arrays.asList(sqale, checkstyle));
+ when(repository.isDisabled("checkstyle")).thenReturn(true);
+
+ new GeneratePluginIndex(fileSystem, repository).start();
+
+ List<String> lines = FileUtils.readLines(index);
+ assertThat(lines.size(), Is.is(1));
+ assertThat(lines.get(0), containsString("sqale"));
+ }
+
+ private PluginMetadata newMetadata(String pluginKey) {
+ PluginMetadata plugin = mock(DefaultPluginMetadata.class);
+ when(plugin.getKey()).thenReturn(pluginKey);
+ when(plugin.getFile()).thenReturn(new File(pluginKey + ".jar"));
+ return plugin;
+ }
+}
diff --git a/sonar-server/src/test/resources/org/sonar/server/plugins/ServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar b/sonar-server/src/test/resources/org/sonar/server/plugins/DefaultServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar
index 19533234582..19533234582 100644
--- a/sonar-server/src/test/resources/org/sonar/server/plugins/ServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar
+++ b/sonar-server/src/test/resources/org/sonar/server/plugins/DefaultServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar
Binary files differ