]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19558 Fix issue with test framework
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Wed, 28 Jun 2023 09:08:24 +0000 (11:08 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 28 Jun 2023 20:03:01 +0000 (20:03 +0000)
19 files changed:
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoWithAuditIT.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java
server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/PullActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/IssueFinderIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullTaintActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/NewCodeDefinitionResolverTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ListActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ShowActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/DeleteActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/SettingsUpdaterIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/usergroups/ws/DeleteActionIT.java

index bf19e21ea040149c39fbd2c35abb42847ac1c299..bd047c767ed9fe1b30215b39e9e259a0502d64ce 100644 (file)
@@ -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) {
index 05ceeb5c8418bcd9ee16bc2f86440e2b21dbdc2a..a1773451b0a2c152c3a8c398a2412eca88d008c6 100644 (file)
@@ -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<ComponentNewValue> newValueCaptor;
index cf752455f0a6589175969f266aeec922d2981abc..ff87690d1c3cce0c75c18ca03838f18eac7da867 100644 (file)
@@ -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();
index 7133efd4c540fb8a81358a8bc81c4bc885a2b3e8..d4903dd711f5527758ec2d94e7691b22b26817bb 100644 (file)
@@ -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();
index 2f392e5792bada519dd7e8a3bec8c0b49c4e6896..6755e90309f07038d20c4e44c9d95fc2d0104790 100644 (file)
@@ -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<ProjectDto> 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) {
index 2052180e0ed6ca466ac6905aa2faaba894e6acd1..3b3af2c90dd58b6f36db85a5da50a015b41d9e47 100644 (file)
@@ -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) {
index 4d6841bc393696f666e7a18c451626f6fc6a4c30..1c7b22197087a88676330dd9a0d6c6bc53dfff6d 100644 (file)
@@ -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
index a03151cac616031ec24ce8b37d58110131f0806a..70fb645091a0e9050d9c8e447435fc456bfd0583 100644 (file)
@@ -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));
index 9023c38c46ae1c1a2b80f7081ba7eaa81fce4d12..e1a8df1a18a17d27699e0f04aa0cc9941e22e2b1 100644 (file)
@@ -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));
   }
 
index fc334308a785adf8c08c85f461f394f42355d057..a9b45330c532dca0316050f3fbe7c2ea17017614 100644 (file)
@@ -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());
index 5b9f9acc3375e71bad3bbb4216bb237fd4bbe864..41b81fa2b982be1086fa435258bbdbbed92ea437 100644 (file)
@@ -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());
index 8aa503e2eaa689c0728eef8d62fa576d913fed51..69ab4740e954b09544a41e548c85a51dd8f3a0a3 100644 (file)
@@ -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();
index 68867b8bc10ddb6f298bdd7fd75a68740651771a..3cad8a097a738ce3600a5ef2bf9fa78138975ae8 100644 (file)
  * 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<ShowWSResponse> 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<ShowWSResponse> 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<ShowWSResponse> 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<ShowWSResponse> 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);
   }
+}
index aadb154a276eedb738b46b6e3c76bfe7519ee362..0f9b4964eb38cc65552bdcc09214204b35564c4c 100644 (file)
@@ -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);
   }
 
index 9a073dc3959cbfd9ed3ca2c89258e72ab29a2740..ac7480855f071c240d840f28f39e210a827173ba 100644 (file)
@@ -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);
   }
 
index 543ff39515c7e81ec499edbc7424a9f49be11189..07e15e53be39bead3d50ca9cf8b70142c07c22e7 100644 (file)
@@ -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);
   }
 
index ba9474a1be9dc0c9a3f8588d1f1cfd90743476ef..9763ef867eb198e97b60958fd83101a59cb616af 100644 (file)
@@ -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();
 
index 4211e304b5cfd5b053ce72da23c6bd19834fb01e..681ef67f4cffecc2590345a21a62c462fb8e0da9 100644 (file)
@@ -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
index 8243090d3fcb28547a8a0dacc18afb3ef3f5dbfc..8a65fe1d3593fa025f131e76d083593614843858 100644 (file)
@@ -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();