aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2012-09-05 10:26:04 +0000
committerFabrice Bellingard <bellingard@gmail.com>2012-09-05 10:26:04 +0000
commit80971d59f5c0ce60ae53715fa525dd5d5a81e9c8 (patch)
treef448190dada93b3ab30a526bf28ae9d2ae88062e /src/test
parentc7bcceb0933561fbf90ccc39225e24b47822c5d4 (diff)
downloadsonar-scanner-cli-80971d59f5c0ce60ae53715fa525dd5d5a81e9c8.tar.gz
sonar-scanner-cli-80971d59f5c0ce60ae53715fa525dd5d5a81e9c8.zip
SONARPLUGINS-2217 Move Sonar Batch Bootstrapper classes from Sonar to Sonar Runner
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/sonar/runner/LauncherTest.java19
-rw-r--r--src/test/java/org/sonar/runner/RunnerTest.java21
-rw-r--r--src/test/java/org/sonar/runner/bootstrapper/BootstrapClassLoaderTest.java61
-rw-r--r--src/test/java/org/sonar/runner/bootstrapper/BootstrapperTest.java65
-rw-r--r--src/test/java/org/sonar/runner/bootstrapper/BootstrapperVersionTest.java36
5 files changed, 183 insertions, 19 deletions
diff --git a/src/test/java/org/sonar/runner/LauncherTest.java b/src/test/java/org/sonar/runner/LauncherTest.java
index 0cec5f5..ea78d82 100644
--- a/src/test/java/org/sonar/runner/LauncherTest.java
+++ b/src/test/java/org/sonar/runner/LauncherTest.java
@@ -23,6 +23,8 @@ import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
import org.junit.Test;
+import java.util.Properties;
+
import static org.fest.assertions.Assertions.assertThat;
public class LauncherTest {
@@ -53,4 +55,21 @@ public class LauncherTest {
assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("WARN");
}
+ @Test
+ public void shouldDetermineVerboseMode() {
+ Properties properties = new Properties();
+ Launcher launcher = new Launcher(properties);
+ assertThat(launcher.isDebug()).isFalse();
+ properties.setProperty(Runner.PROPERTY_VERBOSE, "true");
+ assertThat(launcher.isDebug()).isTrue();
+ }
+
+ @Test
+ public void shouldSupportDeprecatedDebugProperty() {
+ Properties properties = new Properties();
+ Launcher launcher = new Launcher(properties);
+ properties.setProperty(Runner.PROPERTY_OLD_DEBUG_MODE, "true");
+ assertThat(launcher.isDebug()).isTrue();
+ }
+
}
diff --git a/src/test/java/org/sonar/runner/RunnerTest.java b/src/test/java/org/sonar/runner/RunnerTest.java
index 1099d1d..f1681ee 100644
--- a/src/test/java/org/sonar/runner/RunnerTest.java
+++ b/src/test/java/org/sonar/runner/RunnerTest.java
@@ -22,8 +22,8 @@ package org.sonar.runner;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.batch.bootstrapper.BootstrapException;
-import org.sonar.batch.bootstrapper.Bootstrapper;
+import org.sonar.runner.bootstrapper.BootstrapException;
+import org.sonar.runner.bootstrapper.Bootstrapper;
import java.io.File;
import java.util.Properties;
@@ -96,23 +96,6 @@ public class RunnerTest {
}
@Test
- public void shouldDetermineVerboseMode() {
- Properties properties = new Properties();
- Runner runner = Runner.create(properties);
- assertThat(runner.isDebug()).isFalse();
- properties.setProperty(Runner.PROPERTY_VERBOSE, "true");
- assertThat(runner.isDebug()).isTrue();
- }
-
- @Test
- public void shouldSupportDeprecatedDebugProperty() {
- Properties properties = new Properties();
- Runner runner = Runner.create(properties);
- properties.setProperty(Runner.DEBUG_MODE, "true");
- assertThat(runner.isDebug()).isTrue();
- }
-
- @Test
public void shouldInitDirs() throws Exception {
Properties props = new Properties();
File home = new File(getClass().getResource("/org/sonar/runner/RunnerTest/shouldInitDirs/").toURI());
diff --git a/src/test/java/org/sonar/runner/bootstrapper/BootstrapClassLoaderTest.java b/src/test/java/org/sonar/runner/bootstrapper/BootstrapClassLoaderTest.java
new file mode 100644
index 0000000..87496ba
--- /dev/null
+++ b/src/test/java/org/sonar/runner/bootstrapper/BootstrapClassLoaderTest.java
@@ -0,0 +1,61 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.runner.bootstrapper;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.runner.bootstrapper.BootstrapClassLoader;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class BootstrapClassLoaderTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void shouldRestrictLoadingFromParent() throws Exception {
+ BootstrapClassLoader classLoader = new BootstrapClassLoader(getClass().getClassLoader(), "org.sonar.ant");
+ assertThat(classLoader.canLoadFromParent("org.sonar.ant.Launcher")).isTrue();
+ assertThat(classLoader.canLoadFromParent("org.objectweb.asm.ClassVisitor")).isFalse();
+ }
+
+ @Test
+ public void use_isolated_system_classloader_when_parent_is_excluded() throws ClassNotFoundException {
+ thrown.expect(ClassNotFoundException.class);
+ thrown.expectMessage("org.junit.Test");
+ ClassLoader parent = getClass().getClassLoader();
+ BootstrapClassLoader classLoader = new BootstrapClassLoader(parent);
+
+ // JUnit is available in the parent classloader (classpath used to execute this test) but not in the core JVM
+ assertThat(classLoader.loadClass("java.lang.String", false)).isNotNull();
+ classLoader.loadClass("org.junit.Test", false);
+ }
+
+ @Test
+ public void find_in_parent_when_matches_unmasked_packages() throws ClassNotFoundException {
+ ClassLoader parent = getClass().getClassLoader();
+ BootstrapClassLoader classLoader = new BootstrapClassLoader(parent, "org.junit");
+
+ // JUnit is available in the parent classloader (classpath used to execute this test) but not in the core JVM
+ assertThat(classLoader.loadClass("org.junit.Test", false)).isNotNull();
+ }
+}
diff --git a/src/test/java/org/sonar/runner/bootstrapper/BootstrapperTest.java b/src/test/java/org/sonar/runner/bootstrapper/BootstrapperTest.java
new file mode 100644
index 0000000..0741701
--- /dev/null
+++ b/src/test/java/org/sonar/runner/bootstrapper/BootstrapperTest.java
@@ -0,0 +1,65 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.runner.bootstrapper;
+
+import org.junit.Test;
+import org.sonar.runner.bootstrapper.Bootstrapper;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class BootstrapperTest {
+
+ @Test
+ public void shouldRemoveLastUrlSlash() {
+ Bootstrapper bootstrapper = new Bootstrapper("", "http://test/", new File("target"));
+ assertThat(bootstrapper.getServerUrl()).isEqualTo("http://test");
+ }
+
+ @Test(expected = Exception.class)
+ public void shouldFailIfCanNotConnectServer() {
+ Bootstrapper bootstrapper = new Bootstrapper("", "http://unknown.foo", new File("target"));
+ bootstrapper.getServerVersion();
+ }
+
+ @Test
+ public void shouldReturnUserAgent() {
+ Bootstrapper bootstrapper = new Bootstrapper("test/0.1", "http://unknown.foo", new File("target"));
+ String userAgent = bootstrapper.getUserAgent();
+
+ assertThat(userAgent.length()).isGreaterThan(0);
+ assertThat(userAgent).startsWith("sonar-bootstrapper/");
+ assertThat(userAgent).endsWith(" test/0.1");
+ }
+
+ @Test
+ public void shouldReturnValidVersion() {
+ Bootstrapper bootstrapper = new Bootstrapper("", "http://test", new File("target")) {
+ @Override
+ String remoteContent(String path) throws IOException {
+ return "2.6";
+ }
+ };
+ assertThat(bootstrapper.getServerVersion()).isEqualTo("2.6");
+ }
+
+}
diff --git a/src/test/java/org/sonar/runner/bootstrapper/BootstrapperVersionTest.java b/src/test/java/org/sonar/runner/bootstrapper/BootstrapperVersionTest.java
new file mode 100644
index 0000000..c42fd18
--- /dev/null
+++ b/src/test/java/org/sonar/runner/bootstrapper/BootstrapperVersionTest.java
@@ -0,0 +1,36 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.runner.bootstrapper;
+
+import org.junit.Test;
+import org.sonar.runner.bootstrapper.BootstrapperVersion;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class BootstrapperVersionTest {
+
+ @Test
+ public void shouldLoadVersion() {
+ String version = BootstrapperVersion.getVersion();
+ assertThat(version).contains(".");
+ assertThat(version).doesNotContain("$");
+ }
+
+}