@@ -38,7 +38,6 @@ import org.junit.runner.RunWith; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.issue.Issue; | |||
import org.sonar.api.rules.RuleType; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.core.issue.DefaultIssue; | |||
import org.sonar.core.issue.FieldDiffs; | |||
@@ -57,6 +56,7 @@ import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verifyZeroInteractions; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.api.issue.Issue.STATUS_CLOSED; | |||
import static org.sonar.api.rules.RuleType.CODE_SMELL; | |||
import static org.sonar.api.utils.DateUtils.addDays; | |||
import static org.sonar.api.utils.DateUtils.parseDateTime; | |||
@@ -66,24 +66,24 @@ public class ComponentIssuesLoaderTest { | |||
private static final Date DATE_LIMIT_30_DAYS_BACK_MIDNIGHT = parseDateTime("2018-07-18T00:00:00+0000"); | |||
@Rule | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private DbClient dbClient = dbTester.getDbClient(); | |||
private DbClient dbClient = db.getDbClient(); | |||
private System2 system2 = mock(System2.class); | |||
@Test | |||
public void loadClosedIssues_returns_single_DefaultIssue_by_issue_based_on_first_row() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertPublicProject(organization); | |||
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = dbTester.rules().insert(t -> t.setType(RuleType.CODE_SMELL)); | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertPublicProject(organization); | |||
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); | |||
Date issueDate = addDays(NOW, -10); | |||
IssueDto issue = dbTester.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setIsFromHotspot(false)); | |||
dbTester.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(issueDate, 10)); | |||
dbTester.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 3), 20)); | |||
dbTester.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 1), 30)); | |||
IssueDto issue = db.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setType(CODE_SMELL).setIsFromHotspot(false)); | |||
db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(issueDate, 10)); | |||
db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 3), 20)); | |||
db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 1), 30)); | |||
when(system2.now()).thenReturn(NOW.getTime()); | |||
ComponentIssuesLoader underTest = newComponentIssuesLoader(newEmptySettings()); | |||
@@ -95,15 +95,15 @@ public class ComponentIssuesLoaderTest { | |||
@Test | |||
public void loadClosedIssues_returns_single_DefaultIssue_with_null_line_if_first_row_has_no_line_diff() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertPublicProject(organization); | |||
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = dbTester.rules().insert(t -> t.setType(RuleType.CODE_SMELL)); | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertPublicProject(organization); | |||
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); | |||
Date issueDate = addDays(NOW, -10); | |||
IssueDto issue = dbTester.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setIsFromHotspot(false)); | |||
dbTester.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(issueDate, 10)); | |||
dbTester.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 2), null)); | |||
dbTester.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 1), 30)); | |||
IssueDto issue = db.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setType(CODE_SMELL).setIsFromHotspot(false)); | |||
db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(issueDate, 10)); | |||
db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 2), null)); | |||
db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 1), 30)); | |||
when(system2.now()).thenReturn(NOW.getTime()); | |||
ComponentIssuesLoader underTest = newComponentIssuesLoader(newEmptySettings()); | |||
@@ -115,15 +115,15 @@ public class ComponentIssuesLoaderTest { | |||
@Test | |||
public void loadClosedIssues_returns_only_closed_issues_with_close_date() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertPublicProject(organization); | |||
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = dbTester.rules().insert(t -> t.setType(RuleType.CODE_SMELL)); | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertPublicProject(organization); | |||
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); | |||
Date issueDate = addDays(NOW, -10); | |||
IssueDto closedIssue = dbTester.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setIsFromHotspot(false)); | |||
dbTester.issues().insertFieldDiffs(closedIssue, newToClosedDiffsWithLine(issueDate, 10)); | |||
IssueDto issueNoCloseDate = dbTester.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIsFromHotspot(false)); | |||
dbTester.issues().insertFieldDiffs(issueNoCloseDate, newToClosedDiffsWithLine(issueDate, 10)); | |||
IssueDto closedIssue = db.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setType(CODE_SMELL).setIsFromHotspot(false)); | |||
db.issues().insertFieldDiffs(closedIssue, newToClosedDiffsWithLine(issueDate, 10)); | |||
IssueDto issueNoCloseDate = db.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIsFromHotspot(false)); | |||
db.issues().insertFieldDiffs(issueNoCloseDate, newToClosedDiffsWithLine(issueDate, 10)); | |||
when(system2.now()).thenReturn(NOW.getTime()); | |||
ComponentIssuesLoader underTest = newComponentIssuesLoader(newEmptySettings()); | |||
@@ -184,10 +184,10 @@ public class ComponentIssuesLoaderTest { | |||
} | |||
private void loadClosedIssues_returns_only_closed_issues_with_close_date_is_from_30_days_ago(ComponentIssuesLoader underTest) { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertPublicProject(organization); | |||
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = dbTester.rules().insert(t -> t.setType(RuleType.CODE_SMELL)); | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertPublicProject(organization); | |||
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); | |||
Date[] issueDates = new Date[] { | |||
addDays(NOW, -10), | |||
addDays(NOW, -31), | |||
@@ -198,8 +198,8 @@ public class ComponentIssuesLoaderTest { | |||
}; | |||
IssueDto[] issues = Arrays.stream(issueDates) | |||
.map(issueDate -> { | |||
IssueDto closedIssue = dbTester.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setIsFromHotspot(false)); | |||
dbTester.issues().insertFieldDiffs(closedIssue, newToClosedDiffsWithLine(issueDate, 10)); | |||
IssueDto closedIssue = db.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setType(CODE_SMELL).setIsFromHotspot(false)); | |||
db.issues().insertFieldDiffs(closedIssue, newToClosedDiffsWithLine(issueDate, 10)); | |||
return closedIssue; | |||
}) | |||
.toArray(IssueDto[]::new); | |||
@@ -240,13 +240,13 @@ public class ComponentIssuesLoaderTest { | |||
@Test | |||
@UseDataProvider("statusOrResolutionFieldName") | |||
public void loadLatestDiffChangesForReopeningOfClosedIssues_add_diff_change_with_most_recent_status_or_resolution(String statusOrResolutionFieldName) { | |||
ComponentDto project = dbTester.components().insertPublicProject(); | |||
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = dbTester.rules().insert(); | |||
IssueDto issue = dbTester.issues().insert(rule, project, file); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val1")).setIssueChangeCreationDate(5)); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val2")).setIssueChangeCreationDate(20)); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val3")).setIssueChangeCreationDate(13)); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
IssueDto issue = db.issues().insert(rule, project, file); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val1")).setIssueChangeCreationDate(5)); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val2")).setIssueChangeCreationDate(20)); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val3")).setIssueChangeCreationDate(13)); | |||
ComponentIssuesLoader underTest = new ComponentIssuesLoader(dbClient, | |||
null /* not used in method */, null /* not used in method */, newConfiguration("0"), null /* not used by method */); | |||
DefaultIssue defaultIssue = new DefaultIssue().setKey(issue.getKey()); | |||
@@ -263,14 +263,14 @@ public class ComponentIssuesLoaderTest { | |||
@Test | |||
public void loadLatestDiffChangesForReopeningOfClosedIssues_add_single_diff_change_when_most_recent_status_and_resolution_is_the_same_diff() { | |||
ComponentDto project = dbTester.components().insertPublicProject(); | |||
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = dbTester.rules().insert(); | |||
IssueDto issue = dbTester.issues().insert(rule, project, file); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus1")).setIssueChangeCreationDate(5)); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus2")).setIssueChangeCreationDate(19)); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus3", "resolution", "valRes3")).setIssueChangeCreationDate(20)); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("resolution", "valRes4")).setIssueChangeCreationDate(13)); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
IssueDto issue = db.issues().insert(rule, project, file); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus1")).setIssueChangeCreationDate(5)); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus2")).setIssueChangeCreationDate(19)); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus3", "resolution", "valRes3")).setIssueChangeCreationDate(20)); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("resolution", "valRes4")).setIssueChangeCreationDate(13)); | |||
ComponentIssuesLoader underTest = new ComponentIssuesLoader(dbClient, | |||
null /* not used in method */, null /* not used in method */, newConfiguration("0"), null /* not used by method */); | |||
DefaultIssue defaultIssue = new DefaultIssue().setKey(issue.getKey()); | |||
@@ -291,14 +291,14 @@ public class ComponentIssuesLoaderTest { | |||
@Test | |||
public void loadLatestDiffChangesForReopeningOfClosedIssues_adds_2_diff_changes_if_most_recent_status_and_resolution_are_not_the_same_diff() { | |||
ComponentDto project = dbTester.components().insertPublicProject(); | |||
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = dbTester.rules().insert(); | |||
IssueDto issue = dbTester.issues().insert(rule, project, file); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus1")).setIssueChangeCreationDate(5)); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus2", "resolution", "valRes2")).setIssueChangeCreationDate(19)); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus3")).setIssueChangeCreationDate(20)); | |||
dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("resolution", "valRes4")).setIssueChangeCreationDate(13)); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
IssueDto issue = db.issues().insert(rule, project, file); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus1")).setIssueChangeCreationDate(5)); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus2", "resolution", "valRes2")).setIssueChangeCreationDate(19)); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus3")).setIssueChangeCreationDate(20)); | |||
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("resolution", "valRes4")).setIssueChangeCreationDate(13)); | |||
ComponentIssuesLoader underTest = new ComponentIssuesLoader(dbClient, | |||
null /* not used in method */, null /* not used in method */, newConfiguration("0"), null /* not used by method */); | |||
DefaultIssue defaultIssue = new DefaultIssue().setKey(issue.getKey()); |
@@ -52,8 +52,7 @@ public class IssueTesting { | |||
return new IssueDto() | |||
.setKee("uuid_" + randomAlphabetic(5)) | |||
.setRule(rule) | |||
// exclude security hotspots | |||
.setType(RuleType.values()[nextInt(RuleType.values().length - 1)]) | |||
.setType(RuleType.values()[nextInt(RuleType.values().length)]) | |||
.setProject(project) | |||
.setComponent(file) | |||
.setStatus(Issue.STATUS_OPEN) |
@@ -72,8 +72,7 @@ public class RuleTesting { | |||
.setName("name_" + randomAlphanumeric(5)) | |||
.setDescription("description_" + randomAlphanumeric(5)) | |||
.setDescriptionFormat(Format.HTML) | |||
// exclude security hotspots | |||
.setType(RuleType.values()[nextInt(RuleType.values().length - 1)]) | |||
.setType(RuleType.values()[nextInt(RuleType.values().length)]) | |||
.setStatus(RuleStatus.READY) | |||
.setConfigKey("configKey_" + randomAlphanumeric(5)) | |||
.setSeverity(Severity.ALL.get(nextInt(Severity.ALL.size()))) |
@@ -186,6 +186,7 @@ public class SearchAction implements IssuesWsAction, Startable { | |||
PARAM_COMPONENT_KEYS, PARAM_COMPONENT_UUIDS) | |||
.setSince("3.6") | |||
.setChangelog( | |||
new Change("7.8", "Security hotspots are returned by default"), | |||
new Change("7.7", format("Value '%s' in parameter '%s' is deprecated, please use '%s' instead", DEPRECATED_PARAM_AUTHORS, FACETS, PARAM_AUTHOR)), | |||
new Change("7.6", format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT_KEYS)), | |||
new Change("7.4", "The facet 'projectUuids' is dropped in favour of the new facet 'projects'. " + | |||
@@ -244,7 +245,6 @@ public class SearchAction implements IssuesWsAction, Startable { | |||
.setDescription("Comma-separated list of types.") | |||
.setSince("5.5") | |||
.setPossibleValues((Object[]) RuleType.values()) | |||
.setDefaultValue(format("%s,%s,%s", RuleType.BUG, RuleType.VULNERABILITY, RuleType.CODE_SMELL)) | |||
.setExampleValue(format("%s,%s", RuleType.CODE_SMELL, RuleType.BUG)); | |||
action.createParam(PARAM_OWASP_TOP_10) | |||
.setDescription("Comma-separated list of OWASP Top 10 lowercase categories. Use '" + UNKNOWN_STANDARD + "' to select issues not associated to any OWASP Top 10 category.") |
@@ -39,6 +39,7 @@ import org.sonar.server.tester.UserSessionRule; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.api.issue.Issue.STATUS_CONFIRMED; | |||
import static org.sonar.api.issue.Issue.STATUS_OPEN; | |||
import static org.sonar.api.rules.RuleType.CODE_SMELL; | |||
import static org.sonar.api.web.UserRole.ISSUE_ADMIN; | |||
import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
@@ -66,7 +67,7 @@ public class TransitionServiceTest { | |||
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)); | |||
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
userSession.logIn().addProjectPermission(ISSUE_ADMIN, project); | |||
List<Transition> result = underTest.listTransitions(issue.toDefaultIssue()); | |||
@@ -79,7 +80,7 @@ public class TransitionServiceTest { | |||
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)); | |||
IssueDto externalIssue = db.issues().insert(externalRule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
userSession.logIn().addProjectPermission(ISSUE_ADMIN, project); | |||
List<Transition> result = underTest.listTransitions(externalIssue.toDefaultIssue()); | |||
@@ -92,7 +93,7 @@ public class TransitionServiceTest { | |||
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)); | |||
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
userSession.logIn(); | |||
List<Transition> result = underTest.listTransitions(issue.toDefaultIssue()); | |||
@@ -105,7 +106,7 @@ public class TransitionServiceTest { | |||
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)); | |||
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
List<Transition> result = underTest.listTransitions(issue.toDefaultIssue()); | |||
@@ -117,7 +118,7 @@ public class TransitionServiceTest { | |||
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)); | |||
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
DefaultIssue defaultIssue = issue.toDefaultIssue(); | |||
boolean result = underTest.doTransition(defaultIssue, IssueChangeContext.createUser(new Date(), "user_uuid"), "confirm"); | |||
@@ -131,7 +132,7 @@ public class TransitionServiceTest { | |||
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)); | |||
IssueDto externalIssue = db.issues().insert(externalRule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
DefaultIssue defaultIssue = externalIssue.toDefaultIssue(); | |||
expectedException.expect(IllegalArgumentException.class); |
@@ -86,6 +86,7 @@ import static org.sonar.api.issue.Issue.STATUS_OPEN; | |||
import static org.sonar.api.rule.Severity.MAJOR; | |||
import static org.sonar.api.rule.Severity.MINOR; | |||
import static org.sonar.api.rules.RuleType.BUG; | |||
import static org.sonar.api.rules.RuleType.CODE_SMELL; | |||
import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; | |||
import static org.sonar.api.rules.RuleType.VULNERABILITY; | |||
import static org.sonar.api.web.UserRole.ISSUE_ADMIN; | |||
@@ -147,12 +148,12 @@ public class BulkChangeActionTest { | |||
BulkChangeWsResponse response = call(builder() | |||
.setIssues(singletonList(issue.getKey())) | |||
.setSetType(RuleType.CODE_SMELL.name()) | |||
.setSetType(CODE_SMELL.name()) | |||
.build()); | |||
checkResponse(response, 1, 1, 0, 0); | |||
IssueDto reloaded = getIssueByKeys(issue.getKey()).get(0); | |||
assertThat(reloaded.getType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant()); | |||
assertThat(reloaded.getType()).isEqualTo(CODE_SMELL.getDbConstant()); | |||
assertThat(reloaded.getUpdatedAt()).isEqualTo(NOW); | |||
verifyPostProcessorCalled(file); | |||
@@ -166,7 +167,7 @@ public class BulkChangeActionTest { | |||
ComponentDto file = db.components().insertComponent(newFileDto(project)); | |||
addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setSeverity(MAJOR) | |||
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setSeverity(MAJOR).setType(CODE_SMELL) | |||
.setStatus(STATUS_OPEN).setResolution(null)); | |||
BulkChangeWsResponse response = call(builder() | |||
@@ -270,11 +271,11 @@ public class BulkChangeActionTest { | |||
UserDto userToAssign = db.users().insertUser(); | |||
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); | |||
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); | |||
i -> i.setAssigneeUuid(userToAssign.getUuid()).setType(CODE_SMELL).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); | |||
i -> i.setAssigneeUuid(null).setType(VULNERABILITY).setSeverity(MAJOR).setStatus(STATUS_OPEN).setResolution(null)); | |||
BulkChangeWsResponse response = call(builder() | |||
.setIssues(asList(issue1.getKey(), issue2.getKey(), issue3.getKey())) | |||
@@ -559,9 +560,9 @@ public class BulkChangeActionTest { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
IssueDto issue = db.issues().insert(rule, project, project, i -> i.setStatus(STATUS_OPEN).setResolution(null)); | |||
IssueDto issue = db.issues().insert(rule, project, project, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
RuleDefinitionDto externalRule = db.rules().insert(r -> r.setIsExternal(true)); | |||
IssueDto externalIssue = db.issues().insert(externalRule, project, project, i -> i.setStatus(STATUS_OPEN).setResolution(null)); | |||
IssueDto externalIssue = db.issues().insert(externalRule, project, project, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
BulkChangeWsResponse response = call(builder() | |||
.setIssues(asList(issue.getKey(), externalIssue.getKey())) | |||
@@ -645,12 +646,12 @@ public class BulkChangeActionTest { | |||
addUserProjectPermissions(user, project2, USER); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
IssueDto authorizedIssue1 = db.issues().insert(rule, project1, project1, i -> i.setSeverity(MAJOR) | |||
.setStatus(STATUS_OPEN).setResolution(null)); | |||
.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
// User has not issue admin permission on these 2 issues | |||
IssueDto notAuthorizedIssue1 = db.issues().insert(rule, project2, project2, i -> i.setSeverity(MAJOR) | |||
.setStatus(STATUS_OPEN).setResolution(null)); | |||
.setStatus(STATUS_OPEN).setResolution(null).setType(BUG)); | |||
IssueDto notAuthorizedIssue2 = db.issues().insert(rule, project2, project2, i -> i.setSeverity(MAJOR) | |||
.setStatus(STATUS_OPEN).setResolution(null)); | |||
.setStatus(STATUS_OPEN).setResolution(null).setType(VULNERABILITY)); | |||
BulkChangeWsResponse response = call(builder() | |||
.setIssues(asList(authorizedIssue1.getKey(), notAuthorizedIssue1.getKey(), notAuthorizedIssue2.getKey())) |
@@ -66,6 +66,7 @@ import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.sonar.api.issue.Issue.STATUS_CONFIRMED; | |||
import static org.sonar.api.issue.Issue.STATUS_OPEN; | |||
import static org.sonar.api.rules.RuleType.CODE_SMELL; | |||
import static org.sonar.api.web.UserRole.CODEVIEWER; | |||
import static org.sonar.api.web.UserRole.USER; | |||
import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
@@ -116,7 +117,7 @@ public class DoTransitionActionTest { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
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)); | |||
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
userSession.logIn(db.users().insertUser()).addProjectPermission(USER, project, file); | |||
call(issue.getKey(), "confirm"); | |||
@@ -133,7 +134,7 @@ public class DoTransitionActionTest { | |||
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)); | |||
IssueDto externalIssue = db.issues().insert(externalRule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
userSession.logIn().addProjectPermission(USER, project, file); | |||
expectedException.expect(IllegalArgumentException.class); | |||
@@ -163,7 +164,7 @@ public class DoTransitionActionTest { | |||
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)); | |||
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
userSession.logIn().addProjectPermission(USER, project, file); | |||
expectedException.expect(IllegalArgumentException.class); | |||
@@ -175,7 +176,7 @@ public class DoTransitionActionTest { | |||
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)); | |||
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
userSession.logIn().addProjectPermission(CODEVIEWER, project, file); | |||
expectedException.expect(ForbiddenException.class); | |||
@@ -188,7 +189,7 @@ public class DoTransitionActionTest { | |||
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)); | |||
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); | |||
userSession.logIn().addProjectPermission(USER, project, file); | |||
// False-positive transition is requiring issue admin permission |
@@ -82,6 +82,7 @@ import static org.assertj.core.groups.Tuple.tuple; | |||
import static org.junit.rules.ExpectedException.none; | |||
import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; | |||
import static org.sonar.api.issue.Issue.STATUS_RESOLVED; | |||
import static org.sonar.api.rules.RuleType.CODE_SMELL; | |||
import static org.sonar.api.server.ws.WebService.Param.FACETS; | |||
import static org.sonar.api.utils.DateUtils.formatDateTime; | |||
import static org.sonar.api.utils.DateUtils.parseDate; | |||
@@ -90,6 +91,9 @@ import static org.sonar.api.web.UserRole.ISSUE_ADMIN; | |||
import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
import static org.sonar.db.issue.IssueTesting.newDto; | |||
import static org.sonar.server.tester.UserSessionRule.standalone; | |||
import static org.sonarqube.ws.Common.RuleType.BUG; | |||
import static org.sonarqube.ws.Common.RuleType.SECURITY_HOTSPOT; | |||
import static org.sonarqube.ws.Common.RuleType.VULNERABILITY; | |||
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; | |||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; | |||
@@ -148,6 +152,7 @@ public class SearchActionTest { | |||
.setStatus(STATUS_RESOLVED) | |||
.setResolution(RESOLUTION_FIXED) | |||
.setSeverity("MAJOR") | |||
.setType(CODE_SMELL) | |||
.setAuthorLogin("John") | |||
.setAssigneeUuid(simon.getUuid()) | |||
.setTags(asList("bug", "owasp")) | |||
@@ -333,7 +338,7 @@ public class SearchActionTest { | |||
indexPermissions(); | |||
ComponentDto file = db.components().insertComponent(newFileDto(project)); | |||
RuleDefinitionDto rule = newRule().getDefinition(); | |||
db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(simon.getUuid())); | |||
db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(simon.getUuid()).setType(CODE_SMELL)); | |||
indexIssues(); | |||
userSession.logIn("john"); | |||
@@ -355,7 +360,8 @@ public class SearchActionTest { | |||
IssueDto issue = newDto(newRule(), file, project) | |||
.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") | |||
.setAuthorLogin(fabrice.getLogin()) | |||
.setAssigneeUuid(simon.getUuid()); | |||
.setAssigneeUuid(simon.getUuid()) | |||
.setType(CODE_SMELL); | |||
dbClient.issueDao().insert(session, issue); | |||
session.commit(); | |||
indexIssues(); | |||
@@ -677,13 +683,13 @@ public class SearchActionTest { | |||
} | |||
@Test | |||
public void security_hotspot_type_excluded_by_default() { | |||
public void security_hotspots_are_returned_by_default() { | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto file = db.components().insertComponent(newFileDto(project)); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.BUG)); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.VULNERABILITY)); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.CODE_SMELL)); | |||
db.issues().insert(rule, project, file, i -> i.setType(CODE_SMELL)); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.SECURITY_HOTSPOT)); | |||
indexPermissions(); | |||
indexIssues(); | |||
@@ -692,7 +698,7 @@ public class SearchActionTest { | |||
assertThat(result.getIssuesList()) | |||
.extracting(Issue::getType) | |||
.containsExactlyInAnyOrder(Common.RuleType.BUG, Common.RuleType.VULNERABILITY, Common.RuleType.CODE_SMELL); | |||
.containsExactlyInAnyOrder(BUG, VULNERABILITY, Common.RuleType.CODE_SMELL, SECURITY_HOTSPOT); | |||
} | |||
@Test | |||
@@ -702,7 +708,7 @@ public class SearchActionTest { | |||
RuleDefinitionDto rule = newRule().getDefinition(); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.BUG)); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.VULNERABILITY)); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.CODE_SMELL)); | |||
db.issues().insert(rule, project, file, i -> i.setType(CODE_SMELL)); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.SECURITY_HOTSPOT)); | |||
indexPermissions(); | |||
indexIssues(); | |||
@@ -711,13 +717,13 @@ public class SearchActionTest { | |||
.setParam("types", RuleType.SECURITY_HOTSPOT.toString()) | |||
.executeProtobuf(SearchWsResponse.class).getIssuesList()) | |||
.extracting(Issue::getType) | |||
.containsExactlyInAnyOrder(Common.RuleType.SECURITY_HOTSPOT); | |||
.containsExactlyInAnyOrder(SECURITY_HOTSPOT); | |||
assertThat(ws.newRequest() | |||
.setParam("types", String.format("%s,%s", RuleType.BUG, RuleType.SECURITY_HOTSPOT)) | |||
.executeProtobuf(SearchWsResponse.class).getIssuesList()) | |||
.extracting(Issue::getType) | |||
.containsExactlyInAnyOrder(Common.RuleType.BUG, Common.RuleType.SECURITY_HOTSPOT); | |||
.containsExactlyInAnyOrder(BUG, SECURITY_HOTSPOT); | |||
} | |||
@Test | |||
@@ -727,7 +733,7 @@ public class SearchActionTest { | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.BUG).setSeverity(Severity.MAJOR.name())); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.VULNERABILITY).setSeverity(Severity.MAJOR.name())); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.CODE_SMELL).setSeverity(Severity.MAJOR.name())); | |||
db.issues().insert(rule, project, file, i -> i.setType(CODE_SMELL).setSeverity(Severity.MAJOR.name())); | |||
db.issues().insert(rule, project, file, i -> i.setType(RuleType.SECURITY_HOTSPOT).setSeverity(Severity.MAJOR.name())); | |||
indexPermissions(); | |||
indexIssues(); | |||
@@ -739,7 +745,7 @@ public class SearchActionTest { | |||
assertThat(result.getIssuesList()) | |||
.extracting(Issue::getType) | |||
.containsExactlyInAnyOrder(Common.RuleType.BUG, Common.RuleType.VULNERABILITY, Common.RuleType.CODE_SMELL); | |||
.containsExactlyInAnyOrder(BUG, VULNERABILITY, Common.RuleType.CODE_SMELL); | |||
assertThat(result.getFacets().getFacets(0).getValuesList()) | |||
.extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) | |||
.containsExactlyInAnyOrder(tuple("MAJOR", 3L), tuple("INFO", 0L), tuple("MINOR", 0L), tuple("CRITICAL", 0L), tuple("BLOCKER", 0L)); | |||
@@ -762,8 +768,8 @@ public class SearchActionTest { | |||
assertThat(result.getIssuesList()) | |||
.extracting(Issue::getType, Issue::hasSeverity) | |||
.containsExactlyInAnyOrder( | |||
tuple(Common.RuleType.BUG, true), | |||
tuple(Common.RuleType.SECURITY_HOTSPOT, false)); | |||
tuple(BUG, true), | |||
tuple(SECURITY_HOTSPOT, false)); | |||
} | |||
@Test |