Search in sources :

Example 1 with QualityProfile

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile in project sonarqube by SonarSource.

the class DefaultQualityProfileLoader method loadResource.

private List<QualityProfile> loadResource(String url) {
    GetRequest getRequest = new GetRequest(url);
    InputStream is = wsClient.call(getRequest).contentStream();
    SearchWsResponse profiles = null;
    try {
        profiles = SearchWsResponse.parseFrom(is);
    } catch (IOException e) {
        throw new IllegalStateException("Failed to load quality profiles", e);
    } finally {
        IOUtils.closeQuietly(is);
    }
    List<QualityProfile> profilesList = profiles.getProfilesList();
    if (profilesList == null || profilesList.isEmpty()) {
        throw MessageException.of("No quality profiles have been found, you probably don't have any language plugin installed.");
    }
    return profilesList;
}
Also used : InputStream(java.io.InputStream) GetRequest(org.sonarqube.ws.client.GetRequest) QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) IOException(java.io.IOException)

Example 2 with QualityProfile

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile in project sonarqube by SonarSource.

the class DefaultQualityProfileLoaderTest method use_real_response.

@Test
public void use_real_response() throws IOException {
    InputStream is = getTestResource("quality_profile_search_default");
    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true", is);
    List<QualityProfile> loaded = qpLoader.loadDefault(null);
    WsTestUtil.verifyCall(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true");
    verifyNoMoreInteractions(wsClient);
    assertThat(loaded).hasSize(1);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) Test(org.junit.Test)

Example 3 with QualityProfile

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile in project sonarqube by SonarSource.

the class DefaultQualityProfileLoaderTest method testEncoding.

@Test
public void testEncoding() throws IOException {
    InputStream is = createEncodedQP("qp");
    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232", is);
    List<QualityProfile> loaded = qpLoader.load("foo#2", "my-profile#2");
    WsTestUtil.verifyCall(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232");
    verifyNoMoreInteractions(wsClient);
    assertThat(loaded).hasSize(1);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) Test(org.junit.Test)

Example 4 with QualityProfile

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile in project sonarqube by SonarSource.

the class DefaultQualityProfileLoaderTest method createEncodedQP.

private static InputStream createEncodedQP(String... names) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    QualityProfiles.SearchWsResponse.Builder responseBuilder = QualityProfiles.SearchWsResponse.newBuilder();
    for (String n : names) {
        QualityProfile qp = QualityProfile.newBuilder().setKey(n).setName(n).setLanguage("lang").build();
        responseBuilder.addProfiles(qp);
    }
    responseBuilder.build().writeTo(os);
    return new ByteArrayInputStream(os.toByteArray());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with QualityProfile

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile in project sonarqube by SonarSource.

the class SearchActionTest method ignore_profiles_on_unknown_language.

@Test
public void ignore_profiles_on_unknown_language() {
    QProfileDto profile1OnXoo1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    QProfileDto profile2OnXoo1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
    QProfileDto profileOnUnknownLanguage = db.qualityProfiles().insert(p -> p.setLanguage("unknown"));
    SearchWsResponse result = call(ws.newRequest());
    assertThat(result.getProfilesList()).extracting(QualityProfile::getKey).containsExactlyInAnyOrder(profile1OnXoo1.getKee(), profile2OnXoo1.getKee()).doesNotContain(profileOnUnknownLanguage.getKee());
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) QualityProfile(org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile) SearchWsResponse(org.sonarqube.ws.Qualityprofiles.SearchWsResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 QualityProfile (org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile)16 SearchWsResponse (org.sonarqube.ws.Qualityprofiles.SearchWsResponse)13 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)12 ProjectDto (org.sonar.db.project.ProjectDto)7 QualityProfile (org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile)7 QualityProfileTesting.newQualityProfileDto (org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto)5 InputStream (java.io.InputStream)4 List (java.util.List)4 IntStream.range (java.util.stream.IntStream.range)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4 Assertions.tuple (org.assertj.core.api.Assertions.tuple)4 Rule (org.junit.Rule)4 Language (org.sonar.api.resources.Language)4 Languages (org.sonar.api.resources.Languages)4 DEPRECATED (org.sonar.api.rule.RuleStatus.DEPRECATED)4 Change (org.sonar.api.server.ws.Change)4 WebService (org.sonar.api.server.ws.WebService)4 DateUtils (org.sonar.api.utils.DateUtils)4