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;
}
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);
}
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);
}
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());
}
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());
}
Aggregations