Skip to content

Commit

Permalink
SLCORE-1091 stop using deprecated setHtmlDesc method in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sophio-japharidze-sonarsource committed Dec 17, 2024
1 parent 36e755c commit 1a583f9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ private static RuleMonolithicDescriptionDto transformMonolithicDescription(RuleD
htmlSnippets.addAll(ruleDetails.getDescriptionSectionsByKey().get("default").stream().map(RuleDetails.DescriptionSection::getHtmlContent).collect(Collectors.toList()));
} else {
htmlSnippets.add(ruleDetails.getHtmlDescription());
htmlSnippets.add(ruleDetails.getExtendedDescription());
}
htmlSnippets.add(ruleDetails.getExtendedDescription());
htmlSnippets.add(getCleanCodePrinciplesContent(ruleDetails.getCleanCodePrincipleKeys()));
return new RuleMonolithicDescriptionDto(concat(htmlSnippets));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ void should_get_rule() {
.setSeverity("MINOR")
.setType(Common.RuleType.VULNERABILITY)
.setLang(SonarLanguage.PYTHON.getSonarLanguageKey())
.setHtmlDesc("htmlDesc")
.setHtmlNote("htmlNote")
.setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder()
.addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder()
.setKey("default")
.setContent("desc")
.build())
.build())
.setCleanCodeAttribute(Common.CleanCodeAttribute.COMPLETE)
.setImpacts(Rules.Rule.Impacts.newBuilder().addImpacts(Common.Impact.newBuilder().setSeverity(Common.ImpactSeverity.HIGH).setSoftwareQuality(Common.SoftwareQuality.MAINTAINABILITY).build()).build())
.build())
Expand All @@ -76,8 +81,9 @@ void should_get_rule() {

var rule = rulesApi.getRule("java:S1234", new SonarLintCancelMonitor()).get();

assertThat(rule).extracting("name", "severity", "type", "language", "htmlDesc", "htmlNote", "cleanCodeAttribute", "impacts")
.contains("name", IssueSeverity.MINOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlDesc", "htmlNote", CleanCodeAttribute.COMPLETE, Map.of(SoftwareQuality.MAINTAINABILITY, ImpactSeverity.HIGH));
assertThat(rule).extracting("name", "severity", "type", "language", "htmlNote", "cleanCodeAttribute", "impacts")
.contains("name", IssueSeverity.MINOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlNote", CleanCodeAttribute.COMPLETE, Map.of(SoftwareQuality.MAINTAINABILITY, ImpactSeverity.HIGH));
assertThat(rule.getDescriptionSections().get(0).getHtmlContent()).isEqualTo("desc");
}

@Test
Expand All @@ -89,7 +95,6 @@ void should_get_rule_with_description_sections() {
.setSeverity("MINOR")
.setType(Common.RuleType.VULNERABILITY)
.setLang(SonarLanguage.PYTHON.getSonarLanguageKey())
.setHtmlDesc("htmlDesc")
.setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder()
.addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder().setKey("sectionKey").setContent("htmlContent").build())
.addDescriptionSections(
Expand All @@ -106,8 +111,8 @@ void should_get_rule_with_description_sections() {

var rule = rulesApi.getRule("java:S1234", new SonarLintCancelMonitor()).get();

assertThat(rule).extracting("name", "severity", "type", "language", "htmlDesc", "htmlNote", "cleanCodeAttribute", "impacts")
.contains("name", IssueSeverity.MINOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlDesc", "htmlNote", CleanCodeAttribute.CONVENTIONAL, Map.of(SoftwareQuality.RELIABILITY, ImpactSeverity.LOW));
assertThat(rule).extracting("name", "severity", "type", "language","htmlNote", "cleanCodeAttribute", "impacts")
.contains("name", IssueSeverity.MINOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlNote", CleanCodeAttribute.CONVENTIONAL, Map.of(SoftwareQuality.RELIABILITY, ImpactSeverity.LOW));

var sections = rule.getDescriptionSections();
assertThat(sections).hasSize(2);
Expand All @@ -131,17 +136,23 @@ void should_get_rule_from_organization() {
.setSeverity("MAJOR")
.setType(Common.RuleType.VULNERABILITY)
.setLang(SonarLanguage.PYTHON.getSonarLanguageKey())
.setHtmlDesc("htmlDesc")
.setHtmlNote("htmlNote")
.setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder()
.addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder()
.setKey("default")
.setContent("desc")
.build())
.build())
.build())
.build());

var rulesApi = new RulesApi(mockServer.serverApiHelper("orgKey"));

var rule = rulesApi.getRule("java:S1234", new SonarLintCancelMonitor()).get();

assertThat(rule).extracting("name", "severity", "type", "language", "htmlDesc", "htmlNote")
.contains("name", IssueSeverity.MAJOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlDesc", "htmlNote");
assertThat(rule).extracting("name", "severity", "type", "language", "htmlNote")
.contains("name", IssueSeverity.MAJOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlNote");
assertThat(rule.getDescriptionSections().get(0).getHtmlContent()).isEqualTo("desc");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void it_should_merge_rule_from_storage_and_server_when_project_is_bound() {
.withConnectedEmbeddedPluginAndEnabledLanguage(TestPlugin.PYTHON)
.build();
mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:S139", Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc").build())
.build());

var details = getEffectiveRuleDetails("scopeId", "python:S139");
Expand All @@ -188,7 +188,7 @@ void it_should_merge_rule_from_storage_and_server_when_parent_project_is_bound()
.withConnectedEmbeddedPluginAndEnabledLanguage(TestPlugin.PYTHON)
.build();
mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:S139", Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc").build())
.build());

