aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--it/it-tests/src/test/java/it/serverSystem/RestartTest.java9
-rw-r--r--it/it-tests/src/test/java/util/ItUtils.java9
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/HttpWsClient.java8
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java3
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/system/SystemService.java34
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/system/package-info.java24
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/system/SystemServiceTest.java46
7 files changed, 129 insertions, 4 deletions
diff --git a/it/it-tests/src/test/java/it/serverSystem/RestartTest.java b/it/it-tests/src/test/java/it/serverSystem/RestartTest.java
index 021a928aa89..949f8f193a2 100644
--- a/it/it-tests/src/test/java/it/serverSystem/RestartTest.java
+++ b/it/it-tests/src/test/java/it/serverSystem/RestartTest.java
@@ -32,6 +32,8 @@ import org.junit.rules.Timeout;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
+import static util.ItUtils.newAdminWsClient;
+import static util.ItUtils.newWsClient;
/**
* This class starts a new orchestrator on each test case
@@ -45,6 +47,7 @@ public class RestartTest {
@Rule
public TestRule globalTimeout = new DisableOnDebug(Timeout.seconds(120));
+
@After
public void stop() {
if (orchestrator != null) {
@@ -62,13 +65,13 @@ public class RestartTest {
orchestrator.start();
try {
- orchestrator.getServer().wsClient().systemClient().restart();
+ newWsClient(orchestrator).system().restart();
fail();
} catch (Exception e) {
assertThat(e.getMessage()).contains("403");
}
- orchestrator.getServer().adminWsClient().systemClient().restart();
+ newAdminWsClient(orchestrator).system().restart();
// we just wait five seconds, for a lack of a better approach to waiting for the restart process to start in SQ
Thread.sleep(5000);
@@ -90,7 +93,7 @@ public class RestartTest {
.build();
orchestrator.start();
- orchestrator.getServer().adminWsClient().systemClient().restart();
+ newAdminWsClient(orchestrator).system().restart();
assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs()))
.contains("Fast restarting WebServer...")
.contains("WebServer restarted");
diff --git a/it/it-tests/src/test/java/util/ItUtils.java b/it/it-tests/src/test/java/util/ItUtils.java
index 834545b7b32..060b434fbd7 100644
--- a/it/it-tests/src/test/java/util/ItUtils.java
+++ b/it/it-tests/src/test/java/util/ItUtils.java
@@ -103,6 +103,13 @@ public class ItUtils {
.build());
}
+ public static WsClient newWsClient(Orchestrator orchestrator) {
+ Server server = orchestrator.getServer();
+ return new HttpWsClient(new HttpConnector.Builder()
+ .url(server.getUrl())
+ .build());
+ }
+
/**
* Locate the directory of sample project
*
@@ -223,7 +230,7 @@ public class ItUtils {
setServerProperty(orchestrator, null, key, value);
}
- public static void setServerProperty(Orchestrator orchestrator, @Nullable String componentKey, String key, @Nullable String value) {
+ public static void setServerProperty(Orchestrator orchestrator, @Nullable String componentKey, String key, @Nullable String value) {
if (value == null) {
orchestrator.getServer().getAdminWsClient().delete(new PropertyDeleteQuery(key).setResourceKeyOrId(componentKey));
} else {
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpWsClient.java
index 522c20f7ed0..664960aec8d 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpWsClient.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpWsClient.java
@@ -25,6 +25,7 @@ import org.sonarqube.ws.client.measure.MeasuresService;
import org.sonarqube.ws.client.permission.PermissionsService;
import org.sonarqube.ws.client.qualitygate.QualityGatesService;
import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
+import org.sonarqube.ws.client.system.SystemService;
import org.sonarqube.ws.client.usertoken.UserTokensService;
/**
@@ -41,6 +42,7 @@ public class HttpWsClient implements WsClient {
private final UserTokensService userTokensService;
private final QualityGatesService qualityGatesService;
private final MeasuresService measuresService;
+ private final SystemService systemService;
private final WsConnector wsConnector;
public HttpWsClient(WsConnector wsConnector) {
@@ -52,6 +54,7 @@ public class HttpWsClient implements WsClient {
this.userTokensService = new UserTokensService(wsConnector);
this.qualityGatesService = new QualityGatesService(wsConnector);
this.measuresService = new MeasuresService(wsConnector);
+ this.systemService = new SystemService(wsConnector);
}
@Override
@@ -93,4 +96,9 @@ public class HttpWsClient implements WsClient {
public MeasuresService measures() {
return measuresService;
}
+
+ @Override
+ public SystemService system() {
+ return systemService;
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
index 8fbd2e74168..db7ab7ba245 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
@@ -25,6 +25,7 @@ import org.sonarqube.ws.client.measure.MeasuresService;
import org.sonarqube.ws.client.permission.PermissionsService;
import org.sonarqube.ws.client.qualitygate.QualityGatesService;
import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
+import org.sonarqube.ws.client.system.SystemService;
import org.sonarqube.ws.client.usertoken.UserTokensService;
/**
@@ -45,5 +46,7 @@ public interface WsClient {
MeasuresService measures();
+ SystemService system();
+
WsConnector wsConnector();
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/system/SystemService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/system/SystemService.java
new file mode 100644
index 00000000000..4412dac0984
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/system/SystemService.java
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * 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 02110-1301, USA.
+ */
+package org.sonarqube.ws.client.system;
+
+import org.sonarqube.ws.client.BaseService;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.WsConnector;
+
+public class SystemService extends BaseService {
+ public SystemService(WsConnector wsConnector) {
+ super(wsConnector, "api/system");
+ }
+
+ public void restart() {
+ call(new PostRequest(path("restart")));
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/system/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/system/package-info.java
new file mode 100644
index 00000000000..acaa4e65f91
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/system/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * 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 02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonarqube.ws.client.system;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/system/SystemServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/system/SystemServiceTest.java
new file mode 100644
index 00000000000..182b4c68dd5
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/system/SystemServiceTest.java
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * 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 02110-1301, USA.
+ */
+package org.sonarqube.ws.client.system;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.ServiceTester;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.mockito.Mockito.mock;
+
+public class SystemServiceTest {
+
+ @Rule
+ public ServiceTester<SystemService> serviceTester = new ServiceTester<>(new SystemService(mock(WsConnector.class)));
+
+ private SystemService underTest = serviceTester.getInstanceUnderTest();
+
+ @Test
+ public void testName() throws Exception {
+ underTest.restart();
+
+ PostRequest postRequest = serviceTester.getPostRequest();
+ serviceTester.assertThat(postRequest)
+ .hasPath("restart")
+ .andNoOtherParam();
+ }
+}