diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2019-12-23 12:43:54 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2020-01-13 20:46:33 +0100 |
commit | 26604f21a73191ad70cfe85076644268039a771a (patch) | |
tree | ae9e9bdebea8bbd63155032d1b242141f013f2cf /server/sonar-webserver-webapi | |
parent | adc4fa5bd0c179b6a16823987538fbdc0a0b47ce (diff) | |
download | sonarqube-26604f21a73191ad70cfe85076644268039a771a.tar.gz sonarqube-26604f21a73191ad70cfe85076644268039a771a.zip |
SONAR-12723 text fixtures enforce split of issue from secu hotspot
Diffstat (limited to 'server/sonar-webserver-webapi')
10 files changed, 108 insertions, 139 deletions
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AddCommentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AddCommentActionTest.java index e22f345a62b..3049c5304ab 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AddCommentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AddCommentActionTest.java @@ -166,8 +166,7 @@ public class AddCommentActionTest { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto notAHotspot = dbTester.issues().insertIssue(newIssue(rule, project, file) - .setType(SECURITY_HOTSPOT).setStatus(STATUS_CLOSED)); + IssueDto notAHotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_CLOSED)); userSessionRule.logIn(); TestRequest request = newRequest(notAHotspot, randomAlphabetic(12)); @@ -182,7 +181,7 @@ public class AddCommentActionTest { userSessionRule.logIn().registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); String comment = randomAlphabetic(12); TestRequest request = newRequest(hotspot, comment); @@ -197,7 +196,7 @@ public class AddCommentActionTest { userSessionRule.logIn().registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); String comment = randomAlphabetic(12); newRequest(hotspot, comment).execute().assertNoContent(); @@ -209,7 +208,7 @@ public class AddCommentActionTest { userSessionRule.logIn().registerComponents(project).addProjectPermission(UserRole.USER, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); String comment = randomAlphabetic(12); newRequest(hotspot, comment).execute().assertNoContent(); @@ -224,7 +223,7 @@ public class AddCommentActionTest { userSessionRule.logIn().registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule).setStatus(currentStatus).setResolution(currentResolution)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(currentStatus).setResolution(currentResolution)); String comment = randomAlphabetic(12); newRequest(hotspot, comment).execute().assertNoContent(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AssignActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AssignActionTest.java index 5cde732f5ea..9eeb1827582 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AssignActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AssignActionTest.java @@ -107,7 +107,7 @@ public class AssignActionTest { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, STATUS_TO_REVIEW)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW)); UserDto userDto = insertUser(randomAlphanumeric(10)); userSessionRule.logIn(userDto).registerComponents(project); @@ -125,7 +125,7 @@ public class AssignActionTest { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, STATUS_TO_REVIEW)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW)); UserDto me = insertUser(randomAlphanumeric(10)); userSessionRule.logIn(me).registerComponents(project); @@ -142,7 +142,7 @@ public class AssignActionTest { ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, STATUS_TO_REVIEW)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW)); insertAndLoginAsUserWithProjectUserPermission(randomAlphanumeric(10), hotspot, project, UserRole.USER); UserDto assignee = insertUserWithProjectUserPermission(randomAlphanumeric(15), project); @@ -159,7 +159,7 @@ public class AssignActionTest { ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, STATUS_TO_REVIEW)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW)); insertAndLoginAsUserWithProjectUserPermission(randomAlphanumeric(10), hotspot, project, UserRole.USER); UserDto assignee = insertUser(randomAlphanumeric(15)); @@ -177,7 +177,7 @@ public class AssignActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, STATUS_TO_REVIEW)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW)); UserDto me = insertAndLoginAsUserWithProjectUserPermission(randomAlphanumeric(10), hotspot, project, UserRole.USER); @@ -194,7 +194,7 @@ public class AssignActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, STATUS_TO_REVIEW)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW)); UserDto userDto = insertUser(randomAlphanumeric(10)); userSessionRule.logIn(userDto).registerComponents(project); @@ -214,7 +214,7 @@ public class AssignActionTest { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, STATUS_TO_REVIEW)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW)); UserDto userDto = insertUser(randomAlphanumeric(10)); userSessionRule.logIn(userDto).registerComponents(project); @@ -234,7 +234,7 @@ public class AssignActionTest { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, STATUS_TO_REVIEW)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW)); UserDto userDto = insertUser(randomAlphanumeric(10)); userSessionRule.logIn(userDto).registerComponents(project); @@ -253,7 +253,7 @@ public class AssignActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, status)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(status)); UserDto userDto = insertUser(randomAlphanumeric(10)); userSessionRule.logIn(userDto).registerComponents(project); @@ -269,7 +269,7 @@ public class AssignActionTest { ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, status)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(status)); UserDto userDto = insertUser(randomAlphanumeric(10)); userSessionRule.logIn(userDto).registerComponents(project); @@ -293,7 +293,7 @@ public class AssignActionTest { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, STATUS_TO_REVIEW)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW)); userSessionRule.anonymous(); @@ -309,7 +309,7 @@ public class AssignActionTest { ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule, STATUS_TO_REVIEW)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW)); UserDto me = insertAndLoginAsUserWithProjectUserPermission(randomAlphanumeric(10), hotspot, project, UserRole.CODEVIEWER); @@ -372,10 +372,8 @@ public class AssignActionTest { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto issue = dbTester.issues().insertIssue( - newIssue(rule, project, file) - .setStatus(STATUS_CLOSED) - .setType(SECURITY_HOTSPOT)); + IssueDto issue = dbTester.issues().insertHotspot(rule, project, file, + t -> t.setStatus(STATUS_CLOSED).setType(SECURITY_HOTSPOT)); UserDto me = insertUser(randomAlphanumeric(10)); userSessionRule.logIn().registerComponents(project); @@ -413,10 +411,6 @@ public class AssignActionTest { }); } - private static IssueDto newHotspot(ComponentDto project, ComponentDto file, RuleDefinitionDto rule, String status) { - return newIssue(rule, project, file).setStatus(status).setType(SECURITY_HOTSPOT); - } - private void executeRequest(IssueDto hotspot, @Nullable String assignee, @Nullable String comment) { executeRequest(hotspot.getKey(), assignee, comment); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java index 5417c830535..c436c75f781 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java @@ -241,8 +241,8 @@ public class ChangeStatusActionTest { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto closedHotspot = dbTester.issues().insertIssue(IssueTesting.newIssue(rule, project, file) - .setType(SECURITY_HOTSPOT).setStatus(STATUS_CLOSED)); + IssueDto closedHotspot = dbTester.issues().insertHotspot(rule, project, file, + t -> t.setType(SECURITY_HOTSPOT).setStatus(STATUS_CLOSED)); userSessionRule.logIn(); TestRequest request = actionTester.newRequest() .setParam("hotspot", closedHotspot.getKey()) @@ -296,7 +296,7 @@ public class ChangeStatusActionTest { .addProjectPermission(permission, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); Arrays.stream(validStatusAndResolutions()) .forEach(o -> { @@ -327,7 +327,7 @@ public class ChangeStatusActionTest { .addProjectPermission(permission, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); Arrays.stream(validStatusAndResolutions()) .forEach(o -> { @@ -360,7 +360,7 @@ public class ChangeStatusActionTest { .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); newRequest(hotspot, status, resolution, NO_COMMENT).execute().assertNoContent(); } @@ -373,7 +373,7 @@ public class ChangeStatusActionTest { .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); newRequest(hotspot, status, resolution, NO_COMMENT).execute().assertNoContent(); } @@ -386,7 +386,7 @@ public class ChangeStatusActionTest { .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule).setStatus(status).setResolution(resolution)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(status).setResolution(resolution)); newRequest(hotspot, status, resolution, NO_COMMENT).execute().assertNoContent(); @@ -404,7 +404,7 @@ public class ChangeStatusActionTest { ; ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule).setStatus(STATUS_TO_REVIEW).setResolution(null)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW).setResolution(null)); when(transitionService.doTransition(any(), any(), any())).thenReturn(transitionDone); newRequest(hotspot, STATUS_REVIEWED, resolution, NO_COMMENT).execute().assertNoContent(); @@ -452,7 +452,7 @@ public class ChangeStatusActionTest { ; ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule).setStatus(STATUS_REVIEWED).setResolution(resolution)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_REVIEWED).setResolution(resolution)); when(transitionService.doTransition(any(), any(), any())).thenReturn(transitionDone); newRequest(hotspot, STATUS_TO_REVIEW, null, NO_COMMENT).execute().assertNoContent(); @@ -501,7 +501,7 @@ public class ChangeStatusActionTest { ; ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule).setStatus(currentStatus).setResolution(currentResolution)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(currentStatus).setResolution(currentResolution)); when(transitionService.doTransition(any(), any(), any())).thenReturn(transitionDone); String comment = randomAlphabetic(12); @@ -554,7 +554,7 @@ public class ChangeStatusActionTest { ; ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule).setStatus(status).setResolution(resolution)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(status).setResolution(resolution)); String comment = randomAlphabetic(12); newRequest(hotspot, status, resolution, comment).execute().assertNoContent(); @@ -562,10 +562,6 @@ public class ChangeStatusActionTest { verifyNoInteractions(transitionService, issueUpdater, issueFieldsSetter); } - private static IssueDto newHotspot(ComponentDto project, ComponentDto file, RuleDefinitionDto rule) { - return IssueTesting.newIssue(rule, project, file).setType(SECURITY_HOTSPOT); - } - private TestRequest newRequest(IssueDto hotspot, String newStatus, @Nullable String newResolution, @Nullable String comment) { TestRequest res = actionTester.newRequest() .setParam("hotspot", hotspot.getKey()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java index d7d8852fb72..d2b44b7766d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java @@ -854,7 +854,7 @@ public class SearchActionTest { }) .collect(toList()); Collections.shuffle(hotspots); - hotspots.forEach(t -> dbTester.issues().insertIssue(t)); + hotspots.forEach(t -> dbTester.issues().insertHotspot(t)); return hotspots.stream(); } @@ -1117,7 +1117,7 @@ public class SearchActionTest { String[] expectedHotspotKeys = hotspots.stream().map(IssueDto::getKey).toArray(String[]::new); // insert hotspots in random order Collections.shuffle(hotspots); - hotspots.forEach(dbTester.issues()::insertIssue); + hotspots.forEach(dbTester.issues()::insertHotspot); indexIssues(); SearchWsResponse response = newRequest(project) @@ -1150,7 +1150,7 @@ public class SearchActionTest { String[] expectedHotspotKeys = hotspots.stream().map(IssueDto::getKey).toArray(String[]::new); // insert hotspots in random order Collections.shuffle(hotspots); - hotspots.forEach(dbTester.issues()::insertIssue); + hotspots.forEach(dbTester.issues()::insertHotspot); indexIssues(); SearchWsResponse response = newRequest(project) @@ -1170,8 +1170,7 @@ public class SearchActionTest { RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); int total = 436; List<IssueDto> hotspots = IntStream.range(0, total) - .mapToObj(i -> newHotspot(rule, project, file).setLine(i)) - .map(i -> dbTester.issues().insertIssue(i)) + .mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))) .collect(toList()); indexIssues(); @@ -1213,8 +1212,7 @@ public class SearchActionTest { private void verifyPaging(ComponentDto project, ComponentDto file, RuleDefinitionDto rule, int total, int pageSize) { List<IssueDto> hotspots = IntStream.range(0, total) - .mapToObj(i -> newHotspot(rule, project, file).setLine(i).setKee("issue_" + i)) - .map(i -> dbTester.issues().insertIssue(i)) + .mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i).setKee("issue_" + i))) .collect(toList()); indexIssues(); @@ -1264,8 +1262,7 @@ public class SearchActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); List<IssueDto> hotspots = IntStream.range(0, 1 + RANDOM.nextInt(15)) - .mapToObj(i -> newHotspot(rule, project, file).setLine(i)) - .map(i -> dbTester.issues().insertIssue(i)) + .mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))) .collect(toList()); indexIssues(); @@ -1284,8 +1281,7 @@ public class SearchActionTest { RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); int total = 1 + RANDOM.nextInt(20); List<IssueDto> hotspots = IntStream.range(0, total) - .mapToObj(i -> newHotspot(rule, project, file).setLine(i)) - .map(i -> dbTester.issues().insertIssue(i)) + .mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))) .collect(toList()); Collections.shuffle(hotspots); List<IssueDto> selectedHotspots = hotspots.stream().limit(total == 1 ? 1 : 1 + RANDOM.nextInt(total - 1)).collect(toList()); @@ -1312,21 +1308,18 @@ public class SearchActionTest { List<IssueDto> hotspotsInLeakPeriod = IntStream.range(0, 1 + RANDOM.nextInt(20)) .mapToObj(i -> { long issueCreationDate = periodDate + ONE_MINUTE + (RANDOM.nextInt(300) * ONE_MINUTE); - return newHotspot(rule, project, file).setLine(i).setIssueCreationTime(issueCreationDate); + return dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i).setIssueCreationTime(issueCreationDate)); }) - .map(i -> dbTester.issues().insertIssue(i)) .collect(toList()); // included because List<IssueDto> atLeakPeriod = IntStream.range(0, 1 + RANDOM.nextInt(20)) - .mapToObj(i -> newHotspot(rule, project, file).setLine(i).setIssueCreationTime(periodDate)) - .map(i -> dbTester.issues().insertIssue(i)) + .mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i).setIssueCreationTime(periodDate))) .collect(toList()); List<IssueDto> hotspotsBefore = IntStream.range(0, 1 + RANDOM.nextInt(20)) .mapToObj(i -> { long issueCreationDate = periodDate - ONE_MINUTE - (RANDOM.nextInt(300) * ONE_MINUTE); - return newHotspot(rule, project, file).setLine(i).setIssueCreationTime(issueCreationDate); + return dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i).setIssueCreationTime(issueCreationDate)); }) - .map(i -> dbTester.issues().insertIssue(i)) .collect(toList()); indexIssues(); @@ -1404,7 +1397,7 @@ public class SearchActionTest { } private IssueDto insertHotspot(RuleDefinitionDto rule, ComponentDto project, ComponentDto file, Consumer<IssueDto> consumer) { - return dbTester.issues().insertIssue(newHotspot(rule, project, file, consumer)); + return dbTester.issues().insertHotspot(rule, project, file, consumer); } private static IssueDto newHotspot(RuleDefinitionDto rule, ComponentDto project, ComponentDto component) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java index 78fbcd362ac..51556bd6945 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java @@ -161,17 +161,17 @@ public class ShowActionTest { } @Test - public void fails_with_NotFoundException_if_issue_is_hotspot_is_called() { + public void fails_with_NotFoundException_if_issue_is_hotspot_is_closed() { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto notAHotspot = dbTester.issues().insertIssue(IssueTesting.newIssue(rule, project, file) - .setType(SECURITY_HOTSPOT).setStatus(Issue.STATUS_CLOSED)); - TestRequest request = newRequest(notAHotspot); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, + t -> t.setStatus(Issue.STATUS_CLOSED)); + TestRequest request = newRequest(hotspot); assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) - .hasMessage("Hotspot '%s' does not exist", notAHotspot.getKey()); + .hasMessage("Hotspot '%s' does not exist", hotspot.getKey()); } @Test @@ -180,7 +180,7 @@ public class ShowActionTest { userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); TestRequest request = newRequest(hotspot); assertThatThrownBy(request::execute) @@ -194,7 +194,7 @@ public class ShowActionTest { userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -210,7 +210,7 @@ public class ShowActionTest { userSessionRule.logIn().addProjectPermission(UserRole.USER, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -227,7 +227,7 @@ public class ShowActionTest { userSessionRule.logIn().addProjectPermission(UserRole.USER, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule).setStatus(status).setResolution(resolution)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(status).setResolution(resolution)); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -256,7 +256,7 @@ public class ShowActionTest { userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -275,8 +275,8 @@ public class ShowActionTest { userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setLocations(DbIssues.Locations.newBuilder().build())); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, + t -> t.setLocations(DbIssues.Locations.newBuilder().build())); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -292,8 +292,8 @@ public class ShowActionTest { userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setLocations(DbIssues.Locations.newBuilder() + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, + t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder() .setStartLine(startLine) .setEndLine(endLine) @@ -320,8 +320,7 @@ public class ShowActionTest { userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setAssigneeUuid(randomAlphabetic(10))); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAssigneeUuid(randomAlphabetic(10))); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -337,8 +336,7 @@ public class ShowActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); UserDto assignee = dbTester.users().insertUser(); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setAssigneeUuid(assignee.getUuid())); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAssigneeUuid(assignee.getUuid())); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -360,8 +358,7 @@ public class ShowActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); UserDto assignee = dbTester.users().insertUser(t -> t.setEmail(null)); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setAssigneeUuid(assignee.getUuid())); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAssigneeUuid(assignee.getUuid())); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -378,8 +375,7 @@ public class ShowActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); UserDto assignee = dbTester.users().insertUser(t -> t.setActive(false)); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setAssigneeUuid(assignee.getUuid())); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAssigneeUuid(assignee.getUuid())); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -396,8 +392,7 @@ public class ShowActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); String authorLogin = randomAlphabetic(10); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setAuthorLogin(authorLogin)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAuthorLogin(authorLogin)); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -414,8 +409,7 @@ public class ShowActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); UserDto author = dbTester.users().insertUser(); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setAuthorLogin(author.getLogin())); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAuthorLogin(author.getLogin())); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -436,8 +430,7 @@ public class ShowActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); UserDto author = dbTester.users().insertUser(t -> t.setEmail(null)); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setAuthorLogin(author.getLogin())); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAuthorLogin(author.getLogin())); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -454,8 +447,7 @@ public class ShowActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); UserDto author = dbTester.users().insertUser(t -> t.setActive(false)); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setAuthorLogin(author.getLogin())); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAuthorLogin(author.getLogin())); mockChangelogAndCommentsFormattingContext(); Hotspots.ShowWsResponse response = newRequest(hotspot) @@ -482,8 +474,8 @@ public class ShowActionTest { userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setLocations(DbIssues.Locations.newBuilder() + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, + t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) .build())); mockChangelogAndCommentsFormattingContext(); @@ -507,8 +499,8 @@ public class ShowActionTest { userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT, t -> t.setSecurityStandards(standards)); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setLocations(DbIssues.Locations.newBuilder() + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, + t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) .build())); mockChangelogAndCommentsFormattingContext(); @@ -542,8 +534,8 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, project, rule) - .setLocations(DbIssues.Locations.newBuilder() + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, project, + t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) .build())); mockChangelogAndCommentsFormattingContext(); @@ -562,8 +554,8 @@ public class ShowActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(branch)); userSessionRule.registerComponents(project); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(branch, file, rule) - .setLocations(DbIssues.Locations.newBuilder() + IssueDto hotspot = dbTester.issues().insertHotspot(rule, branch, file, + t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) .build())); mockChangelogAndCommentsFormattingContext(); @@ -583,8 +575,8 @@ public class ShowActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest)); userSessionRule.registerComponents(project); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(pullRequest, file, rule) - .setLocations(DbIssues.Locations.newBuilder() + IssueDto hotspot = dbTester.issues().insertHotspot(rule, pullRequest, file, + t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) .build())); mockChangelogAndCommentsFormattingContext(); @@ -602,8 +594,8 @@ public class ShowActionTest { userSessionRule.registerComponents(project); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setLocations(DbIssues.Locations.newBuilder() + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, + t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) .build())); List<Common.Changelog> changelog = IntStream.range(0, 1 + new Random().nextInt(12)) @@ -639,7 +631,7 @@ public class ShowActionTest { userSessionRule.registerComponents(project); RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule)); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); FormattingContext formattingContext = mockChangelogAndCommentsFormattingContext(); Set<UserDto> changeLogAndCommentsUsers = IntStream.range(0, 1 + RANDOM.nextInt(14)) .mapToObj(i -> UserTesting.newUserDto()) @@ -665,9 +657,9 @@ public class ShowActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); UserDto author = dbTester.users().insertUser(); UserDto assignee = dbTester.users().insertUser(); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setAuthorLogin(author.getLogin()) - .setAssigneeUuid(assignee.getUuid())); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, + t -> t.setAuthorLogin(author.getLogin()) + .setAssigneeUuid(assignee.getUuid())); FormattingContext formattingContext = mockChangelogAndCommentsFormattingContext(); Set<UserDto> changeLogAndCommentsUsers = IntStream.range(0, 1 + RANDOM.nextInt(14)) .mapToObj(i -> UserTesting.newUserDto()) @@ -694,9 +686,9 @@ public class ShowActionTest { RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); UserDto author = dbTester.users().insertUser(); - IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule) - .setAuthorLogin(author.getLogin()) - .setAssigneeUuid(author.getUuid())); + IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, + t -> t.setAuthorLogin(author.getLogin()) + .setAssigneeUuid(author.getUuid())); FormattingContext formattingContext = mockChangelogAndCommentsFormattingContext(); when(formattingContext.getUsers()).thenReturn(ImmutableSet.of(author)); @@ -743,10 +735,6 @@ public class ShowActionTest { } } - private static IssueDto newHotspot(ComponentDto project, ComponentDto file, RuleDefinitionDto rule) { - return IssueTesting.newIssue(rule, project, file).setType(SECURITY_HOTSPOT); - } - private TestRequest newRequest(IssueDto hotspot) { return actionTester.newRequest() .setParam("hotspot", hotspot.getKey()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssueFinderTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssueFinderTest.java index f9e7497f5ce..b523f5f6e66 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssueFinderTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssueFinderTest.java @@ -92,7 +92,7 @@ public class IssueFinderTest { RuleDto rule = ruleDbTester.insertRule(newRuleDto()); ComponentDto project = componentDbTester.insertPrivateProject(); ComponentDto file = componentDbTester.insertComponent(newFileDto(project)); - return issueDbTester.insertIssue(newDto(rule, file, project)); + return issueDbTester.insert(newDto(rule, file, project)); } private void addProjectPermission(IssueDto issueDto, String permission) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/IssueUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/IssueUpdaterTest.java index 3b6c8542865..f9a277d8937 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/IssueUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/IssueUpdaterTest.java @@ -273,7 +273,7 @@ public class IssueUpdaterTest { ComponentDto project = db.components().insertMainBranch(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issueDto = IssueTesting.newIssue(rule.getDefinition(), project, file); - DefaultIssue issue = db.issues().insertIssue(issueDto).setSeverity(MAJOR).toDefaultIssue(); + DefaultIssue issue = db.issues().insert(issueDto).setSeverity(MAJOR).toDefaultIssue(); UserDto changeAuthor = db.users().insertUser(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid()); issueFieldsSetter.setSeverity(issue, BLOCKER, context); @@ -299,7 +299,7 @@ public class IssueUpdaterTest { ComponentDto project = db.components().insertMainBranch(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issueDto = IssueTesting.newIssue(rule.getDefinition(), project, file); - DefaultIssue issue = db.issues().insertIssue(issueDto).setSeverity(MAJOR).toDefaultIssue(); + DefaultIssue issue = db.issues().insert(issueDto).setSeverity(MAJOR).toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid"); issueFieldsSetter.setSeverity(issue, BLOCKER, context); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java index 727046b3948..418a6f6cebb 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java @@ -37,10 +37,10 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; -import org.sonar.server.issue.AvatarResolverImpl; -import org.sonar.server.issue.TextRangeResponseFormatter; import org.sonar.server.es.EsTester; +import org.sonar.server.issue.AvatarResolverImpl; import org.sonar.server.issue.IssueFieldsSetter; +import org.sonar.server.issue.TextRangeResponseFormatter; import org.sonar.server.issue.TransitionService; import org.sonar.server.issue.index.IssueIndex; import org.sonar.server.issue.index.IssueIndexer; @@ -74,7 +74,6 @@ import static org.sonar.db.component.ComponentTesting.newModuleDto; import static org.sonar.db.component.ComponentTesting.newProjectCopy; import static org.sonar.db.component.ComponentTesting.newSubView; import static org.sonar.db.component.ComponentTesting.newView; -import static org.sonar.db.issue.IssueTesting.newIssue; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS; @@ -118,7 +117,7 @@ public class SearchActionComponentsTest { 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)); + IssueDto issue = db.issues().insert(rule, project, projectFile); allowAnyoneOnProjects(project); indexIssues(); @@ -656,11 +655,11 @@ public class SearchActionComponentsTest { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertMainBranch(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - IssueDto issue = db.issues().insertIssue(newIssue(rule, project, file)); + IssueDto issue = db.issues().insert(rule, project, file); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH)); ComponentDto branchFile = db.components().insertComponent(newFileDto(branch)); - IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile)); + IssueDto branchIssue = db.issues().insert(rule, branch, branchFile); allowAnyoneOnProjects(project); indexIssuesAndViews(); @@ -694,10 +693,10 @@ public class SearchActionComponentsTest { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); - IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile)); + IssueDto projectIssue = db.issues().insert(rule, project, projectFile); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH)); ComponentDto branchFile = db.components().insertComponent(newFileDto(branch)); - IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile)); + IssueDto branchIssue = db.issues().insert(rule, branch, branchFile); allowAnyoneOnProjects(project); indexIssuesAndViews(); @@ -718,10 +717,10 @@ public class SearchActionComponentsTest { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); - IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile)); + IssueDto projectIssue = db.issues().insert(rule, project, projectFile); ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST)); ComponentDto pullRequestFile = db.components().insertComponent(newFileDto(pullRequest)); - IssueDto pullRequestIssue = db.issues().insertIssue(newIssue(rule, pullRequest, pullRequestFile)); + IssueDto pullRequestIssue = db.issues().insert(rule, pullRequest, pullRequestFile); allowAnyoneOnProjects(project); indexIssuesAndViews(); @@ -745,7 +744,7 @@ public class SearchActionComponentsTest { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertMainBranch(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); - IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile)); + IssueDto projectIssue = db.issues().insert(rule, project, projectFile); allowAnyoneOnProjects(project); indexIssuesAndViews(); @@ -769,10 +768,10 @@ public class SearchActionComponentsTest { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); - IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile)); + IssueDto projectIssue = db.issues().insert(rule, project, projectFile); ComponentDto branch = db.components().insertProjectBranch(project); ComponentDto branchFile = db.components().insertComponent(newFileDto(branch)); - IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile)); + IssueDto branchIssue = db.issues().insert(rule, branch, branchFile); allowAnyoneOnProjects(project); indexIssuesAndViews(); @@ -788,10 +787,10 @@ public class SearchActionComponentsTest { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); - IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile)); + IssueDto projectIssue = db.issues().insert(rule, project, projectFile); ComponentDto branch = db.components().insertProjectBranch(project); ComponentDto branchFile = db.components().insertComponent(newFileDto(branch)); - IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile)); + IssueDto branchIssue = db.issues().insert(rule, branch, branchFile); allowAnyoneOnProjects(project); indexIssues(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java index 60c537df939..82cc7bfacda 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java @@ -99,7 +99,7 @@ public class SetTagsActionTest { @Test public void set_tags() { - IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); + IssueDto issueDto = db.issues().insert(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "bug", "todo"); @@ -113,7 +113,7 @@ public class SetTagsActionTest { @Test public void remove_existing_tags_when_value_is_not_set() { - IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); + IssueDto issueDto = db.issues().insert(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey()); @@ -125,7 +125,7 @@ public class SetTagsActionTest { @Test public void remove_existing_tags_when_value_is_empty_string() { - IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); + IssueDto issueDto = db.issues().insert(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), ""); @@ -136,7 +136,7 @@ public class SetTagsActionTest { @Test public void set_tags_using_deprecated_key_param() { - IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); + IssueDto issueDto = db.issues().insert(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); ws.newRequest().setParam("key", issueDto.getKey()).setParam("tags", "bug").execute(); @@ -147,7 +147,7 @@ public class SetTagsActionTest { @Test public void tags_are_stored_as_lowercase() { - IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); + IssueDto issueDto = db.issues().insert(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "bug", "Convention"); @@ -158,7 +158,7 @@ public class SetTagsActionTest { @Test public void empty_tags_are_ignored() { - IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); + IssueDto issueDto = db.issues().insert(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "security", "", "convention"); @@ -169,7 +169,7 @@ public class SetTagsActionTest { @Test public void insert_entry_in_changelog_when_setting_tags() { - IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); + IssueDto issueDto = db.issues().insert(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "new-tag"); @@ -183,7 +183,7 @@ public class SetTagsActionTest { @Test public void fail_when_tag_use_bad_format() { - IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); + IssueDto issueDto = db.issues().insert(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); expectedException.expect(IllegalArgumentException.class); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java index 8f600cacb37..8cc50ad6b5b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java @@ -192,7 +192,7 @@ public class SetTypeActionTest { public void fail_if_trying_to_change_type_of_a_hotspot(RuleType type) { long now = 1_999_777_234L; when(system2.now()).thenReturn(now); - IssueDto issueDto = issueDbTester.insertIssue(newIssue().setType(SECURITY_HOTSPOT)); + IssueDto issueDto = issueDbTester.insertHotspot(); setUserWithBrowseAndAdministerIssuePermission(issueDto); expectedException.expect(IllegalArgumentException.class); |