From: Léo Geoffroy Date: Wed, 28 Jun 2023 09:08:24 +0000 (+0200) Subject: SONAR-19558 Fix issue with test framework X-Git-Tag: 10.2.0.77647~500 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cb1d5a94c220a335f43b7eda501f31ab723c9a0b;p=sonarqube.git SONAR-19558 Fix issue with test framework --- diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java index bf19e21ea04..bd047c767ed 100644 --- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java +++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java @@ -90,7 +90,6 @@ public class ViewsPersistComponentsStepIT extends BaseStepTest { private final System2 system2 = mock(System2.class); private final DbClient dbClient = dbTester.getDbClient(); private Date now; - private final ComponentDbTester componentDbTester = new ComponentDbTester(dbTester); private final MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS); private PersistComponentsStep underTest; @@ -459,7 +458,7 @@ public class ViewsPersistComponentsStepIT extends BaseStepTest { } private void persistComponents(ComponentDto... componentDtos) { - componentDbTester.insertComponents(componentDtos); + dbTester.components().insertComponents(componentDtos); } private ComponentDto getComponentFromDb(String componentKey) { diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoWithAuditIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoWithAuditIT.java index 05ceeb5c841..a1773451b0a 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoWithAuditIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoWithAuditIT.java @@ -43,7 +43,7 @@ public class PurgeDaoWithAuditIT { private final System2 system2 = mock(System2.class); @Rule - public DbTester db = DbTester.create(system2); + public DbTester db = DbTester.create(system2, true); @Captor ArgumentCaptor newValueCaptor; diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java index cf752455f0a..ff87690d1c3 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java @@ -50,10 +50,6 @@ public class ComponentDbTester { private final DbSession dbSession; private final boolean useDifferentUuids; - public ComponentDbTester(DbTester db) { - this(db, false); - } - public ComponentDbTester(DbTester db, boolean useDifferentProjectUuids) { this.db = db; this.dbClient = db.getDbClient(); diff --git a/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java b/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java index 7133efd4c54..d4903dd711f 100644 --- a/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java +++ b/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java @@ -61,7 +61,6 @@ public class PermissionIndexerDaoIT { private final DbClient dbClient = dbTester.getDbClient(); private final DbSession dbSession = dbTester.getSession(); - private final ComponentDbTester componentDbTester = new ComponentDbTester(dbTester); private final UserDbTester userDbTester = new UserDbTester(dbTester); private ProjectDto publicProject; @@ -78,12 +77,12 @@ public class PermissionIndexerDaoIT { @Before public void setUp() { - publicProject = componentDbTester.insertPublicProject().getProjectDto(); - privateProject1 = componentDbTester.insertPrivateProject().getProjectDto(); - privateProject2 = componentDbTester.insertPrivateProject().getProjectDto(); - view1 = componentDbTester.insertPublicPortfolioDto(); - view2 = componentDbTester.insertPublicPortfolioDto(); - application = componentDbTester.insertPublicApplication().getProjectDto(); + publicProject = dbTester.components().insertPublicProject().getProjectDto(); + privateProject1 = dbTester.components().insertPrivateProject().getProjectDto(); + privateProject2 = dbTester.components().insertPrivateProject().getProjectDto(); + view1 = dbTester.components().insertPublicPortfolioDto(); + view2 = dbTester.components().insertPublicPortfolioDto(); + application = dbTester.components().insertPublicApplication().getProjectDto(); user1 = userDbTester.insertUser(); user2 = userDbTester.insertUser(); group = userDbTester.insertGroup(); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java index 2f392e5792b..6755e90309f 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java @@ -56,11 +56,9 @@ public abstract class ComponentIndexTest { protected ComponentIndex index = new ComponentIndex(es.client(), new WebAuthorizationTypeSupport(userSession), System2.INSTANCE); protected PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, indexer); - private final ComponentDbTester componentDbTester = new ComponentDbTester(db); - protected void assertResultOrder(String query, String... resultsInOrder) { List projects = Arrays.stream(resultsInOrder) - .map(r -> componentDbTester.insertPublicProject(c -> c.setName(r)).getProjectDto()) + .map(r -> db.components().insertPublicProject(c -> c.setName(r)).getProjectDto()) .toList(); // index them, but not in the expected order @@ -106,11 +104,11 @@ public abstract class ComponentIndexTest { } protected ProjectDto indexProject(String key, String name) { - return index(componentDbTester.insertPublicProject("UUID" + key, c -> c.setKey(key).setName(name)).getProjectDto()); + return index(db.components().insertPublicProject("UUID" + key, c -> c.setKey(key).setName(name)).getProjectDto()); } protected EntityDto newProject(String key, String name) { - return componentDbTester.insertPublicProject("UUID_" + key, c -> c.setKey(key).setName(name)).getProjectDto(); + return db.components().insertPublicProject("UUID_" + key, c -> c.setKey(key).setName(name)).getProjectDto(); } protected ProjectDto index(ProjectDto dto) { diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java index 2052180e0ed..3b3af2c90dd 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java @@ -53,8 +53,6 @@ public class ComponentServiceUpdateKeyIT { public final UserSessionRule userSession = UserSessionRule.standalone(); @Rule public final DbTester db = DbTester.create(system2); - - private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); private TestProjectIndexers projectIndexers = new TestProjectIndexers(); @@ -64,13 +62,13 @@ public class ComponentServiceUpdateKeyIT { @Test public void update_project_key() { ComponentDto project = insertSampleProject(); - ComponentDto file = componentDb.insertComponent(ComponentTesting.newFileDto(project).setKey("sample:root:src/File.xoo")); - ComponentDto inactiveFile = componentDb.insertComponent(ComponentTesting.newFileDto(project).setKey("sample:root:src/InactiveFile.xoo").setEnabled(false)); + ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project).setKey("sample:root:src/File.xoo")); + ComponentDto inactiveFile = db.components().insertComponent(ComponentTesting.newFileDto(project).setKey("sample:root:src/InactiveFile.xoo").setEnabled(false)); dbSession.commit(); logInAsProjectAdministrator(project); - underTest.updateKey(dbSession, componentDb.getProjectDtoByMainBranch(project), "sample2:root"); + underTest.updateKey(dbSession, db.components().getProjectDtoByMainBranch(project), "sample2:root"); dbSession.commit(); // Check project key has been updated @@ -105,7 +103,7 @@ public class ComponentServiceUpdateKeyIT { dbSession.commit(); logInAsProjectAdministrator(provisionedProject); - underTest.updateKey(dbSession, componentDb.getProjectDtoByMainBranch(provisionedProject), "provisionedProject2"); + underTest.updateKey(dbSession, db.components().getProjectDtoByMainBranch(provisionedProject), "provisionedProject2"); dbSession.commit(); assertComponentKeyHasBeenUpdated(provisionedProject.getKey(), "provisionedProject2"); @@ -117,7 +115,7 @@ public class ComponentServiceUpdateKeyIT { ComponentDto project = insertSampleProject(); userSession.logIn("john").addProjectPermission(UserRole.USER, project); - ProjectDto projectDto = componentDb.getProjectDtoByMainBranch(project); + ProjectDto projectDto = db.components().getProjectDtoByMainBranch(project); assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, "sample2:root")) .isInstanceOf(ForbiddenException.class); } @@ -125,10 +123,10 @@ public class ComponentServiceUpdateKeyIT { @Test public void fail_if_old_key_and_new_key_are_the_same() { ComponentDto project = insertSampleProject(); - ComponentDto anotherProject = componentDb.insertPrivateProject().getMainBranchComponent(); + ComponentDto anotherProject = db.components().insertPrivateProject().getMainBranchComponent(); logInAsProjectAdministrator(project); - ProjectDto projectDto = componentDb.getProjectDtoByMainBranch(project); + ProjectDto projectDto = db.components().getProjectDtoByMainBranch(project); String anotherProjectDbKey = anotherProject.getKey(); assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, anotherProjectDbKey)) @@ -141,7 +139,7 @@ public class ComponentServiceUpdateKeyIT { ComponentDto project = insertSampleProject(); logInAsProjectAdministrator(project); - ProjectDto projectDto = componentDb.getProjectDtoByMainBranch(project); + ProjectDto projectDto = db.components().getProjectDtoByMainBranch(project); assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, "")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Malformed key for ''. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit."); @@ -152,7 +150,7 @@ public class ComponentServiceUpdateKeyIT { ComponentDto project = insertSampleProject(); logInAsProjectAdministrator(project); - ProjectDto projectDto = componentDb.getProjectDtoByMainBranch(project); + ProjectDto projectDto = db.components().getProjectDtoByMainBranch(project); assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, "sample?root")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Malformed key for 'sample?root'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit."); @@ -163,7 +161,7 @@ public class ComponentServiceUpdateKeyIT { } private ComponentDto insertProject(String key) { - return componentDb.insertPrivateProject(c -> c.setKey(key)).getMainBranchComponent(); + return db.components().insertPrivateProject(c -> c.setKey(key)).getMainBranchComponent(); } private void assertComponentKeyHasBeenUpdated(String oldKey, String newKey) { diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java index 4d6841bc393..1c7b2219708 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java @@ -106,7 +106,6 @@ public class ChangeStatusActionIT { private HotspotWsSupport hotspotWsSupport = new HotspotWsSupport(dbClient, userSessionRule, system2); private ChangeStatusAction underTest = new ChangeStatusAction(dbClient, hotspotWsSupport, transitionService, issueFieldsSetter, issueUpdater, hotspotChangeEventService); private WsActionTester actionTester = new WsActionTester(underTest); - private final ComponentDbTester componentDbTester = new ComponentDbTester(dbTester); private BranchDto branchDto = mock(BranchDto.class); @Before diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/PullActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/PullActionIT.java index a03151cac61..70fb645091a 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/PullActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/PullActionIT.java @@ -86,7 +86,6 @@ public class PullActionIT { private final ComponentFinder componentFinder = new ComponentFinder(db.getDbClient(), resourceTypes); private final IssueDbTester issueDbTester = new IssueDbTester(db); - private final ComponentDbTester componentDbTester = new ComponentDbTester(db); private final PullAction underTest = new PullAction(system2, componentFinder, db.getDbClient(), userSession, pullActionProtobufObjectGenerator); @@ -228,7 +227,7 @@ public class PullActionIT { @Test public void wsExecution_whenHotspotOnAnotherBranchThanMain_shouldReturnOneIssue() throws IOException { - ProjectData projectData = componentDbTester.insertPrivateProjectWithCustomBranch("develop"); + ProjectData projectData = db.components().insertPrivateProjectWithCustomBranch("develop"); ProjectDto project = projectData.getProjectDto(); ComponentDto developBranch = projectData.getMainBranchComponent(); ComponentDto developFile = db.components().insertComponent(newFileDto(developBranch)); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/IssueFinderIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/IssueFinderIT.java index 9023c38c46a..e1a8df1a18a 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/IssueFinderIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/IssueFinderIT.java @@ -52,7 +52,6 @@ public class IssueFinderIT { private RuleDbTester ruleDbTester = new RuleDbTester(db); private IssueDbTester issueDbTester = new IssueDbTester(db); - private ComponentDbTester componentDbTester = new ComponentDbTester(db); private IssueFinder underTest = new IssueFinder(db.getDbClient(), userSession); @@ -88,8 +87,8 @@ public class IssueFinderIT { private IssueDto insertIssue() { RuleDto rule = ruleDbTester.insert(newRule()); - ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent(); - ComponentDto file = componentDbTester.insertComponent(newFileDto(project)); + ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); + ComponentDto file = db.components().insertComponent(newFileDto(project)); return issueDbTester.insert(newIssue(rule, project, file)); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullActionIT.java index fc334308a78..a9b45330c53 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullActionIT.java @@ -81,7 +81,6 @@ public class PullActionIT { private final ComponentFinder componentFinder = new ComponentFinder(db.getDbClient(), resourceTypes); private final IssueDbTester issueDbTester = new IssueDbTester(db); - private final ComponentDbTester componentDbTester = new ComponentDbTester(db); private final PullAction underTest = new PullAction(system2, componentFinder, db.getDbClient(), userSession, pullActionProtobufObjectGenerator, taintChecker); @@ -265,7 +264,7 @@ public class PullActionIT { @Test public void givenIssueOnAnotherBranch_returnOneIssue() throws IOException { - ComponentDto developBranch = componentDbTester.insertPrivateProjectWithCustomBranch("develop").getMainBranchComponent(); + ComponentDto developBranch = db.components().insertPrivateProjectWithCustomBranch("develop").getMainBranchComponent(); ComponentDto developFile = db.components().insertComponent(newFileDto(developBranch)); generateIssues(correctRule, developBranch, developFile, 1); loginWithBrowsePermission(developBranch.uuid(), developFile.uuid()); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullTaintActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullTaintActionIT.java index 5b9f9acc337..41b81fa2b98 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullTaintActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullTaintActionIT.java @@ -82,7 +82,6 @@ public class PullTaintActionIT { private final ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT); private final ComponentFinder componentFinder = new ComponentFinder(db.getDbClient(), resourceTypes); private final IssueDbTester issueDbTester = new IssueDbTester(db); - private final ComponentDbTester componentDbTester = new ComponentDbTester(db); private PullTaintActionProtobufObjectGenerator objectGenerator = new PullTaintActionProtobufObjectGenerator(db.getDbClient(), userSession); private PullTaintAction underTest = new PullTaintAction(system2, componentFinder, db.getDbClient(), userSession, @@ -264,7 +263,7 @@ public class PullTaintActionIT { @Test public void givenTaintOnAnotherBranch_returnOneTaint() throws IOException { - ComponentDto developBranch = componentDbTester.insertPrivateProjectWithCustomBranch("develop").getMainBranchComponent(); + ComponentDto developBranch = db.components().insertPrivateProjectWithCustomBranch("develop").getMainBranchComponent(); ComponentDto developFile = db.components().insertComponent(newFileDto(developBranch)); generateTaints(correctRule, developBranch, developFile, 1); loginWithBrowsePermission(developBranch.uuid(), developFile.uuid()); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/NewCodeDefinitionResolverTest.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/NewCodeDefinitionResolverTest.java index 8aa503e2eaa..69ab4740e95 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/NewCodeDefinitionResolverTest.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/NewCodeDefinitionResolverTest.java @@ -47,7 +47,6 @@ public class NewCodeDefinitionResolverTest { private static final String DEFAULT_PROJECT_ID = "12345"; private static final String MAIN_BRANCH = "main"; - private ComponentDbTester componentDb = new ComponentDbTester(db); private DbSession dbSession = db.getSession(); private DbClient dbClient = db.getDbClient(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ListActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ListActionIT.java index 68867b8bc10..3cad8a097a7 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ListActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ListActionIT.java @@ -17,26 +17,26 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - /* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - package org.sonar.server.newcodeperiod.ws; +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.newcodeperiod.ws; import java.time.Instant; import java.util.Optional; @@ -51,14 +51,17 @@ import org.sonar.core.documentation.DocumentationLinkGenerator; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbTester; +import org.sonar.db.component.BranchDto; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ProjectData; import org.sonar.db.component.SnapshotDto; import org.sonar.db.newcodeperiod.NewCodePeriodDao; import org.sonar.db.newcodeperiod.NewCodePeriodDbTester; import org.sonar.db.newcodeperiod.NewCodePeriodDto; import org.sonar.db.newcodeperiod.NewCodePeriodType; +import org.sonar.db.project.ProjectDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; @@ -77,326 +80,325 @@ import static org.mockito.Mockito.when; import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME; import static org.sonar.db.component.SnapshotTesting.newAnalysis; - public class ListActionIT { - @Rule - public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule - public DbTester db = DbTester.create(System2.INSTANCE, true); - - private ComponentDbTester componentDb = new ComponentDbTester(db); - private DbClient dbClient = db.getDbClient(); - private ComponentFinder componentFinder = TestComponentFinder.from(db); - private NewCodePeriodDao dao = new NewCodePeriodDao(System2.INSTANCE, UuidFactoryFast.getInstance()); - private NewCodePeriodDbTester tester = new NewCodePeriodDbTester(db); - private DocumentationLinkGenerator documentationLinkGenerator = mock(DocumentationLinkGenerator.class); - private WsActionTester ws; - - @Before - public void setup(){ - when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarqube.org/9.9/project-administration/defining-new-code/"); - ws = new WsActionTester(new ListAction(dbClient, userSession, componentFinder, dao, documentationLinkGenerator)); - } +public class ListActionIT { + @Rule + public UserSessionRule userSession = UserSessionRule.standalone(); + @Rule + public DbTester db = DbTester.create(System2.INSTANCE, true); + private DbClient dbClient = db.getDbClient(); + private ComponentFinder componentFinder = TestComponentFinder.from(db); + private NewCodePeriodDao dao = new NewCodePeriodDao(System2.INSTANCE, UuidFactoryFast.getInstance()); + private NewCodePeriodDbTester tester = new NewCodePeriodDbTester(db); + private DocumentationLinkGenerator documentationLinkGenerator = mock(DocumentationLinkGenerator.class); + private WsActionTester ws; + + @Before + public void setup() { + when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarqube.org/9.9/project-administration/defining-new-code/"); + ws = new WsActionTester(new ListAction(dbClient, userSession, componentFinder, dao, documentationLinkGenerator)); + } - @Test - public void test_definition() { + @Test + public void test_definition() { - WebService.Action definition = ws.getDef(); + WebService.Action definition = ws.getDef(); - assertThat(definition.description()).contains("https://docs.sonarqube.org/9.9/project-administration/defining-new-code/"); + assertThat(definition.description()).contains("https://docs.sonarqube.org/9.9/project-administration/defining-new-code/"); - assertThat(definition.key()).isEqualTo("list"); - assertThat(definition.isInternal()).isFalse(); - assertThat(definition.since()).isEqualTo("8.0"); - assertThat(definition.isPost()).isFalse(); + assertThat(definition.key()).isEqualTo("list"); + assertThat(definition.isInternal()).isFalse(); + assertThat(definition.since()).isEqualTo("8.0"); + assertThat(definition.isPost()).isFalse(); - assertThat(definition.params()).extracting(WebService.Param::key).containsOnly("project"); - assertThat(definition.param("project").isRequired()).isTrue(); - } + assertThat(definition.params()).extracting(WebService.Param::key).containsOnly("project"); + assertThat(definition.param("project").isRequired()).isTrue(); + } - @Test - public void throw_NFE_if_project_not_found() { - assertThatThrownBy(() -> ws.newRequest() - .setParam("project", "unknown") - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("Project 'unknown' not found"); - } + @Test + public void throw_NFE_if_project_not_found() { + assertThatThrownBy(() -> ws.newRequest() + .setParam("project", "unknown") + .execute()) + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("Project 'unknown' not found"); + } - @Test - public void throw_FE_if_no_project_permission() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + @Test + public void throw_FE_if_no_project_permission() { + ProjectDto project = db.components().insertPublicProject().getProjectDto(); - assertThatThrownBy(() -> ws.newRequest() - .setParam("project", project.getKey()) - .execute()) - .isInstanceOf(ForbiddenException.class) - .hasMessageContaining("Insufficient privileges"); - } + assertThatThrownBy(() -> ws.newRequest() + .setParam("project", project.getKey()) + .execute()) + .isInstanceOf(ForbiddenException.class) + .hasMessageContaining("Insufficient privileges"); + } - @Test - public void list_only_branches() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + @Test + public void list_only_branches() { + ProjectDto project = db.components().insertPublicProject().getProjectDto(); - createBranches(project, 5, BranchType.BRANCH); - createBranches(project, 3, BranchType.PULL_REQUEST); + createBranches(project, 5, BranchType.BRANCH); + createBranches(project, 3, BranchType.PULL_REQUEST); - logInAsProjectAdministrator(project); + logInAsProjectAdministrator(project); - ListWSResponse response = ws.newRequest() - .setParam("project", project.getKey()) - .executeProtobuf(ListWSResponse.class); + ListWSResponse response = ws.newRequest() + .setParam("project", project.getKey()) + .executeProtobuf(ListWSResponse.class); - assertThat(response).isNotNull(); - assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) - .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); + assertThat(response).isNotNull(); + assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) + .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); - //check if global default is set - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) - .contains(NewCodePeriods.NewCodePeriodType.PREVIOUS_VERSION); - } + //check if global default is set + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) + .contains(NewCodePeriods.NewCodePeriodType.PREVIOUS_VERSION); + } - @Test - public void list_inherited_global_settings() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("uuid")); + @Test + public void list_inherited_global_settings() { + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("uuid")); - createBranches(project, 5, BranchType.BRANCH); + createBranches(project, 5, BranchType.BRANCH); - logInAsProjectAdministrator(project); + logInAsProjectAdministrator(project); - ListWSResponse response = ws.newRequest() - .setParam("project", project.getKey()) - .executeProtobuf(ListWSResponse.class); + ListWSResponse response = ws.newRequest() + .setParam("project", project.getKey()) + .executeProtobuf(ListWSResponse.class); - assertThat(response).isNotNull(); - assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) - .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); + assertThat(response).isNotNull(); + assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) + .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); - //check if global default is set - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) - .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) - .contains("uuid"); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) - .contains(true); - } + //check if global default is set + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) + .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) + .contains("uuid"); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) + .contains(true); + } - @Test - public void list_inherited_project_settings() { - ComponentDto projectWithOwnSettings = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto projectWithGlobalSettings = componentDb.insertPublicProject().getMainBranchComponent(); - tester.insert(new NewCodePeriodDto() - .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) - .setValue("global_uuid")); - tester.insert(new NewCodePeriodDto() - .setProjectUuid(projectWithOwnSettings.uuid()) - .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) - .setValue("project_uuid")); - - createBranches(projectWithOwnSettings, 5, BranchType.BRANCH); - - logInAsProjectAdministrator(projectWithOwnSettings, projectWithGlobalSettings); - - ListWSResponse response = ws.newRequest() - .setParam("project", projectWithOwnSettings.getKey()) - .executeProtobuf(ListWSResponse.class); - - //verify project with project level settings - assertThat(response).isNotNull(); - assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) - .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); - - //check if project setting is set - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) - .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) - .containsOnly("project_uuid"); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) - .containsOnly(true); - - //verify project with global level settings - response = ws.newRequest() - .setParam("project", projectWithGlobalSettings.getKey()) - .executeProtobuf(ListWSResponse.class); - - assertThat(response).isNotNull(); - assertThat(response.getNewCodePeriodsCount()).isOne(); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) - .containsOnly(DEFAULT_MAIN_BRANCH_NAME); - - //check if global setting is set - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) - .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) - .contains("global_uuid"); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) - .containsOnly(true); - } + @Test + public void list_inherited_project_settings() { + ProjectDto projectWithOwnSettings = db.components().insertPublicProject().getProjectDto(); + ProjectDto projectWithGlobalSettings = db.components().insertPublicProject().getProjectDto(); + tester.insert(new NewCodePeriodDto() + .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) + .setValue("global_uuid")); + tester.insert(new NewCodePeriodDto() + .setProjectUuid(projectWithOwnSettings.getUuid()) + .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) + .setValue("project_uuid")); + + createBranches(projectWithOwnSettings, 5, BranchType.BRANCH); + + logInAsProjectAdministrator(projectWithOwnSettings, projectWithGlobalSettings); + + ListWSResponse response = ws.newRequest() + .setParam("project", projectWithOwnSettings.getKey()) + .executeProtobuf(ListWSResponse.class); + + //verify project with project level settings + assertThat(response).isNotNull(); + assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) + .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); + + //check if project setting is set + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) + .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) + .containsOnly("project_uuid"); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) + .containsOnly(true); + + //verify project with global level settings + response = ws.newRequest() + .setParam("project", projectWithGlobalSettings.getKey()) + .executeProtobuf(ListWSResponse.class); + + assertThat(response).isNotNull(); + assertThat(response.getNewCodePeriodsCount()).isOne(); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) + .containsOnly(DEFAULT_MAIN_BRANCH_NAME); + + //check if global setting is set + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) + .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) + .contains("global_uuid"); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) + .containsOnly(true); + } - @Test - public void list_branch_and_inherited_global_settings() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branchWithOwnSettings = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS")); - componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("GLOBAL_SETTINGS")); - - tester.insert(new NewCodePeriodDto() - .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) - .setValue("global_uuid")); - - tester.insert(new NewCodePeriodDto() - .setProjectUuid(project.uuid()) - .setBranchUuid(branchWithOwnSettings.uuid()) - .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) - .setValue("branch_uuid")); - - logInAsProjectAdministrator(project); - - ListWSResponse response = ws.newRequest() - .setParam("project", project.getKey()) - .executeProtobuf(ListWSResponse.class); - - assertThat(response).isNotNull(); - assertThat(response.getNewCodePeriodsCount()).isEqualTo(3); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) - .contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "GLOBAL_SETTINGS"); - - Optional ownSettings = response.getNewCodePeriodsList().stream() - .filter(s -> !s.getInherited()) - .findFirst(); - - assertThat(ownSettings) - .isNotNull() - .isNotEmpty(); - assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey()); - assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS"); - assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); - assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid"); - assertThat(ownSettings.get().getInherited()).isFalse(); - - //check if global default is set - assertThat(response.getNewCodePeriodsList()) - .filteredOn(ShowWSResponse::getInherited) - .extracting(ShowWSResponse::getType) - .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); - assertThat(response.getNewCodePeriodsList()) - .filteredOn(ShowWSResponse::getInherited) - .extracting(ShowWSResponse::getValue) - .contains("global_uuid"); - } + @Test + public void list_branch_and_inherited_global_settings() { + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + BranchDto branchWithOwnSettings = db.components().insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS")); + db.components().insertProjectBranch(project, branchDto -> branchDto.setKey("GLOBAL_SETTINGS")); + + tester.insert(new NewCodePeriodDto() + .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) + .setValue("global_uuid")); + + tester.insert(new NewCodePeriodDto() + .setProjectUuid(project.getUuid()) + .setBranchUuid(branchWithOwnSettings.getUuid()) + .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) + .setValue("branch_uuid")); + + logInAsProjectAdministrator(project); + + ListWSResponse response = ws.newRequest() + .setParam("project", project.getKey()) + .executeProtobuf(ListWSResponse.class); + + assertThat(response).isNotNull(); + assertThat(response.getNewCodePeriodsCount()).isEqualTo(3); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) + .contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "GLOBAL_SETTINGS"); + + Optional ownSettings = response.getNewCodePeriodsList().stream() + .filter(s -> !s.getInherited()) + .findFirst(); + + assertThat(ownSettings) + .isNotNull() + .isNotEmpty(); + assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey()); + assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS"); + assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); + assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid"); + assertThat(ownSettings.get().getInherited()).isFalse(); + + //check if global default is set + assertThat(response.getNewCodePeriodsList()) + .filteredOn(ShowWSResponse::getInherited) + .extracting(ShowWSResponse::getType) + .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); + assertThat(response.getNewCodePeriodsList()) + .filteredOn(ShowWSResponse::getInherited) + .extracting(ShowWSResponse::getValue) + .contains("global_uuid"); + } - @Test - public void list_branch_and_inherited_project_settings() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branchWithOwnSettings = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS")); - componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_SETTINGS")); - - tester.insert(new NewCodePeriodDto() - .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) - .setValue("global_uuid")); - - tester.insert(new NewCodePeriodDto() - .setProjectUuid(project.uuid()) - .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) - .setValue("project_uuid")); - - tester.insert(new NewCodePeriodDto() - .setProjectUuid(project.uuid()) - .setBranchUuid(branchWithOwnSettings.uuid()) - .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) - .setValue("branch_uuid")); - - logInAsProjectAdministrator(project); - - ListWSResponse response = ws.newRequest() - .setParam("project", project.getKey()) - .executeProtobuf(ListWSResponse.class); - - assertThat(response).isNotNull(); - assertThat(response.getNewCodePeriodsCount()).isEqualTo(3); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) - .contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "PROJECT_SETTINGS"); - - Optional ownSettings = response.getNewCodePeriodsList().stream() - .filter(s -> !s.getInherited()) - .findFirst(); - - assertThat(ownSettings) - .isNotNull() - .isNotEmpty(); - assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey()); - assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS"); - assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); - assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid"); - assertThat(ownSettings.get().getInherited()).isFalse(); - - //check if global default is set - assertThat(response.getNewCodePeriodsList()) - .filteredOn(ShowWSResponse::getInherited) - .extracting(ShowWSResponse::getType) - .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); - assertThat(response.getNewCodePeriodsList()) - .filteredOn(ShowWSResponse::getInherited) - .extracting(ShowWSResponse::getValue) - .contains("project_uuid"); - } + @Test + public void list_branch_and_inherited_project_settings() { + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + BranchDto branchWithOwnSettings = db.components().insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS")); + db.components().insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_SETTINGS")); + + tester.insert(new NewCodePeriodDto() + .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) + .setValue("global_uuid")); + + tester.insert(new NewCodePeriodDto() + .setProjectUuid(project.getUuid()) + .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) + .setValue("project_uuid")); + + tester.insert(new NewCodePeriodDto() + .setProjectUuid(project.getUuid()) + .setBranchUuid(branchWithOwnSettings.getUuid()) + .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) + .setValue("branch_uuid")); + + logInAsProjectAdministrator(project); + + ListWSResponse response = ws.newRequest() + .setParam("project", project.getKey()) + .executeProtobuf(ListWSResponse.class); + + assertThat(response).isNotNull(); + assertThat(response.getNewCodePeriodsCount()).isEqualTo(3); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) + .contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "PROJECT_SETTINGS"); + + Optional ownSettings = response.getNewCodePeriodsList().stream() + .filter(s -> !s.getInherited()) + .findFirst(); + + assertThat(ownSettings) + .isNotNull() + .isNotEmpty(); + assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey()); + assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS"); + assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); + assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid"); + assertThat(ownSettings.get().getInherited()).isFalse(); + + //check if global default is set + assertThat(response.getNewCodePeriodsList()) + .filteredOn(ShowWSResponse::getInherited) + .extracting(ShowWSResponse::getType) + .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); + assertThat(response.getNewCodePeriodsList()) + .filteredOn(ShowWSResponse::getInherited) + .extracting(ShowWSResponse::getValue) + .contains("project_uuid"); + } - @Test - public void verify_specific_analysis_effective_value() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_BRANCH")); - - SnapshotDto analysis = componentDb.insertSnapshot(newAnalysis(project) - .setUuid("A1") - .setCreatedAt(Instant.now().toEpochMilli()) - .setProjectVersion("1.2") - .setBuildString("1.2.0.322") - .setRevision("bfe36592eb7f9f2708b5d358b5b5f33ed535c8cf") - ); - - componentDb.insertSnapshot(newAnalysis(project) - .setUuid("A2") - .setCreatedAt(Instant.now().toEpochMilli()) - .setProjectVersion("1.2") - .setBuildString("1.2.0.322") - .setRevision("2d6d5d8d5fabe2223f07aa495e794d0401ff4b04") - ); - - tester.insert(new NewCodePeriodDto() - .setProjectUuid(project.uuid()) - .setBranchUuid(branch.uuid()) - .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) - .setValue(analysis.getUuid())); - - logInAsProjectAdministrator(project); - - ListWSResponse response = ws.newRequest() - .setParam("project", project.getKey()) - .executeProtobuf(ListWSResponse.class); - - assertThat(response).isNotNull(); - assertThat(response.getNewCodePeriodsCount()).isEqualTo(2); - assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) - .containsOnly(DEFAULT_MAIN_BRANCH_NAME, "PROJECT_BRANCH"); - - ShowWSResponse result = response.getNewCodePeriodsList().get(0); - assertThat(result.getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); - assertThat(result.getValue()).isEqualTo("A1"); - assertThat(result.getProjectKey()).isEqualTo(project.getKey()); - assertThat(result.getBranchKey()).isEqualTo("PROJECT_BRANCH"); - assertThat(result.getEffectiveValue()).isEqualTo(DateUtils.formatDateTime(analysis.getCreatedAt())); - } + @Test + public void verify_specific_analysis_effective_value() { + ProjectData projectData = db.components().insertPublicProject(); + ProjectDto project = projectData.getProjectDto(); + BranchDto branch = db.components().insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_BRANCH")); + + SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(projectData.getMainBranchComponent()) + .setUuid("A1") + .setCreatedAt(Instant.now().toEpochMilli()) + .setProjectVersion("1.2") + .setBuildString("1.2.0.322") + .setRevision("bfe36592eb7f9f2708b5d358b5b5f33ed535c8cf") + ); + + db.components().insertSnapshot(newAnalysis(projectData.getMainBranchComponent()) + .setUuid("A2") + .setCreatedAt(Instant.now().toEpochMilli()) + .setProjectVersion("1.2") + .setBuildString("1.2.0.322") + .setRevision("2d6d5d8d5fabe2223f07aa495e794d0401ff4b04") + ); + + tester.insert(new NewCodePeriodDto() + .setProjectUuid(project.getUuid()) + .setBranchUuid(branch.getUuid()) + .setType(NewCodePeriodType.SPECIFIC_ANALYSIS) + .setValue(analysis.getUuid())); + + logInAsProjectAdministrator(project); + + ListWSResponse response = ws.newRequest() + .setParam("project", project.getKey()) + .executeProtobuf(ListWSResponse.class); + + assertThat(response).isNotNull(); + assertThat(response.getNewCodePeriodsCount()).isEqualTo(2); + assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) + .containsOnly(DEFAULT_MAIN_BRANCH_NAME, "PROJECT_BRANCH"); + + ShowWSResponse result = response.getNewCodePeriodsList().get(0); + assertThat(result.getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); + assertThat(result.getValue()).isEqualTo("A1"); + assertThat(result.getProjectKey()).isEqualTo(project.getKey()); + assertThat(result.getBranchKey()).isEqualTo("PROJECT_BRANCH"); + assertThat(result.getEffectiveValue()).isEqualTo(DateUtils.formatDateTime(analysis.getCreatedAt())); + } - private void createBranches(ComponentDto project, int numberOfBranches, BranchType branchType) { - for (int branchCount = 0; branchCount < numberOfBranches; branchCount++) { - String branchKey = String.format("%s_%d", branchType.name(), branchCount); - componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey(branchKey).setBranchType(branchType)); - } + private void createBranches(ProjectDto project, int numberOfBranches, BranchType branchType) { + for (int branchCount = 0; branchCount < numberOfBranches; branchCount++) { + String branchKey = String.format("%s_%d", branchType.name(), branchCount); + db.components().insertProjectBranch(project, branchDto -> branchDto.setKey(branchKey).setBranchType(branchType)); } + } - private void logInAsProjectAdministrator(ComponentDto... project) { - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - } + private void logInAsProjectAdministrator(ProjectDto... project) { + userSession.logIn().addProjectPermission(UserRole.ADMIN, project); } +} diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java index aadb154a276..0f9b4964eb3 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java @@ -38,11 +38,14 @@ import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ProjectData; import org.sonar.db.component.SnapshotDto; import org.sonar.db.newcodeperiod.NewCodePeriodDao; import org.sonar.db.newcodeperiod.NewCodePeriodType; +import org.sonar.db.project.ProjectDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; @@ -65,8 +68,6 @@ public class SetActionIT { public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public DbTester db = DbTester.create(System2.INSTANCE, true); - - private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); private ComponentFinder componentFinder = TestComponentFinder.from(db); @@ -123,7 +124,7 @@ public class SetActionIT { @Test public void throw_IAE_if_type_is_invalid_for_project() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); assertThatThrownBy(() -> ws.newRequest() @@ -136,7 +137,7 @@ public class SetActionIT { @Test public void throw_IAE_if_no_value_for_days() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); assertThatThrownBy(() -> ws.newRequest() @@ -150,7 +151,7 @@ public class SetActionIT { @Test public void throw_IAE_if_no_value_for_analysis() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); assertThatThrownBy(() -> ws.newRequest() @@ -164,7 +165,7 @@ public class SetActionIT { @Test public void throw_IAE_if_days_is_invalid() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); assertThatThrownBy(() -> ws.newRequest() @@ -179,7 +180,7 @@ public class SetActionIT { @Test public void throw_IAE_if_setting_is_not_cayc_compliant() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); TestRequest request = ws.newRequest() @@ -196,7 +197,7 @@ public class SetActionIT { @Test public void no_error_if_setting_is_cayc_compliant() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); ws.newRequest() @@ -205,12 +206,12 @@ public class SetActionIT { .setParam("value", "90") .execute(); - assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "90"); + assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "90"); } @Test public void throw_IAE_if_analysis_is_not_found() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); assertThatThrownBy(() -> ws.newRequest() @@ -225,8 +226,9 @@ public class SetActionIT { @Test public void throw_IAE_if_analysis_doesnt_belong_to_branch() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); + ProjectData projectData = db.components().insertPublicProject(); + ProjectDto project = projectData.getProjectDto(); + ComponentDto branch = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("branch")); SnapshotDto analysisMaster = db.components().insertSnapshot(project); SnapshotDto analysisBranch = db.components().insertSnapshot(branch); @@ -266,7 +268,7 @@ public class SetActionIT { @Test public void throw_NFE_if_branch_not_found() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); assertThatThrownBy(() -> ws.newRequest() @@ -281,7 +283,7 @@ public class SetActionIT { // permission @Test public void throw_NFE_if_no_project_permission() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); assertThatThrownBy(() -> ws.newRequest() .setParam("project", project.getKey()) @@ -313,21 +315,22 @@ public class SetActionIT { @Test public void set_project_period_to_number_of_days() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); ws.newRequest() .setParam("project", project.getKey()) .setParam("type", "number_of_days") .setParam("value", "5") .execute(); - assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "5"); + assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "5"); } @Test @UseDataProvider("provideNewCodePeriodTypeAndValue") public void never_set_project_value_in_community_edition(NewCodePeriodType type, @Nullable String value) { when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY)); - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectData projectData = db.components().insertPublicProject(); + ProjectDto project = projectData.getProjectDto(); if (value != null && NewCodePeriodType.SPECIFIC_ANALYSIS.equals(type)) { db.components().insertSnapshot(project, snapshotDto -> snapshotDto.setUuid(value)); @@ -343,7 +346,7 @@ public class SetActionIT { } request.execute(); - assertTableContainsOnly(project.uuid(), project.uuid(), type, value); + assertTableContainsOnly(project.getUuid(), projectData.getMainBranchComponent().uuid(), type, value); } @DataProvider @@ -358,26 +361,27 @@ public class SetActionIT { @Test public void set_project_twice_period_to_number_of_days() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); ws.newRequest() .setParam("project", project.getKey()) .setParam("type", "previous_version") .execute(); - assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null); + assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null); ws.newRequest() .setParam("project", project.getKey()) .setParam("type", "number_of_days") .setParam("value", "5") .execute(); - assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "5"); + assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "5"); } @Test public void set_branch_period_to_analysis() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); + ProjectData projectData = db.components().insertPublicProject(); + ProjectDto project = projectData.getProjectDto(); + ComponentDto branch = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("branch")); SnapshotDto analysisMaster = db.components().insertSnapshot(project); SnapshotDto analysisBranch = db.components().insertSnapshot(branch); @@ -391,13 +395,14 @@ public class SetActionIT { .setParam("value", analysisBranch.getUuid()) .execute(); - assertTableContainsOnly(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, analysisBranch.getUuid()); + assertTableContainsOnly(project.getUuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, analysisBranch.getUuid()); } @Test public void set_branch_period_twice_to_analysis() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); + ProjectData projectData = db.components().insertPublicProject(); + ProjectDto project = projectData.getProjectDto(); + BranchDto branch = db.components().insertProjectBranch(projectData.getProjectDto(), b -> b.setKey("branch")); SnapshotDto analysisMaster = db.components().insertSnapshot(project); SnapshotDto analysisBranch = db.components().insertSnapshot(branch); @@ -417,7 +422,7 @@ public class SetActionIT { .setParam("branch", "branch") .execute(); - assertTableContainsOnly(project.uuid(), branch.uuid(), NewCodePeriodType.PREVIOUS_VERSION, null); + assertTableContainsOnly(project.getUuid(), branch.getUuid(), NewCodePeriodType.PREVIOUS_VERSION, null); } private void assertTableContainsOnly(@Nullable String projectUuid, @Nullable String branchUuid, NewCodePeriodType type, @Nullable String value) { @@ -426,7 +431,7 @@ public class SetActionIT { .containsOnly(entry("PROJECT_UUID", projectUuid), entry("BRANCH_UUID", branchUuid), entry("TYPE", type.name()), entry("VALUE", value)); } - private void logInAsProjectAdministrator(ComponentDto project) { + private void logInAsProjectAdministrator(ProjectDto project) { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ShowActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ShowActionIT.java index 9a073dc3959..ac7480855f0 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ShowActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ShowActionIT.java @@ -29,12 +29,14 @@ import org.sonar.core.documentation.DocumentationLinkGenerator; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbTester; +import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.newcodeperiod.NewCodePeriodDao; import org.sonar.db.newcodeperiod.NewCodePeriodDbTester; import org.sonar.db.newcodeperiod.NewCodePeriodDto; import org.sonar.db.newcodeperiod.NewCodePeriodType; +import org.sonar.db.project.ProjectDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; @@ -54,8 +56,6 @@ public class ShowActionIT { public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public DbTester db = DbTester.create(System2.INSTANCE, true); - - private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private ComponentFinder componentFinder = TestComponentFinder.from(db); private NewCodePeriodDao dao = new NewCodePeriodDao(System2.INSTANCE, UuidFactoryFast.getInstance()); @@ -96,7 +96,7 @@ public class ShowActionIT { @Test public void throw_FE_if_no_project_permission() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); assertThatThrownBy(() -> ws.newRequest() .setParam("project", project.getKey()) @@ -107,7 +107,7 @@ public class ShowActionIT { @Test public void throw_FE_if_project_issue_admin() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectIssueAdmin(project); assertThatThrownBy(() -> ws.newRequest() @@ -129,11 +129,11 @@ public class ShowActionIT { @Test public void show_project_setting() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); tester.insert(new NewCodePeriodDto() - .setProjectUuid(project.uuid()) + .setProjectUuid(project.getUuid()) .setType(NewCodePeriodType.NUMBER_OF_DAYS) .setValue("4")); @@ -146,14 +146,14 @@ public class ShowActionIT { @Test public void show_branch_setting() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); + BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch")); tester.insert(new NewCodePeriodDto() - .setProjectUuid(project.uuid()) - .setBranchUuid(branch.uuid()) + .setProjectUuid(project.getUuid()) + .setBranchUuid(branch.getUuid()) .setType(NewCodePeriodType.NUMBER_OF_DAYS) .setValue("1")); @@ -167,7 +167,7 @@ public class ShowActionIT { @Test public void show_inherited_project_setting() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.PREVIOUS_VERSION)); @@ -180,13 +180,13 @@ public class ShowActionIT { @Test public void show_inherited_branch_setting_from_project() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); + BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch")); tester.insert(new NewCodePeriodDto() - .setProjectUuid(project.uuid()) + .setProjectUuid(project.getUuid()) .setType(NewCodePeriodType.NUMBER_OF_DAYS) .setValue("1")); @@ -200,9 +200,9 @@ public class ShowActionIT { @Test public void show_inherited_branch_setting_from_global() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); + BranchDto branchDto = db.components().insertProjectBranch(project, b -> b.setKey("branch")); tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.NUMBER_OF_DAYS).setValue("3")); ShowWSResponse response = ws.newRequest() @@ -226,10 +226,10 @@ public class ShowActionIT { @Test public void show_inherited_if_branch_not_found() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectScan(project); - tester.insert(project.branchUuid(), NewCodePeriodType.NUMBER_OF_DAYS, "3"); + tester.insert(project.getUuid(), NewCodePeriodType.NUMBER_OF_DAYS, "3"); ShowWSResponse response = ws.newRequest() .setParam("project", project.getKey()) @@ -247,15 +247,15 @@ public class ShowActionIT { assertThat(response.getType()).isEqualTo(type); } - private void logInAsProjectAdministrator(ComponentDto project) { + private void logInAsProjectAdministrator(ProjectDto project) { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); } - private void logInAsProjectScan(ComponentDto project) { + private void logInAsProjectScan(ProjectDto project) { userSession.logIn().addProjectPermission(UserRole.SCAN, project); } - private void logInAsProjectIssueAdmin(ComponentDto project) { + private void logInAsProjectIssueAdmin(ProjectDto project) { userSession.logIn().addProjectPermission(UserRole.ISSUE_ADMIN, project); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java index 543ff39515c..07e15e53be3 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java @@ -34,10 +34,13 @@ import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ProjectData; import org.sonar.db.newcodeperiod.NewCodePeriodDao; import org.sonar.db.newcodeperiod.NewCodePeriodType; +import org.sonar.db.project.ProjectDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; @@ -58,8 +61,6 @@ public class UnsetActionIT { public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public DbTester db = DbTester.create(System2.INSTANCE, true); - - private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); private ComponentFinder componentFinder = TestComponentFinder.from(db); @@ -113,7 +114,7 @@ public class UnsetActionIT { @Test public void throw_NFE_if_branch_not_found() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); assertThatThrownBy(() -> ws.newRequest() @@ -128,7 +129,7 @@ public class UnsetActionIT { // permission @Test public void throw_NFE_if_no_project_permission() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); assertThatThrownBy(() -> ws.newRequest() .setParam("project", project.getKey()) @@ -159,7 +160,7 @@ public class UnsetActionIT { @Test public void delete_project_period() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); logInAsProjectAdministrator(project); ws.newRequest() .setParam("project", project.getKey()) @@ -170,31 +171,31 @@ public class UnsetActionIT { @Test public void delete_project_period_twice() { - ComponentDto project1 = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto project2 = componentDb.insertPublicProject().getMainBranchComponent(); - db.newCodePeriods().insert(project1.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid1"); - db.newCodePeriods().insert(project2.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2"); + ProjectDto project1 = db.components().insertPublicProject().getProjectDto(); + ProjectDto project2 = db.components().insertPublicProject().getProjectDto(); + db.newCodePeriods().insert(project1.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid1"); + db.newCodePeriods().insert(project2.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2"); logInAsProjectAdministrator(project1); ws.newRequest() .setParam("project", project1.getKey()) .execute(); - assertTableContainsOnly(project2.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2"); + assertTableContainsOnly(project2.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2"); ws.newRequest() .setParam("project", project1.getKey()) .execute(); - assertTableContainsOnly(project2.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2"); + assertTableContainsOnly(project2.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2"); } @Test public void delete_branch_period() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch")); - db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "20"); - db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2"); + db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "20"); + db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2"); logInAsProjectAdministrator(project); @@ -203,15 +204,16 @@ public class UnsetActionIT { .setParam("branch", "branch") .execute(); - assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "20"); + assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "20"); } @Test public void delete_branch_and_project_period_in_community_edition() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectData projectData = db.components().insertPublicProject(); + ProjectDto project = projectData.getProjectDto(); - db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid1"); - db.newCodePeriods().insert(project.uuid(), project.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2"); + db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid1"); + db.newCodePeriods().insert(project.getUuid(), projectData.getMainBranchComponent().uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2"); when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY)); @@ -226,10 +228,10 @@ public class UnsetActionIT { @Test public void throw_IAE_if_unset_branch_NCD_and_project_NCD_not_compliant() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); - db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "97"); - db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch")); + db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "97"); + db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); TestRequest request = ws.newRequest() .setParam("project", project.getKey()) @@ -245,10 +247,10 @@ public class UnsetActionIT { @Test public void throw_IAE_if_unset_branch_NCD_and_no_project_NCD_and_instance_NCD_not_compliant() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch")); db.newCodePeriods().insert(null, null, NewCodePeriodType.NUMBER_OF_DAYS, "97"); - db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); + db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); TestRequest request = ws.newRequest() .setParam("project", project.getKey()) @@ -263,9 +265,9 @@ public class UnsetActionIT { @Test public void throw_IAE_if_unset_project_NCD_and_instance_NCD_not_compliant() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); db.newCodePeriods().insert(null, null, NewCodePeriodType.NUMBER_OF_DAYS, "97"); - db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); + db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); logInAsProjectAdministrator(project); @@ -279,8 +281,8 @@ public class UnsetActionIT { @Test public void do_not_throw_IAE_if_unset_project_NCD_and_no_instance_NCD() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); logInAsProjectAdministrator(project); ws.newRequest() @@ -292,10 +294,10 @@ public class UnsetActionIT { @Test public void do_not_throw_IAE_if_unset_branch_NCD_and_project_NCD_compliant() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); - db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); - db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch")); + db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); + db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null); logInAsProjectAdministrator(project); ws.newRequest() @@ -303,14 +305,14 @@ public class UnsetActionIT { .setParam("branch", "branch") .execute(); - assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null); + assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null); } @Test public void do_not_throw_IAE_if_unset_branch_NCD_and_project_NCD_not_compliant_and_no_branch_NCD() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - componentDb.insertProjectBranch(project, b -> b.setKey("branch")); - db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "93"); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + db.components().insertProjectBranch(project, b -> b.setKey("branch")); + db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "93"); logInAsProjectAdministrator(project); ws.newRequest() @@ -318,14 +320,14 @@ public class UnsetActionIT { .setParam("branch", "branch") .execute(); - assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "93"); + assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "93"); } @Test public void do_not_throw_IAE_if_unset_branch_NCD_and_no_project_NCD_and_instance_NCD_compliant() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); - db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch")); + db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); db.newCodePeriods().insert(null, null, NewCodePeriodType.PREVIOUS_VERSION, null); logInAsProjectAdministrator(project); @@ -339,9 +341,9 @@ public class UnsetActionIT { @Test public void do_not_throw_IAE_if_unset_branch_NCD_and_no_project_NCD_and_no_instance() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); - db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch")); + db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid"); logInAsProjectAdministrator(project); ws.newRequest() @@ -354,10 +356,10 @@ public class UnsetActionIT { @Test public void do_not_throw_IAE_if_unset_project_NCD_and_instance_NCD_compliant() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch")); db.newCodePeriods().insert(null, null, NewCodePeriodType.PREVIOUS_VERSION, null); - db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null); + db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null); logInAsProjectAdministrator(project); ws.newRequest() @@ -369,8 +371,8 @@ public class UnsetActionIT { @Test public void do_not_throw_IAE_if_unset_project_NCD_and_instance_NCD_not_compliant_and_no_project_NCD() { - ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent(); - ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch")); + ProjectDto project = db.components().insertPublicProject().getProjectDto(); + BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch")); db.newCodePeriods().insert(null, null, NewCodePeriodType.NUMBER_OF_DAYS, "93"); logInAsProjectAdministrator(project); @@ -391,7 +393,7 @@ public class UnsetActionIT { .containsOnly(entry("PROJECT_UUID", projectUuid), entry("BRANCH_UUID", branchUuid), entry("TYPE", type.name()), entry("VALUE", value)); } - private void logInAsProjectAdministrator(ComponentDto project) { + private void logInAsProjectAdministrator(ProjectDto project) { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/DeleteActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/DeleteActionIT.java index ba9474a1be9..9763ef867eb 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/DeleteActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/DeleteActionIT.java @@ -68,7 +68,6 @@ public class DeleteActionIT { private final DbClient dbClient = db.getDbClient(); private final DbSession dbSession = db.getSession(); private final WebhookDbTester webhookDbTester = db.webhooks(); - private final ComponentDbTester componentDbTester = new ComponentDbTester(db); private final ComponentCleanerService componentCleanerService = mock(ComponentCleanerService.class); private final ProjectLifeCycleListeners projectLifeCycleListeners = mock(ProjectLifeCycleListeners.class); private final ResourceTypes mockResourceTypes = mock(ResourceTypes.class); @@ -82,7 +81,7 @@ public class DeleteActionIT { @Test public void global_administrator_deletes_project_by_key() { - ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent(); + ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); userSessionRule.logIn().addPermission(GlobalPermission.ADMINISTER); call(tester.newRequest().setParam(PARAM_PROJECT, project.getKey())); @@ -93,7 +92,7 @@ public class DeleteActionIT { @Test public void project_administrator_deletes_the_project_by_key() { - ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent(); + ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); userSessionRule.logIn().addProjectPermission(UserRole.ADMIN, project); call(tester.newRequest().setParam(PARAM_PROJECT, project.getKey())); @@ -104,7 +103,7 @@ public class DeleteActionIT { @Test public void project_deletion_also_ensure_that_homepage_on_this_project_if_it_exists_is_cleared() { - ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent(); + ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); UserDto insert = dbClient.userDao().insert(dbSession, newUserDto().setHomepageType("PROJECT").setHomepageParameter(project.uuid())); dbSession.commit(); @@ -125,7 +124,7 @@ public class DeleteActionIT { @Test public void project_deletion_also_ensure_that_webhooks_on_this_project_if_they_exists_are_deleted() { - ProjectDto project = componentDbTester.insertPrivateProject().getProjectDto(); + ProjectDto project = db.components().insertPrivateProject().getProjectDto(); webhookDbTester.insertWebhook(project); webhookDbTester.insertWebhook(project); webhookDbTester.insertWebhook(project); @@ -147,7 +146,7 @@ public class DeleteActionIT { @Test public void return_403_if_not_project_admin_nor_org_admin() { - ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent(); + ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); userSessionRule.logIn() .addProjectPermission(UserRole.CODEVIEWER, project) @@ -161,7 +160,7 @@ public class DeleteActionIT { @Test public void return_401_if_not_logged_in() { - ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent(); + ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); userSessionRule.anonymous(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/SettingsUpdaterIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/SettingsUpdaterIT.java index 4211e304b5c..681ef67f4cf 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/SettingsUpdaterIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/SettingsUpdaterIT.java @@ -54,7 +54,6 @@ public class SettingsUpdaterIT { DbSession dbSession = db.getSession(); PropertyDbTester propertyDb = new PropertyDbTester(db); - ComponentDbTester componentDb = new ComponentDbTester(db); PropertyDefinitions definitions = new PropertyDefinitions(System2.INSTANCE); ProjectDto project; @@ -63,7 +62,7 @@ public class SettingsUpdaterIT { @Before public void setUp() { - project = componentDb.insertPrivateProject().getProjectDto(); + project = db.components().insertPrivateProject().getProjectDto(); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/usergroups/ws/DeleteActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/usergroups/ws/DeleteActionIT.java index 8243090d3fc..8a65fe1d359 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/usergroups/ws/DeleteActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/usergroups/ws/DeleteActionIT.java @@ -63,8 +63,6 @@ public class DeleteActionIT { public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public DbTester db = DbTester.create(new AlwaysIncreasingSystem2()); - - private final ComponentDbTester componentTester = new ComponentDbTester(db); private final GroupService groupService = new GroupService(db.getDbClient(), UuidFactoryImpl.INSTANCE); private final ManagedInstanceService managedInstanceService = mock(ManagedInstanceService.class); @@ -144,7 +142,7 @@ public class DeleteActionIT { addAdmin(); insertDefaultGroup(); GroupDto group = db.users().insertGroup(); - ComponentDto project = componentTester.insertPrivateProject().getMainBranchComponent(); + ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); db.users().insertProjectPermissionOnGroup(group, UserRole.ADMIN, project); loginAsAdmin();