diff options
author | Aurelien <100427063+aurelien-poscia-sonarsource@users.noreply.github.com> | 2022-04-28 15:10:35 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-05-06 20:02:43 +0000 |
commit | 5cea1b86e42b9b71bd289ee35d4b376cb62e51c4 (patch) | |
tree | 7d9b79f624d732275d037980322b68b3345e3696 /server/sonar-db-dao | |
parent | 6bb200a692f7a200c0ca27900c24c8c89982e521 (diff) | |
download | sonarqube-5cea1b86e42b9b71bd289ee35d4b376cb62e51c4.tar.gz sonarqube-5cea1b86e42b9b71bd289ee35d4b376cb62e51c4.zip |
SONAR-16302 Renamed RULE_DESC_SECTIONS.DESCRIPTION to RULE_DESC_SECTIONS.CONTENT and corresponding java objects
Diffstat (limited to 'server/sonar-db-dao')
9 files changed, 97 insertions, 37 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java index 0837c3e2821..e5709520abe 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java @@ -159,7 +159,7 @@ public class RuleDao implements Dao { insertRuleDescriptionSectionDtos(ruleDefinitionDto, mapper); } - private void insertRuleDescriptionSectionDtos(RuleDefinitionDto ruleDefinitionDto, RuleMapper mapper) { + private static void insertRuleDescriptionSectionDtos(RuleDefinitionDto ruleDefinitionDto, RuleMapper mapper) { ruleDefinitionDto.getRuleDescriptionSectionDtos() .forEach(section -> mapper.insertRuleDescriptionSection(ruleDefinitionDto.getUuid(), section)); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java index 208987e3f75..ae91fe2bbe7 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java @@ -29,12 +29,12 @@ public class RuleDescriptionSectionDto { private final String uuid; private final String key; - private final String description; + private final String content; - private RuleDescriptionSectionDto(String uuid, String key, String description) { + private RuleDescriptionSectionDto(String uuid, String key, String content) { this.uuid = uuid; this.key = key; - this.description = description; + this.content = content; } public String getUuid() { @@ -45,15 +45,15 @@ public class RuleDescriptionSectionDto { return key; } - public String getDescription() { - return description; + public String getContent() { + return content; } public static RuleDescriptionSectionDto createDefaultRuleDescriptionSection(String uuid, String description) { return RuleDescriptionSectionDto.builder() .setDefault() .uuid(uuid) - .description(description) + .content(description) .build(); } @@ -70,7 +70,7 @@ public class RuleDescriptionSectionDto { return new StringJoiner(", ", RuleDescriptionSectionDto.class.getSimpleName() + "[", "]") .add("uuid='" + uuid + "'") .add("key='" + key + "'") - .add("description='" + description + "'") + .add("content='" + content + "'") .toString(); } @@ -83,18 +83,18 @@ public class RuleDescriptionSectionDto { return false; } RuleDescriptionSectionDto that = (RuleDescriptionSectionDto) o; - return Objects.equals(uuid, that.uuid) && Objects.equals(key, that.key) && Objects.equals(description, that.description); + return Objects.equals(uuid, that.uuid) && Objects.equals(key, that.key) && Objects.equals(content, that.content); } @Override public int hashCode() { - return Objects.hash(uuid, key, description); + return Objects.hash(uuid, key, content); } public static final class RuleDescriptionSectionDtoBuilder { private String uuid; private String key = null; - private String description; + private String content; private RuleDescriptionSectionDtoBuilder() { } @@ -116,13 +116,13 @@ public class RuleDescriptionSectionDto { return this; } - public RuleDescriptionSectionDtoBuilder description(String description) { - this.description = description; + public RuleDescriptionSectionDtoBuilder content(String content) { + this.content = content; return this; } public RuleDescriptionSectionDto build() { - return new RuleDescriptionSectionDto(uuid, key, description); + return new RuleDescriptionSectionDto(uuid, key, content); } } } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml index 4cea9e1e39b..ed94cc4598a 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml @@ -6,7 +6,7 @@ <sql id="selectRuleDescriptionSectionColumns"> rds.uuid as "rds_uuid", rds.kee as "rds_kee", - rds.description as "rds_description", + rds.content as "rds_content", </sql> <sql id="leftOuterJoinRulesDescriptionSections"> @@ -50,7 +50,7 @@ <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto"> <id property="uuid" column="rds_uuid"/> <result property="key" column="rds_kee"/> - <result property="description" column="rds_description" typeHandler="org.apache.ibatis.type.StringTypeHandler"/> + <result property="content" column="rds_content" typeHandler="org.apache.ibatis.type.StringTypeHandler"/> </collection> </resultMap> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml index 685b9be1a72..ad74a26fab4 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml @@ -6,7 +6,7 @@ <sql id="selectRuleDescriptionSectionColumns"> rds.uuid as "rds_uuid", rds.kee as "rds_kee", - rds.description as "rds_description", + rds.content as "rds_content", </sql> <sql id="leftOuterJoinRulesDescriptionSections"> @@ -127,7 +127,7 @@ <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto"> <id property="uuid" column="rds_uuid"/> <result property="key" column="rds_kee"/> - <result property="description" column="rds_description" typeHandler="org.apache.ibatis.type.StringTypeHandler"/> + <result property="content" column="rds_content" typeHandler="org.apache.ibatis.type.StringTypeHandler"/> </collection> </resultMap> @@ -160,7 +160,7 @@ <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto"> <id property="uuid" column="rds_uuid"/> <result property="key" column="rds_kee"/> - <result property="description" column="rds_description" typeHandler="org.apache.ibatis.type.StringTypeHandler"/> + <result property="content" column="rds_content" typeHandler="org.apache.ibatis.type.StringTypeHandler"/> </collection> </resultMap> @@ -403,13 +403,13 @@ uuid, rule_uuid, kee, - description + content ) values ( #{dto.uuid,jdbcType=VARCHAR}, #{ruleUuid,jdbcType=VARCHAR}, #{dto.key,jdbcType=VARCHAR}, - #{dto.description,jdbcType=VARCHAR} + #{dto.content,jdbcType=VARCHAR} ) </insert> diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index f04aa9a8c4d..b6fdecd4f33 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -811,7 +811,7 @@ CREATE TABLE "RULE_DESC_SECTIONS"( "UUID" CHARACTER VARYING(40) NOT NULL, "RULE_UUID" CHARACTER VARYING(40) NOT NULL, "KEE" CHARACTER VARYING(50) NOT NULL, - "DESCRIPTION" CHARACTER LARGE OBJECT NOT NULL + "CONTENT" CHARACTER LARGE OBJECT NOT NULL ); ALTER TABLE "RULE_DESC_SECTIONS" ADD CONSTRAINT "PK_RULE_DESC_SECTIONS" PRIMARY KEY("UUID"); CREATE UNIQUE INDEX "UNIQ_RULE_DESC_SECTIONS_KEE" ON "RULE_DESC_SECTIONS"("RULE_UUID" NULLS FIRST, "KEE" NULLS FIRST); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java index 5e4912e4e64..3806c062f8f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java @@ -73,14 +73,14 @@ public class QualityProfileExportDaoTest { String language = "java"; RuleDefinitionDto ruleTemplate = createRule(language); RuleDefinitionDto customRule = createRule(language, RuleStatus.READY, ruleTemplate.getUuid()); - var customRuleDescription = customRule.getDefaultRuleDescriptionSectionDto().getDescription(); + var customRuleContent = customRule.getDefaultRuleDescriptionSectionDto().getContent(); RuleMetadataDto customRuleMetadata = createRuleMetadata(new RuleMetadataDto() .setRuleUuid(customRule.getUuid()) .setNoteData("Extended description") .setTags(Sets.newHashSet("tag1", "tag2", "tag3"))); RuleDefinitionDto rule = createRule(language, RuleStatus.READY, null); - var ruleDescription = rule.getDefaultRuleDescriptionSectionDto().getDescription(); + var ruleContent = rule.getDefaultRuleDescriptionSectionDto().getContent(); RuleMetadataDto ruleMetadata = createRuleMetadata(new RuleMetadataDto() .setRuleUuid(rule.getUuid())); QProfileDto profile = createProfile(language); @@ -96,7 +96,7 @@ public class QualityProfileExportDaoTest { assertThat(exportCustomRuleDto).isNotNull(); assertThat(exportCustomRuleDto.isCustomRule()).isTrue(); assertThat(exportCustomRuleDto.getParams()).isEmpty(); - assertThat(exportCustomRuleDto.getRuleDescriptionSections().iterator().next().getDescription()).isEqualTo(customRuleDescription); + assertThat(exportCustomRuleDto.getRuleDescriptionSections().iterator().next().getContent()).isEqualTo(customRuleContent); assertThat(exportCustomRuleDto.getExtendedDescription()).isEqualTo(customRuleMetadata.getNoteData()); assertThat(exportCustomRuleDto.getName()).isEqualTo(customRule.getName()); assertThat(exportCustomRuleDto.getRuleKey()).isEqualTo(customRule.getKey()); @@ -112,7 +112,7 @@ public class QualityProfileExportDaoTest { assertThat(exportRuleDto).isNotNull(); assertThat(exportRuleDto.isCustomRule()).isFalse(); assertThat(exportRuleDto.getParams()).isEmpty(); - assertThat(exportRuleDto.getRuleDescriptionSections().iterator().next().getDescription()).isEqualTo(ruleDescription); + assertThat(exportRuleDto.getRuleDescriptionSections().iterator().next().getContent()).isEqualTo(ruleContent); assertThat(exportRuleDto.getExtendedDescription()).isEqualTo(ruleMetadata.getNoteData()); assertThat(exportRuleDto.getName()).isEqualTo(rule.getName()); assertThat(exportRuleDto.getRuleKey()).isEqualTo(rule.getKey()); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java index 4654954af46..849392b92d7 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java @@ -31,6 +31,7 @@ import java.util.Set; import java.util.function.Consumer; import org.apache.commons.lang.RandomStringUtils; import org.apache.ibatis.exceptions.PersistenceException; +import org.jetbrains.annotations.NotNull; import org.junit.Rule; import org.junit.Test; import org.sonar.api.rule.RuleKey; @@ -547,7 +548,7 @@ public class RuleDaoTest { RuleDescriptionSectionDto newSection = RuleDescriptionSectionDto.builder() .uuid(randomAlphanumeric(20)) .key("new_key") - .description(randomAlphanumeric(1000)) + .content(randomAlphanumeric(1000)) .build(); rule.addRuleDescriptionSectionDto(newSection); @@ -569,7 +570,7 @@ public class RuleDaoTest { RuleDescriptionSectionDto replacingSection = RuleDescriptionSectionDto.builder() .uuid(randomAlphanumeric(20)) .key(existingSection.getKey()) - .description(randomAlphanumeric(1000)) + .content(randomAlphanumeric(1000)) .build(); rule.addOrReplaceRuleDescriptionSectionDto(replacingSection); @@ -837,7 +838,7 @@ public class RuleDaoTest { RuleDescriptionSectionDto ruleDescriptionSectionDto = RuleDescriptionSectionDto.builder() .key("DESC") .uuid("uuid") - .description("my description") + .content("my description") .build(); RuleDefinitionDto r1 = db.rules().insert(r -> { r.addRuleDescriptionSectionDto(ruleDescriptionSectionDto); @@ -846,11 +847,14 @@ public class RuleDaoTest { underTest.selectIndexingRules(db.getSession(), accumulator); - assertThat(accumulator.list) + RuleForIndexingDto firstRule = findRuleForIndexingWithUuid(accumulator, r1.getUuid()); + RuleForIndexingDto secondRule = findRuleForIndexingWithUuid(accumulator, r2.getUuid()); + + assertThat(Arrays.asList(firstRule, secondRule)) .extracting(RuleForIndexingDto::getUuid, RuleForIndexingDto::getRuleKey) .containsExactlyInAnyOrder(tuple(r1.getUuid(), r1.getKey()), tuple(r2.getUuid(), r2.getKey())); Iterator<RuleForIndexingDto> it = accumulator.list.iterator(); - RuleForIndexingDto firstRule = it.next(); + assertThat(firstRule.getRepository()).isEqualTo(r1.getRepositoryKey()); assertThat(firstRule.getPluginRuleKey()).isEqualTo(r1.getRuleKey()); @@ -874,7 +878,6 @@ public class RuleDaoTest { assertThat(firstRule.getCreatedAt()).isEqualTo(r1.getCreatedAt()); assertThat(firstRule.getUpdatedAt()).isEqualTo(r1.getUpdatedAt()); - RuleForIndexingDto secondRule = it.next(); assertThat(secondRule.isExternal()).isTrue(); } @@ -888,8 +891,8 @@ public class RuleDaoTest { underTest.selectIndexingRules(db.getSession(), accumulator); assertThat(accumulator.list).hasSize(2); - RuleForIndexingDto firstRule = accumulator.list.get(0); - RuleForIndexingDto secondRule = accumulator.list.get(1); + RuleForIndexingDto firstRule = findRuleForIndexingWithUuid(accumulator, r1.getUuid()); + RuleForIndexingDto secondRule = findRuleForIndexingWithUuid(accumulator, r2.getUuid()); assertRuleDefinitionFieldsAreEquals(r1, firstRule); assertRuleMetadataFieldsAreEquals(r1Metadatas, firstRule); @@ -900,6 +903,13 @@ public class RuleDaoTest { assertThat(secondRule.getTemplateRepository()).isEqualTo(r1.getRepositoryKey()); } + @NotNull + private static RuleForIndexingDto findRuleForIndexingWithUuid(Accumulator<RuleForIndexingDto> accumulator, String uuid) { + return accumulator.list.stream() + .filter(rule -> rule.getUuid().equals(uuid)) + .findFirst().orElseThrow(); + } + @Test public void scrollIndexingRulesByKeys() { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java new file mode 100644 index 00000000000..229a1860930 --- /dev/null +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java @@ -0,0 +1,48 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info 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.sonar.db.rule; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +public class RuleDescriptionSectionDtoTest { + private static final RuleDescriptionSectionDto SECTION = RuleDescriptionSectionDto.builder() + .key("key") + .uuid("uuid") + .content("desc").build(); + + @Test + public void testEquals() { + + Assertions.assertThat(RuleDescriptionSectionDto.builder() + .key("key") + .uuid("uuid") + .content("desc") + .build()) + .isEqualTo(SECTION); + + Assertions.assertThat(SECTION).isEqualTo(SECTION); + } + + @Test + public void testToString() { + Assertions.assertThat(SECTION).hasToString("RuleDescriptionSectionDto[uuid='uuid', key='key', content='desc']"); + } +} diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java index 833f932a8b2..d2c72d2ef46 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java @@ -75,6 +75,7 @@ public class RuleTesting { } public static RuleDefinitionDto newRuleWithoutDescriptionSection(RuleKey ruleKey) { + long currentTimeMillis = System.currentTimeMillis(); return new RuleDefinitionDto() .setRepositoryKey(ruleKey.repository()) .setRuleKey(ruleKey.rule()) @@ -92,10 +93,11 @@ public class RuleTesting { .setLanguage("lang_" + randomAlphanumeric(3)) .setGapDescription("gapDescription_" + randomAlphanumeric(5)) .setDefRemediationBaseEffort(nextInt(10) + "h") - .setDefRemediationGapMultiplier(nextInt(10) + "h") + //voluntarily offset the remediation to be able to detect issues + .setDefRemediationGapMultiplier((nextInt(10) + 10) + "h") .setDefRemediationFunction("LINEAR_OFFSET") - .setCreatedAt(System.currentTimeMillis()) - .setUpdatedAt(System.currentTimeMillis()) + .setCreatedAt(currentTimeMillis) + .setUpdatedAt(currentTimeMillis + 5) .setScope(Scope.MAIN); } |