aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-10-27 00:29:44 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-10-27 00:29:44 +0200
commitf7a628ba80b14f5ae3a61853b7a04eca7178755f (patch)
treed79388c497d2cf323f42bce41e2b9e709e02a510 /sonar-batch/src/test
parente123a94cb32ab7b73fdaffb15feea9356ddcf94f (diff)
downloadsonarqube-f7a628ba80b14f5ae3a61853b7a04eca7178755f.tar.gz
sonarqube-f7a628ba80b14f5ae3a61853b7a04eca7178755f.zip
SONAR-3895 remove unused code and fix quality flaws
Diffstat (limited to 'sonar-batch/src/test')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchModuleTest.java50
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapExtensionExecutorTest.java55
3 files changed, 107 insertions, 6 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchModuleTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchModuleTest.java
new file mode 100644
index 00000000000..9f297a762a2
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchModuleTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.Test;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.platform.ComponentContainer;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class BatchModuleTest {
+ @Test
+ public void should_register_batch_extensions() {
+ final ExtensionInstaller extensionInstaller = mock(ExtensionInstaller.class);
+ Module bootstrapModule = new Module() {
+ @Override
+ protected void configure() {
+ // used to install project extensions
+ container.addSingleton(extensionInstaller);
+ }
+ };
+ bootstrapModule.init();
+ BatchModule module = new BatchModule();
+ bootstrapModule.installChild(module);
+
+ verify(extensionInstaller).install(any(ComponentContainer.class), eq(InstantiationStrategy.BATCH));
+ assertThat(module.container.getComponentByType(MetricProvider.class)).isNotNull();
+ }
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
index 080e48c767c..c1a56e96f06 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
@@ -62,7 +62,6 @@ public class BatchPluginRepositoryTest {
repository.doStart(Arrays.asList(checkstyle));
- assertThat(repository.getPlugins().size(), Matchers.is(1));
assertThat(repository.getPlugin("checkstyle"), not(nullValue()));
assertThat(repository.getMetadata().size(), Matchers.is(1));
assertThat(repository.getMetadata("checkstyle").getName(), Matchers.is("Checkstyle"));
@@ -82,7 +81,6 @@ public class BatchPluginRepositoryTest {
repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
- assertThat(repository.getPlugins().size(), Matchers.is(2));
assertThat(repository.getPlugin("checkstyle"), not(nullValue()));
assertThat(repository.getPlugin("checkstyleextensions"), not(nullValue()));
assertThat(repository.getMetadata().size(), Matchers.is(2));
@@ -93,7 +91,7 @@ public class BatchPluginRepositoryTest {
@Test
public void shouldLoadPluginDeprecatedExtensions() throws IOException {
RemotePlugin checkstyle = new RemotePlugin("checkstyle", true)
- .addFilename("checkstyle-ext.xml");
+ .addFilename("checkstyle-ext.xml");
PluginDownloader downloader = mock(PluginDownloader.class);
when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar", "checkstyle-ext.xml"));
@@ -102,12 +100,11 @@ public class BatchPluginRepositoryTest {
repository.doStart(Arrays.asList(checkstyle));
- assertThat(repository.getPlugins().size(), Matchers.is(1));
assertThat(repository.getPlugin("checkstyle"), not(nullValue()));
assertThat(repository.getMetadata().size(), Matchers.is(1));
assertThat(repository.getMetadata("checkstyle").getName(), Matchers.is("Checkstyle"));
assertThat(repository.getMetadata("checkstyle").getDeployedFiles().size(), Matchers.is(5)); // plugin + 3 dependencies + 1 deprecated
- // extension
+ // extension
}
@Test
@@ -125,7 +122,6 @@ public class BatchPluginRepositoryTest {
repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
- assertThat(repository.getPlugins().size(), Matchers.is(0));
assertThat(repository.getMetadata().size(), Matchers.is(0));
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapExtensionExecutorTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapExtensionExecutorTest.java
new file mode 100644
index 00000000000..6ee1a684040
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapExtensionExecutorTest.java
@@ -0,0 +1,55 @@
+package org.sonar.batch.bootstrap;
+
+import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.picocontainer.Startable;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.Settings;
+import org.sonar.api.platform.ComponentContainer;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class BootstrapExtensionExecutorTest {
+ private ProjectReactor reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo"));
+
+ @Test
+ public void start() {
+ ComponentContainer container = new ComponentContainer();
+ // dependencies required for ProjectExclusions
+ container.addSingleton(reactor);
+ container.addSingleton(new Settings());
+
+ // declare a bootstrap component
+ final Startable bootstrapComponent = mock(Startable.class);
+ ExtensionInstaller installer = mock(ExtensionInstaller.class);
+ doAnswer(new Answer() {
+ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
+ ComponentContainer childContainer = (ComponentContainer) invocationOnMock.getArguments()[0];
+ childContainer.addSingleton(bootstrapComponent);
+ return null;
+ }
+ }).when(installer).install(any(ComponentContainer.class), eq(InstantiationStrategy.BOOTSTRAP));
+
+ BootstrapExtensionExecutor executor = new BootstrapExtensionExecutor(container, installer);
+ executor.start();
+
+ // should install bootstrap components into a ephemeral container
+ verify(installer).install(any(ComponentContainer.class), eq(InstantiationStrategy.BOOTSTRAP));
+ verify(bootstrapComponent).start();
+ verify(bootstrapComponent).stop();
+
+ // the ephemeral container is destroyed
+ assertThat(container.getComponentByType(ProjectExclusions.class)).isNull();
+ assertThat(container.getChild()).isNull();
+ }
+
+
+}