aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/test
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-06-10 00:15:37 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-06-10 00:15:37 +0200
commitd574f6dd70fefa9b2e9818c71ae58a51e934697c (patch)
tree76a7df2dc3c794c02fff45e9a517ccf560cc2351 /sonar-server/src/test
parent39bca3376660b2ad6edbd4ec9fabf527a16ffe78 (diff)
downloadsonarqube-d574f6dd70fefa9b2e9818c71ae58a51e934697c.tar.gz
sonarqube-d574f6dd70fefa9b2e9818c71ae58a51e934697c.zip
SONAR-2507 Batch must load plugins without connecting to database
Diffstat (limited to 'sonar-server/src/test')
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/PluginClassLoadersTest.java66
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java145
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/PluginMetadataTest.java54
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java34
4 files changed, 66 insertions, 233 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/PluginClassLoadersTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/PluginClassLoadersTest.java
deleted file mode 100644
index 42124156673..00000000000
--- a/sonar-server/src/test/java/org/sonar/server/plugins/PluginClassLoadersTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.plugins;
-
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
-
-import java.io.File;
-import java.io.IOException;
-
-import com.google.common.collect.Lists;
-import org.junit.Test;
-import org.sonar.test.TestUtils;
-
-public class PluginClassLoadersTest {
-
- @Test
- public void createClassloaderFromJar() throws IOException {
- // foo-plugin.jar is a simple plugin with correct metadata.
- // It just includes the file foo.txt
- File jar = getFile("foo-plugin.jar");
- PluginMetadata metadata = PluginMetadata.createFromJar(jar, false);
- metadata.addDeployedFile(jar);
-
- assertNull(getClass().getClassLoader().getResource("foo.txt"));
-
- PluginClassLoaders classloaders = new PluginClassLoaders();
- ClassLoader classloader = classloaders.create(metadata.getKey(), metadata.getDeployedFiles(), metadata.isUseChildFirstClassLoader());
-
- assertNotNull(classloader);
- assertNotNull(classloader.getResource("foo.txt"));
- }
-
- @Test
- public void shouldGetClassByName() throws IOException {
- File jar = getFile("sonar-build-breaker-plugin-0.1.jar");
-
- PluginClassLoaders classloaders = new PluginClassLoaders();
- classloaders.create("build-breaker", Lists.<File> newArrayList(jar), false);
-
- assertNotNull(classloaders.getClass("build-breaker", "org.sonar.plugins.buildbreaker.BuildBreakerPlugin"));
- assertNull(classloaders.getClass("build-breaker", "org.sonar.plugins.buildbreaker.Unknown"));
- assertNull(classloaders.getClass("unknown", "org.sonar.plugins.buildbreaker.BuildBreakerPlugin"));
- }
-
- private File getFile(String filename) {
- return TestUtils.getResource(PluginClassLoadersTest.class, filename);
- }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java
index 37eafa9e03f..ed969ac7738 100644
--- a/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java
@@ -1,54 +1,45 @@
/*
- * 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
- */
+* 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.plugins;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.List;
-
-import org.apache.commons.io.FileUtils;
+import org.hamcrest.core.Is;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
-import org.sonar.api.platform.Server;
-import org.sonar.core.plugin.JpaPlugin;
-import org.sonar.core.plugin.JpaPluginDao;
-import org.sonar.core.plugin.JpaPluginFile;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.core.plugins.PluginFileExtractor;
import org.sonar.server.platform.DefaultServerFileSystem;
-import org.sonar.server.platform.ServerImpl;
import org.sonar.server.platform.ServerStartException;
import org.sonar.test.TestUtils;
-public class PluginDeployerTest extends AbstractDbUnitTestCase {
+import java.io.File;
+import java.io.IOException;
+import java.text.ParseException;
- private Server server;
- private JpaPluginDao dao;
- private PluginClassLoaders classloaders;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class PluginDeployerTest {
+
+ private PluginFileExtractor extractor;
private DefaultServerFileSystem fileSystem;
private File homeDir;
private File deployDir;
@@ -59,117 +50,81 @@ public class PluginDeployerTest extends AbstractDbUnitTestCase {
@Before
public void start() throws ParseException {
- server = new ServerImpl("1", "2.2", new SimpleDateFormat("yyyy-MM-dd").parse("2010-05-18"));
- dao = new JpaPluginDao(getSessionFactory());
- classloaders = new PluginClassLoaders();
homeDir = TestUtils.getResource(PluginDeployerTest.class, name.getMethodName());
deployDir = TestUtils.getTestTempDir(PluginDeployerTest.class, name.getMethodName() + "/deploy");
fileSystem = new DefaultServerFileSystem(null, homeDir, deployDir);
- deployer = new PluginDeployer(server, fileSystem, dao, classloaders);
+ extractor = new PluginFileExtractor();
+ deployer = new PluginDeployer(fileSystem, extractor);
}
@Test
public void deployPlugin() throws IOException {
- setupData("shared");
deployer.start();
- // check that the plugin is registered in database
- List<JpaPlugin> plugins = dao.getPlugins();
- assertThat(plugins.size(), is(1)); // no more checkstyle
- JpaPlugin plugin = plugins.get(0);
+ // check that the plugin is registered
+ assertThat(deployer.getMetadata().size(), Is.is(1)); // no more checkstyle
+
+ PluginMetadata plugin = deployer.getMetadata("foo");
assertThat(plugin.getName(), is("Foo"));
- assertThat(plugin.getFiles().size(), is(1));
+ assertThat(plugin.getDeployedFiles().size(), is(1));
assertThat(plugin.isCore(), is(false));
assertThat(plugin.isUseChildFirstClassLoader(), is(false));
- JpaPluginFile pluginFile = plugin.getFiles().get(0);
- assertThat(pluginFile.getFilename(), is("foo-plugin.jar"));
- assertThat(pluginFile.getPath(), is("foo/foo-plugin.jar"));
-
+
// check that the file is deployed
File deployedJar = new File(deployDir, "plugins/foo/foo-plugin.jar");
assertThat(deployedJar.exists(), is(true));
assertThat(deployedJar.isFile(), is(true));
-
- // check that the plugin has its own classloader
- classloaders.completeCreation();
- ClassLoader classloader = classloaders.getClassLoader("foo");
- assertNotNull(classloader);
}
@Test
public void deployDeprecatedPlugin() throws IOException, ClassNotFoundException {
- setupData("shared");
deployer.start();
- // check that the plugin is registered in database
- List<JpaPlugin> plugins = dao.getPlugins();
- assertThat(plugins.size(), is(1)); // no more checkstyle
- JpaPlugin plugin = plugins.get(0);
- assertThat(plugin.getKey(), is("buildbreaker"));
- assertThat(plugin.getFiles().size(), is(1));
+ // check that the plugin is registered
+ assertThat(deployer.getMetadata().size(), Is.is(1)); // no more checkstyle
+
+ PluginMetadata plugin = deployer.getMetadata("buildbreaker");
assertThat(plugin.isCore(), is(false));
assertThat(plugin.isUseChildFirstClassLoader(), is(false));
- JpaPluginFile pluginFile = plugin.getFiles().get(0);
- assertThat(pluginFile.getFilename(), is("sonar-build-breaker-plugin-0.1.jar"));
- assertThat(pluginFile.getPath(), is("buildbreaker/sonar-build-breaker-plugin-0.1.jar"));
// check that the file is deployed
File deployedJar = new File(deployDir, "plugins/buildbreaker/sonar-build-breaker-plugin-0.1.jar");
assertThat(deployedJar.exists(), is(true));
assertThat(deployedJar.isFile(), is(true));
-
- // check that the plugin has its own classloader
- classloaders.completeCreation();
- ClassLoader classloader = classloaders.getClassLoader("buildbreaker");
- assertNotNull(classloader);
- assertNotNull(classloader.loadClass("org.sonar.plugins.buildbreaker.BuildBreakerPlugin"));
}
@Test
public void deployPluginExtensions() throws IOException {
- setupData("shared");
deployer.start();
- // check that the plugin is registered in database
- List<JpaPlugin> plugins = dao.getPlugins();
- assertThat(plugins.size(), is(1)); // no more checkstyle
- JpaPlugin plugin = plugins.get(0);
- assertThat(plugin.getFiles().size(), is(2));
- JpaPluginFile pluginFile = plugin.getFiles().get(1);
- assertThat(pluginFile.getFilename(), is("foo-extension.txt"));
- assertThat(pluginFile.getPath(), is("foo/foo-extension.txt"));
+ // check that the plugin is registered
+ assertThat(deployer.getMetadata().size(), Is.is(1)); // no more checkstyle
+
+ PluginMetadata plugin = deployer.getMetadata("foo");
+ assertThat(plugin.getDeployedFiles().size(), is(2));
+ File extFile = plugin.getDeployedFiles().get(1);
+ assertThat(extFile.getName(), is("foo-extension.txt"));
// check that the extension file is deployed
File deployedJar = new File(deployDir, "plugins/foo/foo-extension.txt");
assertThat(deployedJar.exists(), is(true));
assertThat(deployedJar.isFile(), is(true));
-
- // check that the extension is in the classloader
- classloaders.completeCreation();
- ClassLoader classloader = classloaders.getClassLoader("foo");
- File extensionFile = FileUtils.toFile(classloader.getResource("foo-extension.txt"));
- assertThat(extensionFile.exists(), is(true));
}
@Test
public void ignoreJarsWhichAreNotPlugins() throws IOException {
- setupData("shared");
deployer.start();
- // check that the plugin is registered in database
- List<JpaPlugin> plugins = dao.getPlugins();
- assertThat(plugins.size(), is(0));
+ assertThat(deployer.getMetadata().size(), Is.is(0));
}
@Test(expected = ServerStartException.class)
public void failIfTwoPluginsWithSameKey() throws IOException {
- setupData("shared");
deployer.start();
}
@Test(expected = ServerStartException.class)
public void failIfTwoDeprecatedPluginsWithSameKey() throws IOException {
- setupData("shared");
deployer.start();
}
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/PluginMetadataTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/PluginMetadataTest.java
deleted file mode 100644
index b3c4ff799d1..00000000000
--- a/sonar-server/src/test/java/org/sonar/server/plugins/PluginMetadataTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.plugins;
-
-import org.junit.Test;
-import org.sonar.test.TestUtils;
-
-import java.io.IOException;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
-public class PluginMetadataTest {
-
- @Test
- public void testCreateFromJar() throws IOException {
- PluginMetadata metadata = PluginMetadata.createFromJar(TestUtils.getResource(getClass(), "foo-plugin.jar"), false);
- assertThat(metadata.getKey(), is("foo"));
- assertThat(metadata.getFilename(), is("foo-plugin.jar"));
- assertThat(metadata.getMainClass(), is("foo.Main"));
- assertThat(metadata.getVersion(), is("2.2-SNAPSHOT"));
- assertThat(metadata.getOrganization(), is("SonarSource"));
- assertThat(metadata.isUseChildFirstClassLoader(), is(false));
- assertThat(metadata.getDependencyPaths().length, is(0));
- assertThat(metadata.isCore(), is(false));
- }
-
- @Test
- public void testOldPlugin() {
- PluginMetadata metadata = new PluginMetadata();
- metadata.setMainClass("foo.Main");
- assertThat(metadata.isOldManifest(), is(true));
-
- metadata.setKey("foo");
- assertThat(metadata.isOldManifest(), is(false));
- }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
index 0eb01ed9b0e..82af3fcc770 100644
--- a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
@@ -19,28 +19,26 @@
*/
package org.sonar.server.plugins;
-import org.junit.Test;
+import org.junit.Ignore;
import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
+@Ignore
public class ServerPluginRepositoryTest {
- @Test
- public void shouldRegisterServerExtensions() {
- ServerPluginRepository repository = new ServerPluginRepository();
-
- // check classes
- assertThat(repository.shouldRegisterExtension(null, "foo", FakeBatchExtension.class), is(false));
- assertThat(repository.shouldRegisterExtension(null, "foo", FakeServerExtension.class), is(true));
- assertThat(repository.shouldRegisterExtension(null, "foo", String.class), is(false));
-
- // check objects
- assertThat(repository.shouldRegisterExtension(null, "foo", new FakeBatchExtension()), is(false));
- assertThat(repository.shouldRegisterExtension(null, "foo", new FakeServerExtension()), is(true));
- assertThat(repository.shouldRegisterExtension(null, "foo", "foo"), is(false));
- }
+// @Test
+// public void shouldRegisterServerExtensions() {
+// ServerPluginRepository repository = new ServerPluginRepository();
+//
+// // check classes
+// assertThat(repository.shouldRegisterExtension(null, "foo", FakeBatchExtension.class), is(false));
+// assertThat(repository.shouldRegisterExtension(null, "foo", FakeServerExtension.class), is(true));
+// assertThat(repository.shouldRegisterExtension(null, "foo", String.class), is(false));
+//
+// // check objects
+// assertThat(repository.shouldRegisterExtension(null, "foo", new FakeBatchExtension()), is(false));
+// assertThat(repository.shouldRegisterExtension(null, "foo", new FakeServerExtension()), is(true));
+// assertThat(repository.shouldRegisterExtension(null, "foo", "foo"), is(false));
+// }
public static class FakeBatchExtension implements BatchExtension {