import org.sonar.db.protobuf.DbIssues;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleTesting;
+import org.sonar.db.user.UserDto;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
private static final String ISSUE_KEY1 = "I1";
private static final String ISSUE_KEY2 = "I2";
private static final String TEST_CONTEXT_KEY = "test_context_key";
+ private static final String USER_LOGIN = "user_login";
private static final RuleType[] RULE_TYPES_EXCEPT_HOTSPOT = Stream.of(RuleType.values())
.filter(r -> r != RuleType.SECURITY_HOTSPOT)
private final IssueDao underTest = db.getDbClient().issueDao();
private ComponentDto projectDto;
+ private UserDto userDto;
@Before
public void setup() {
db.rules().insert(RULE.setIsExternal(true));
projectDto = db.components().insertPrivateProject(t -> t.setUuid(PROJECT_UUID).setKey(PROJECT_KEY)).getMainBranchComponent();
db.components().insertComponent(newFileDto(projectDto).setUuid(FILE_UUID).setKey(FILE_KEY));
+ userDto = db.users().insertUser(USER_LOGIN);
}
@Test
.setResolution("FIXED")
.setChecksum("123456789")
.setAuthorLogin("morgan")
- .setAssigneeUuid("karadoc")
+ .setAssigneeUuid(userDto.getUuid())
+ .setAssigneeLogin(USER_LOGIN)
.setCreatedAt(1_440_000_000_000L)
.setUpdatedAt(1_440_000_000_000L)
.setRule(RULE)
List<IssueDto> issues = underTest.selectByKeys(db.getSession(), asList("I1", "I2", "I3"));
assertThat(issues).extracting(IssueDto::getKey).containsExactlyInAnyOrder("I1", "I2");
+ assertThat(issues).filteredOn(issueDto -> issueDto.getKey().equals("I1"))
+ .extracting(IssueDto::getAssigneeLogin)
+ .containsExactly(USER_LOGIN);
assertThat(issues).filteredOn(issueDto -> issueDto.getKey().equals("I1"))
.extracting(IssueDto::getImpacts)
.flatMap(issueImpactDtos -> issueImpactDtos)
tuple("issueB1", STATUS_RESOLVED));
}
- @Test
- public void selectByComponentUuidPaginated() {
- // contains I1 and I2
- prepareTables();
-
- List<IssueDto> issues = underTest.selectByComponentUuidPaginated(db.getSession(), PROJECT_UUID, 1);
-
- // results are not ordered, so do not use "containsExactly"
- assertThat(issues).extracting("key").containsOnly("I1", "I2");
- }
-
@Test
public void selectOpenByComponentUuid() {
RuleDto rule = db.rules().insert();
.setRuleUuid(RULE.getUuid())
.setComponentUuid(FILE_UUID)
.setProjectUuid(PROJECT_UUID)
+ .setAssigneeUuid(userDto.getUuid())
.addImpact(newIssueImpact(RELIABILITY, MEDIUM))
.addImpact(newIssueImpact(SECURITY, LOW)));
underTest.insert(db.getSession(), newIssueDto(ISSUE_KEY2)
<select id="selectByKeys" parameterType="map" resultMap="issueResultMap">
select
- <include refid="issueColumns"/>
+ <include refid="issueColumns"/>,
+ u.login as assigneeLogin
from issues i
inner join rules r on r.uuid=i.rule_uuid
inner join components p on p.uuid=i.component_uuid
inner join components root on root.uuid=i.project_uuid
+ left join users u on i.assignee = u.uuid
left join new_code_reference_issues n on i.kee = n.issue_key
left outer join issues_impacts ii on i.kee = ii.issue_key
left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
<include refid="org.sonar.db.common.Common.pagination"/>
</select>
- <select id="selectByComponentUuidPaginated" parameterType="map" resultMap="issueResultMap">
- select
- <include refid="issueColumns"/>,
- u.login as assigneeLogin
- from issues i
- inner join rules r on r.uuid=i.rule_uuid
- inner join components p on p.uuid=i.component_uuid
- inner join components root on root.uuid=i.project_uuid
- left join users u on i.assignee = u.uuid
- left join new_code_reference_issues n on i.kee = n.issue_key
- left outer join issues_impacts ii on i.kee = ii.issue_key
- left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
- where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
- order by i.issue_creation_date ASC
- <include refid="org.sonar.db.common.Common.pagination"/>
- </select>
-
<sql id="selectByBranchColumns">
i.kee as kee,
i.rule_uuid as ruleUuid,