var details = getEffectiveRuleDetails("childScopeId", "python:S139");
Expand All @@ -213,7 +213,6 @@ void it_return_single_section_from_server_when_project_is_bound() {
.build();
mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=jssecurity:S5696", Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName(name).setSeverity("BLOCKER").setType(Common.RuleType.VULNERABILITY).setLang("js")
.setHtmlDesc(desc)
.setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder()
.addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder()
.setKey("default")
Expand Down Expand Up @@ -278,7 +277,14 @@ void it_should_merge_template_rule_from_storage_and_server_when_project_is_bound
.withConnectedEmbeddedPluginAndEnabledLanguage(TestPlugin.PYTHON)
.build();
mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:custom", Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc")
.setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder()
.addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder()
.setKey("default")
.setContent("desc")
.build())
.build())
.build())
.build());

var details = getEffectiveRuleDetails("scopeId", "python:custom");
Expand All @@ -300,7 +306,14 @@ void it_should_merge_rule_from_storage_and_server_rule_when_rule_is_unknown_in_l
.withEnabledLanguageInStandaloneMode(PYTHON)
.build();
mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:S139", Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc")
.setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder()
.addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder()
.setKey("default")
.setContent("desc")
.build())
.build())
.build())
.build());

var details = getEffectiveRuleDetails("scopeId", "python:S139");
Expand Down Expand Up @@ -410,7 +423,7 @@ void it_should_add_a_more_info_tab_if_no_resource_section_exists_and_extended_de
.withEnabledLanguageInStandaloneMode(PYTHON)
.build();
mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:S139", Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc")
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc")
.setEducationPrinciples(Rules.Rule.EducationPrinciples.newBuilder().addEducationPrinciples("never_trust_user_input").build())
.setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder()
.addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder()
Expand Down Expand Up @@ -486,7 +499,7 @@ private void prepareForRuleDescriptionSectionsAndContext() {
.withEnabledLanguageInStandaloneMode(PYTHON)
.build();
mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:S139", Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc")
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc")
.setEducationPrinciples(Rules.Rule.EducationPrinciples.newBuilder().addEducationPrinciples("never_trust_user_input").build())
.setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder()
.addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.sonarsource.sonarlint.core.commons.api.SonarLanguage;
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcServer;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.rules.EffectiveRuleDetailsDto;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.rules.GetEffectiveRuleDetailsParams;
import org.sonarsource.sonarlint.core.commons.api.SonarLanguage;
import org.sonarsource.sonarlint.core.serverapi.proto.sonarqube.ws.Common;
import org.sonarsource.sonarlint.core.serverapi.proto.sonarqube.ws.Rules;

