@Test public void indexOnStartup_scrolls_db_and_adds_all_issues_to_index() { IssueDto issue1 = db.issues().insertIssue(organization); IssueDto issue2 = db.issues().insertIssue(organization); underTest.indexOnStartup(emptySet()); assertThatIndexHasOnly(issue1, issue2); }
@Test public void insert_entry_in_changelog_when_setting_tags() { IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "new-tag"); List<FieldDiffs> fieldDiffs = dbClient.issueChangeDao().selectChangelogByIssue(db.getSession(), issueDto.getKey()); assertThat(fieldDiffs).hasSize(1); assertThat(fieldDiffs.get(0).diffs()).hasSize(1); assertThat(fieldDiffs.get(0).diffs().get("tags").oldValue()).isEqualTo("old-tag"); assertThat(fieldDiffs.get(0).diffs().get("tags").newValue()).isEqualTo("new-tag"); }
@SafeVarargs public final IssueDto insertIssue(OrganizationDto organizationDto, Consumer<IssueDto>... populators) { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(organizationDto); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue = newIssue(rule, project, file); stream(populators).forEach(p -> p.accept(issue)); return insertIssue(issue); }
@Test public void delete_unknown_key() { IssueDto issue = db.issues().insertIssue(); db.issues().insertChange(issue); assertThat(underTest.delete(db.getSession(), "UNKNOWN")).isFalse(); }
@Test public void index_is_not_updated_when_creating_project() { // it's impossible to already have an issue on a project // that is being created, but it's just to verify that // indexing is disabled IssueDto issue = db.issues().insertIssue(organization); IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_CREATION); assertThat(result.getTotal()).isEqualTo(0L); assertThatIndexHasSize(0); }
@Test public void insert_entry_in_changelog_when_setting_type() { IssueDto issueDto = issueDbTester.insertIssue(newIssue().setType(CODE_SMELL)); setUserWithBrowseAndAdministerIssuePermission(issueDto); call(issueDto.getKey(), BUG.name()); List<FieldDiffs> fieldDiffs = dbClient.issueChangeDao().selectChangelogByIssue(dbTester.getSession(), issueDto.getKey()); assertThat(fieldDiffs).hasSize(1); assertThat(fieldDiffs.get(0).diffs()).hasSize(1); assertThat(fieldDiffs.get(0).diffs().get("type").newValue()).isEqualTo(BUG.name()); assertThat(fieldDiffs.get(0).diffs().get("type").oldValue()).isEqualTo(CODE_SMELL.name()); }
@Test public void set_tags() { IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "bug", "todo"); verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); verifyContentOfPreloadedSearchResponseData(issueDto); IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issueDto.getKey()).get(); assertThat(issueReloaded.getTags()).containsOnly("bug", "todo"); assertThat(issueChangePostProcessor.wasCalled()).isFalse(); }
@Test public void do_nothing_if_no_new_issue() { db.issues().insertIssue(IssueTesting.newIssue(rule, branch1Dto, fileOnBranch1Dto).setKee("issue1").setStatus(Issue.STATUS_CONFIRMED).setLine(1).setChecksum("checksum")); copier.tryMerge(FILE_1, Collections.emptyList()); verifyZeroInteractions(issueLifecycle); }
@Test public void fail_when_missing_administer_issue_permission() { IssueDto issueDto = issueDbTester.insertIssue(); logInAndAddProjectPermission(issueDto, USER); expectedException.expect(ForbiddenException.class); call(issueDto.getKey(), MAJOR); }
@Test public void update_issue() { DefaultIssue issue = db.issues().insertIssue(i -> i.setSeverity(MAJOR)).toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid"); issueFieldsSetter.setSeverity(issue, BLOCKER, context); underTest.saveIssue(db.getSession(), issue, context, null); IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issue.key()).get(); assertThat(issueReloaded.getSeverity()).isEqualTo(BLOCKER); }
@Test public void delete_comment_using_deprecated_key_parameter() { IssueDto issueDto = issueDbTester.insertIssue(); UserDto user = dbTester.users().insertUser(); IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it"); loginAndAddProjectPermission(user, issueDto, USER); tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute(); verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); assertThat(dbClient.issueChangeDao().selectCommentByKey(dbTester.getSession(), commentDto.getKey())).isNotPresent(); verifyContentOfPreloadedSearchResponseData(issueDto); }
@Test public void tags_are_stored_as_lowercase() { IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "bug", "Convention"); IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issueDto.getKey()).get(); assertThat(issueReloaded.getTags()).containsOnly("bug", "convention"); }
private IssueDto insertIssue() { RuleDto rule = ruleDbTester.insertRule(newRuleDto()); ComponentDto project = componentDbTester.insertPrivateProject(); ComponentDto file = componentDbTester.insertComponent(newFileDto(project)); return issueDbTester.insertIssue(newDto(rule, file, project)); }
@Test public void fail_when_tag_use_bad_format() { IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Tags 'pol op' are invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'"); call(issueDto.getKey(), "pol op"); }
@Test public void changelog_of_file_move_is_empty_when_files_does_not_exists() { IssueDto issueDto = db.issues().insertIssue(newIssue()); userSession.logIn("john") .addMembership(db.getDefaultOrganization()) .addProjectPermission(USER, project, file); db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setDiff("file", "UNKNOWN_1", "UNKNOWN_2").setCreationDate(new Date())); ChangelogWsResponse result = call(issueDto.getKey()); assertThat(result.getChangelogList()).hasSize(1); assertThat(result.getChangelogList().get(0).getDiffsList()).extracting(Diff::getKey, Diff::hasOldValue, Diff::hasNewValue) .containsOnly(tuple("file", false, false)); }
@Test public void fail_if_bad_severity() { IssueDto issueDto = issueDbTester.insertIssue(newIssue().setSeverity("unknown")); setUserWithBrowseAndAdministerIssuePermission(issueDto); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Value of parameter 'severity' (unknown) must be one of: [INFO, MINOR, MAJOR, CRITICAL, BLOCKER]"); call(issueDto.getKey(), "unknown"); }
@Test public void fail_if_bad_type_value() { IssueDto issueDto = issueDbTester.insertIssue(newIssue().setType(CODE_SMELL)); setUserWithBrowseAndAdministerIssuePermission(issueDto); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Value of parameter 'type' (unknown) must be one of: [CODE_SMELL, BUG, VULNERABILITY, SECURITY_HOTSPOT]"); call(issueDto.getKey(), "unknown"); }
@Test public void commitAndIndexIssues_removes_issue_from_index_if_it_does_not_exist_in_db() { IssueDto issue1 = new IssueDto().setKee("I1").setProjectUuid("P1"); addIssueToIndex(issue1.getProjectUuid(), issue1.getKey()); IssueDto issue2 = db.issues().insertIssue(organization); underTest.commitAndIndexIssues(db.getSession(), asList(issue1, issue2)); // issue1 is removed from index, issue2 is persisted and indexed assertThatIndexHasOnly(issue2); assertThatDbHasOnly(issue2); assertThatEsQueueTableHasSize(0); }
@Test public void fail_when_comment_does_not_belong_to_current_user() { IssueDto issueDto = issueDbTester.insertIssue(); UserDto user = dbTester.users().insertUser(); IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it"); UserDto another = dbTester.users().insertUser(); loginWithBrowsePermission(another, USER, issueDto); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("You can only edit your own comments"); call(commentDto.getKey(), "please have a look"); }
@Test public void search_all_issues_when_no_parameter() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); IssueDto issue = db.issues().insertIssue(newIssue(rule, project, projectFile)); allowAnyoneOnProjects(project); indexIssues(); SearchWsResponse result = ws.newRequest().executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).extracting(Issues.Issue::getKey) .containsExactlyInAnyOrder(issue.getKey()); }