@Test public void merge_confirmed_issues() { db.issues().insertIssue(IssueTesting.newIssue(rule, branch1Dto, fileOnBranch1Dto).setKee("issue1").setStatus(Issue.STATUS_CONFIRMED).setLine(1).setChecksum("checksum")); DefaultIssue newIssue = createIssue("issue2", rule.getKey(), Issue.STATUS_OPEN, null, new Date()); copier.tryMerge(FILE_1, Collections.singleton(newIssue)); ArgumentCaptor<DefaultIssue> issueToMerge = ArgumentCaptor.forClass(DefaultIssue.class); verify(issueLifecycle).mergeConfirmedOrResolvedFromShortLivingBranch(eq(newIssue), issueToMerge.capture(), eq("myBranch1")); assertThat(issueToMerge.getValue().key()).isEqualTo("issue1"); }
@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"); }
@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 prefer_confirmed_issues_if_no_resolved() { db.issues().insertIssue(IssueTesting.newIssue(rule, branch1Dto, fileOnBranch1Dto).setKee("issue1").setStatus(Issue.STATUS_REOPENED).setLine(1).setChecksum("checksum")); db.issues().insertIssue(IssueTesting.newIssue(rule, branch2Dto, fileOnBranch2Dto).setKee("issue2").setStatus(Issue.STATUS_OPEN).setLine(1).setChecksum("checksum")); db.issues().insertIssue(IssueTesting.newIssue(rule, branch3Dto, fileOnBranch3Dto).setKee("issue3").setStatus(Issue.STATUS_CONFIRMED).setLine(1).setChecksum("checksum")); DefaultIssue newIssue = createIssue("newIssue", rule.getKey(), Issue.STATUS_OPEN, null, new Date()); copier.tryMerge(FILE_1, Collections.singleton(newIssue)); ArgumentCaptor<DefaultIssue> issueToMerge = ArgumentCaptor.forClass(DefaultIssue.class); verify(issueLifecycle).mergeConfirmedOrResolvedFromShortLivingBranch(eq(newIssue), issueToMerge.capture(), eq("myBranch3")); assertThat(issueToMerge.getValue().key()).isEqualTo("issue3"); }
@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 prefer_resolved_issues() { db.issues().insertIssue(IssueTesting.newIssue(rule, branch1Dto, fileOnBranch1Dto).setKee("issue1").setStatus(Issue.STATUS_REOPENED).setLine(1).setChecksum("checksum")); db.issues().insertIssue(IssueTesting.newIssue(rule, branch2Dto, fileOnBranch2Dto).setKee("issue2").setStatus(Issue.STATUS_CONFIRMED).setLine(1).setChecksum("checksum")); db.issues().insertIssue(IssueTesting.newIssue(rule, branch3Dto, fileOnBranch3Dto).setKee("issue3").setStatus(Issue.STATUS_RESOLVED) .setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setLine(1).setChecksum("checksum")); DefaultIssue newIssue = createIssue("newIssue", rule.getKey(), Issue.STATUS_OPEN, null, new Date()); copier.tryMerge(FILE_1, Collections.singleton(newIssue)); ArgumentCaptor<DefaultIssue> issueToMerge = ArgumentCaptor.forClass(DefaultIssue.class); verify(issueLifecycle).mergeConfirmedOrResolvedFromShortLivingBranch(eq(newIssue), issueToMerge.capture(), eq("myBranch3")); assertThat(issueToMerge.getValue().key()).isEqualTo("issue3"); }
@Test public void remove_existing_tags_when_value_is_not_set() { IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey()); IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issueDto.getKey()).get(); assertThat(issueReloaded.getTags()).isEmpty(); assertThat(issueChangePostProcessor.wasCalled()).isFalse(); }
@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 do_transition() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null)); DefaultIssue defaultIssue = issue.toDefaultIssue(); boolean result = underTest.doTransition(defaultIssue, IssueChangeContext.createUser(new Date(), "user_uuid"), "confirm"); assertThat(result).isTrue(); assertThat(defaultIssue.status()).isEqualTo(STATUS_CONFIRMED); }
@Test public void return_only_open_project_issues_if_no_modules_and_folders() { ComponentDto file = dbTester.components().insertComponent(newFileDto(rootProjectDto)); IssueDto openIssueOnProject = dbTester.issues().insert(rule, rootProjectDto, rootProjectDto, i -> i.setStatus("OPEN").setResolution(null)); IssueDto closedIssueOnProject = dbTester.issues().insert(rule, rootProjectDto, rootProjectDto, i -> i.setStatus("CLOSED").setResolution("FIXED")); IssueDto openIssue1OnFile = dbTester.issues().insert(rule, rootProjectDto, file, i -> i.setStatus("OPEN").setResolution(null)); assertThat(underTest.loadIssues()).extracting(DefaultIssue::key).containsOnly(openIssueOnProject.getKey()); }
@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"); }
@Test public void fail_when_missing_browse_permission() { IssueDto issueDto = db.issues().insertIssue(); logInAndAddProjectPermission(issueDto, ISSUE_ADMIN); expectedException.expect(ForbiddenException.class); call(issueDto.getKey(), "bug"); }
private ComponentDto insertProjectWithBranchAndRelatedData() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); ComponentDto module = db.components().insertComponent(newModuleDto(branch)); ComponentDto subModule = db.components().insertComponent(newModuleDto(module)); ComponentDto file = db.components().insertComponent(newFileDto(subModule)); db.issues().insert(rule, branch, file); db.issues().insert(rule, branch, subModule); db.issues().insert(rule, branch, module); return project; }
@Test public void fail_when_not_enough_permission() { IssueDto issueDto = db.issues().insertIssue(newIssue()); userSession.logIn("john").addProjectPermission(CODEVIEWER, project, file); expectedException.expect(ForbiddenException.class); call(issueDto.getKey()); }
@Test public void json_example() { ComponentDto project = db.components().insertPrivateProject(); permissionIndexer.allowOnlyAnyone(project); RuleDefinitionDto rule = db.rules().insert(); db.issues().insert(rule, project, project, issue -> issue.setAuthorLogin("luke.skywalker")); db.issues().insert(rule, project, project, issue -> issue.setAuthorLogin("leia.organa")); issueIndexer.indexOnStartup(emptySet()); userSession.logIn().addMembership(db.getDefaultOrganization()); String result = ws.newRequest().execute().getInput(); assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString()); }
@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 do_transition_fail_on_external_issue() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto externalRule = db.rules().insert(r -> r.setIsExternal(true)); IssueDto externalIssue = db.issues().insert(externalRule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null)); DefaultIssue defaultIssue = externalIssue.toDefaultIssue(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Transition is not allowed on issues imported from external rule engines"); underTest.doTransition(defaultIssue, IssueChangeContext.createUser(new Date(), "user_uuid"), "confirm"); } }
@Test public void fail_when_trying_to_assign_hotspot() { IssueDto issueDto = db.issues().insertIssue(i -> i.setType(RuleType.SECURITY_HOTSPOT)); setUserWithBrowsePermission(issueDto); UserDto arthur = insertUser("arthur"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("It is not allowed to assign a security hotspot"); ws.newRequest() .setParam("issue", issueDto.getKey()) .setParam("assignee", "arthur") .execute(); }
@Test public void fail_if_no_transition_param() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null)); userSession.logIn().addProjectPermission(USER, project, file); expectedException.expect(IllegalArgumentException.class); call(issue.getKey(), null); }
@Test public void fail_if_external_issue() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto externalRule = db.rules().insert(r -> r.setIsExternal(true)); IssueDto externalIssue = db.issues().insert(externalRule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null)); userSession.logIn().addProjectPermission(USER, project, file); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Transition is not allowed on issues imported from external rule engines"); call(externalIssue.getKey(), "confirm"); }