Expand Down Expand Up @@ -79,8 +79,7 @@ void it_should_authenticate_preemptively_on_sonarqube_with_login_password() {
"\"UP\"}")));
sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139")
.willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc(
"desc").setHtmlNote("extendedDesc from server").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build())
.build()))));

var details = getEffectiveRuleDetails("scopeId", "python:S139");
Expand All @@ -105,8 +104,7 @@ void it_should_authenticate_preemptively_on_sonarqube_9_9_with_token_and_basic_s
.build(fakeClient);
sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139")
.willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc(
"desc").setHtmlNote("extendedDesc from server").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build())
.build()))));
sonarqubeMock.stubFor(get("/api/system/status")
.willReturn(aResponse().withStatus(200).withBody("{\"id\": \"20160308094653\",\"version\": \"9.9\",\"status\": " +
Expand Down Expand Up @@ -134,8 +132,7 @@ void it_should_authenticate_preemptively_on_sonarqube_10_0_with_token_and_bearer
.build(fakeClient);
sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139")
.willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc(
"desc").setHtmlNote("extendedDesc from server").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build())
.build()))));
sonarqubeMock.stubFor(get("/api/system/status")
.willReturn(aResponse().withStatus(200).withBody("{\"id\": \"20160308094653\",\"version\": \"10.0\",\"status\": " +
Expand Down
18 changes: 6 additions & 12 deletions medium-tests/src/test/java/mediumtest/http/ProxyMediumTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ void it_should_honor_http_proxy_settings() {
.build(fakeClient);
sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139")
.willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc(
"desc").setHtmlNote("extendedDesc from server").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build())
.build()))));

var details = getEffectiveRuleDetails("scopeId", "python:S139");
Expand All @@ -150,8 +149,7 @@ void it_should_honor_http_direct_proxy_settings() {
.build(fakeClient);
sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139")
.willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc(
"desc").setHtmlNote("extendedDesc from server").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build())
.build()))));

var details = getEffectiveRuleDetails("scopeId", "python:S139");
Expand Down Expand Up @@ -182,8 +180,7 @@ void it_should_honor_http_proxy_authentication() {
.build(fakeClient);
sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139")
.willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc(
"desc").setHtmlNote("extendedDesc from server").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build())
.build()))));

var details = getEffectiveRuleDetails("scopeId", "python:S139");
Expand Down Expand Up @@ -213,8 +210,7 @@ void it_should_honor_http_proxy_authentication_with_null_password() {
.build(fakeClient);
sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139")
.willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc(
"desc").setHtmlNote("extendedDesc from server").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build())
.build()))));

var details = getEffectiveRuleDetails("scopeId", "python:S139");
Expand Down Expand Up @@ -244,8 +240,7 @@ void it_should_fail_if_proxy_port_is_smaller_than_valid_range() {
.build(fakeClient);
sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139")
.willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc(
"desc").setHtmlNote("extendedDesc from server").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build())
.build()))));

var details = getEffectiveRuleDetails("scopeId", "python:S139");
Expand Down Expand Up @@ -280,8 +275,7 @@ void it_should_fail_if_proxy_port_is_higher_than_valid_range() {
.build(fakeClient);
sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139")
.willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc(
"desc").setHtmlNote("extendedDesc from server").build())
.setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build())
.build()))));

var details = getEffectiveRuleDetails("scopeId", "python:S139");
Expand Down

0 comments on commit 1a583f9

Please sign in to comment.