import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rule.RuleKey;
-import org.sonar.api.utils.DateUtils;
import org.sonar.batch.scan.LastSnapshots;
import org.sonar.core.issue.db.IssueDto;
import java.io.IOException;
import java.util.Arrays;
-import java.util.Date;
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
public class IssueTrackingTest {
- private final Date analysisDate = DateUtils.parseDate("2013-04-11");
-
IssueTracking tracking;
Resource project;
LastSnapshots lastSnapshots;
<select id="selectByKey" parameterType="String" resultType="Issue">
select
<include refid="issueColumns"/>
- from issues i, rules r, projects p, projects root
- where i.kee=#{kee} and i.rule_id=r.id and p.id=i.component_id and i.root_component_id=root.id
+ from issues i
+ inner join rules r on r.id=i.rule_id
+ inner join projects p on p.id=i.component_id
+ inner join projects root on root.id=i.root_component_id
+ <where>
+ and i.kee=#{kee}
+ </where>
</select>
<select id="selectNonClosedIssuesByModule" parameterType="int" resultType="Issue">
r.plugin_rule_key as ruleKey,
r.plugin_name as ruleRepo,
p.kee as componentKey
- from issues i, rules r, projects p
- where i.status <> 'CLOSED'
- and (p.root_id=#{id} or (p.root_id is null and p.id=#{id}))
- and i.component_id=p.id
- and r.id=i.rule_id
+ from issues i
+ inner join rules r on r.id=i.rule_id
+ inner join (select p.id,p.kee from projects p where (p.root_id=#{id} and p.qualifier <> 'BRC') or (p.id=#{id})) p on p.id=i.component_id
+ <where>
+ and i.status <> 'CLOSED'
+ </where>
</select>
<select id="selectByIds" parameterType="map" resultType="Issue">
select
<include refid="issueColumns"/>
- from issues i, rules r, projects p, projects root
+ from issues i
+ inner join rules r on r.id=i.rule_id
+ inner join projects p on p.id=i.component_id
+ inner join projects root on root.id=i.root_component_id
<where>
and
<foreach collection="ids" open="i.id in (" close=")" item="list" separator=") or i.id in (">
#{element}
</foreach>
</foreach>
- and i.rule_id=r.id
- and p.id=i.component_id
- and i.root_component_id=root.id
</where>
order by i.id desc
</select>
public void should_select_non_closed_issues_by_module() {
setupData("shared", "should_select_non_closed_issues_by_module");
- // 400 is a non-root module
+ // 400 is a non-root module, we should find 2 issues from classes and one on itself
DefaultResultHandler handler = new DefaultResultHandler();
dao.selectNonClosedIssuesByModule(400, handler);
- assertThat(handler.getResultList()).hasSize(2);
+ assertThat(handler.getResultList()).hasSize(3);
IssueDto issue = (IssueDto) handler.getResultList().get(0);
assertThat(issue.getRuleRepo()).isNotNull();
assertThat(issue.getRule()).isNotNull();
assertThat(issue.getComponentKey()).isNotNull();
- // 399 is the root module. It does not have issues.
+ // 399 is the root module, we should only find 1 issue on itself
handler = new DefaultResultHandler();
dao.selectNonClosedIssuesByModule(399, handler);
- assertThat(handler.getResultList()).isEmpty();
-
+ assertThat(handler.getResultList()).hasSize(1);
}
@Test
<dataset>
+ <!-- Open Issue on a file -->
<issues
id="100"
kee="100"
updated_at="[null]"
/>
+ <!-- Open Issue on a file -->
<issues
id="101"
kee="101"
line="120"
effort_to_fix="[null]"
status="OPEN"
- resolution="FIXED"
+ resolution="[null]"
checksum="[null]"
reporter="[null]"
assignee="user"
updated_at="[null]"
/>
+ <!-- Closed Issue on a file -->
<issues
id="102"
kee="102"
updated_at="[null]"
/>
+ <!-- Open Issue on a sub module -->
+ <issues
+ id="103"
+ kee="103"
+ component_id="400"
+ root_component_id="399"
+ rule_id="501"
+ severity="MAJOR"
+ manual_severity="[false]"
+ message="[null]"
+ line="[null]"
+ effort_to_fix="[null]"
+ status="OPEN"
+ resolution="[null]"
+ checksum="[null]"
+ reporter="[null]"
+ assignee="user"
+ author_login="[null]"
+ issue_attributes="[null]"
+ issue_creation_date="2013-04-16"
+ issue_update_date="2013-04-16"
+ issue_close_date="2013-04-16"
+ created_at="2013-04-10"
+ updated_at="[null]"
+ />
+
+ <!-- Open Issue on a root module -->
+ <issues
+ id="104"
+ kee="104"
+ component_id="399"
+ root_component_id="399"
+ rule_id="501"
+ severity="MAJOR"
+ manual_severity="[false]"
+ message="[null]"
+ line="[null]"
+ effort_to_fix="[null]"
+ status="OPEN"
+ resolution="[null]"
+ checksum="[null]"
+ reporter="[null]"
+ assignee="user"
+ author_login="[null]"
+ issue_attributes="[null]"
+ issue_creation_date="2013-04-16"
+ issue_update_date="2013-04-16"
+ issue_close_date="2013-04-16"
+ created_at="2013-04-10"
+ updated_at="[null]"
+ />
+
</dataset>