@@ -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"); |
@@ -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 { |
@@ -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; | |||
} | |||
} |
@@ -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(); | |||
} |
@@ -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"))); | |||
} | |||
} |
@@ -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; | |||
@@ -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(); | |||
} | |||
} |