]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16316 Migrate Quality Profile & Quality Gate queries to Quality Gate & Quality...
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>
Tue, 24 May 2022 07:52:38 +0000 (09:52 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 25 May 2022 20:03:16 +0000 (20:03 +0000)
16 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileFindingDto.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/report/QualityGateFindingDto.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/report/QualityProfileFindingDto.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/report/RegulatoryReportDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/report/RegulatoryReportMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java

index d05ce597cb0228bd6c886562898d3ff32e4723b0..3b1426d8191b21829567666281952593c113e542 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.db.qualitygate;
 import java.util.Collection;
 import java.util.Date;
 import javax.annotation.CheckForNull;
+import org.apache.ibatis.session.ResultHandler;
 import org.sonar.core.util.UuidFactory;
 import org.sonar.db.Dao;
 import org.sonar.db.DatabaseUtils;
@@ -78,6 +79,10 @@ public class QualityGateDao implements Dao {
     mapper(dbSession).ensureOneBuiltInQualityGate(builtInName);
   }
 
+  public void selectQualityGateFindings(DbSession dbSession, String qualityGateUuid, ResultHandler<QualityGateFindingDto> handler) {
+    mapper(dbSession).selectQualityGateFindings(qualityGateUuid, handler);
+  }
+
   public QualityGateDto selectBuiltIn(DbSession dbSession) {
     return mapper(dbSession).selectBuiltIn();
   }
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java
new file mode 100644 (file)
index 0000000..171215f
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * 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.qualitygate;
+
+import javax.annotation.CheckForNull;
+
+public class QualityGateFindingDto {
+  public static final String NEW_CODE_METRIC_PREFIX = "new_";
+
+  private String description = null;
+  private String operator = null;
+  private String kee = null;
+  private Boolean isEnabled = null;
+  private String valueType = null;
+  private Double bestValue = null;
+  private Double worstValue = null;
+  private Boolean optimizedBestValue = null;
+  private String errorThreshold = null;
+  private Integer decimalScale = null;
+
+  private String getOperator() {
+    return operator;
+  }
+
+  public String getDescription() {
+    return description;
+  }
+
+  public String getOperatorDescription() {
+    return OperatorDescription.valueOf(getOperator()).getDescription();
+  }
+
+  public Boolean isNewCodeMetric() {
+    return kee.startsWith(NEW_CODE_METRIC_PREFIX);
+  }
+
+  public boolean isEnabled() {
+    return isEnabled;
+  }
+
+  public String getValueType() {
+    return valueType;
+  }
+
+  @CheckForNull
+  public Double getBestValue() {
+    return bestValue;
+  }
+
+  @CheckForNull
+  public Double getWorstValue() {
+    return worstValue;
+  }
+
+  public String getErrorThreshold() {
+    return errorThreshold;
+  }
+
+  public boolean isOptimizedBestValue() {
+    return optimizedBestValue;
+  }
+
+  @CheckForNull
+  public Integer getDecimalScale() {
+    return decimalScale;
+  }
+
+  public enum OperatorDescription {
+    LT("Is Less Than"),
+    GT("Is Greater Than"),
+    EQ("Is Equal To"),
+    NE("Is Not Equal To");
+
+    private final String desc;
+
+    OperatorDescription(String desc) {
+      this.desc = desc;
+    }
+
+    public String getDescription() {
+      return desc;
+    }
+  }
+}
index ec4901e102b33fe64867d1a15b3f9cdafec59a5c..75f99bf0f4cae10363deb1f9b1114f8f8c80475f 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.db.qualitygate;
 import java.util.Collection;
 import java.util.List;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.ResultHandler;
 
 public interface QualityGateMapper {
 
@@ -41,6 +42,8 @@ public interface QualityGateMapper {
 
   void ensureOneBuiltInQualityGate(String builtInQualityName);
 
+  void selectQualityGateFindings(String qualityGateUuid, ResultHandler<QualityGateFindingDto> handler);
+
   QualityGateDto selectByUuid(String uuid);
 
   QualityGateDto selectDefault();
index 2948705b2a910b5516f75f452fce3f5ae06b7cc0..eab5232a9c24a6d597640c3b889b06d4d019c300 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Map;
 import java.util.Set;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+import org.apache.ibatis.session.ResultHandler;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactory;
 import org.sonar.core.util.stream.MoreCollectors;
@@ -207,6 +208,10 @@ public class QualityProfileDao implements Dao {
     return mapper(dbSession).selectByNameAndLanguages(name, languages);
   }
 
+  public void selectQualityProfileFindings(DbSession dbSession, String qualityProfileUuid, ResultHandler<QualityProfileFindingDto> handler) {
+    mapper(dbSession).selectQualityProfileFindings(qualityProfileUuid, handler);
+  }
+
   public Map<String, Long> countProjectsByProfiles(DbSession dbSession, List<QProfileDto> profiles) {
     List<String> profileUuids = profiles.stream().map(QProfileDto::getKee).collect(MoreCollectors.toList());
     return KeyLongValue.toMap(executeLargeInputs(profileUuids, partition -> mapper(dbSession).countProjectsByProfiles(partition)));
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileFindingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileFindingDto.java
new file mode 100644 (file)
index 0000000..64af7bd
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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.qualityprofile;
+
+import javax.annotation.CheckForNull;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.RuleStatus;
+import org.sonar.api.rules.RuleType;
+import org.sonar.db.rule.SeverityUtil;
+
+public class QualityProfileFindingDto {
+  private String language = null;
+  private String title = null;
+  private String repository = null;
+  private String ruleKey = null;
+  private String status = null;
+  private Integer type = null;
+  private Integer severity = null;
+
+  public String getLanguage() {
+    return language;
+  }
+
+  public String getTitle() {
+    return title;
+  }
+
+  public RuleKey getReferenceKey() {
+    return RuleKey.of(repository, ruleKey);
+  }
+
+  public RuleStatus getStatus() {
+    return RuleStatus.valueOf(status);
+  }
+
+  public RuleType getType() {
+    return RuleType.valueOf(type);
+  }
+
+  @CheckForNull
+  public String getSeverity() {
+    return SeverityUtil.getSeverityFromOrdinal(severity);
+  }
+}
index 96bbb6a7efb153d908fbc20d58109eadb991cff0..3b3333f48943eef0350006717bc89fc0f237e2c9 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Date;
 import java.util.List;
 import javax.annotation.CheckForNull;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.ResultHandler;
 import org.sonar.db.KeyLongValue;
 
 public interface QualityProfileMapper {
@@ -93,6 +94,10 @@ public interface QualityProfileMapper {
 
   List<String> selectQProfileUuidsByProjectUuid(@Param("projectUuid") String projectUuid);
 
+  void selectQualityProfileFindings(
+    @Param("qualityProfileUuid") String qualityProfileUuid,
+    @Param("handler") ResultHandler<QualityProfileFindingDto> handler);
+
   void insertProjectProfileAssociation(
     @Param("uuid") String uuid,
     @Param("projectUuid") String projectUuid,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/report/QualityGateFindingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/report/QualityGateFindingDto.java
deleted file mode 100644 (file)
index 1a21276..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.report;
-
-import javax.annotation.CheckForNull;
-
-public class QualityGateFindingDto {
-  public static final String NEW_CODE_METRIC_PREFIX = "new_";
-
-  private String description = null;
-  private String operator = null;
-  private String kee = null;
-  private Boolean isEnabled = null;
-  private String valueType = null;
-  private Double bestValue = null;
-  private Double worstValue = null;
-  private Boolean optimizedBestValue = null;
-  private String errorThreshold = null;
-  private Integer decimalScale = null;
-
-  private String getOperator() {
-    return operator;
-  }
-
-  public String getDescription() {
-    return description;
-  }
-
-  public String getOperatorDescription() {
-    return OperatorDescription.valueOf(getOperator()).getDescription();
-  }
-
-  public Boolean isNewCodeMetric() {
-    return kee.startsWith(NEW_CODE_METRIC_PREFIX);
-  }
-
-  public boolean isEnabled() {
-    return isEnabled;
-  }
-
-  public String getValueType() {
-    return valueType;
-  }
-
-  @CheckForNull
-  public Double getBestValue() {
-    return bestValue;
-  }
-
-  @CheckForNull
-  public Double getWorstValue() {
-    return worstValue;
-  }
-
-  public String getErrorThreshold() {
-    return errorThreshold;
-  }
-
-  public boolean isOptimizedBestValue() {
-    return optimizedBestValue;
-  }
-
-  @CheckForNull
-  public Integer getDecimalScale() {
-    return decimalScale;
-  }
-
-  public enum OperatorDescription {
-    LT("Is Less Than"),
-    GT("Is Greater Than"),
-    EQ("Is Equal To"),
-    NE("Is Not Equal To");
-
-    private final String desc;
-
-    OperatorDescription(String desc) {
-      this.desc = desc;
-    }
-
-    public String getDescription() {
-      return desc;
-    }
-  }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/report/QualityProfileFindingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/report/QualityProfileFindingDto.java
deleted file mode 100644 (file)
index 43017f1..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.report;
-
-import javax.annotation.CheckForNull;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rule.RuleStatus;
-import org.sonar.api.rules.RuleType;
-import org.sonar.db.rule.SeverityUtil;
-
-public class QualityProfileFindingDto {
-  private String language = null;
-  private String title = null;
-  private String repository = null;
-  private String ruleKey = null;
-  private String status = null;
-  private Integer type = null;
-  private Integer severity = null;
-
-  public String getLanguage() {
-    return language;
-  }
-
-  public String getTitle() {
-    return title;
-  }
-
-  public RuleKey getReferenceKey() {
-    return RuleKey.of(repository, ruleKey);
-  }
-
-  public RuleStatus getStatus() {
-    return RuleStatus.valueOf(status);
-  }
-
-  public RuleType getType() {
-    return RuleType.valueOf(type);
-  }
-
-  @CheckForNull
-  public String getSeverity() {
-    return SeverityUtil.getSeverityFromOrdinal(severity);
-  }
-}
index e7eb4291de1b6439ce4a76a6231563d09cab238a..8c6ca026ef0fa7ce1aea7fd27171ad9984344e11 100644 (file)
@@ -28,16 +28,7 @@ public class RegulatoryReportDao implements Dao {
     mapper(dbSession).scrollIssues(branchUuid, handler);
   }
 
-  public void getQualityGateFindings(DbSession dbSession, String qualityGateUuid, ResultHandler<QualityGateFindingDto> handler) {
-    mapper(dbSession).getQualityGateFindings(qualityGateUuid, handler);
-  }
-
-  public void getQualityProfileFindings(DbSession dbSession, String qualityProfileUuid, ResultHandler<QualityProfileFindingDto> handler) {
-    mapper(dbSession).getQualityProfileFindings(qualityProfileUuid, handler);
-  }
-
   private static RegulatoryReportMapper mapper(DbSession dbSession) {
     return dbSession.getMapper(RegulatoryReportMapper.class);
   }
-
 }
index a73fddc21ddc329b63f57035eb44e4e1da240a27..1a75e22bdcb4db5f8212c75ff0261f9033b7c7cf 100644 (file)
@@ -23,8 +23,4 @@ import org.apache.ibatis.session.ResultHandler;
 
 public interface RegulatoryReportMapper {
   void scrollIssues(String branchUuid, ResultHandler<IssueFindingDto> handler);
-
-  void getQualityGateFindings(String qualityGateUuid, ResultHandler<QualityGateFindingDto> handler);
-
-  void getQualityProfileFindings(String qualityProfileUuid, ResultHandler<QualityProfileFindingDto> handler);
 }
index 0b52c10da77d90821948dd9b642bcdd11ba01fab..2488f9adcfbaff72839947fcaa977d08db398c17 100644 (file)
@@ -2,11 +2,23 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
 
 <mapper namespace="org.sonar.db.qualitygate.QualityGateMapper">
-
   <sql id="gateColumns">
       qg.uuid, qg.name, qg.is_built_in as isBuiltIn, qg.created_at as createdAt, qg.updated_at as updatedAt
   </sql>
 
+  <sql id="qualityGateFindingColumns">
+    m.description as description,
+    qgc.operator as operator,
+    m.name as kee,
+    m.enabled as isEnabled,
+    m.val_type as valueType,
+    m.best_value as bestValue,
+    m.worst_value as worstValue,
+    m.optimized_best_value as optimizedBestValue,
+    qgc.value_error as errorThreshold,
+    m.decimal_scale as decimalScale
+  </sql>
+
   <insert id="insertQualityGate" parameterType="QualityGate" useGeneratedKeys="false">
     insert into quality_gates (uuid, name, is_built_in, created_at, updated_at)
     values (#{uuid, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{isBuiltIn, jdbcType=BOOLEAN}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP})
       and p.user_uuid is null
   </select>
 
+  <select id="selectQualityGateFindings" parameterType="String" resultType="org.sonar.db.qualitygate.QualityGateFindingDto">
+    select
+    <include refid="qualityGateFindingColumns"/>
+    from quality_gates qg
+    left join quality_gate_conditions qgc on qgc.qgate_uuid = qg.uuid
+    left join metrics m on m.uuid = qgc.metric_uuid
+    where qg.uuid=#{qualityGateUuid,jdbcType=VARCHAR}
+  </select>
+
   <update id="delete" parameterType="String">
     delete from quality_gates where uuid=#{uuid}
   </update>
index db706ae4d65b09e4cbad56ff3a09721fee176cfc..c5ca6a87473d51eb4d93a3fb707e858bb61230d3 100644 (file)
     rp.is_built_in as isBuiltIn
   </sql>
 
+  <sql id="qualityProfileFindingColumns">
+    r.language as language,
+    r.name as title,
+    r.plugin_name as repository,
+    r.plugin_rule_key as ruleKey,
+    r.status as status,
+    r.rule_type as type,
+    r.priority as defaultSeverity,
+    ar.failure_level as severity
+  </sql>
+
   <insert id="insertRuleProfile" parameterType="map" useGeneratedKeys="false">
     insert into rules_profiles (
       uuid,
       and rp.is_built_in = ${_false}
   </select>
 
+  <select id="selectQualityProfileFindings" parameterType="String" resultType="org.sonar.db.qualityprofile.QualityProfileFindingDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
+    select
+    <include refid="qualityProfileFindingColumns"/>
+    from rules r
+    left join active_rules ar on ar.rule_uuid = r.uuid
+    inner join org_qprofiles oqp on oqp.rules_profile_uuid = ar.profile_uuid
+    where oqp.uuid=#{qualityProfileUuid,jdbcType=VARCHAR}
+  </select>
+
   <update id="renameRuleProfiles" parameterType="map">
     update rules_profiles
     set
index 50111cac5369190a17a0095e4ba52bb1acecb794..ea6b2bb051fadb5ceb5a431d29e46a855c35ee65 100644 (file)
     </collection>
   </resultMap>
 
-  <sql id="qualityGateFindingColumns">
-    m.description as description,
-    qgc.operator as operator,
-    m.name as kee,
-    m.enabled as isEnabled,
-    m.val_type as valueType,
-    m.best_value as bestValue,
-    m.worst_value as worstValue,
-    m.optimized_best_value as optimizedBestValue,
-    qgc.value_error as errorThreshold,
-    m.decimal_scale as decimalScale
-  </sql>
-
-  <sql id="qualityProfileFindingColumns">
-    r.language as language,
-    r.name as title,
-    r.plugin_name as repository,
-    r.plugin_rule_key as ruleKey,
-    r.status as status,
-    r.rule_type as type,
-    r.priority as defaultSeverity,
-    ar.failure_level as severity
-  </sql>
-
   <sql id="issueColumns">
     i.kee as kee,
     i.severity as severity,
     r.security_standards as securityStandards,
     r.name as ruleName,
     i.issue_creation_date as creationDate,
-
     <include refid="org.sonar.db.issue.IssueMapper.isNewCodeReferenceIssue"/>
   </sql>
 
-  <select id="getQualityGateFindings" parameterType="String" resultType="org.sonar.db.report.QualityGateFindingDto">
-    select
-    <include refid="qualityGateFindingColumns"/>
-    from quality_gates qg
-    left join quality_gate_conditions qgc on qgc.qgate_uuid = qg.uuid
-    left join metrics m on m.uuid = qgc.metric_uuid
-    where qg.uuid=#{qualityGateUuid,jdbcType=VARCHAR}
-  </select>
-
-  <select id="getQualityProfileFindings" parameterType="String" resultType="org.sonar.db.report.QualityProfileFindingDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
-    select
-    <include refid="qualityProfileFindingColumns"/>
-    from rules r
-    left join active_rules ar on ar.rule_uuid = r.uuid
-    inner join org_qprofiles oqp on oqp.rules_profile_uuid = ar.profile_uuid
-    where oqp.uuid=#{qualityProfileUuid,jdbcType=VARCHAR}
-  </select>
-
   <select id="scrollIssues" parameterType="String" resultMap="issueResultMap" resultOrdered="true" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
     select
     <include refid="issueColumns"/>,
index 4adca22600f1429cfd95bf62e1b116ec3dbe2ab1..4225abb47783f0c9f8ab554898963cab9caa0368 100644 (file)
  */
 package org.sonar.db.qualitygate;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.Uuids;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
+import org.sonar.db.component.BranchType;
+import org.sonar.db.metric.MetricDto;
 import org.sonar.db.project.ProjectDto;
 
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.within;
+import static org.sonar.db.qualitygate.QualityGateFindingDto.NEW_CODE_METRIC_PREFIX;
 
 public class QualityGateDaoTest {
 
@@ -116,6 +124,45 @@ public class QualityGateDaoTest {
     assertThat(underTest.selectByProjectUuid(dbSession, "not-existing-uuid")).isNull();
   }
 
+  @Test
+  public void selectQualityGateFindings_returns_all_quality_gate_details_for_project() {
+    ProjectDto project = db.components().insertPublicProjectDto();
+    BranchDto branch = db.components().insertProjectBranch(project).setBranchType(BranchType.BRANCH);
+    QualityGateDto gate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(gate);
+
+    MetricDto metric1 = db.measures().insertMetric(m -> m.setDescription("metric 1 description").setDecimalScale(0));
+    QualityGateConditionDto condition1 = db.qualityGates().addCondition(gate, metric1);
+
+    MetricDto metric2 = db.measures().insertMetric(m -> m.setDescription("metric 2 description").setDecimalScale(1));
+    QualityGateConditionDto condition2 = db.qualityGates().addCondition(gate, metric2);
+
+    MetricDto metric3 = db.measures().insertMetric(m -> m.setDescription("metric 3 description").setDecimalScale(0));
+    QualityGateConditionDto condition3 = db.qualityGates().addCondition(gate, metric3);
+
+    db.qualityGates().associateProjectToQualityGate(project, gate);
+    db.commit();
+
+    List<QualityGateFindingDto> findings = new ArrayList<>();
+    underTest.selectQualityGateFindings(db.getSession(), gate.getUuid(), result -> findings.add(result.getResultObject()));
+
+    QualityGateFindingDto finding = findings.stream().filter(f -> f.getDescription().equals("metric 1 description")).findFirst().get();
+
+    // check fields
+    assertThat(findings).hasSize(3);
+    assertThat(findings.stream().map(f -> f.getDescription()).collect(Collectors.toSet())).containsExactlyInAnyOrder("metric 1 description", "metric 2 description", "metric 3 description");
+    assertThat(finding.getDescription()).isEqualTo(metric1.getDescription());
+    assertThat(finding.getOperatorDescription()).isEqualTo(QualityGateFindingDto.OperatorDescription.valueOf(condition1.getOperator()).getDescription());
+    assertThat(finding.getErrorThreshold()).isEqualTo(condition1.getErrorThreshold());
+    assertThat(finding.getValueType()).isEqualTo(metric1.getValueType());
+    assertThat(finding.isNewCodeMetric()).isEqualTo(metric1.getKey().startsWith(NEW_CODE_METRIC_PREFIX));
+    assertThat(finding.isEnabled()).isEqualTo(metric1.isEnabled());
+    assertThat(finding.getBestValue()).isEqualTo(metric1.getBestValue(), within(0.00001));
+    assertThat(finding.getWorstValue()).isEqualTo(metric1.getWorstValue(), within(0.00001));
+    assertThat(finding.isOptimizedBestValue()).isEqualTo(metric1.isOptimizedBestValue());
+    assertThat(finding.getDecimalScale()).isEqualTo(metric1.getDecimalScale());
+  }
+
   @Test
   public void delete() {
     QualityGateDto qualityGate = qualityGateDbTester.insertQualityGate();
index 2ea5e44292cc041a18b54147bcc45b979cc44e6d..c4b3fc210ca41807dd170fd91ebf20c6a0964c49 100644 (file)
 package org.sonar.db.qualityprofile;
 
 import com.google.common.collect.Sets;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 import org.assertj.core.data.MapEntry;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.RuleType;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.UtcDateUtils;
 import org.sonar.core.util.Uuids;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
+import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.rule.RuleDto;
+import org.sonar.db.rule.SeverityUtil;
 
 import static com.google.common.collect.ImmutableList.of;
 import static com.google.common.collect.Lists.newArrayList;
@@ -399,6 +406,55 @@ public class QualityProfileDaoTest {
     assertThat(result.getRulesProfileUuid()).isEqualTo(profile.getRulesProfileUuid());
   }
 
+  @Test
+  public void selectQualityProfileFindings_returns_all_quality_profile_details_for_project() {
+    String projectUuid = "project_uuid";
+    String projectKey = "project_key";
+    String branchUuid = "branch_uuid";
+    String branchName = "branch";
+
+    BranchDto branch = new BranchDto()
+      .setBranchType(BranchType.BRANCH)
+      .setKey(branchName)
+      .setUuid(branchUuid)
+      .setProjectUuid(projectUuid);
+
+    db.getDbClient().branchDao().insert(db.getSession(), branch);
+
+    ProjectDto project = db.components().insertPublicProjectDto(t -> t.setProjectUuid(projectUuid)
+      .setUuid(projectUuid)
+      .setDbKey(projectKey)
+      .setMainBranchProjectUuid(branchUuid));
+
+    QProfileDto cppQPWithoutActiveRules = db.qualityProfiles().insert(qp -> qp.setIsBuiltIn(true).setLanguage("cpp"));
+    db.qualityProfiles().setAsDefault(cppQPWithoutActiveRules);
+
+    QProfileDto javaBuiltInQPWithActiveRules = db.qualityProfiles().insert(qp -> qp.setIsBuiltIn(true).setLanguage("java"));
+    RuleDto rule1 = db.rules().insert(r -> r.setName("rule 1 title"));
+    ActiveRuleDto activeRule1 = db.qualityProfiles().activateRule(javaBuiltInQPWithActiveRules, rule1);
+    RuleDto rule2 = db.rules().insert(r -> r.setName("rule 2 title"));
+    ActiveRuleDto activeRule2 = db.qualityProfiles().activateRule(javaBuiltInQPWithActiveRules, rule2);
+    RuleDto rule3 = db.rules().insert(r -> r.setName("rule 3 title"));
+    ActiveRuleDto activeRule3 = db.qualityProfiles().activateRule(javaBuiltInQPWithActiveRules, rule3);
+
+    db.qualityProfiles().associateWithProject(project, cppQPWithoutActiveRules, javaBuiltInQPWithActiveRules);
+    db.getSession().commit();
+
+    List<QualityProfileFindingDto> findings = new ArrayList<>();
+    underTest.selectQualityProfileFindings(db.getSession(), javaBuiltInQPWithActiveRules.getKee(), result -> findings.add(result.getResultObject()));
+
+    QualityProfileFindingDto finding = findings.stream().filter(f -> f.getTitle().equals("rule 1 title")).findFirst().get();
+
+    assertThat(findings).hasSize(3);
+    assertThat(findings.stream().map(f -> f.getTitle()).collect(Collectors.toSet())).containsExactlyInAnyOrder("rule 1 title", "rule 2 title", "rule 3 title");
+    assertThat(finding.getLanguage()).isEqualTo(rule1.getLanguage());
+    assertThat(finding.getTitle()).isEqualTo(rule1.getName());
+    assertThat(finding.getReferenceKey()).isEqualTo(RuleKey.of(rule1.getRepositoryKey(), rule1.getRuleKey()));
+    assertThat(finding.getStatus()).isEqualTo(rule1.getStatus());
+    assertThat(finding.getType()).isEqualTo(RuleType.valueOf(rule1.getType()));
+    assertThat(finding.getSeverity()).isEqualTo(SeverityUtil.getSeverityFromOrdinal(activeRule1.getSeverity()));
+  }
+
   @Test
   public void should_not_selectByLanguage_with_wrong_language() {
     QProfileDto profile = QualityProfileTesting.newQualityProfileDto();
index e2e96733c50471b11a60bc71eda74c26c85c2a70..e500e8bfa13854566a3f370195d73e0da2a2ff26 100644 (file)
@@ -21,34 +21,18 @@ package org.sonar.db.report;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.stream.Collectors;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rules.RuleType;
 import org.sonar.api.utils.System2;
-import org.sonar.core.util.UuidFactoryFast;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.BranchDto;
-import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.issue.IssueDto;
-import org.sonar.db.metric.MetricDto;
-import org.sonar.db.project.ProjectDto;
-import org.sonar.db.qualitygate.QualityGateConditionDto;
-import org.sonar.db.qualitygate.QualityGateDto;
-import org.sonar.db.qualityprofile.ActiveRuleDto;
-import org.sonar.db.qualityprofile.QProfileDto;
 import org.sonar.db.rule.RuleDto;
-import org.sonar.db.rule.SeverityUtil;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.AssertionsForClassTypes.within;
 import static org.sonar.api.issue.Issue.RESOLUTION_WONT_FIX;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.report.QualityGateFindingDto.NEW_CODE_METRIC_PREFIX;
 
 public class RegulatoryReportDaoTest {
   private static final String PROJECT_UUID = "prj_uuid";
@@ -73,94 +57,6 @@ public class RegulatoryReportDaoTest {
     file = db.components().insertComponent(newFileDto(project).setUuid(FILE_UUID).setDbKey(FILE_KEY));
   }
 
-  @Test
-  public void getQualityGateFindings_returns_all_quality_gate_details_for_project() {
-    ProjectDto project = db.components().insertPublicProjectDto();
-    BranchDto branch = db.components().insertProjectBranch(project).setBranchType(BranchType.BRANCH);
-    QualityGateDto gate = db.qualityGates().insertQualityGate();
-    db.qualityGates().setDefaultQualityGate(gate);
-
-    MetricDto metric1 = db.measures().insertMetric(m -> m.setDescription("metric 1 description").setDecimalScale(0));
-    QualityGateConditionDto condition1 = db.qualityGates().addCondition(gate, metric1);
-
-    MetricDto metric2 = db.measures().insertMetric(m -> m.setDescription("metric 2 description").setDecimalScale(1));
-    QualityGateConditionDto condition2 = db.qualityGates().addCondition(gate, metric2);
-
-    MetricDto metric3 = db.measures().insertMetric(m -> m.setDescription("metric 3 description").setDecimalScale(0));
-    QualityGateConditionDto condition3 = db.qualityGates().addCondition(gate, metric3);
-
-    db.qualityGates().associateProjectToQualityGate(project, gate);
-    db.commit();
-
-    List<QualityGateFindingDto> findings = new ArrayList<>();
-    underTest.getQualityGateFindings(db.getSession(), gate.getUuid(), result -> findings.add(result.getResultObject()));
-
-    QualityGateFindingDto finding = findings.stream().filter(f -> f.getDescription().equals("metric 1 description")).findFirst().get();
-
-    // check fields
-    assertThat(findings).hasSize(3);
-    assertThat(findings.stream().map(f -> f.getDescription()).collect(Collectors.toSet())).containsExactlyInAnyOrder("metric 1 description", "metric 2 description", "metric 3 description");
-    assertThat(finding.getDescription()).isEqualTo(metric1.getDescription());
-    assertThat(finding.getOperatorDescription()).isEqualTo(QualityGateFindingDto.OperatorDescription.valueOf(condition1.getOperator()).getDescription());
-    assertThat(finding.getErrorThreshold()).isEqualTo(condition1.getErrorThreshold());
-    assertThat(finding.getValueType()).isEqualTo(metric1.getValueType());
-    assertThat(finding.isNewCodeMetric()).isEqualTo(metric1.getKey().startsWith(NEW_CODE_METRIC_PREFIX));
-    assertThat(finding.isEnabled()).isEqualTo(metric1.isEnabled());
-    assertThat(finding.getBestValue()).isEqualTo(metric1.getBestValue(), within(0.00001));
-    assertThat(finding.getWorstValue()).isEqualTo(metric1.getWorstValue(), within(0.00001));
-    assertThat(finding.isOptimizedBestValue()).isEqualTo(metric1.isOptimizedBestValue());
-    assertThat(finding.getDecimalScale()).isEqualTo(metric1.getDecimalScale());
-  }
-
-  @Test
-  public void getQualityProfileFindings_returns_all_quality_profile_details_for_project() {
-    String projectUuid = "project_uuid";
-    String projectKey = "project_key";
-    String branchUuid = "branch_uuid";
-    String branchName = "branch";
-
-    BranchDto branch = new BranchDto()
-      .setBranchType(BranchType.BRANCH)
-      .setKey(branchName)
-      .setUuid(branchUuid)
-      .setProjectUuid(projectUuid);
-
-    db.getDbClient().branchDao().insert(db.getSession(), branch);
-
-    ProjectDto project = db.components().insertPublicProjectDto(t -> t.setProjectUuid(projectUuid)
-      .setUuid(projectUuid)
-      .setDbKey(projectKey)
-      .setMainBranchProjectUuid(branchUuid));
-
-    QProfileDto cppQPWithoutActiveRules = db.qualityProfiles().insert(qp -> qp.setIsBuiltIn(true).setLanguage("cpp"));
-    db.qualityProfiles().setAsDefault(cppQPWithoutActiveRules);
-
-    QProfileDto javaBuiltInQPWithActiveRules = db.qualityProfiles().insert(qp -> qp.setIsBuiltIn(true).setLanguage("java"));
-    RuleDto rule1 = db.rules().insert(r -> r.setName("rule 1 title"));
-    ActiveRuleDto activeRule1 = db.qualityProfiles().activateRule(javaBuiltInQPWithActiveRules, rule1);
-    RuleDto rule2 = db.rules().insert(r -> r.setName("rule 2 title"));
-    ActiveRuleDto activeRule2 = db.qualityProfiles().activateRule(javaBuiltInQPWithActiveRules, rule2);
-    RuleDto rule3 = db.rules().insert(r -> r.setName("rule 3 title"));
-    ActiveRuleDto activeRule3 = db.qualityProfiles().activateRule(javaBuiltInQPWithActiveRules, rule3);
-
-    db.qualityProfiles().associateWithProject(project, cppQPWithoutActiveRules, javaBuiltInQPWithActiveRules);
-    db.getSession().commit();
-
-    List<QualityProfileFindingDto> findings = new ArrayList<>();
-    underTest.getQualityProfileFindings(db.getSession(), javaBuiltInQPWithActiveRules.getKee(), result -> findings.add(result.getResultObject()));
-
-    QualityProfileFindingDto finding = findings.stream().filter(f -> f.getTitle().equals("rule 1 title")).findFirst().get();
-
-    assertThat(findings).hasSize(3);
-    assertThat(findings.stream().map(f -> f.getTitle()).collect(Collectors.toSet())).containsExactlyInAnyOrder("rule 1 title", "rule 2 title", "rule 3 title");
-    assertThat(finding.getLanguage()).isEqualTo(rule1.getLanguage());
-    assertThat(finding.getTitle()).isEqualTo(rule1.getName());
-    assertThat(finding.getReferenceKey()).isEqualTo(RuleKey.of(rule1.getRepositoryKey(), rule1.getRuleKey()));
-    assertThat(finding.getStatus()).isEqualTo(rule1.getStatus());
-    assertThat(finding.getType()).isEqualTo(RuleType.valueOf(rule1.getType()));
-    assertThat(finding.getSeverity()).isEqualTo(SeverityUtil.getSeverityFromOrdinal(activeRule1.getSeverity()));
-  }
-
   @Test
   public void scrollIssues_returns_all_non_closed_issues_for_project() {
     IssueDto issue1 = db.issues().insertIssue(rule, project, file, i -> i.setStatus("OPEN").setResolution(null));