aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/test/java
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-16 19:05:09 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-16 19:05:09 +0200
commit8ea5c540ef2c1c9e22e06b717758a0d2dcb647a5 (patch)
tree12623b8fcbf7404931ecb8cabc42806e9f328384 /sonar-server/src/test/java
parentb86b183dfd764d432e353ce19a243ca321dd4f63 (diff)
downloadsonarqube-8ea5c540ef2c1c9e22e06b717758a0d2dcb647a5.tar.gz
sonarqube-8ea5c540ef2c1c9e22e06b717758a0d2dcb647a5.zip
Replacement injection of ServletContext by Properties in Platform
Diffstat (limited to 'sonar-server/src/test/java')
-rw-r--r--sonar-server/src/test/java/org/sonar/server/platform/PersistentSettingsTest.java6
-rw-r--r--sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java59
-rw-r--r--sonar-server/src/test/java/org/sonar/server/platform/ServerLifecycleNotifierTest.java18
-rw-r--r--sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java46
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java5
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/GenerateBootstrapIndexTest.java35
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/GwtPublisherTest.java1
-rw-r--r--sonar-server/src/test/java/org/sonar/server/text/MacroInterpreterTest.java9
8 files changed, 103 insertions, 76 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/platform/PersistentSettingsTest.java b/sonar-server/src/test/java/org/sonar/server/platform/PersistentSettingsTest.java
index cc6f008d474..3612c104526 100644
--- a/sonar-server/src/test/java/org/sonar/server/platform/PersistentSettingsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/platform/PersistentSettingsTest.java
@@ -28,9 +28,9 @@ import org.sonar.api.config.PropertyDefinitions;
import org.sonar.core.properties.PropertiesDao;
import org.sonar.core.properties.PropertyDto;
-import java.io.File;
import java.net.URISyntaxException;
import java.util.Arrays;
+import java.util.Properties;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.argThat;
@@ -44,11 +44,11 @@ public class PersistentSettingsTest {
@Before
public void init() throws URISyntaxException {
dao = mock(PropertiesDao.class);
+
settings = new ServerSettings(
new PropertyDefinitions(),
new PropertiesConfiguration(),
- new File("."),
- new File(PersistentSettingsTest.class.getResource("/org/sonar/server/platform/PersistentSettingsTest/").toURI()));
+ new Properties());
}
@Test
diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java
index 2101db16a78..44954c85fb6 100644
--- a/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java
@@ -20,22 +20,41 @@
package org.sonar.server.platform;
import org.hamcrest.core.Is;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
+import java.io.File;
+
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.assertThat;
public class ServerImplTest {
+
@Rule
public ExpectedException exception = ExpectedException.none();
+ @Rule
+ public TemporaryFolder sonarHome = new TemporaryFolder();
+
+ Settings settings;
+
+ ServerImpl server;
+
+ @Before
+ public void setUp() throws Exception {
+ settings = new Settings().setProperty(CoreProperties.SONAR_HOME, sonarHome.getRoot().getAbsolutePath());
+ new File(sonarHome.getRoot(), "web/deploy").mkdirs();
+
+ server = new ServerImpl(settings, "/org/sonar/server/platform/ServerImplTest/build.properties", "/org/sonar/server/platform/ServerImplTest/version.txt");
+ }
+
@Test
- public void alwaysReturnTheSameValues() {
- ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/pom-with-version.properties");
+ public void always_return_the_same_values() {
server.start();
assertThat(server.getId()).isNotNull();
@@ -49,52 +68,48 @@ public class ServerImplTest {
}
@Test
- public void getVersionFromFile() {
- ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/pom-with-version.properties");
+ public void read_version_from_file() {
server.start();
assertThat(server.getVersion()).isEqualTo("1.0");
}
@Test
- public void getImplementationBuildFromManifest() {
- ServerImpl server = new ServerImpl(new Settings(),
- "/org/sonar/server/platform/ServerImplTest/build.properties",
- "/org/sonar/server/platform/ServerImplTest/pom-with-version.properties");
+ public void read_implementation_build_from_manifest() {
server.start();
assertThat(server.getImplementationBuild()).isEqualTo("0b9545a8b74aca473cb776275be4dc93a327c363");
}
@Test
- public void testFileWithNoVersion() {
+ public void read_file_with_no_version() {
exception.expect(IllegalStateException.class);
exception.expectMessage("Unknown SonarQube version");
- ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/pom-without-version.properties");
+ ServerImpl server = new ServerImpl(settings, "", "/org/sonar/server/platform/ServerImplTest/empty-version.txt");
server.start();
}
@Test
- public void testFileWithEmptyVersionParameter() {
+ public void read_file_with_empty_version() {
exception.expect(IllegalStateException.class);
exception.expectMessage("Unknown SonarQube version");
- ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/pom-with-empty-version.properties");
+ ServerImpl server = new ServerImpl(settings, "", "/org/sonar/server/platform/ServerImplTest/empty-version.txt");
server.start();
}
@Test
- public void shouldFailIfFileNotFound() {
+ public void fail_if_version_file_not_found() {
exception.expect(IllegalStateException.class);
exception.expectMessage("Unknown SonarQube version");
- ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/unknown-file.properties");
+ ServerImpl server = new ServerImpl(settings, "", "/org/sonar/server/platform/ServerImplTest/unknown-file.properties");
server.start();
}
@Test
- public void shouldLoadServerIdFromDatabase() {
+ public void load_server_id_from_database() {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PERMANENT_SERVER_ID, "abcde");
@@ -102,4 +117,18 @@ public class ServerImplTest {
assertThat(server.getPermanentServerId(), Is.is("abcde"));
}
+
+ @Test
+ public void use_default_context_path() {
+ server.start();
+ assertThat(server.getContextPath()).isEqualTo("/");
+ }
+
+ @Test
+ public void get_context_path_from_settings() {
+ settings.setProperty("sonar.web.context", "/my_path");
+ server.start();
+ assertThat(server.getContextPath()).isEqualTo("/my_path");
+ }
+
}
diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ServerLifecycleNotifierTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ServerLifecycleNotifierTest.java
index 4acb5baf2ce..8907b3e6d5d 100644
--- a/sonar-server/src/test/java/org/sonar/server/platform/ServerLifecycleNotifierTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/platform/ServerLifecycleNotifierTest.java
@@ -21,10 +21,11 @@ package org.sonar.server.platform;
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.platform.Server;
import org.sonar.api.platform.ServerStartHandler;
import org.sonar.api.platform.ServerStopHandler;
-import org.sonar.api.platform.Server;
+import java.io.File;
import java.util.Date;
import static org.mockito.Mockito.*;
@@ -100,6 +101,21 @@ class FakeServer extends Server {
}
@Override
+ public File getRootDir() {
+ return null;
+ }
+
+ @Override
+ public File getDeployDir() {
+ return null;
+ }
+
+ @Override
+ public String getContextPath() {
+ return null;
+ }
+
+ @Override
public String getURL() {
return null;
}
diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java
index 4b7ef9b0edf..af0cc558e8f 100644
--- a/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java
@@ -21,44 +21,37 @@ package org.sonar.server.platform;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.configuration.BaseConfiguration;
+import org.junit.Before;
import org.junit.Test;
import org.sonar.api.config.PropertyDefinitions;
-import java.io.File;
-import java.net.URISyntaxException;
import java.util.Map;
+import java.util.Properties;
import static org.fest.assertions.Assertions.assertThat;
public class ServerSettingsTest {
- private static File home = getHome();
+ Properties properties;
- @Test
- public void load_properties_file() {
- ServerSettings settings = new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), new File("."), home);
+ ServerSettings settings;
- assertThat(settings.getString("hello")).isEqualTo("world");
+ @Before
+ public void before() throws Exception {
+ properties = new Properties();
+ properties.put("hello", "world");
+ properties.put("in_file", "true");
+ properties.put("ServerSettingsTestEnv", "in_file");
+ settings = new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), properties);
}
@Test
- public void systemPropertiesShouldOverridePropertiesFile() {
- System.setProperty("ServerSettingsTestEnv", "in_env");
- ServerSettings settings = new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), new File("."), home);
-
- assertThat(settings.getString("ServerSettingsTestEnv")).isEqualTo("in_env");
- }
-
- @Test(expected = IllegalStateException.class)
- public void fail_if_properties_file_is_not_found() {
- File sonarHome = new File("unknown/path");
- new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), new File("."), sonarHome);
+ public void load_properties_file() {
+ assertThat(settings.getString("hello")).isEqualTo("world");
}
@Test
- public void activateDatabaseSettings() {
- ServerSettings settings = new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), new File("."), home);
-
+ public void activate_database_settings() {
Map<String, String> databaseProperties = ImmutableMap.of("in_db", "true");
settings.activateDatabaseSettings(databaseProperties);
@@ -67,7 +60,6 @@ public class ServerSettingsTest {
@Test
public void file_settings_override_db_settings() {
- ServerSettings settings = new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), new File("."), home);
assertThat(settings.getString("in_file")).isEqualTo("true");
Map<String, String> databaseProperties = ImmutableMap.of("in_file", "false");
@@ -79,7 +71,7 @@ public class ServerSettingsTest {
@Test
public void synchronize_deprecated_commons_configuration() {
BaseConfiguration deprecated = new BaseConfiguration();
- ServerSettings settings = new ServerSettings(new PropertyDefinitions(), deprecated, new File("."), home);
+ ServerSettings settings = new ServerSettings(new PropertyDefinitions(), deprecated, properties);
assertThat(settings.getString("in_file")).isEqualTo("true");
assertThat(deprecated.getString("in_file")).isEqualTo("true");
@@ -90,12 +82,4 @@ public class ServerSettingsTest {
settings.removeProperty("foo");
assertThat(deprecated.getString("foo")).isNull();
}
-
- private static File getHome() {
- try {
- return new File(ServerSettingsTest.class.getResource("/org/sonar/server/platform/ServerSettingsTest/").toURI());
- } catch (URISyntaxException e) {
- throw new IllegalStateException(e);
- }
- }
}
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java
index caf2b8f7acc..fc0ef01ada4 100644
--- a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java
@@ -50,7 +50,7 @@ public class ServerPluginJarsInstallerTest {
public TemporaryFolder temp = new TemporaryFolder();
DefaultServerFileSystem fileSystem;
- File homeDir, deployDir, pluginsDir, downloadsDir, bundledDir, trashDir, coreDir;
+ File homeDir, pluginsDir, downloadsDir, bundledDir, trashDir, coreDir;
ServerPluginJarInstaller jarInstaller;
ServerPluginJarsInstaller jarsInstaller;
Server server = mock(Server.class);
@@ -67,8 +67,7 @@ public class ServerPluginJarsInstallerTest {
bundledDir = new File(homeDir, "lib/bundled-plugins");
coreDir = new File(homeDir, "lib/core-plugins");
FileUtils.forceMkdir(bundledDir);
- deployDir = temp.newFolder("deploy");
- fileSystem = new DefaultServerFileSystem(mock(Database.class), homeDir, deployDir);
+ fileSystem = new DefaultServerFileSystem(mock(Database.class), homeDir, server);
jarInstaller = new ServerPluginJarInstaller();
jarsInstaller = new ServerPluginJarsInstaller(server, upgradeStatus, fileSystem, jarInstaller);
}
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/GenerateBootstrapIndexTest.java b/sonar-server/src/test/java/org/sonar/server/startup/GenerateBootstrapIndexTest.java
index 3b4686a461c..ca6f7c74e0e 100644
--- a/sonar-server/src/test/java/org/sonar/server/startup/GenerateBootstrapIndexTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/startup/GenerateBootstrapIndexTest.java
@@ -19,40 +19,41 @@
*/
package org.sonar.server.startup;
-import com.google.common.collect.Sets;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
-import javax.servlet.ServletContext;
-
-import java.util.Set;
+import java.io.File;
+import java.io.IOException;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public class GenerateBootstrapIndexTest {
+ @Rule
+ public TemporaryFolder rootDir = new TemporaryFolder();
+
@Before
public void setUp() throws Exception {
}
@Test
- public void shouldDetermineListOfResources() {
- ServletContext servletContext = mock(ServletContext.class);
- Set<String> libs = Sets.newHashSet();
- libs.add("/WEB-INF/lib/sonar-core-2.6.jar");
- libs.add("/WEB-INF/lib/treemap.rb");
- libs.add("/WEB-INF/lib/directory/");
- when(servletContext.getResourcePaths(anyString())).thenReturn(libs);
+ public void determine_list_of_resources() throws IOException {
+ new File(rootDir.getRoot(), "/web/WEB-INF/lib").mkdirs();
+ File webInf = new File(rootDir.getRoot(), "/web/WEB-INF");
+ File lib = new File(rootDir.getRoot(), "/web/WEB-INF/lib");
+ new File(webInf, "directory").mkdir();
+ new File(lib, "sonar-core-2.6.jar").createNewFile();
+ new File(lib, "treemap.rbr").createNewFile();
+ new File(lib, "sonar-core-2.6.jar").createNewFile();
- assertThat(GenerateBootstrapIndex.getLibs(servletContext)).hasSize(1);
- assertThat(GenerateBootstrapIndex.getLibs(servletContext).get(0)).isEqualTo("sonar-core-2.6.jar");
+ assertThat(GenerateBootstrapIndex.getLibs(lib)).hasSize(1);
+ assertThat(GenerateBootstrapIndex.getLibs(lib).get(0)).isEqualTo("sonar-core-2.6.jar");
}
@Test
- public void shouldIgnore() {
+ public void ignore_some_jars() {
assertThat(GenerateBootstrapIndex.isIgnored("sonar-batch-2.6-SNAPSHOT.jar")).isFalse();
assertThat(GenerateBootstrapIndex.isIgnored("mysql-connector-java-5.1.13.jar")).isTrue();
assertThat(GenerateBootstrapIndex.isIgnored("postgresql-9.0-801.jdbc3.jar")).isTrue();
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/GwtPublisherTest.java b/sonar-server/src/test/java/org/sonar/server/startup/GwtPublisherTest.java
index fc6ffdc3945..8e900809fc4 100644
--- a/sonar-server/src/test/java/org/sonar/server/startup/GwtPublisherTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/startup/GwtPublisherTest.java
@@ -45,7 +45,6 @@ public class GwtPublisherTest {
outputDir = new File("./target/test-tmp/org/sonar/server/startup/GwtPublisherTest/output");
if (outputDir.exists()) {
FileUtils.forceDelete(outputDir);
-
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/text/MacroInterpreterTest.java b/sonar-server/src/test/java/org/sonar/server/text/MacroInterpreterTest.java
index ef9ad6775ae..b993dbfd058 100644
--- a/sonar-server/src/test/java/org/sonar/server/text/MacroInterpreterTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/text/MacroInterpreterTest.java
@@ -22,8 +22,7 @@ package org.sonar.server.text;
import org.junit.Before;
import org.junit.Test;
-
-import javax.servlet.ServletContext;
+import org.sonar.api.platform.Server;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -36,9 +35,9 @@ public class MacroInterpreterTest {
@Before
public void setUp() {
- ServletContext servletContext = mock(ServletContext.class);
- when(servletContext.getContextPath()).thenReturn(path);
- interpreter = new MacroInterpreter(servletContext);
+ Server server = mock(Server.class);
+ when(server.getContextPath()).thenReturn(path);
+ interpreter = new MacroInterpreter(server);
}
@Test