aboutsummaryrefslogtreecommitdiffstats
path: root/server/process
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-08-13 17:30:17 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-08-13 17:30:17 +0200
commit4056a9ca7e06c148aef69b2768fc703ea2555921 (patch)
tree71dbc89a27895d36539e4073106590aeebef10d8 /server/process
parent80346c2d8aaff33baf91f94817d9f22d09d94c6d (diff)
downloadsonarqube-4056a9ca7e06c148aef69b2768fc703ea2555921.tar.gz
sonarqube-4056a9ca7e06c148aef69b2768fc703ea2555921.zip
added tests for sonar-process
Diffstat (limited to 'server/process')
-rw-r--r--server/process/pom.xml1
-rw-r--r--server/process/sonar-process-test/pom.xml114
-rw-r--r--server/process/sonar-process/pom.xml32
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/JmxUtils.java6
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/JmxUtilsTest.java89
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java30
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/ProcessWrapperTest.java (renamed from server/process/sonar-process-test/src/test/java/org/sonar/application/ProcessWrapperTest.java)5
-rw-r--r--server/process/sonar-process/src/test/resources/sonar-dummy-app.jarbin0 -> 854048 bytes
8 files changed, 157 insertions, 120 deletions
diff --git a/server/process/pom.xml b/server/process/pom.xml
index b6cbcda18fa..b2d9174cbef 100644
--- a/server/process/pom.xml
+++ b/server/process/pom.xml
@@ -17,6 +17,5 @@
<modules>
<module>sonar-dummy-app</module>
<module>sonar-process</module>
- <module>sonar-process-test</module>
</modules>
</project>
diff --git a/server/process/sonar-process-test/pom.xml b/server/process/sonar-process-test/pom.xml
deleted file mode 100644
index 195a02f8fd6..00000000000
--- a/server/process/sonar-process-test/pom.xml
+++ /dev/null
@@ -1,114 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>process</artifactId>
- <version>4.5-SNAPSHOT</version>
- <relativePath>../</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>sonar-process-test</artifactId>
- <packaging>jar</packaging>
- <name>SonarQube :: Process :: Tests</name>
-
- <dependencies>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </dependency>
-
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- </dependency>
- <dependency>
- <groupId>com.google.code.findbugs</groupId>
- <artifactId>jsr305</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.easytesting</groupId>
- <artifactId>fest-assert</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-dummy-app</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-process</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.8</version>
- <executions>
- <execution>
- <id>copy</id>
- <phase>process-test-resources</phase>
- <goals>
- <goal>copy</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-dummy-app</artifactId>
- <version>${project.version}</version>
- <type>jar</type>
- <outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
- <destFileName>sonar-dummy-app.jar</destFileName>
- </artifactItem>
- </artifactItems>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/server/process/sonar-process/pom.xml b/server/process/sonar-process/pom.xml
index 42c05518fd5..4753b693998 100644
--- a/server/process/sonar-process/pom.xml
+++ b/server/process/sonar-process/pom.xml
@@ -69,4 +69,36 @@
<scope>test</scope>
</dependency>
</dependencies>
+ <!--
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.8</version>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-dummy-app</artifactId>
+ <version>${project.version}</version>
+ <type>jar</type>
+ <outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
+ <destFileName>sonar-dummy-app.jar</destFileName>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ -->
</project>
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/JmxUtils.java b/server/process/sonar-process/src/main/java/org/sonar/process/JmxUtils.java
index c2486d8033b..0f35d65212b 100644
--- a/server/process/sonar-process/src/main/java/org/sonar/process/JmxUtils.java
+++ b/server/process/sonar-process/src/main/java/org/sonar/process/JmxUtils.java
@@ -25,16 +25,20 @@ import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
public class JmxUtils {
+
private JmxUtils() {
// only static stuff
}
+ public static final String DOMAIN = "org.sonar";
+ public static final String NAME_PROPERTY = "name";
+
public static final String WEB_SERVER_NAME = "web";
public static final String SEARCH_SERVER_NAME = "search";
public static ObjectName objectName(String name) {
try {
- return new ObjectName("org.sonar", "name", name);
+ return new ObjectName(DOMAIN, NAME_PROPERTY, name);
} catch (MalformedObjectNameException e) {
throw new IllegalStateException("Cannot create ObjectName for " + name, e);
}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/JmxUtilsTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/JmxUtilsTest.java
new file mode 100644
index 00000000000..7d9dcc54094
--- /dev/null
+++ b/server/process/sonar-process/src/test/java/org/sonar/process/JmxUtilsTest.java
@@ -0,0 +1,89 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 02110-1301, USA.
+ */
+package org.sonar.process;
+
+import org.junit.Test;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import java.lang.management.ManagementFactory;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+
+public class JmxUtilsTest {
+
+ class MyBean implements ProcessMXBean {
+
+ @Override
+ public boolean isReady() {
+ return false;
+ }
+
+ @Override
+ public long ping() {
+ return 0;
+ }
+
+ @Override
+ public void terminate() {
+
+ }
+ }
+
+ @Test
+ public void construct_jmx_objectName() throws Exception {
+ MyBean mxBean = new MyBean();
+ ObjectName objectName = JmxUtils.objectName(mxBean.getClass().getSimpleName());
+ assertThat(objectName).isNotNull();
+ assertThat(objectName.getDomain()).isEqualTo(JmxUtils.DOMAIN);
+ assertThat(objectName.getKeyProperty(JmxUtils.NAME_PROPERTY)).isEqualTo(mxBean.getClass().getSimpleName());
+ }
+
+ @Test
+ public void fail_jmx_objectName() throws Exception {
+ try {
+ ObjectName objectName = JmxUtils.objectName(":");
+ fail();
+ } catch (Exception e) {
+ assertThat(e.getMessage()).isEqualTo("Cannot create ObjectName for :");
+ }
+ }
+
+ @Test
+ public void testRegisterMBean() throws Exception {
+
+ // 0 Get mbServer and create out test MXBean
+ MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+ MyBean mxBean = new MyBean();
+ ObjectName objectName = JmxUtils.objectName(mxBean.getClass().getSimpleName());
+
+ // 1 assert that mxBean gets registered
+ assertThat(mbeanServer.isRegistered(objectName)).isFalse();
+ JmxUtils.registerMBean(mxBean, mxBean.getClass().getSimpleName());
+ assertThat(mbeanServer.isRegistered(objectName)).isTrue();
+
+ // 2 assert that we can over-register
+ assertThat(mbeanServer.isRegistered(objectName)).isTrue();
+ JmxUtils.registerMBean(mxBean, mxBean.getClass().getSimpleName());
+ assertThat(mbeanServer.isRegistered(objectName)).isTrue();
+ }
+} \ No newline at end of file
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java
new file mode 100644
index 00000000000..09ddf79ba5f
--- /dev/null
+++ b/server/process/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java
@@ -0,0 +1,30 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 02110-1301, USA.
+ */
+package org.sonar.process;
+
+import org.junit.Test;
+
+public class ProcessUtilsTest {
+
+ @Test
+ public void check_process_alive() {
+ ProcessBuilder processBuilder = new ProcessBuilder();
+ }
+} \ No newline at end of file
diff --git a/server/process/sonar-process-test/src/test/java/org/sonar/application/ProcessWrapperTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/ProcessWrapperTest.java
index 760b964cf67..f7564f0200f 100644
--- a/server/process/sonar-process-test/src/test/java/org/sonar/application/ProcessWrapperTest.java
+++ b/server/process/sonar-process/src/test/java/org/sonar/process/ProcessWrapperTest.java
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.application;
+package org.sonar.process;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
@@ -26,9 +26,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.process.MonitoredProcess;
-import org.sonar.process.ProcessWrapper;
-import org.sonar.process.Props;
import java.io.File;
import java.io.IOException;
diff --git a/server/process/sonar-process/src/test/resources/sonar-dummy-app.jar b/server/process/sonar-process/src/test/resources/sonar-dummy-app.jar
new file mode 100644
index 00000000000..6dfd458329a
--- /dev/null
+++ b/server/process/sonar-process/src/test/resources/sonar-dummy-app.jar
Binary files differ