]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16302 - Update to add mybatis automapping (#5926)
authorLéo Geoffroy <99647462+leo-geoffroy-sonarsource@users.noreply.github.com>
Mon, 16 May 2022 08:55:00 +0000 (10:55 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 16 May 2022 20:03:56 +0000 (20:03 +0000)
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java
server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java

index c537404f6370ce2ab211620ad35959ab1fa19702..c992f7457323431caa83ce44e2f34e81e092f059 100644 (file)
@@ -103,7 +103,7 @@ public class AdHocRuleCreatorTest {
       .setEngineId("eslint")
       .setRuleId("no-cond-assign")
       .setName(repeat("a", 201))
-      .setDescription(repeat("a", 1_000_000))
+      .setDescription(repeat("a", 16_777_216))
       .setSeverity(Constants.Severity.BLOCKER)
       .setType(ScannerReport.IssueType.BUG)
       .build());
@@ -111,7 +111,7 @@ public class AdHocRuleCreatorTest {
     RuleDto rule = underTest.persistAndIndex(dbSession, addHocRule);
 
     assertThat(rule.getMetadata().getAdHocName()).isEqualTo(repeat("a", 200));
-    assertThat(rule.getMetadata().getAdHocDescription()).isEqualTo(repeat("a", 1_000_000));
+    assertThat(rule.getMetadata().getAdHocDescription()).isEqualTo(repeat("a", 16_777_215));
   }
 
   @Test
index 261298c4cd3b5da0908eb426ea85bf5492e83111..f96f68623105fbc8c28e923149dc06c772065b55 100644 (file)
@@ -9,9 +9,10 @@
   </sql>
 
   <sql id="selectJoinedTablesColumns">
+    rds.content as "rds_content",
     rds.uuid as "rds_uuid",
     rds.kee as "rds_kee",
-    rds.content as "rds_content",
+
     r.uuid as "r_uuid",
     r.plugin_rule_key as "ruleKey",
     r.plugin_name as "repositoryKey",
     <include refid="leftOuterJoinRulesDescriptionSections"/>
   </select>
 
-  <resultMap id="ruleResultMap" type="org.sonar.db.rule.RuleDto">
+  <resultMap id="ruleResultMap" type="org.sonar.db.rule.RuleDto" autoMapping="true">
     <id property="uuid" column="r_uuid"/>
 
-    <result property="createdAt" column="createdAt"/>
-    <result property="updatedAt" column="updatedAt"/>
-    <result property="noteData" column="noteData" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
-    <result property="noteUserUuid" column="noteUserUuid"/>
-    <result property="noteCreatedAt" column="noteCreatedAt"/>
-    <result property="noteUpdatedAt" column="noteUpdatedAt"/>
-    <result property="remediationFunction" column="remediationFunction"/>
-    <result property="remediationGapMultiplier" column="remediationGapMultiplier"/>
-    <result property="remediationBaseEffort" column="remediationBaseEffort"/>
-    <result property="tagsField" column="tagsField"/>
-    <result property="adHocName" column="adHocName"/>
-    <result property="adHocDescription" column="adHocDescription" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
-    <result property="adHocSeverity" column="adHocSeverity"/>
-    <result property="adHocType" column="adHocType"/>
-
-    <result property="ruleKey" column="ruleKey"/>
-    <result property="repositoryKey" column="repositoryKey"/>
-    <result property="descriptionFormat" column="descriptionFormat"/>
-    <result property="status" column="status"/>
-    <result property="name" column="name"/>
-    <result property="configKey" column="configKey"/>
-    <result property="severity" column="severity"/>
-    <result property="isTemplate" column="isTemplate"/>
-    <result property="isExternal" column="isExternal"/>
-    <result property="isAdHoc" column="isAdHoc"/>
-    <result property="language" column="language"/>
-    <result property="templateUuid" column="templateUuid"/>
-    <result property="defRemediationFunction" column="defRemediationFunction"/>
-    <result property="defRemediationGapMultiplier" column="defRemediationGapMultiplier"/>
-    <result property="defRemediationBaseEffort" column="defRemediationBaseEffort"/>
-    <result property="gapDescription" column="gapDescription"/>
-    <result property="systemTagsField" column="systemTagsField"/>
-    <result property="securityStandardsField" column="securityStandardsField"/>
-    <result property="type" column="type"/>
-    <result property="pluginKey" column="pluginKey"/>
-    <result property="scope" column="scope"/>
-
-    <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto">
-      <id property="uuid" column="rds_uuid"/>
-      <result property="key" column="rds_kee"/>
-      <result property="content" column="rds_content" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
+    <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto" autoMapping="true"
+                columnPrefix="rds_">
+      <result property="key" column="kee"/>
     </collection>
   </resultMap>
 
index 15b4249eace243996e7babf441f028c1203f5b9f..e859952d32f141b95d98110cea927adc7503632f 100644 (file)
@@ -130,6 +130,25 @@ public class RuleDaoTest {
     verifyMetadata(rule.getMetadata(), metadata);
   }
 
+  @Test
+  public void selectByUuidWithDifferentsValuesOfBooleans() {
+    for (int i = 0; i < 3; i++) {
+      int indexBoolean = i;
+      RuleDto ruleDto = db.rules().insert((ruleDto1 -> {
+        ruleDto1.setIsTemplate(indexBoolean == 0);
+        ruleDto1.setIsExternal(indexBoolean == 1);
+        ruleDto1.setIsAdHoc(indexBoolean == 2);
+      }));
+      RuleMetadataDto metadata = newRuleMetadata(ruleDto);
+      RuleDto expected = db.rules().insertRule(ruleDto, metadata);
+
+      assertThat(underTest.selectByUuid(expected.getUuid() + 500, db.getSession())).isEmpty();
+      RuleDto rule = underTest.selectByUuid(expected.getUuid(), db.getSession()).get();
+      assertEquals(rule, ruleDto);
+      verifyMetadata(rule.getMetadata(), metadata);
+    }
+  }
+
   @Test
   public void selectDefinitionByUuid() {
     RuleDto rule = db.rules().insert();
@@ -251,6 +270,7 @@ public class RuleDaoTest {
     assertThat(actual.getSeverityString()).isEqualTo(expected.getSeverityString());
     assertThat(actual.isExternal()).isEqualTo(expected.isExternal());
     assertThat(actual.isTemplate()).isEqualTo(expected.isTemplate());
+    assertThat(actual.isCustomRule()).isEqualTo(expected.isCustomRule());
     assertThat(actual.getLanguage()).isEqualTo(expected.getLanguage());
     assertThat(actual.getTemplateUuid()).isEqualTo(expected.getTemplateUuid());
     assertThat(actual.getDefRemediationFunction()).isEqualTo(expected.getDefRemediationFunction());
@@ -851,15 +871,14 @@ public class RuleDaoTest {
       .containsExactlyInAnyOrder(tuple(r1.getUuid(), r1.getKey()), tuple(r2.getUuid(), r2.getKey()));
     Iterator<RuleForIndexingDto> it = accumulator.list.iterator();
 
-
     assertThat(firstRule.getRepository()).isEqualTo(r1.getRepositoryKey());
     assertThat(firstRule.getPluginRuleKey()).isEqualTo(r1.getRuleKey());
     assertThat(firstRule.getName()).isEqualTo(r1.getName());
     assertThat(firstRule.getRuleDescriptionSectionsDtos().stream()
       .filter(s -> s.getKey().equals(ruleDescriptionSectionDto.getKey()))
       .collect(MoreCollectors.onlyElement()))
-      .usingRecursiveComparison()
-      .isEqualTo(ruleDescriptionSectionDto);
+        .usingRecursiveComparison()
+        .isEqualTo(ruleDescriptionSectionDto);
     assertThat(firstRule.getDescriptionFormat()).isEqualTo(r1.getDescriptionFormat());
     assertThat(firstRule.getSeverity()).isEqualTo(r1.getSeverity());
     assertThat(firstRule.getStatus()).isEqualTo(r1.getStatus());
@@ -910,7 +929,6 @@ public class RuleDaoTest {
       .findFirst().orElseThrow();
   }
 
-
   @Test
   public void scrollIndexingRulesByKeys() {
     Accumulator<RuleForIndexingDto> accumulator = new Accumulator<>();