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
@Rule
public TestRule globalTimeout = new DisableOnDebug(Timeout.seconds(120));
+
@After
public void stop() {
if (orchestrator != null) {
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);
.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");
.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
*
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 {
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;
/**
private final UserTokensService userTokensService;
private final QualityGatesService qualityGatesService;
private final MeasuresService measuresService;
+ private final SystemService systemService;
private final WsConnector wsConnector;
public HttpWsClient(WsConnector wsConnector) {
this.userTokensService = new UserTokensService(wsConnector);
this.qualityGatesService = new QualityGatesService(wsConnector);
this.measuresService = new MeasuresService(wsConnector);
+ this.systemService = new SystemService(wsConnector);
}
@Override
public MeasuresService measures() {
return measuresService;
}
+
+ @Override
+ public SystemService system() {
+ return systemService;
+ }
}
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;
/**
MeasuresService measures();
+ SystemService system();
+
WsConnector wsConnector();
}
--- /dev/null
+/*
+ * 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")));
+ }
+}
--- /dev/null
+/*
+ * 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;
+
--- /dev/null
+/*
+ * 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();
+ }
+}