aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-application/src/test
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-07-24 11:58:00 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-07-24 11:58:33 +0200
commit46461efc7d8a0eb23cd1019ed066c5b97b203197 (patch)
treecef3ec404a852e830b4c2883147f311d3a8d4e5f /sonar-application/src/test
parent128427dc9d9e76369ec5db3702b345148949dc8e (diff)
downloadsonarqube-46461efc7d8a0eb23cd1019ed066c5b97b203197.tar.gz
sonarqube-46461efc7d8a0eb23cd1019ed066c5b97b203197.zip
SONAR-4898 - Added JMX registration to StartServer and base test
Diffstat (limited to 'sonar-application/src/test')
-rw-r--r--sonar-application/src/test/java/org/sonar/application/StartServerTest.java74
-rw-r--r--sonar-application/src/test/resources/conf/sonar.properties0
2 files changed, 74 insertions, 0 deletions
diff --git a/sonar-application/src/test/java/org/sonar/application/StartServerTest.java b/sonar-application/src/test/java/org/sonar/application/StartServerTest.java
new file mode 100644
index 00000000000..1f3fa455bc1
--- /dev/null
+++ b/sonar-application/src/test/java/org/sonar/application/StartServerTest.java
@@ -0,0 +1,74 @@
+package org.sonar.application;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.process.Process;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import java.io.File;
+import java.lang.management.ManagementFactory;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+public class StartServerTest {
+
+ @Rule
+ public TemporaryFolder sonarHome = new TemporaryFolder();
+
+ @Before
+ public void setUp() throws Exception {
+ sonarHome.create();
+ FileUtils.copyURLToFile(this.getClass().getClassLoader().getResource("conf/"),
+ new File(sonarHome.getRoot().getAbsolutePath(), "conf"));
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ sonarHome.delete();
+ }
+
+ @Test
+ public void should_register_mbean() throws Exception {
+
+ Installation installation = mock(Installation.class);
+ when(installation.detectHomeDir()).thenReturn(sonarHome.getRoot());
+
+ MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+
+ StartServer server = new StartServer(installation);
+
+ // 0 Can have a valid ObjectName
+ assertThat(server).isNotNull();
+
+ // 1 assert that process MBean is registered
+ ObjectName serverObjectName = Process.objectNameFor(StartServer.PROCESS_NAME);
+ assertThat(mbeanServer.isRegistered(serverObjectName)).isTrue();
+
+ ObjectInstance serverMXBean = mbeanServer.getObjectInstance(serverObjectName);
+
+
+ System.out.println("serverMXBean.getClassName() = " + serverMXBean.getClassName());
+
+// Class<?> processClass = serverMXBean.getClassName();
+//
+// Method method =
+// Reflection.invoke(serverMXBean, "ping", Long.class);
+//
+// // 2 assert that we cannot make another Process in the same JVM
+// try {
+// process = new TestProcess(props);
+// fail();
+// } catch (IllegalStateException e) {
+// assertThat(e.getMessage()).isEqualTo("Process already exists in current JVM");
+// }
+ }
+} \ No newline at end of file
diff --git a/sonar-application/src/test/resources/conf/sonar.properties b/sonar-application/src/test/resources/conf/sonar.properties
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sonar-application/src/test/resources/conf/sonar.properties