Server { public Server restoreProfile(Location backup) { try (InputStream input = locators.openInputStream(backup)) { newHttpCall("/api/qualityprofiles/restore") .setMethod(HttpMethod.MULTIPART_POST) .setAdminCredentials() .setParam("backup", IOUtils.toString(input, UTF_8)) .execute(); return this; } catch (IOException e) { throw new IllegalStateException("Cannot restore Quality profile", e); } } Server(Locators locators, File home, Edition edition, Version version, HttpUrl url, int searchPort, @Nullable String clusterNodeName); File getHome(); Edition getEdition(); String getUrl(); Version version(); @Deprecated File getLogs(); File getAppLogs(); File getWebLogs(); File getCeLogs(); File getEsLogs(); int getSearchPort(); Optional<String> getClusterNodeName(); Server restoreProfile(Location backup); void provisionProject(String projectKey, String projectName); @Deprecated String post(String relativePath, Map<String, Object> params); HttpCall newHttpCall(String relativePath); void associateProjectToQualityProfile(String projectKey, String languageKey, String profileName); static final String ADMIN_LOGIN; static final String ADMIN_PASSWORD; }
@Test public void restoreProfile_sends_POST_request() throws Exception { File backup = temp.newFile(); FileUtils.write(backup, "<backup/>"); server.enqueue(new MockResponse()); File home = temp.newFolder(); FileUtils.touch(new File(home, "lib/sonar-application-6.3.0.1234.jar")); Locators locators = mock(Locators.class); when(locators.openInputStream(any())).thenReturn(FileUtils.openInputStream(backup)); Server underTest = new Server(locators, home, Edition.COMMUNITY, Version.create("6.3.0.1234"), HttpUrl.parse(this.server.url("").toString()), randomPort, null); underTest.restoreProfile(FileLocation.of(backup)); RecordedRequest receivedRequest = server.takeRequest(); assertThat(receivedRequest.getMethod()).isEqualTo("POST"); assertThat(receivedRequest.getPath()).isEqualTo("/api/qualityprofiles/restore"); assertThat(receivedRequest.getBody().readUtf8()) .contains("Content-Disposition: form-data; name=\"backup\"") .contains("Content-Length: 9") .contains("<backup/>"); }