@Test public void should_not_sort_with_null_sort() { IssueDto issue1 = new IssueDto().setId(1L).setAssigneeUuid("perceval"); IssueDto issue2 = new IssueDto().setId(2L).setAssigneeUuid("arthur"); IssueDto issue3 = new IssueDto().setId(3L).setAssigneeUuid("vincent"); IssueDto issue4 = new IssueDto().setId(4L).setAssigneeUuid(null); List<IssueDto> dtoList = newArrayList(issue1, issue2, issue3, issue4); IssueQuery query = IssueQuery.builder().sort(null).build(); IssuesFinderSort issuesFinderSort = new IssuesFinderSort(dtoList, query); List<IssueDto> result = newArrayList(issuesFinderSort.sort()); assertThat(result).hasSize(4); assertThat(result.get(0).getAssigneeUuid()).isEqualTo("perceval"); assertThat(result.get(1).getAssigneeUuid()).isEqualTo("arthur"); assertThat(result.get(2).getAssigneeUuid()).isEqualTo("vincent"); assertThat(result.get(3).getAssigneeUuid()).isNull(); }
@Test public void set_assignee() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(); UserDto user = db.users().insertUser(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(user.getUuid())); NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true); IntStream.rangeClosed(1, 5).forEach(i -> stats.add(issue.toDefaultIssue())); underTest.setStatistics(project.longName(), stats); assertThat(underTest.getFieldValue(ASSIGNEE + ".1.label")).isEqualTo(user.getName()); assertThat(underTest.getFieldValue(ASSIGNEE + ".1.count")).isEqualTo("5"); }
RuleDefinitionDto rule = db.rules().insert(); NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true); IntStream.rangeClosed(1, 10).forEach(i -> stats.add(db.issues().insert(rule, project, file, issue -> issue.setAssigneeUuid(user1.getUuid())).toDefaultIssue())); IntStream.rangeClosed(1, 9).forEach(i -> stats.add(db.issues().insert(rule, project, file, issue -> issue.setAssigneeUuid(user2.getUuid())).toDefaultIssue())); IntStream.rangeClosed(1, 8).forEach(i -> stats.add(db.issues().insert(rule, project, file, issue -> issue.setAssigneeUuid(user3.getUuid())).toDefaultIssue())); IntStream.rangeClosed(1, 7).forEach(i -> stats.add(db.issues().insert(rule, project, file, issue -> issue.setAssigneeUuid(user4.getUuid())).toDefaultIssue())); IntStream.rangeClosed(1, 6).forEach(i -> stats.add(db.issues().insert(rule, project, file, issue -> issue.setAssigneeUuid(user5.getUuid())).toDefaultIssue())); IntStream.rangeClosed(1, 5).forEach(i -> stats.add(db.issues().insert(rule, project, file, issue -> issue.setAssigneeUuid(user6.getUuid())).toDefaultIssue())); IntStream.rangeClosed(1, 4).forEach(i -> stats.add(db.issues().insert(rule, project, file, issue -> issue.setAssigneeUuid(user7.getUuid())).toDefaultIssue())); IntStream.rangeClosed(1, 3).forEach(i -> stats.add(db.issues().insert(rule, project, file, issue -> issue.setAssigneeUuid(user8.getUuid())).toDefaultIssue()));
@Test public void verify_notification() { UserDto assignee = db.users().insertUser(); RuleDto rule = db.rules().insertRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file) .setType(randomTypeExceptHotspot)) .setSeverity(MAJOR) .setAssigneeUuid(assignee.getUuid()) .toDefaultIssue(); UserDto changeAuthor = db.users().insertUser(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid()); issueFieldsSetter.setSeverity(issue, BLOCKER, context); underTest.saveIssue(db.getSession(), issue, context, "increase severity"); verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture()); IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue(); assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key()); assertThat(issueChangeNotification.getFieldValue("old.severity")).isEqualTo(MAJOR); assertThat(issueChangeNotification.getFieldValue("new.severity")).isEqualTo(BLOCKER); assertThat(issueChangeNotification.getFieldValue("componentKey")).isEqualTo(file.getDbKey()); assertThat(issueChangeNotification.getFieldValue("componentName")).isEqualTo(file.longName()); assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.getDbKey()); assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.name()); assertThat(issueChangeNotification.getFieldValue("ruleName")).isEqualTo(rule.getName()); assertThat(issueChangeNotification.getFieldValue("changeAuthor")).isEqualTo(changeAuthor.getLogin()); assertThat(issueChangeNotification.getFieldValue("comment")).isEqualTo("increase severity"); assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(assignee.getLogin()); }
.setLine(10) .setChecksum("ABC") .setAssigneeUuid(user.getUuid())); addPermissionTo(project);
private IssueDto newIssue(String assignee) { IssueDto issue = db.issues().insertIssue( issueDto -> issueDto .setAssigneeUuid(assignee) .setCreatedAt(PAST).setIssueCreationTime(PAST) .setUpdatedAt(PAST).setIssueUpdateTime(PAST) .setType(RuleType.CODE_SMELL)); return issue; }
@Test public void should_reload_issue_and_resolve_conflict() { DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setType(CODE_SMELL) .setRuleKey(RuleKey.of("squid", "AvoidCycles")) .setProjectUuid("U1") .setComponentUuid("U2") .setNew(false) .setStatus(STATUS_OPEN); // Issue as seen and changed by end-user IssueMapper mapper = mock(IssueMapper.class); IssueDto issueDto = new IssueDto() .setKee("ABCDE") .setType(CODE_SMELL) .setRuleId(10) .setRuleKey("squid", "AvoidCycles") .setProjectUuid("U1") .setComponentUuid("U2") .setLine(10) .setStatus(STATUS_OPEN) // field changed by user .setAssigneeUuid("arthur-uuid"); new UpdateConflictResolver().resolve(issue, issueDto, mapper); ArgumentCaptor<IssueDto> argument = ArgumentCaptor.forClass(IssueDto.class); verify(mapper).update(argument.capture()); IssueDto updatedIssue = argument.getValue(); assertThat(updatedIssue.getKee()).isEqualTo("ABCDE"); assertThat(updatedIssue.getAssigneeUuid()).isEqualTo("arthur-uuid"); }
@Test public void verify_notification_when_assignee_has_changed() { UserDto oldAssignee = db.users().insertUser(); RuleDto rule = db.rules().insertRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file) .setType(randomTypeExceptHotspot)) .setAssigneeUuid(oldAssignee.getUuid()) .toDefaultIssue(); UserDto changeAuthor = db.users().insertUser(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid()); UserDto newAssignee = db.users().insertUser(); issueFieldsSetter.assign(issue, newAssignee, context); underTest.saveIssue(db.getSession(), issue, context, null); verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture()); IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue(); assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key()); assertThat(issueChangeNotification.getFieldValue("new.assignee")).isEqualTo(newAssignee.getName()); assertThat(issueChangeNotification.getFieldValue("old.assignee")).isNull(); assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(newAssignee.getLogin()); }
.setType(RuleType.CODE_SMELL) .setEffort(10L) .setAssigneeUuid(null)); indexPermissions(); indexIssues();
@Test public void assigned_to_me_facet_is_sticky_relative_to_assignees() { ComponentDto project = db.components().insertPublicProject(); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(); UserDto john = db.users().insertUser(); UserDto alice = db.users().insertUser(); db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(john.getUuid())); db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(alice.getUuid())); db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(null)); indexIssues(); userSession.logIn(john); SearchWsResponse response = ws.newRequest() .setParam("resolved", "false") .setParam("assignees", alice.getLogin()) .setParam(FACETS, "assignees,assigned_to_me") .executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder( tuple("assignees", of(john.getLogin(), 1L, alice.getLogin(), 1L, "", 1L)), tuple("assigned_to_me", of(john.getLogin(), 1L))); }
.setType(RuleType.CODE_SMELL) .setEffort(10L) .setAssigneeUuid(user.getUuid())); indexPermissions(); indexIssues();
@Test public void verify_no_notification_on_hotspot() { UserDto assignee = db.users().insertUser(); RuleDto rule = db.rules().insertRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file) .setType(RuleType.SECURITY_HOTSPOT)) .setSeverity(MAJOR) .setAssigneeUuid(assignee.getUuid()) .toDefaultIssue(); UserDto changeAuthor = db.users().insertUser(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid()); issueFieldsSetter.setSeverity(issue, BLOCKER, context); underTest.saveIssue(db.getSession(), issue, context, "increase severity"); verify(notificationManager, never()).scheduleForSending(any()); }
@Test public void remove_assignee() { UserDto user = db.users().insertUser(); userSession.logIn(user); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); RuleDefinitionDto rule = db.rules().insert(); UserDto assignee = db.users().insertUser(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(assignee.getUuid()) .setStatus(STATUS_OPEN).setResolution(null)); BulkChangeWsResponse response = call(builder() .setIssues(singletonList(issue.getKey())) .setAssign("") .build()); checkResponse(response, 1, 1, 0, 0); IssueDto reloaded = getIssueByKeys(issue.getKey()).get(0); assertThat(reloaded.getAssigneeUuid()).isNull(); assertThat(reloaded.getUpdatedAt()).isEqualTo(NOW); // no need to refresh measures verifyPostProcessorNotCalled(); }
@Test public void load_additional_fields() { UserDto simon = db.users().insertUser(u -> u.setLogin("simon").setName("Simon").setEmail("simon@email.com")); ComponentDto project = db.components().insertPublicProject(); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule().getDefinition(); db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(simon.getUuid())); indexIssues(); userSession.logIn("john"); ws.newRequest() .setParam("additionalFields", "_all").execute() .assertJson(this.getClass(), "load_additional_fields.json"); }
@Test public void apply_paging_with_one_component() { RuleDto rule = newRule(); OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org-2")); ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto(organization, "PROJECT_ID").setDbKey("PROJECT_KEY")); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); for (int i = 0; i < SearchOptions.MAX_LIMIT + 1; i++) { IssueDto issue = newDto(rule, file, project).setAssigneeUuid(null); dbClient.issueDao().insert(session, issue); } session.commit(); indexIssues(); ws.newRequest().setParam(PARAM_COMPONENTS, file.getDbKey()).execute() .assertJson(this.getClass(), "apply_paging_with_one_component.json"); }
@Test public void deprecated_paging() { RuleDto rule = newRule(); OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org-1")); ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto(organization, "PROJECT_ID").setDbKey("PROJECT_KEY")); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); for (int i = 0; i < 12; i++) { IssueDto issue = newDto(rule, file, project).setAssigneeUuid(null); dbClient.issueDao().insert(session, issue); } session.commit(); indexIssues(); ws.newRequest() .setParam(PARAM_PAGE_INDEX, "2") .setParam(PARAM_PAGE_SIZE, "9") .execute() .assertJson(this.getClass(), "deprecated_paging.json"); }
db.organizations().addMember(db.getDefaultOrganization(), userToAssign); IssueDto issue1 = db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(oldAssignee.getUuid())).setType(BUG).setSeverity(MINOR).setStatus(STATUS_OPEN).setResolution(null); IssueDto issue2 = db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(userToAssign.getUuid())).setType(BUG).setSeverity(MAJOR).setStatus(STATUS_OPEN).setResolution(null); IssueDto issue3 = db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(null)).setType(VULNERABILITY).setSeverity(MAJOR).setStatus(STATUS_OPEN).setResolution(null);
.setSeverity("MAJOR") .setAuthorLogin("John") .setAssigneeUuid(simon.getUuid()) .setTags(asList("bug", "owasp")) .setIssueCreationDate(parseDate("2014-09-03"))
@Test public void load_additional_fields_with_issue_admin_permission() { UserDto simon = db.users().insertUser(u -> u.setLogin("simon").setName("Simon").setEmail("simon@email.com")); UserDto fabrice = db.users().insertUser(u -> u.setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com")); OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org-1")); ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto(organization, "PROJECT_ID").setDbKey("PROJECT_KEY").setLanguage("java")); grantPermissionToAnyone(project, ISSUE_ADMIN); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY").setLanguage("js")); IssueDto issue = newDto(newRule(), file, project) .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setAuthorLogin(fabrice.getLogin()) .setAssigneeUuid(simon.getUuid()); dbClient.issueDao().insert(session, issue); session.commit(); indexIssues(); userSession.logIn("john") .addProjectPermission(ISSUE_ADMIN, project); // granted by Anyone ws.newRequest() .setParam("additionalFields", "_all").execute() .assertJson(this.getClass(), "load_additional_fields_with_issue_admin_permission.json"); }
.setChecksum(issue.checksum()) .setManualSeverity(issue.manualSeverity()) .setAssigneeUuid(issue.assignee()) .setIssueAttributes(KeyValueFormat.format(issue.attributes())) .setAuthorLogin(issue.authorLogin())