]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18850 remove usage main branch component for private module
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Wed, 29 Mar 2023 14:46:17 +0000 (16:46 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 4 Apr 2023 20:03:16 +0000 (20:03 +0000)
21 files changed:
server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml
server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java
server/sonar-server-common/src/it/java/org/sonar/server/setting/ProjectConfigurationLoaderImplIT.java
server/sonar-server-common/src/main/java/org/sonar/server/setting/ProjectConfigurationLoader.java
server/sonar-server-common/src/main/java/org/sonar/server/setting/ProjectConfigurationLoaderImpl.java
server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexProjectStatisticsTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityCategoriesTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityReportsTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/TestProjectConfigurationLoader.java

index 2cdd6930c6d95b8135f2c2af6488758c5847e694..b5e3ded970a3cafa1d80c6e7c95f2e08572c4a65 100644 (file)
@@ -142,7 +142,7 @@ public class BranchDaoIT {
 
   @DataProvider
   public static Object[][] nullOrEmpty() {
-    return new Object[][] {
+    return new Object[][]{
       {null},
       {""}
     };
@@ -152,7 +152,7 @@ public class BranchDaoIT {
   public static Object[][] oldAndNewValuesCombinations() {
     String value1 = randomAlphabetic(10);
     String value2 = randomAlphabetic(20);
-    return new Object[][] {
+    return new Object[][]{
       {null, value1},
       {"", value1},
       {value1, null},
@@ -319,7 +319,8 @@ public class BranchDaoIT {
     assertThat(loadedPullRequestData).isNotNull();
     assertThat(loadedPullRequestData.getBranch()).isEqualTo(branch);
     assertThat(loadedPullRequestData.getTitle()).isEqualTo(title);
-    assertThat(loadedPullRequestData.getUrl()).isEqualTo(url);    assertThat(loadedPullRequestData.getAttributesMap()).containsEntry(tokenAttributeName, tokenAttributeValue);
+    assertThat(loadedPullRequestData.getUrl()).isEqualTo(url);
+    assertThat(loadedPullRequestData.getAttributesMap()).containsEntry(tokenAttributeName, tokenAttributeValue);
   }
 
   @Test
@@ -454,8 +455,8 @@ public class BranchDaoIT {
 
     assertThat(branches).hasSize(2);
 
-    assertThat(branches).extracting(BranchDto::getUuid, BranchDto::getKey,BranchDto::isMain, BranchDto::getProjectUuid, BranchDto::getBranchType, BranchDto::getMergeBranchUuid)
-      .containsOnly(tuple(mainBranch.getUuid(), mainBranch.getKey(),mainBranch.isMain(), mainBranch.getProjectUuid(), mainBranch.getBranchType(), mainBranch.getMergeBranchUuid()),
+    assertThat(branches).extracting(BranchDto::getUuid, BranchDto::getKey, BranchDto::isMain, BranchDto::getProjectUuid, BranchDto::getBranchType, BranchDto::getMergeBranchUuid)
+      .containsOnly(tuple(mainBranch.getUuid(), mainBranch.getKey(), mainBranch.isMain(), mainBranch.getProjectUuid(), mainBranch.getBranchType(), mainBranch.getMergeBranchUuid()),
         tuple(featureBranch.getUuid(), featureBranch.getKey(), featureBranch.isMain(), featureBranch.getProjectUuid(), featureBranch.getBranchType(), featureBranch.getMergeBranchUuid()));
   }
 
@@ -624,7 +625,7 @@ public class BranchDaoIT {
 
     assertThat(underTest.selectProjectUuidsWithIssuesNeedSync(db.getSession(),
       Sets.newHashSet(project1Dto.getUuid(), project2Dto.getUuid(), project3Dto.getUuid(), project4Dto.getUuid())))
-        .containsOnly(project1.uuid());
+      .containsOnly(project1.uuid());
   }
 
   @Test
@@ -807,7 +808,7 @@ public class BranchDaoIT {
 
   @DataProvider
   public static Object[][] booleanValues() {
-    return new Object[][] {
+    return new Object[][]{
       {true},
       {false}
     };
@@ -826,4 +827,31 @@ public class BranchDaoIT {
   public void isBranchNeedIssueSync_whenNoBranch_shouldReturnFalse() {
     assertThat(underTest.isBranchNeedIssueSync(dbSession, "unknown")).isFalse();
   }
+
+  @Test
+  public void selectMainBranchByProjectUuid_whenMainBranch_shouldReturnMainBranch() {
+    BranchDto dto = new BranchDto();
+    dto.setProjectUuid("U1");
+    dto.setUuid("U1");
+    dto.setIsMain(true);
+    dto.setBranchType(BranchType.BRANCH);
+    dto.setKey("feature");
+    underTest.insert(dbSession, dto);
+
+    assertThat(underTest.selectMainBranchByProjectUuid(dbSession, "U1")).get()
+      .extracting(e -> e.getUuid()).isEqualTo("U1");
+  }
+
+  @Test
+  public void selectMainBranchByProjectUuid_whenNonMainBranch_shouldReturnEmpty() {
+    BranchDto dto = new BranchDto();
+    dto.setProjectUuid("U1");
+    dto.setUuid("U2");
+    dto.setIsMain(false);
+    dto.setBranchType(BranchType.BRANCH);
+    dto.setKey("feature");
+    underTest.insert(dbSession, dto);
+
+    assertThat(underTest.selectMainBranchByProjectUuid(dbSession, "U1")).isEmpty();
+  }
 }
index c9deb86a2c64ce5ccbd8b69213e45383b56dff2e..759bea823ed2969895a54562e798c44cc5f1c6fa 100644 (file)
@@ -105,6 +105,10 @@ public class BranchDao implements Dao {
     return mapper(dbSession).selectByProjectUuid(project.getUuid());
   }
 
+  public Optional<BranchDto> selectMainBranchByProjectUuid(DbSession dbSession, String projectUuid) {
+    return mapper(dbSession).selectMainBranchByProjectUuid(projectUuid);
+  }
+
   public List<PrBranchAnalyzedLanguageCountByProjectDto> countPrBranchAnalyzedLanguageByProjectUuid(DbSession dbSession){
     return mapper(dbSession).countPrBranchAnalyzedLanguageByProjectUuid();
   }
index 26a23a79bce0833730f9c02b1968b7187ad5f0f4..1973e29b68734ff03fdbcaa34259ceaf9e2d0f50 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.db.component;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import javax.annotation.Nullable;
 import org.apache.ibatis.annotations.Param;
@@ -73,4 +74,5 @@ public interface BranchMapper {
 
   short doAnyOfComponentsNeedIssueSync(@Param("componentKeys") List<String> components);
 
+  Optional<BranchDto> selectMainBranchByProjectUuid(String projectUuid);
 }
index 7c42f968e1cccfc7aa4fc3226d4e9f0416f9db40..462f3d101449a1ed16287bae0ed93c5784c5ef78 100644 (file)
     pb.project_uuid = #{projectUuid, jdbcType=VARCHAR}
   </select>
 
+  <select id="selectMainBranchByProjectUuid" parameterType="string" resultType="org.sonar.db.component.BranchDto">
+    select <include refid="columns"/>
+    from project_branches pb
+    where
+    pb.project_uuid = #{projectUuid, jdbcType=VARCHAR}
+    and is_main = ${_true}
+  </select>
+
   <select id="countPrBranchAnalyzedLanguageByProjectUuid" resultType="org.sonar.db.component.PrBranchAnalyzedLanguageCountByProjectDto">
     select pb.project_uuid as projectUuid,
       sum(case when pb.branch_type = 'PULL_REQUEST' then 1 else 0 end) as pullRequest,
index dae2aeb826fdfd75bf279eafa7a719766e5e1860..3f9aea940814caf4f151709e858a23dd8c53dc14 100644 (file)
@@ -36,6 +36,7 @@ import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.es.EsQueueDto;
@@ -480,6 +481,7 @@ public class IssueIndexerIT {
     RuleDto rule = db.rules().insert();
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo"));
+    BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.uuid()).orElseThrow();
     ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(branch, "src/main/java/foo"));
     ComponentDto file = db.components().insertComponent(newFileDto(branch, dir, "F1"));
     IssueDto issue = db.issues().insert(rule, branch, file);
@@ -489,7 +491,7 @@ public class IssueIndexerIT {
     IssueDoc doc = es.getDocuments(TYPE_ISSUE, IssueDoc.class).get(0);
     assertThat(doc.getId()).isEqualTo(issue.getKey());
     assertThat(doc.componentUuid()).isEqualTo(file.uuid());
-    assertThat(doc.projectUuid()).isEqualTo(branch.getMainBranchProjectUuid());
+    assertThat(doc.projectUuid()).isEqualTo(branchDto.getProjectUuid());
     assertThat(doc.branchUuid()).isEqualTo(branch.uuid());
     assertThat(doc.isMainBranch()).isFalse();
     assertThat(doc.scope()).isEqualTo(IssueScope.MAIN);
index 86abf38a6ed688cbf42e067bac4f1188ea01d9d0..99705d19784388b7ea9e5f3e12a21edc68757866 100644 (file)
  */
 package org.sonar.server.setting;
 
-import javax.annotation.Nullable;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.BranchDto;
+import org.sonar.db.component.BranchType;
 
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class ProjectConfigurationLoaderImplIT {
   @Rule
   public DbTester db = DbTester.create();
 
-  private final String globalPropKey = randomAlphanumeric(9);
-  private final String globalPropValue = randomAlphanumeric(10);
-  private final String mainBranchPropKey = randomAlphanumeric(7);
-  private final String mainBranchPropValue = randomAlphanumeric(8);
-  private final String branchPropKey = randomAlphanumeric(9);
-  private final String branchPropValue = randomAlphanumeric(10);
+  private final static String GLOBAL_PROP_KEY = "GLOBAL_PROP_KEY";
+  private final static String GLOBAL_PROP_VALUE = "GLOBAL_PROP_VALUE";
+  private final static String MAIN_BRANCH_PROP_KEY = "MAIN_BRANCH_PROP_KEY";
+  private final static String MAIN_BRANCH_PROP_VALUE = "MAIN_BRANCH_PROP_VALUE";
+  private final static String BRANCH_PROP_KEY = "BRANCH_PROP_KEY";
+  private final static String BRANCH_PROP_VALUE = "BRANCH_PROP_VALUE";
 
-  private final String mainBranchUuid = randomAlphanumeric(6);
-  private final String branchUuid = randomAlphanumeric(6);
+  private final static String MAIN_BRANCH_UUID = "MAIN_BRANCH_UUID";
+  private final static String BRANCH_UUID = "BRANCH_UUID";
   private final MapSettings globalSettings = new MapSettings();
   private ProjectConfigurationLoaderImpl underTest;
 
@@ -54,52 +53,59 @@ public class ProjectConfigurationLoaderImplIT {
 
   @Test
   public void return_configuration_with_just_global_settings_when_no_component_settings() {
-    globalSettings.setProperty(mainBranchPropKey, mainBranchPropValue);
-    ComponentDto component = newComponentDto(mainBranchUuid);
+    globalSettings.setProperty(MAIN_BRANCH_PROP_KEY, MAIN_BRANCH_PROP_VALUE);
 
-    Configuration configuration = underTest.loadProjectConfiguration(db.getSession(), component);
+    BranchDto mainBranch = insertBranch(MAIN_BRANCH_UUID, MAIN_BRANCH_UUID, true);
+    Configuration configuration = underTest.loadProjectConfiguration(db.getSession(), mainBranch);
 
-    assertThat(configuration.get(mainBranchPropKey)).contains(mainBranchPropValue);
+    assertThat(configuration.get(MAIN_BRANCH_PROP_KEY)).contains(MAIN_BRANCH_PROP_VALUE);
   }
 
   @Test
   public void return_configuration_with_global_settings_and_component_settings() {
-    String projectPropKey1 = randomAlphanumeric(7);
-    String projectPropValue1 = randomAlphanumeric(8);
-    String projectPropKey2 = randomAlphanumeric(9);
-    String projectPropValue2 = randomAlphanumeric(10);
-    globalSettings.setProperty(globalPropKey, globalPropValue);
-    db.properties().insertProperty(projectPropKey1, projectPropValue1, mainBranchUuid);
-    db.properties().insertProperty(projectPropKey2, projectPropValue2, mainBranchUuid);
-    ComponentDto component = newComponentDto(mainBranchUuid);
-
-    Configuration configuration = underTest.loadProjectConfiguration(db.getSession(), component);
-
-    assertThat(configuration.get(globalPropKey)).contains(globalPropValue);
+    String projectPropKey1 = "prop_key_1";
+    String projectPropValue1 = "prop_key_value_1";
+    String projectPropKey2 = "prop_key_2";
+    String projectPropValue2 = "prop_key_value_2";
+    globalSettings.setProperty(GLOBAL_PROP_KEY, GLOBAL_PROP_VALUE);
+    db.properties().insertProperty(projectPropKey1, projectPropValue1, MAIN_BRANCH_UUID);
+    db.properties().insertProperty(projectPropKey2, projectPropValue2, MAIN_BRANCH_UUID);
+    BranchDto mainBranch = insertBranch(MAIN_BRANCH_UUID, MAIN_BRANCH_UUID, true);
+
+
+    Configuration configuration = underTest.loadProjectConfiguration(db.getSession(), mainBranch);
+
+    assertThat(configuration.get(GLOBAL_PROP_KEY)).contains(GLOBAL_PROP_VALUE);
     assertThat(configuration.get(projectPropKey1)).contains(projectPropValue1);
     assertThat(configuration.get(projectPropKey2)).contains(projectPropValue2);
   }
 
   @Test
   public void return_configuration_with_global_settings_main_branch_settings_and_branch_settings() {
-    globalSettings.setProperty(globalPropKey, globalPropValue);
+    globalSettings.setProperty(GLOBAL_PROP_KEY, GLOBAL_PROP_VALUE);
 
-    db.properties().insertProperty(mainBranchPropKey, mainBranchPropValue, mainBranchUuid);
-    db.properties().insertProperty(branchPropKey, branchPropValue, branchUuid);
+    db.properties().insertProperty(MAIN_BRANCH_PROP_KEY, MAIN_BRANCH_PROP_VALUE, MAIN_BRANCH_UUID);
+    db.properties().insertProperty(BRANCH_PROP_KEY, BRANCH_PROP_VALUE, BRANCH_UUID);
 
-    ComponentDto component = newComponentDto(branchUuid, mainBranchUuid);
-    Configuration configuration = underTest.loadProjectConfiguration(db.getSession(), component);
+    BranchDto mainBranch = insertBranch(MAIN_BRANCH_UUID, MAIN_BRANCH_UUID, true);
+    BranchDto branch = insertBranch(BRANCH_UUID, MAIN_BRANCH_UUID, false);
 
-    assertThat(configuration.get(globalPropKey)).contains(globalPropValue);
-    assertThat(configuration.get(mainBranchPropKey)).contains(mainBranchPropValue);
-    assertThat(configuration.get(branchPropKey)).contains(branchPropValue);
-  }
+    Configuration configuration = underTest.loadProjectConfiguration(db.getSession(), branch);
 
-  private ComponentDto newComponentDto(String uuid) {
-    return newComponentDto(uuid, null);
+    assertThat(configuration.get(GLOBAL_PROP_KEY)).contains(GLOBAL_PROP_VALUE);
+    assertThat(configuration.get(MAIN_BRANCH_PROP_KEY)).contains(MAIN_BRANCH_PROP_VALUE);
+    assertThat(configuration.get(BRANCH_PROP_KEY)).contains(BRANCH_PROP_VALUE);
   }
 
-  private ComponentDto newComponentDto(String uuid, @Nullable String mainBranchUuid) {
-    return new ComponentDto().setUuid(uuid).setBranchUuid(uuid).setMainBranchProjectUuid(mainBranchUuid);
+  public BranchDto insertBranch(String uuid, String projectUuid, boolean isMain){
+    BranchDto dto = new BranchDto();
+    dto.setProjectUuid(projectUuid);
+    dto.setUuid(uuid);
+    dto.setIsMain(isMain);
+    dto.setBranchType(BranchType.BRANCH);
+    dto.setKey("key_"+uuid);
+    db.getDbClient().branchDao().insert(db.getSession(), dto);
+    return dto;
   }
+
 }
index 0dff8ddf3c58901dab831963ada1a3836e875d2c..69a220626c4eaab52dd3320c84788734b32901dd 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.setting;
 
 import org.sonar.api.config.Configuration;
 import org.sonar.db.DbSession;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
 
 public interface ProjectConfigurationLoader {
@@ -32,5 +33,5 @@ public interface ProjectConfigurationLoader {
    * <p>
    * Any component is accepted but SQ only supports specific properties for projects and branches.
    */
-  Configuration loadProjectConfiguration(DbSession dbSession, ComponentDto project);
+  Configuration loadProjectConfiguration(DbSession dbSession, BranchDto branch);
 }
index 6bc32fbfc427c102f5ffdcb3e1258b6a5776783c..3f697a5611529206f5a304d2a1fa292577ed93a0 100644 (file)
@@ -24,7 +24,7 @@ import org.sonar.api.config.Configuration;
 import org.sonar.api.config.internal.Settings;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.property.PropertyDto;
 
 public class ProjectConfigurationLoaderImpl implements ProjectConfigurationLoader {
@@ -37,20 +37,21 @@ public class ProjectConfigurationLoaderImpl implements ProjectConfigurationLoade
   }
 
   @Override
-  public Configuration loadProjectConfiguration(DbSession dbSession, ComponentDto projectOrBranch) {
-    boolean isMainBranch = projectOrBranch.getMainBranchProjectUuid() == null;
-    String mainBranchUuid = isMainBranch ? projectOrBranch.branchUuid() : projectOrBranch.getMainBranchProjectUuid();
-    ChildSettings mainBranchSettings = loadMainBranchConfiguration(dbSession, mainBranchUuid);
-
-    if (isMainBranch) {
+  public Configuration loadProjectConfiguration(DbSession dbSession, BranchDto branchDto) {
+    if (branchDto.isMain()) {
+      ChildSettings mainBranchSettings = loadMainBranchConfiguration(dbSession, branchDto.getUuid());
       return mainBranchSettings.asConfiguration();
-    }
+    } else {
+      BranchDto mainBranch = dbClient.branchDao().selectMainBranchByProjectUuid(dbSession, branchDto.getProjectUuid())
+        .orElseThrow(() -> new IllegalStateException("Main branch not found for project: " + branchDto.getProjectUuid()));
 
-    ChildSettings settings = new ChildSettings(mainBranchSettings);
-    dbClient.propertiesDao()
-      .selectComponentProperties(dbSession, projectOrBranch.uuid())
-      .forEach(property -> settings.setProperty(property.getKey(), property.getValue()));
-    return settings.asConfiguration();
+      ChildSettings mainBranchSettings = loadMainBranchConfiguration(dbSession, mainBranch.getUuid());
+      ChildSettings settings = new ChildSettings(mainBranchSettings);
+      dbClient.propertiesDao()
+        .selectComponentProperties(dbSession, branchDto.getUuid())
+        .forEach(property -> settings.setProperty(property.getKey(), property.getValue()));
+      return settings.asConfiguration();
+    }
   }
 
   private ChildSettings loadMainBranchConfiguration(DbSession dbSession, String uuid) {
index d9556e15e378737d3440657c0f9ea4ff882eed88..0736f3048a30f42b6ae4ffc2b0c0cb7cb3d482a4 100644 (file)
@@ -37,20 +37,35 @@ import static org.sonar.api.issue.Issue.STATUS_OPEN;
 
 public class IssueDocTesting {
 
-  public static IssueDoc newDoc(ComponentDto componentDto) {
-    return newDoc(Uuids.createFast(), componentDto);
+  public static IssueDoc newDoc(ComponentDto componentDto, String projectUuid) {
+    return newDoc(Uuids.createFast(), projectUuid, componentDto);
   }
 
-  public static IssueDoc newDoc(String key, ComponentDto componentDto) {
-    String mainBranchProjectUuid = componentDto.getMainBranchProjectUuid();
+  public static IssueDoc newDocForProject(ComponentDto project) {
+    return newDocForProject(Uuids.createFast(), project);
+  }
+
+  public static IssueDoc newDoc(String key, String projectUuid, ComponentDto componentDto) {
     return newDoc()
       .setKey(key)
       .setBranchUuid(componentDto.branchUuid())
       .setComponentUuid(componentDto.uuid())
-      .setProjectUuid(mainBranchProjectUuid == null ? componentDto.branchUuid() : mainBranchProjectUuid)
+      .setProjectUuid(projectUuid)
       // File path make no sens on modules and projects
       .setFilePath(!componentDto.scope().equals(Scopes.PROJECT) ? componentDto.path() : null)
-      .setIsMainBranch(mainBranchProjectUuid == null)
+      .setIsMainBranch(componentDto.branchUuid().equals(projectUuid))
+      .setFuncCreationDate(Date.from(LocalDateTime.of(1970, 1, 1, 1, 1).toInstant(ZoneOffset.UTC)));
+  }
+
+  public static IssueDoc newDocForProject(String key, ComponentDto project) {
+    return newDoc()
+      .setKey(key)
+      .setBranchUuid(project.branchUuid())
+      .setComponentUuid(project.uuid())
+      .setProjectUuid(project.branchUuid())
+      // File path make no sens on modules and projects
+      .setFilePath(!project.scope().equals(Scopes.PROJECT) ? project.path() : null)
+      .setIsMainBranch(true)
       .setFuncCreationDate(Date.from(LocalDateTime.of(1970, 1, 1, 1, 1).toInstant(ZoneOffset.UTC)));
   }
 
index 96ee3db384e264c4c6ae691fc01fd6238b806486..207f38d9443f75192039c4f35395d01cfb2b69e4 100644 (file)
@@ -46,9 +46,9 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto project2 = ComponentTesting.newPrivateProjectDto("EFGH");
 
     indexIssues(
-      IssueDocTesting.newDoc("I1", ComponentTesting.newFileDto(project, null)).setEffort(10L),
-      IssueDocTesting.newDoc("I2", ComponentTesting.newFileDto(project, null)).setEffort(10L),
-      IssueDocTesting.newDoc("I3", ComponentTesting.newFileDto(project2, null)).setEffort(10L));
+      IssueDocTesting.newDoc("I1", project.uuid(), ComponentTesting.newFileDto(project, null)).setEffort(10L),
+      IssueDocTesting.newDoc("I2", project.uuid(), ComponentTesting.newFileDto(project, null)).setEffort(10L),
+      IssueDocTesting.newDoc("I3", project2.uuid(), ComponentTesting.newFileDto(project2, null)).setEffort(10L));
 
     Facets facets = search("projects");
     assertThat(facets.getNames()).containsOnly("projects", FACET_MODE_EFFORT);
@@ -64,11 +64,11 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto file3 = ComponentTesting.newFileDto(project, null, "CDEF");
 
     indexIssues(
-      IssueDocTesting.newDoc("I1", project).setEffort(10L),
-      IssueDocTesting.newDoc("I2", file1).setEffort(10L),
-      IssueDocTesting.newDoc("I3", file2).setEffort(10L),
-      IssueDocTesting.newDoc("I4", file2).setEffort(10L),
-      IssueDocTesting.newDoc("I5", file3).setEffort(10L));
+      IssueDocTesting.newDocForProject("I1", project).setEffort(10L),
+      IssueDocTesting.newDoc("I2", project.uuid(), file1).setEffort(10L),
+      IssueDocTesting.newDoc("I3", project.uuid(), file2).setEffort(10L),
+      IssueDocTesting.newDoc("I4", project.uuid(), file2).setEffort(10L),
+      IssueDocTesting.newDoc("I5", project.uuid(), file3).setEffort(10L));
 
     Facets facets = search("files");
     assertThat(facets.getNames()).containsOnly("files", FACET_MODE_EFFORT);
@@ -84,8 +84,8 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto file2 = ComponentTesting.newFileDto(project, null).setPath("F2.xoo");
 
     indexIssues(
-      IssueDocTesting.newDoc("I1", file1).setDirectoryPath("/src/main/xoo").setEffort(10L),
-      IssueDocTesting.newDoc("I2", file2).setDirectoryPath("/").setEffort(10L));
+      IssueDocTesting.newDoc("I1", project.uuid(), file1).setDirectoryPath("/src/main/xoo").setEffort(10L),
+      IssueDocTesting.newDoc("I2", project.uuid(), file2).setDirectoryPath("/").setEffort(10L));
 
     Facets facets = search("directories");
     assertThat(facets.getNames()).containsOnly("directories", FACET_MODE_EFFORT);
@@ -99,9 +99,9 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto file = ComponentTesting.newFileDto(project, null);
 
     indexIssues(
-      IssueDocTesting.newDoc("I1", file).setSeverity(Severity.INFO).setEffort(10L),
-      IssueDocTesting.newDoc("I2", file).setSeverity(Severity.INFO).setEffort(10L),
-      IssueDocTesting.newDoc("I3", file).setSeverity(Severity.MAJOR).setEffort(10L));
+      IssueDocTesting.newDoc("I1", project.uuid(), file).setSeverity(Severity.INFO).setEffort(10L),
+      IssueDocTesting.newDoc("I2", project.uuid(), file).setSeverity(Severity.INFO).setEffort(10L),
+      IssueDocTesting.newDoc("I3", project.uuid(), file).setSeverity(Severity.MAJOR).setEffort(10L));
 
     Facets facets = search("severities");
     assertThat(facets.getNames()).containsOnly("severities", FACET_MODE_EFFORT);
@@ -115,9 +115,9 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto file = ComponentTesting.newFileDto(project, null);
 
     indexIssues(
-      IssueDocTesting.newDoc("I1", file).setStatus(STATUS_CLOSED).setEffort(10L),
-      IssueDocTesting.newDoc("I2", file).setStatus(STATUS_CLOSED).setEffort(10L),
-      IssueDocTesting.newDoc("I3", file).setStatus(STATUS_OPEN).setEffort(10L));
+      IssueDocTesting.newDoc("I1", project.uuid(), file).setStatus(STATUS_CLOSED).setEffort(10L),
+      IssueDocTesting.newDoc("I2", project.uuid(), file).setStatus(STATUS_CLOSED).setEffort(10L),
+      IssueDocTesting.newDoc("I3", project.uuid(), file).setStatus(STATUS_OPEN).setEffort(10L));
 
     Facets facets = search("statuses");
     assertThat(facets.getNames()).containsOnly("statuses", FACET_MODE_EFFORT);
@@ -131,9 +131,9 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto file = ComponentTesting.newFileDto(project, null);
 
     indexIssues(
-      IssueDocTesting.newDoc("I1", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setEffort(10L),
-      IssueDocTesting.newDoc("I2", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setEffort(10L),
-      IssueDocTesting.newDoc("I3", file).setResolution(Issue.RESOLUTION_FIXED).setEffort(10L));
+      IssueDocTesting.newDoc("I1", project.uuid(), file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setEffort(10L),
+      IssueDocTesting.newDoc("I2", project.uuid(), file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setEffort(10L),
+      IssueDocTesting.newDoc("I3", project.uuid(), file).setResolution(Issue.RESOLUTION_FIXED).setEffort(10L));
 
     Facets facets = search("resolutions");
     assertThat(facets.getNames()).containsOnly("resolutions", FACET_MODE_EFFORT);
@@ -146,7 +146,7 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
     ComponentDto file = ComponentTesting.newFileDto(project, null);
 
-    indexIssues(IssueDocTesting.newDoc("I1", file).setLanguage("xoo").setEffort(10L));
+    indexIssues(IssueDocTesting.newDoc("I1", project.uuid(), file).setLanguage("xoo").setEffort(10L));
 
     Facets facets = search("languages");
     assertThat(facets.getNames()).containsOnly("languages", FACET_MODE_EFFORT);
@@ -160,10 +160,10 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto file = ComponentTesting.newFileDto(project, null);
 
     indexIssues(
-      IssueDocTesting.newDoc("I1", file).setAssigneeUuid("uuid-steph").setEffort(10L),
-      IssueDocTesting.newDoc("I2", file).setAssigneeUuid("uuid-simon").setEffort(10L),
-      IssueDocTesting.newDoc("I3", file).setAssigneeUuid("uuid-simon").setEffort(10L),
-      IssueDocTesting.newDoc("I4", file).setAssigneeUuid(null).setEffort(10L));
+      IssueDocTesting.newDoc("I1", project.uuid(), file).setAssigneeUuid("uuid-steph").setEffort(10L),
+      IssueDocTesting.newDoc("I2", project.uuid(), file).setAssigneeUuid("uuid-simon").setEffort(10L),
+      IssueDocTesting.newDoc("I3", project.uuid(), file).setAssigneeUuid("uuid-simon").setEffort(10L),
+      IssueDocTesting.newDoc("I4", project.uuid(), file).setAssigneeUuid(null).setEffort(10L));
 
     Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(singletonList("assignees"))), system2.getDefaultTimeZone().toZoneId());
     assertThat(facets.getNames()).containsOnly("assignees", FACET_MODE_EFFORT);
@@ -177,10 +177,10 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto file = ComponentTesting.newFileDto(project, null);
 
     indexIssues(
-      IssueDocTesting.newDoc("I1", file).setAuthorLogin("steph").setEffort(10L),
-      IssueDocTesting.newDoc("I2", file).setAuthorLogin("simon").setEffort(10L),
-      IssueDocTesting.newDoc("I3", file).setAuthorLogin("simon").setEffort(10L),
-      IssueDocTesting.newDoc("I4", file).setAuthorLogin(null).setEffort(10L));
+      IssueDocTesting.newDoc("I1", project.uuid(), file).setAuthorLogin("steph").setEffort(10L),
+      IssueDocTesting.newDoc("I2", project.uuid(), file).setAuthorLogin("simon").setEffort(10L),
+      IssueDocTesting.newDoc("I3", project.uuid(), file).setAuthorLogin("simon").setEffort(10L),
+      IssueDocTesting.newDoc("I4", project.uuid(), file).setAuthorLogin(null).setEffort(10L));
 
     Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(singletonList("author"))), system2.getDefaultTimeZone().toZoneId());
     assertThat(facets.getNames()).containsOnly("author", FACET_MODE_EFFORT);
@@ -206,13 +206,13 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
     ComponentDto file = ComponentTesting.newFileDto(project, null);
 
-    IssueDoc issue0 = IssueDocTesting.newDoc("ISSUE0", file).setEffort(10L).setFuncCreationDate(parseDateTime("2011-04-25T01:05:13+0100"));
-    IssueDoc issue1 = IssueDocTesting.newDoc("I1", file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-01T12:34:56+0100"));
-    IssueDoc issue2 = IssueDocTesting.newDoc("I2", file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-01T23:46:00+0100"));
-    IssueDoc issue3 = IssueDocTesting.newDoc("I3", file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-02T12:34:56+0100"));
-    IssueDoc issue4 = IssueDocTesting.newDoc("I4", file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-05T12:34:56+0100"));
-    IssueDoc issue5 = IssueDocTesting.newDoc("I5", file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-20T12:34:56+0100"));
-    IssueDoc issue6 = IssueDocTesting.newDoc("I6", file).setEffort(10L).setFuncCreationDate(parseDateTime("2015-01-18T12:34:56+0100"));
+    IssueDoc issue0 = IssueDocTesting.newDoc("ISSUE0", project.uuid(), file).setEffort(10L).setFuncCreationDate(parseDateTime("2011-04-25T01:05:13+0100"));
+    IssueDoc issue1 = IssueDocTesting.newDoc("I1", project.uuid(), file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-01T12:34:56+0100"));
+    IssueDoc issue2 = IssueDocTesting.newDoc("I2", project.uuid(), file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-01T23:46:00+0100"));
+    IssueDoc issue3 = IssueDocTesting.newDoc("I3", project.uuid(), file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-02T12:34:56+0100"));
+    IssueDoc issue4 = IssueDocTesting.newDoc("I4", project.uuid(), file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-05T12:34:56+0100"));
+    IssueDoc issue5 = IssueDocTesting.newDoc("I5", project.uuid(), file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-20T12:34:56+0100"));
+    IssueDoc issue6 = IssueDocTesting.newDoc("I6", project.uuid(), file).setEffort(10L).setFuncCreationDate(parseDateTime("2015-01-18T12:34:56+0100"));
 
     indexIssues(issue0, issue1, issue2, issue3, issue4, issue5, issue6);
 
index 6ed7ccd74fe8052df5baed58f4ce7b6fc213e594..71136ad4b5e90b4c3d3cc2837a0eb97791a82cbb 100644 (file)
@@ -62,6 +62,7 @@ import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.rule.RuleTesting.newRule;
 import static org.sonar.server.issue.IssueDocTesting.newDoc;
+import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
 
 public class IssueIndexFacetsTest extends IssueIndexTestCommon {
 
@@ -71,9 +72,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto project2 = newPrivateProjectDto("EFGH");
 
     indexIssues(
-      newDoc("I1", newFileDto(project, null)),
-      newDoc("I2", newFileDto(project, null)),
-      newDoc("I3", newFileDto(project2, null)));
+      newDoc("I1", project.uuid(), newFileDto(project, null)),
+      newDoc("I2", project.uuid(), newFileDto(project, null)),
+      newDoc("I3", project2.uuid(), newFileDto(project2, null)));
 
     assertThatFacetHasExactly(IssueQuery.builder(), "projects", entry("ABCD", 2L), entry("EFGH", 1L));
   }
@@ -81,9 +82,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facet_on_projectUuids_return_100_entries_plus_selected_values() {
 
-    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newPrivateProjectDto("a" + i))).toArray(IssueDoc[]::new));
-    IssueDoc issue1 = newDoc(newPrivateProjectDto("project1"));
-    IssueDoc issue2 = newDoc(newPrivateProjectDto("project2"));
+    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDocForProject(newPrivateProjectDto("a" + i))).toArray(IssueDoc[]::new));
+    IssueDoc issue1 = newDocForProject(newPrivateProjectDto("project1"));
+    IssueDoc issue2 = newDocForProject(newPrivateProjectDto("project2"));
     indexIssues(issue1, issue2);
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "projects", 100);
@@ -99,11 +100,11 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file3 = newFileDto(project, dir, "CDEF");
 
     indexIssues(
-      newDoc("I1", project),
-      newDoc("I2", file1),
-      newDoc("I3", file2),
-      newDoc("I4", file2),
-      newDoc("I5", file3));
+      newDocForProject("I1", project),
+      newDoc("I2", project.uuid(), file1),
+      newDoc("I3", project.uuid(), file2),
+      newDoc("I4", project.uuid(), file2),
+      newDoc("I5", project.uuid(), file3));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "files", entry("src/NAME_ABCD", 1L), entry("src/NAME_BCDE", 2L), entry("src/NAME_CDEF", 1L));
   }
@@ -111,9 +112,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facet_on_files_return_100_entries_plus_selected_values() {
     ComponentDto project = newPrivateProjectDto();
-    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null, "a" + i))).toArray(IssueDoc[]::new));
-    IssueDoc issue1 = newDoc(newFileDto(project, null, "file1"));
-    IssueDoc issue2 = newDoc(newFileDto(project, null, "file2"));
+    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null, "a" + i), project.uuid())).toArray(IssueDoc[]::new));
+    IssueDoc issue1 = newDoc(newFileDto(project, null, "file1"), project.uuid());
+    IssueDoc issue2 = newDoc(newFileDto(project, null, "file2"), project.uuid());
     indexIssues(issue1, issue2);
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "files", 100);
@@ -127,8 +128,8 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo");
 
     indexIssues(
-      newDoc("I1", file1).setDirectoryPath("/src/main/xoo"),
-      newDoc("I2", file2).setDirectoryPath("/"));
+      newDoc("I1", project.uuid(), file1).setDirectoryPath("/src/main/xoo"),
+      newDoc("I2", project.uuid(), file2).setDirectoryPath("/"));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "directories", entry("/src/main/xoo", 1L), entry("/", 1L));
   }
@@ -136,9 +137,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facet_on_directories_return_100_entries_plus_selected_values() {
     ComponentDto project = newPrivateProjectDto();
-    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, newDirectory(project, "dir" + i))).setDirectoryPath("a" + i)).toArray(IssueDoc[]::new));
-    IssueDoc issue1 = newDoc(newFileDto(project, newDirectory(project, "path1"))).setDirectoryPath("directory1");
-    IssueDoc issue2 = newDoc(newFileDto(project, newDirectory(project, "path2"))).setDirectoryPath("directory2");
+    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, newDirectory(project, "dir" + i)), project.uuid()).setDirectoryPath("a" + i)).toArray(IssueDoc[]::new));
+    IssueDoc issue1 = newDoc(newFileDto(project, newDirectory(project, "path1")), project.uuid()).setDirectoryPath("directory1");
+    IssueDoc issue2 = newDoc(newFileDto(project, newDirectory(project, "path2")), project.uuid()).setDirectoryPath("directory2");
     indexIssues(issue1, issue2);
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "directories", 100);
@@ -151,9 +152,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setCwe(asList("20", "564", "89", "943")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setCwe(asList("943")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setCwe(asList("20", "564", "89", "943")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setCwe(asList("943")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "cwe",
       entry("943", 2L),
@@ -168,9 +169,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setPciDss32(asList("1", "2")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setPciDss32(singletonList("3")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setPciDss32(asList("1", "2")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setPciDss32(singletonList("3")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatFacetHasOnly(IssueQuery.builder(), V3_2.prefix(),
       entry("1", 1L),
@@ -184,9 +185,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setPciDss40(asList("1", "2")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setPciDss40(singletonList("3")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setPciDss40(asList("1", "2")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setPciDss40(singletonList("3")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatFacetHasOnly(IssueQuery.builder(), V4_0.prefix(),
       entry("1", 1L),
@@ -200,9 +201,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1", "2")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(singletonList("3")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1", "2")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(singletonList("3")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatFacetHasOnly(IssueQuery.builder(), OwaspAsvsVersion.V4_0.prefix(),
       entry("1", 1L),
@@ -216,9 +217,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setOwaspTop10(asList("a1", "a2")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setOwaspTop10(singletonList("a3")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10(asList("a1", "a2")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10(singletonList("a3")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatFacetHasOnly(IssueQuery.builder(), Y2017.prefix(),
       entry("a1", 1L),
@@ -232,9 +233,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setOwaspTop10For2021(asList("a1", "a2")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setOwaspTop10For2021(singletonList("a3")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10For2021(asList("a1", "a2")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10For2021(singletonList("a3")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatFacetHasExactly(IssueQuery.builder(), Y2021.prefix(),
       entry("a1", 1L),
@@ -248,9 +249,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setOwaspTop10For2021(asList("a1", "a2")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setOwaspTop10For2021(singletonList("a3")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10For2021(asList("a1", "a2")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10For2021(singletonList("a3")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatFacetHasExactly(IssueQuery.builder().owaspTop10For2021(Collections.singletonList("a3")), Y2021.prefix(),
       entry("a1", 1L),
@@ -264,9 +265,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setSansTop25(asList("porous-defenses", "risky-resource", "insecure-interaction")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setSansTop25(singletonList("porous-defenses")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setSansTop25(asList("porous-defenses", "risky-resource", "insecure-interaction")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setSansTop25(singletonList("porous-defenses")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "sansTop25",
       entry("insecure-interaction", 1L),
@@ -280,9 +281,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setSonarSourceSecurityCategory(SQCategory.BUFFER_OVERFLOW),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setSonarSourceSecurityCategory(SQCategory.DOS),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setSonarSourceSecurityCategory(SQCategory.BUFFER_OVERFLOW),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setSonarSourceSecurityCategory(SQCategory.DOS),
+      newDoc("I3", project.uuid(), file));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "sonarsourceSecurity",
       entry("buffer-overflow", 1L),
@@ -295,9 +296,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setSeverity(INFO),
-      newDoc("I2", file).setSeverity(INFO),
-      newDoc("I3", file).setSeverity(MAJOR));
+      newDoc("I1", project.uuid(), file).setSeverity(INFO),
+      newDoc("I2", project.uuid(), file).setSeverity(INFO),
+      newDoc("I3", project.uuid(), file).setSeverity(MAJOR));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "severities", entry("INFO", 2L), entry("MAJOR", 1L));
   }
@@ -308,12 +309,12 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I2", file).setSeverity(INFO),
-      newDoc("I1", file).setSeverity(MINOR),
-      newDoc("I3", file).setSeverity(MAJOR),
-      newDoc("I4", file).setSeverity(CRITICAL),
-      newDoc("I5", file).setSeverity(BLOCKER),
-      newDoc("I6", file).setSeverity(MAJOR));
+      newDoc("I2", project.uuid(), file).setSeverity(INFO),
+      newDoc("I1", project.uuid(), file).setSeverity(MINOR),
+      newDoc("I3", project.uuid(), file).setSeverity(MAJOR),
+      newDoc("I4", project.uuid(), file).setSeverity(CRITICAL),
+      newDoc("I5", project.uuid(), file).setSeverity(BLOCKER),
+      newDoc("I6", project.uuid(), file).setSeverity(MAJOR));
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "severities", 5);
   }
@@ -324,9 +325,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setStatus(STATUS_CLOSED),
-      newDoc("I2", file).setStatus(STATUS_CLOSED),
-      newDoc("I3", file).setStatus(STATUS_OPEN));
+      newDoc("I1", project.uuid(), file).setStatus(STATUS_CLOSED),
+      newDoc("I2", project.uuid(), file).setStatus(STATUS_CLOSED),
+      newDoc("I3", project.uuid(), file).setStatus(STATUS_OPEN));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "statuses", entry("CLOSED", 2L), entry("OPEN", 1L));
   }
@@ -337,12 +338,12 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setStatus(STATUS_OPEN),
-      newDoc("I2", file).setStatus(STATUS_CONFIRMED),
-      newDoc("I3", file).setStatus(STATUS_REOPENED),
-      newDoc("I4", file).setStatus(STATUS_RESOLVED),
-      newDoc("I5", file).setStatus(STATUS_CLOSED),
-      newDoc("I6", file).setStatus(STATUS_OPEN));
+      newDoc("I1", project.uuid(), file).setStatus(STATUS_OPEN),
+      newDoc("I2", project.uuid(), file).setStatus(STATUS_CONFIRMED),
+      newDoc("I3", project.uuid(), file).setStatus(STATUS_REOPENED),
+      newDoc("I4", project.uuid(), file).setStatus(STATUS_RESOLVED),
+      newDoc("I5", project.uuid(), file).setStatus(STATUS_CLOSED),
+      newDoc("I6", project.uuid(), file).setStatus(STATUS_OPEN));
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "statuses", 5);
   }
@@ -353,9 +354,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setResolution(RESOLUTION_FALSE_POSITIVE),
-      newDoc("I2", file).setResolution(RESOLUTION_FALSE_POSITIVE),
-      newDoc("I3", file).setResolution(RESOLUTION_FIXED));
+      newDoc("I1", project.uuid(), file).setResolution(RESOLUTION_FALSE_POSITIVE),
+      newDoc("I2", project.uuid(), file).setResolution(RESOLUTION_FALSE_POSITIVE),
+      newDoc("I3", project.uuid(), file).setResolution(RESOLUTION_FIXED));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "resolutions", entry("FALSE-POSITIVE", 2L), entry("FIXED", 1L));
   }
@@ -366,11 +367,11 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setResolution(RESOLUTION_FIXED),
-      newDoc("I2", file).setResolution(RESOLUTION_FALSE_POSITIVE),
-      newDoc("I3", file).setResolution(RESOLUTION_REMOVED),
-      newDoc("I4", file).setResolution(RESOLUTION_WONT_FIX),
-      newDoc("I5", file).setResolution(null));
+      newDoc("I1", project.uuid(), file).setResolution(RESOLUTION_FIXED),
+      newDoc("I2", project.uuid(), file).setResolution(RESOLUTION_FALSE_POSITIVE),
+      newDoc("I3", project.uuid(), file).setResolution(RESOLUTION_REMOVED),
+      newDoc("I4", project.uuid(), file).setResolution(RESOLUTION_WONT_FIX),
+      newDoc("I5", project.uuid(), file).setResolution(null));
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "resolutions", 5);
   }
@@ -382,7 +383,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     RuleDto ruleDefinitionDto = newRule();
     db.rules().insert(ruleDefinitionDto);
 
-    indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid()).setLanguage("xoo"));
+    indexIssues(newDoc("I1", project.uuid(), file).setRuleUuid(ruleDefinitionDto.getUuid()).setLanguage("xoo"));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "languages", entry("xoo", 1L));
   }
@@ -390,9 +391,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_languages_return_100_entries_plus_selected_values() {
     ComponentDto project = newPrivateProjectDto();
-    indexIssues(rangeClosed(1, 100).mapToObj(i -> newDoc(newFileDto(project, null)).setLanguage("a" + i)).toArray(IssueDoc[]::new));
-    IssueDoc issue1 = newDoc(newFileDto(project, null)).setLanguage("language1");
-    IssueDoc issue2 = newDoc(newFileDto(project, null)).setLanguage("language2");
+    indexIssues(rangeClosed(1, 100).mapToObj(i -> newDoc(newFileDto(project, null), project.uuid()).setLanguage("a" + i)).toArray(IssueDoc[]::new));
+    IssueDoc issue1 = newDoc(newFileDto(project, null), project.uuid()).setLanguage("language1");
+    IssueDoc issue2 = newDoc(newFileDto(project, null), project.uuid()).setLanguage("language2");
     indexIssues(issue1, issue2);
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "languages", 100);
@@ -405,10 +406,10 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setAssigneeUuid("steph-uuid"),
-      newDoc("I2", file).setAssigneeUuid("marcel-uuid"),
-      newDoc("I3", file).setAssigneeUuid("marcel-uuid"),
-      newDoc("I4", file).setAssigneeUuid(null));
+      newDoc("I1", project.uuid(), file).setAssigneeUuid("steph-uuid"),
+      newDoc("I2", project.uuid(), file).setAssigneeUuid("marcel-uuid"),
+      newDoc("I3", project.uuid(), file).setAssigneeUuid("marcel-uuid"),
+      newDoc("I4", project.uuid(), file).setAssigneeUuid(null));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "assignees", entry("steph-uuid", 1L), entry("marcel-uuid", 2L), entry("", 1L));
   }
@@ -416,9 +417,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_assignees_return_only_100_entries_plus_selected_values() {
     ComponentDto project = newPrivateProjectDto();
-    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null)).setAssigneeUuid("a" + i)).toArray(IssueDoc[]::new));
-    IssueDoc issue1 = newDoc(newFileDto(project, null)).setAssigneeUuid("user1");
-    IssueDoc issue2 = newDoc(newFileDto(project, null)).setAssigneeUuid("user2");
+    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null), project.uuid()).setAssigneeUuid("a" + i)).toArray(IssueDoc[]::new));
+    IssueDoc issue1 = newDoc(newFileDto(project, null), project.uuid()).setAssigneeUuid("user1");
+    IssueDoc issue2 = newDoc(newFileDto(project, null), project.uuid()).setAssigneeUuid("user2");
     indexIssues(issue1, issue2);
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "assignees", 100);
@@ -431,10 +432,10 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setAssigneeUuid("j-b-uuid"),
-      newDoc("I2", file).setAssigneeUuid("marcel-uuid"),
-      newDoc("I3", file).setAssigneeUuid("marcel-uuid"),
-      newDoc("I4", file).setAssigneeUuid(null));
+      newDoc("I1", project.uuid(), file).setAssigneeUuid("j-b-uuid"),
+      newDoc("I2", project.uuid(), file).setAssigneeUuid("marcel-uuid"),
+      newDoc("I3", project.uuid(), file).setAssigneeUuid("marcel-uuid"),
+      newDoc("I4", project.uuid(), file).setAssigneeUuid(null));
 
     assertThatFacetHasOnly(IssueQuery.builder().assigneeUuids(singletonList("j-b")),
       "assignees", entry("j-b-uuid", 1L), entry("marcel-uuid", 2L), entry("", 1L));
@@ -446,10 +447,10 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setAuthorLogin("steph"),
-      newDoc("I2", file).setAuthorLogin("marcel"),
-      newDoc("I3", file).setAuthorLogin("marcel"),
-      newDoc("I4", file).setAuthorLogin(null));
+      newDoc("I1", project.uuid(), file).setAuthorLogin("steph"),
+      newDoc("I2", project.uuid(), file).setAuthorLogin("marcel"),
+      newDoc("I3", project.uuid(), file).setAuthorLogin("marcel"),
+      newDoc("I4", project.uuid(), file).setAuthorLogin(null));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "author", entry("steph", 1L), entry("marcel", 2L));
   }
@@ -457,9 +458,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_authors_return_100_entries_plus_selected_values() {
     ComponentDto project = newPrivateProjectDto();
-    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null)).setAuthorLogin("a" + i)).toArray(IssueDoc[]::new));
-    IssueDoc issue1 = newDoc(newFileDto(project, null)).setAuthorLogin("user1");
-    IssueDoc issue2 = newDoc(newFileDto(project, null)).setAuthorLogin("user2");
+    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null), project.uuid()).setAuthorLogin("a" + i)).toArray(IssueDoc[]::new));
+    IssueDoc issue1 = newDoc(newFileDto(project, null), project.uuid()).setAuthorLogin("user1");
+    IssueDoc issue2 = newDoc(newFileDto(project, null), project.uuid()).setAuthorLogin("user2");
     indexIssues(issue1, issue2);
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "author", 100);
@@ -647,13 +648,13 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     ComponentDto file = newFileDto(project, null);
 
-    IssueDoc issue0 = newDoc("ISSUE0", file).setFuncCreationDate(parseDateTime("2011-04-25T00:05:13+0000"));
-    IssueDoc issue1 = newDoc("I1", file).setFuncCreationDate(parseDateTime("2014-09-01T10:34:56+0000"));
-    IssueDoc issue2 = newDoc("I2", file).setFuncCreationDate(parseDateTime("2014-09-01T22:46:00+0000"));
-    IssueDoc issue3 = newDoc("I3", file).setFuncCreationDate(parseDateTime("2014-09-02T11:34:56+0000"));
-    IssueDoc issue4 = newDoc("I4", file).setFuncCreationDate(parseDateTime("2014-09-05T11:34:56+0000"));
-    IssueDoc issue5 = newDoc("I5", file).setFuncCreationDate(parseDateTime("2014-09-20T11:34:56+0000"));
-    IssueDoc issue6 = newDoc("I6", file).setFuncCreationDate(parseDateTime("2015-01-18T11:34:56+0000"));
+    IssueDoc issue0 = newDoc("ISSUE0", project.uuid(), file).setFuncCreationDate(parseDateTime("2011-04-25T00:05:13+0000"));
+    IssueDoc issue1 = newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-01T10:34:56+0000"));
+    IssueDoc issue2 = newDoc("I2", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-01T22:46:00+0000"));
+    IssueDoc issue3 = newDoc("I3", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-02T11:34:56+0000"));
+    IssueDoc issue4 = newDoc("I4", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-05T11:34:56+0000"));
+    IssueDoc issue5 = newDoc("I5", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-20T11:34:56+0000"));
+    IssueDoc issue6 = newDoc("I6", project.uuid(), file).setFuncCreationDate(parseDateTime("2015-01-18T11:34:56+0000"));
 
     indexIssues(issue0, issue1, issue2, issue3, issue4, issue5, issue6);
 
index 6c202a81c33edd9181548093eda33d972d868744..72753048a65cc60a556062b9c336733d303f01ff 100644 (file)
@@ -47,6 +47,7 @@ import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.rule.RuleTesting.newRule;
 import static org.sonar.server.issue.IssueDocTesting.newDoc;
+import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
 
 public class IssueIndexFiltersTest extends IssueIndexTestCommon {
 
@@ -55,8 +56,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
 
     indexIssues(
-      newDoc("I1", newFileDto(project, null)),
-      newDoc("I2", newFileDto(project, null)));
+      newDoc("I1", project.uuid(), newFileDto(project, null)),
+      newDoc("I2", project.uuid(), newFileDto(project, null)));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().issueKeys(asList("I1", "I2")), "I1", "I2");
     assertThatSearchReturnsOnly(IssueQuery.builder().issueKeys(singletonList("I1")), "I1");
@@ -68,8 +69,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
 
     indexIssues(
-      newDoc("I1", project),
-      newDoc("I2", newFileDto(project, null)));
+      newDocForProject("I1", project),
+      newDoc("I2", project.uuid(), newFileDto(project, null)));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())), "I1", "I2");
     assertThatSearchReturnsEmpty(IssueQuery.builder().projectUuids(singletonList("unknown")));
@@ -83,8 +84,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     indexView(view, singletonList(project.uuid()));
 
     indexIssues(
-      newDoc("I1", project),
-      newDoc("I2", file1));
+      newDocForProject("I1", project),
+      newDoc("I2", project.uuid(), file1));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().files(asList(file1.path())), "I2");
     assertThatSearchReturnsOnly(IssueQuery.builder().files(singletonList(file1.path())), "I2");
@@ -101,8 +102,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     indexView(view, singletonList(project.uuid()));
 
     indexIssues(
-      newDoc("I1", project),
-      newDoc("I2", file1));
+      newDocForProject("I1", project),
+      newDoc("I2", project.uuid(), file1));
 
     assertThatSearchReturnsEmpty(IssueQuery.builder().projectUuids(singletonList("unknown")));
     assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())), "I1", "I2");
@@ -118,8 +119,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo");
 
     indexIssues(
-      newDoc("I1", file1).setDirectoryPath("/src/main/xoo"),
-      newDoc("I2", file2).setDirectoryPath("/"));
+      newDoc("I1", project.uuid(), file1).setDirectoryPath("/src/main/xoo"),
+      newDoc("I2", project.uuid(), file2).setDirectoryPath("/"));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().directories(singletonList("/src/main/xoo")), "I1");
     assertThatSearchReturnsOnly(IssueQuery.builder().directories(singletonList("/")), "I2");
@@ -134,9 +135,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = db.components().insertComponent(newFileDto(project1));
     ComponentDto project2 = db.components().insertPrivateProject();
 
-    IssueDoc issueOnProject1 = newDoc(project1);
-    IssueDoc issueOnFile = newDoc(file);
-    IssueDoc issueOnProject2 = newDoc(project2);
+    IssueDoc issueOnProject1 = newDocForProject(project1);
+    IssueDoc issueOnFile = newDoc(file, project1.uuid());
+    IssueDoc issueOnProject2 = newDocForProject(project2);
 
     indexIssues(issueOnProject1, issueOnFile, issueOnProject2);
     indexView(portfolio1.uuid(), singletonList(project1.uuid()));
@@ -155,7 +156,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   public void filter_by_portfolios_not_having_projects() {
     ComponentDto project1 = newPrivateProjectDto();
     ComponentDto file1 = newFileDto(project1, null);
-    indexIssues(newDoc("I2", file1));
+    indexIssues(newDoc("I2", project1.uuid(), file1));
     String view1 = "ABCD";
     indexView(view1, emptyList());
 
@@ -170,9 +171,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto fileOnProjectBranch = db.components().insertComponent(newFileDto(projectBranch));
     indexView(portfolio.uuid(), singletonList(project.uuid()));
 
-    IssueDoc issueOnProject = newDoc(project);
-    IssueDoc issueOnProjectBranch = newDoc(projectBranch);
-    IssueDoc issueOnFileOnProjectBranch = newDoc(fileOnProjectBranch);
+    IssueDoc issueOnProject = newDocForProject(project);
+    IssueDoc issueOnProjectBranch = newDoc(projectBranch, project.uuid());
+    IssueDoc issueOnFileOnProjectBranch = newDoc(fileOnProjectBranch, projectBranch.uuid());
     indexIssues(issueOnProject, issueOnFileOnProjectBranch, issueOnProjectBranch);
 
     assertThatSearchReturnsOnly(IssueQuery.builder().viewUuids(singletonList(portfolio.uuid())), issueOnProject.key());
@@ -187,9 +188,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto branch = db.components().insertProjectBranch(project);
     ComponentDto anotherbBranch = db.components().insertProjectBranch(project);
 
-    IssueDoc issueOnProject = newDoc(project);
-    IssueDoc issueOnBranch = newDoc(branch);
-    IssueDoc issueOnAnotherBranch = newDoc(anotherbBranch);
+    IssueDoc issueOnProject = newDocForProject(project);
+    IssueDoc issueOnBranch = newDoc(branch, project.uuid());
+    IssueDoc issueOnAnotherBranch = newDoc(anotherbBranch, project.uuid());
     indexIssues(issueOnProject, issueOnBranch, issueOnAnotherBranch);
 
     assertThatSearchReturnsOnly(IssueQuery.builder().branchUuid(branch.uuid()).mainBranch(false), issueOnBranch.key());
@@ -211,10 +212,10 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
 
     indexIssues(
-      newDoc("I1", project),
-      newDoc("I2", projectFile),
-      newDoc("I3", branch),
-      newDoc("I4", branchFile));
+      newDocForProject("I1", project),
+      newDoc("I2", project.uuid(), projectFile),
+      newDoc("I3", project.uuid(), branch),
+      newDoc("I4", project.uuid(), branchFile));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().branchUuid(branch.uuid()).mainBranch(false), "I3", "I4");
     assertThatSearchReturnsOnly(IssueQuery.builder().files(singletonList(branchFile.path())).branchUuid(branch.uuid()).mainBranch(false), "I4");
@@ -226,8 +227,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(project);
 
-    IssueDoc issueOnProject = newDoc(project);
-    IssueDoc issueOnBranch = newDoc(branch);
+    IssueDoc issueOnProject = newDocForProject(project);
+    IssueDoc issueOnBranch = newDoc(branch, project.uuid());
     indexIssues(issueOnProject, issueOnBranch);
 
     assertThatSearchReturnsOnly(IssueQuery.builder().branchUuid(project.uuid()).mainBranch(true), issueOnProject.key());
@@ -243,8 +244,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
 
-    IssueDoc projectIssue = newDoc(project);
-    IssueDoc branchIssue = newDoc(branch);
+    IssueDoc projectIssue = newDocForProject(project);
+    IssueDoc branchIssue = newDoc(branch, project.uuid());
     indexIssues(projectIssue, branchIssue);
 
     assertThatSearchReturnsOnly(IssueQuery.builder(), projectIssue.key());
@@ -260,9 +261,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     indexView(application1.uuid(), singletonList(project1.uuid()));
     indexView(application2.uuid(), singletonList(project2.uuid()));
 
-    IssueDoc issueOnProject1 = newDoc(project1);
-    IssueDoc issueOnFile = newDoc(file);
-    IssueDoc issueOnProject2 = newDoc(project2);
+    IssueDoc issueOnProject1 = newDocForProject(project1);
+    IssueDoc issueOnFile = newDoc(file, project1.uuid());
+    IssueDoc issueOnProject2 = newDocForProject(project2);
     indexIssues(issueOnProject1, issueOnFile, issueOnProject2);
 
     assertThatSearchReturnsOnly(IssueQuery.builder().viewUuids(singletonList(application1.uuid())), issueOnProject1.key(), issueOnFile.key());
@@ -285,9 +286,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     indexView(branch1.uuid(), singletonList(project1.uuid()));
     indexView(branch2.uuid(), singletonList(project2.uuid()));
 
-    IssueDoc issueOnProject1 = newDoc(project1);
-    IssueDoc issueOnFile = newDoc(file);
-    IssueDoc issueOnProject2 = newDoc(project2);
+    IssueDoc issueOnProject1 = newDocForProject(project1);
+    IssueDoc issueOnFile = newDoc(file, project1.uuid());
+    IssueDoc issueOnProject2 = newDocForProject(project2);
     indexIssues(issueOnProject1, issueOnFile, issueOnProject2);
 
     assertThatSearchReturnsOnly(IssueQuery.builder().viewUuids(singletonList(branch1.uuid())).branchUuid(branch1.uuid()).mainBranch(false),
@@ -313,11 +314,11 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     indexView(applicationBranch1.uuid(), asList(project1Branch1.uuid(), project2.uuid()));
     indexView(applicationBranch2.uuid(), singletonList(project1Branch2.uuid()));
 
-    IssueDoc issueOnProject1 = newDoc(project1);
-    IssueDoc issueOnProject1Branch1 = newDoc(project1Branch1);
-    IssueDoc issueOnFileOnProject1Branch1 = newDoc(fileOnProject1Branch1);
-    IssueDoc issueOnProject1Branch2 = newDoc(project1Branch2);
-    IssueDoc issueOnProject2 = newDoc(project2);
+    IssueDoc issueOnProject1 = newDocForProject(project1);
+    IssueDoc issueOnProject1Branch1 = newDoc(project1Branch1, project1.uuid());
+    IssueDoc issueOnFileOnProject1Branch1 = newDoc(fileOnProject1Branch1, project1.uuid());
+    IssueDoc issueOnProject1Branch2 = newDoc(project1Branch2, project1.uuid());
+    IssueDoc issueOnProject2 = newDocForProject(project2);
     indexIssues(issueOnProject1, issueOnProject1Branch1, issueOnFileOnProject1Branch1, issueOnProject1Branch2, issueOnProject2);
 
     assertThatSearchReturnsOnly(IssueQuery.builder().viewUuids(singletonList(applicationBranch1.uuid())).branchUuid(applicationBranch1.uuid()).mainBranch(false),
@@ -337,11 +338,11 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   public void filter_by_created_after_by_projects() {
     Date now = new Date();
     ComponentDto project1 = newPrivateProjectDto();
-    IssueDoc project1Issue1 = newDoc(project1).setFuncCreationDate(addDays(now, -10));
-    IssueDoc project1Issue2 = newDoc(project1).setFuncCreationDate(addDays(now, -20));
+    IssueDoc project1Issue1 = newDocForProject(project1).setFuncCreationDate(addDays(now, -10));
+    IssueDoc project1Issue2 = newDocForProject(project1).setFuncCreationDate(addDays(now, -20));
     ComponentDto project2 = newPrivateProjectDto();
-    IssueDoc project2Issue1 = newDoc(project2).setFuncCreationDate(addDays(now, -15));
-    IssueDoc project2Issue2 = newDoc(project2).setFuncCreationDate(addDays(now, -30));
+    IssueDoc project2Issue1 = newDocForProject(project2).setFuncCreationDate(addDays(now, -15));
+    IssueDoc project2Issue2 = newDocForProject(project2).setFuncCreationDate(addDays(now, -30));
     indexIssues(project1Issue1, project1Issue2, project2Issue1, project2Issue2);
 
     // Search for issues of project 1 having less than 15 days
@@ -374,21 +375,21 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     Date now = new Date();
 
     ComponentDto project1 = newPrivateProjectDto();
-    IssueDoc project1Issue1 = newDoc(project1).setFuncCreationDate(addDays(now, -10));
-    IssueDoc project1Issue2 = newDoc(project1).setFuncCreationDate(addDays(now, -20));
+    IssueDoc project1Issue1 = newDocForProject(project1).setFuncCreationDate(addDays(now, -10));
+    IssueDoc project1Issue2 = newDocForProject(project1).setFuncCreationDate(addDays(now, -20));
 
     ComponentDto project1Branch1 = db.components().insertProjectBranch(project1);
-    IssueDoc project1Branch1Issue1 = newDoc(project1Branch1).setFuncCreationDate(addDays(now, -10));
-    IssueDoc project1Branch1Issue2 = newDoc(project1Branch1).setFuncCreationDate(addDays(now, -20));
+    IssueDoc project1Branch1Issue1 = newDoc(project1Branch1, project1.uuid()).setFuncCreationDate(addDays(now, -10));
+    IssueDoc project1Branch1Issue2 = newDoc(project1Branch1, project1.uuid()).setFuncCreationDate(addDays(now, -20));
 
     ComponentDto project2 = newPrivateProjectDto();
 
-    IssueDoc project2Issue1 = newDoc(project2).setFuncCreationDate(addDays(now, -15));
-    IssueDoc project2Issue2 = newDoc(project2).setFuncCreationDate(addDays(now, -30));
+    IssueDoc project2Issue1 = newDocForProject(project2).setFuncCreationDate(addDays(now, -15));
+    IssueDoc project2Issue2 = newDocForProject(project2).setFuncCreationDate(addDays(now, -30));
 
     ComponentDto project2Branch1 = db.components().insertProjectBranch(project2);
-    IssueDoc project2Branch1Issue1 = newDoc(project2Branch1).setFuncCreationDate(addDays(now, -15));
-    IssueDoc project2Branch1Issue2 = newDoc(project2Branch1).setFuncCreationDate(addDays(now, -30));
+    IssueDoc project2Branch1Issue1 = newDoc(project2Branch1, project2.uuid()).setFuncCreationDate(addDays(now, -15));
+    IssueDoc project2Branch1Issue2 = newDoc(project2Branch1, project2.uuid()).setFuncCreationDate(addDays(now, -30));
 
     indexIssues(project1Issue1, project1Issue2, project2Issue1, project2Issue2,
       project1Branch1Issue1, project1Branch1Issue2, project2Branch1Issue1, project2Branch1Issue2);
@@ -425,11 +426,11 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_new_code_reference_by_projects() {
     ComponentDto project1 = newPrivateProjectDto();
-    IssueDoc project1Issue1 = newDoc(project1).setIsNewCodeReference(true);
-    IssueDoc project1Issue2 = newDoc(project1).setIsNewCodeReference(false);
+    IssueDoc project1Issue1 = newDocForProject(project1).setIsNewCodeReference(true);
+    IssueDoc project1Issue2 = newDocForProject(project1).setIsNewCodeReference(false);
     ComponentDto project2 = newPrivateProjectDto();
-    IssueDoc project2Issue1 = newDoc(project2).setIsNewCodeReference(false);
-    IssueDoc project2Issue2 = newDoc(project2).setIsNewCodeReference(true);
+    IssueDoc project2Issue1 = newDocForProject(project2).setIsNewCodeReference(false);
+    IssueDoc project2Issue2 = newDocForProject(project2).setIsNewCodeReference(true);
     indexIssues(project1Issue1, project1Issue2, project2Issue1, project2Issue2);
 
     // Search for issues of project 1 and project 2 that are new code on a branch using reference for new code
@@ -441,21 +442,21 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_new_code_reference_branches() {
     ComponentDto project1 = newPrivateProjectDto();
-    IssueDoc project1Issue1 = newDoc(project1).setIsNewCodeReference(true);
-    IssueDoc project1Issue2 = newDoc(project1).setIsNewCodeReference(false);
+    IssueDoc project1Issue1 = newDocForProject(project1).setIsNewCodeReference(true);
+    IssueDoc project1Issue2 = newDocForProject(project1).setIsNewCodeReference(false);
 
     ComponentDto project1Branch1 = db.components().insertProjectBranch(project1);
-    IssueDoc project1Branch1Issue1 = newDoc(project1Branch1).setIsNewCodeReference(false);
-    IssueDoc project1Branch1Issue2 = newDoc(project1Branch1).setIsNewCodeReference(true);
+    IssueDoc project1Branch1Issue1 = newDoc(project1Branch1, project1.uuid()).setIsNewCodeReference(false);
+    IssueDoc project1Branch1Issue2 = newDoc(project1Branch1, project1.uuid()).setIsNewCodeReference(true);
 
     ComponentDto project2 = newPrivateProjectDto();
 
-    IssueDoc project2Issue1 = newDoc(project2).setIsNewCodeReference(true);
-    IssueDoc project2Issue2 = newDoc(project2).setIsNewCodeReference(false);
+    IssueDoc project2Issue1 = newDocForProject(project2).setIsNewCodeReference(true);
+    IssueDoc project2Issue2 = newDocForProject(project2).setIsNewCodeReference(false);
 
     ComponentDto project2Branch1 = db.components().insertProjectBranch(project2);
-    IssueDoc project2Branch1Issue1 = newDoc(project2Branch1).setIsNewCodeReference(false);
-    IssueDoc project2Branch1Issue2 = newDoc(project2Branch1).setIsNewCodeReference(true);
+    IssueDoc project2Branch1Issue1 = newDoc(project2Branch1, project2.uuid()).setIsNewCodeReference(false);
+    IssueDoc project2Branch1Issue2 = newDoc(project2Branch1, project2.uuid()).setIsNewCodeReference(true);
 
     indexIssues(project1Issue1, project1Issue2, project2Issue1, project2Issue2,
       project1Branch1Issue1, project1Branch1Issue2, project2Branch1Issue1, project2Branch1Issue2);
@@ -473,8 +474,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setSeverity(Severity.INFO),
-      newDoc("I2", file).setSeverity(Severity.MAJOR));
+      newDoc("I1", project.uuid(), file).setSeverity(Severity.INFO),
+      newDoc("I2", project.uuid(), file).setSeverity(Severity.MAJOR));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().severities(asList(Severity.INFO, Severity.MAJOR)), "I1", "I2");
     assertThatSearchReturnsOnly(IssueQuery.builder().severities(singletonList(Severity.INFO)), "I1");
@@ -487,8 +488,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setStatus(Issue.STATUS_CLOSED),
-      newDoc("I2", file).setStatus(Issue.STATUS_OPEN));
+      newDoc("I1", project.uuid(), file).setStatus(Issue.STATUS_CLOSED),
+      newDoc("I2", project.uuid(), file).setStatus(Issue.STATUS_OPEN));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().statuses(asList(Issue.STATUS_CLOSED, Issue.STATUS_OPEN)), "I1", "I2");
     assertThatSearchReturnsOnly(IssueQuery.builder().statuses(singletonList(Issue.STATUS_CLOSED)), "I1");
@@ -501,8 +502,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
-      newDoc("I2", file).setResolution(Issue.RESOLUTION_FIXED));
+      newDoc("I1", project.uuid(), file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
+      newDoc("I2", project.uuid(), file).setResolution(Issue.RESOLUTION_FIXED));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().resolutions(asList(Issue.RESOLUTION_FALSE_POSITIVE, Issue.RESOLUTION_FIXED)), "I1", "I2");
     assertThatSearchReturnsOnly(IssueQuery.builder().resolutions(singletonList(Issue.RESOLUTION_FALSE_POSITIVE)), "I1");
@@ -515,9 +516,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED),
-      newDoc("I2", file).setStatus(Issue.STATUS_OPEN).setResolution(null),
-      newDoc("I3", file).setStatus(Issue.STATUS_OPEN).setResolution(null));
+      newDoc("I1", project.uuid(), file).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED),
+      newDoc("I2", project.uuid(), file).setStatus(Issue.STATUS_OPEN).setResolution(null),
+      newDoc("I3", project.uuid(), file).setStatus(Issue.STATUS_OPEN).setResolution(null));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().resolved(true), "I1");
     assertThatSearchReturnsOnly(IssueQuery.builder().resolved(false), "I2", "I3");
@@ -531,7 +532,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     RuleDto ruleDefinitionDto = newRule();
     db.rules().insert(ruleDefinitionDto);
 
-    indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid()));
+    indexIssues(newDoc("I1", project.uuid(), file).setRuleUuid(ruleDefinitionDto.getUuid()));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().ruleUuids(singletonList(ruleDefinitionDto.getUuid())), "I1");
     assertThatSearchReturnsEmpty(IssueQuery.builder().ruleUuids(singletonList("uuid-abc")));
@@ -544,7 +545,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     RuleDto ruleDefinitionDto = newRule();
     db.rules().insert(ruleDefinitionDto);
 
-    indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid()).setLanguage("xoo"));
+    indexIssues(newDoc("I1", project.uuid(), file).setRuleUuid(ruleDefinitionDto.getUuid()).setLanguage("xoo"));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().languages(singletonList("xoo")), "I1");
     assertThatSearchReturnsEmpty(IssueQuery.builder().languages(singletonList("unknown")));
@@ -556,9 +557,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setAssigneeUuid("steph-uuid"),
-      newDoc("I2", file).setAssigneeUuid("marcel-uuid"),
-      newDoc("I3", file).setAssigneeUuid(null));
+      newDoc("I1", project.uuid(), file).setAssigneeUuid("steph-uuid"),
+      newDoc("I2", project.uuid(), file).setAssigneeUuid("marcel-uuid"),
+      newDoc("I3", project.uuid(), file).setAssigneeUuid(null));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().assigneeUuids(singletonList("steph-uuid")), "I1");
     assertThatSearchReturnsOnly(IssueQuery.builder().assigneeUuids(asList("steph-uuid", "marcel-uuid")), "I1", "I2");
@@ -571,9 +572,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setAssigneeUuid("steph-uuid"),
-      newDoc("I2", file).setAssigneeUuid(null),
-      newDoc("I3", file).setAssigneeUuid(null));
+      newDoc("I1", project.uuid(), file).setAssigneeUuid("steph-uuid"),
+      newDoc("I2", project.uuid(), file).setAssigneeUuid(null),
+      newDoc("I3", project.uuid(), file).setAssigneeUuid(null));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().assigned(true), "I1");
     assertThatSearchReturnsOnly(IssueQuery.builder().assigned(false), "I2", "I3");
@@ -586,9 +587,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setAuthorLogin("steph"),
-      newDoc("I2", file).setAuthorLogin("marcel"),
-      newDoc("I3", file).setAssigneeUuid(null));
+      newDoc("I1", project.uuid(), file).setAuthorLogin("steph"),
+      newDoc("I2", project.uuid(), file).setAuthorLogin("marcel"),
+      newDoc("I3", project.uuid(), file).setAssigneeUuid(null));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().authors(singletonList("steph")), "I1");
     assertThatSearchReturnsOnly(IssueQuery.builder().authors(asList("steph", "marcel")), "I1", "I2");
@@ -601,8 +602,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setFuncCreationDate(parseDate("2014-09-20")),
-      newDoc("I2", file).setFuncCreationDate(parseDate("2014-09-23")));
+      newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-20")),
+      newDoc("I2", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-23")));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().createdAfter(parseDate("2014-09-19")), "I1", "I2");
     // Lower bound is included
@@ -617,8 +618,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setFuncCreationDate(parseDate("2014-09-20")),
-      newDoc("I2", file).setFuncCreationDate(parseDate("2014-09-23")));
+      newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-20")),
+      newDoc("I2", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-23")));
 
     assertThatSearchReturnsEmpty(IssueQuery.builder().createdBefore(parseDate("2014-09-19")));
     // Upper bound is excluded
@@ -633,8 +634,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setFuncCreationDate(parseDate("2014-09-20")),
-      newDoc("I2", file).setFuncCreationDate(parseDate("2014-09-23")));
+      newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-20")),
+      newDoc("I2", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-23")));
 
     // 19 < createdAt < 25
     assertThatSearchReturnsOnly(IssueQuery.builder().createdAfter(parseDate("2014-09-19")).createdBefore(parseDate("2014-09-25")),
@@ -673,8 +674,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setFuncCreationDate(parseDateTime("2014-09-20T00:00:00+0100")),
-      newDoc("I2", file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")));
+      newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-20T00:00:00+0100")),
+      newDoc("I2", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().createdAfter(parseDateTime("2014-09-19T23:00:00+0000")).createdBefore(parseDateTime("2014-09-22T23:00:01+0000")),
       "I1", "I2");
@@ -716,7 +717,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     ComponentDto file = newFileDto(project, null);
 
-    indexIssues(newDoc("I1", file).setFuncCreationDate(parseDate("2014-09-20")));
+    indexIssues(newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-20")));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().createdAt(parseDate("2014-09-20")), "I1");
     assertThatSearchReturnsEmpty(IssueQuery.builder().createdAt(parseDate("2014-09-21")));
@@ -727,8 +728,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     ComponentDto file = newFileDto(project, null);
 
-    indexIssues(newDoc("I1", file).setIsNewCodeReference(true),
-      newDoc("I2", file).setIsNewCodeReference(false));
+    indexIssues(newDoc("I1", project.uuid(), file).setIsNewCodeReference(true),
+      newDoc("I2", project.uuid(), file).setIsNewCodeReference(false));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().newCodeOnReference(true), "I1");
   }
@@ -739,9 +740,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setCwe(asList("20", "564", "89", "943")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setCwe(singletonList("943")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setCwe(asList("20", "564", "89", "943")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setCwe(singletonList("943")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().cwe(singletonList("20")), "I1");
   }
@@ -752,9 +753,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.2.2", "2.2.2")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.2.2")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.2.2", "2.2.2")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.2.2")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().owaspAsvs40(singletonList("1")), "I1", "I2");
     assertThatSearchReturnsOnly(IssueQuery.builder().owaspAsvs40(singletonList("2")), "I1");
@@ -767,9 +768,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.2.2", "2.2.2")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.2.2")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.2.2", "2.2.2")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.2.2")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().owaspAsvs40(singletonList("1.1.1")), "I1", "I2");
     assertThatSearchReturnsOnly(IssueQuery.builder().owaspAsvs40(singletonList("2.2.2")), "I1");
@@ -782,11 +783,11 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("2.1.1", "1.1.1", "1.11.3")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.11.3")),
-      newDoc("I3", file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(singletonList("1.11.3")),
-      newDoc("IError1", file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("5.5.1", "7.2.2", "10.2.6")),
-      newDoc("IError2", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("2.1.1", "1.1.1", "1.11.3")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.11.3")),
+      newDoc("I3", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(singletonList("1.11.3")),
+      newDoc("IError1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("5.5.1", "7.2.2", "10.2.6")),
+      newDoc("IError2", project.uuid(), file));
 
     assertThatSearchReturnsOnly(
       IssueQuery.builder().owaspAsvs40(singletonList("1.1.1")).owaspAsvsLevel(1));
@@ -804,9 +805,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setOwaspTop10(asList("a1", "a2")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setCwe(singletonList("a3")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10(asList("a1", "a2")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setCwe(singletonList("a3")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().owaspTop10(singletonList("a1")), "I1");
   }
@@ -817,9 +818,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setSansTop25(asList("porous-defenses", "risky-resource", "insecure-interaction")),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setSansTop25(singletonList("porous-defenses")),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setSansTop25(asList("porous-defenses", "risky-resource", "insecure-interaction")),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setSansTop25(singletonList("porous-defenses")),
+      newDoc("I3", project.uuid(), file));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().sansTop25(singletonList("risky-resource")), "I1");
   }
@@ -830,9 +831,9 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(RuleType.VULNERABILITY).setSonarSourceSecurityCategory(SQCategory.BUFFER_OVERFLOW),
-      newDoc("I2", file).setType(RuleType.VULNERABILITY).setSonarSourceSecurityCategory(SQCategory.DOS),
-      newDoc("I3", file));
+      newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setSonarSourceSecurityCategory(SQCategory.BUFFER_OVERFLOW),
+      newDoc("I2", project.uuid(), file).setType(RuleType.VULNERABILITY).setSonarSourceSecurityCategory(SQCategory.DOS),
+      newDoc("I3", project.uuid(), file));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().sonarsourceSecurity(singletonList("buffer-overflow")), "I1");
   }
index 2f6ba0272ceefeb0a2fee944bb488e53aa1cdd08..51a3f46797047bb4caf7767eaed576e04c4834d4 100644 (file)
@@ -35,6 +35,7 @@ import static org.sonar.db.component.ComponentTesting.newBranchComponent;
 import static org.sonar.db.component.ComponentTesting.newBranchDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.server.issue.IssueDocTesting.newDoc;
+import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
 
 public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
 
@@ -55,7 +56,7 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     String userUuid = randomAlphanumeric(40);
     long from = 1_111_234_567_890L;
-    indexIssues(newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
+    indexIssues(newDocForProject("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList(project.uuid()), singletonList(from), userUuid);
 
@@ -68,7 +69,7 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     String user1Uuid = randomAlphanumeric(40);
     String user2Uuid = randomAlphanumeric(40);
     long from = 1_111_234_567_890L;
-    indexIssues(newDoc("issue1", project).setAssigneeUuid(user1Uuid).setFuncCreationDate(new Date(from + 1L)));
+    indexIssues(newDocForProject("issue1", project).setAssigneeUuid(user1Uuid).setFuncCreationDate(new Date(from + 1L)));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList(project.uuid()), singletonList(from), user2Uuid);
 
@@ -80,7 +81,7 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     String user1Uuid = randomAlphanumeric(40);
     long from = 1_111_234_567_890L;
-    indexIssues(newDoc("issue1", project).setAssigneeUuid(user1Uuid).setFuncCreationDate(new Date(from + 1L)));
+    indexIssues(newDocForProject("issue1", project).setAssigneeUuid(user1Uuid).setFuncCreationDate(new Date(from + 1L)));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList(project.uuid()), singletonList(from), user1Uuid);
 
@@ -92,7 +93,7 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     String userUuid = randomAlphanumeric(40);
     long from = 1_111_234_567_890L;
-    indexIssues(newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
+    indexIssues(newDocForProject("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList(project.uuid()), singletonList(from), userUuid);
 
@@ -104,7 +105,7 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     String userUuid = randomAlphanumeric(40);
     long from = 1_111_234_567_890L;
-    indexIssues(newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from)));
+    indexIssues(newDocForProject("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from)));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList(project.uuid()), singletonList(from), userUuid);
 
@@ -117,10 +118,10 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     String userUuid = randomAlphanumeric(40);
     long from = 1_111_234_567_890L;
     indexIssues(
-      newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
-      newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)).setResolution(Issue.RESOLUTION_FIXED),
-      newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)).setResolution(Issue.RESOLUTION_REMOVED),
-      newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)).setResolution(Issue.RESOLUTION_WONT_FIX));
+      newDocForProject("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
+      newDocForProject("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)).setResolution(Issue.RESOLUTION_FIXED),
+      newDocForProject("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)).setResolution(Issue.RESOLUTION_REMOVED),
+      newDocForProject("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)).setResolution(Issue.RESOLUTION_WONT_FIX));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList(project.uuid()), singletonList(from), userUuid);
 
@@ -132,7 +133,7 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     String userUuid = randomAlphanumeric(40);
     long from = 1_111_234_567_890L;
-    indexIssues(newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from - 1000L)));
+    indexIssues(newDocForProject("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from - 1000L)));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList(project.uuid()), singletonList(from), userUuid);
 
@@ -145,9 +146,9 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     String userUuid = randomAlphanumeric(40);
     long from = 1_111_234_567_890L;
     indexIssues(
-      newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
-      newDoc("issue2", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
-      newDoc("issue3", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
+      newDocForProject("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
+      newDocForProject("issue2", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
+      newDocForProject("issue3", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList(project.uuid()), singletonList(from), userUuid);
 
@@ -162,12 +163,12 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     String userUuid = randomAlphanumeric(40);
     long from = 1_111_234_567_890L;
     indexIssues(
-      newDoc("issue1", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
-      newDoc("issue2", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
-      newDoc("issue3", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
+      newDocForProject("issue1", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
+      newDocForProject("issue2", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
+      newDocForProject("issue3", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
 
-      newDoc("issue4", project3).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
-      newDoc("issue5", project3).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
+      newDocForProject("issue4", project3).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
+      newDocForProject("issue5", project3).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(
       asList(project1.uuid(), project2.uuid(), project3.uuid()),
@@ -189,12 +190,12 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     String userUuid = randomAlphanumeric(40);
     long from = 1_111_234_567_000L;
     indexIssues(
-      newDoc("issue1", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1_000L)),
-      newDoc("issue2", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 2_000L)),
-      newDoc("issue3", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 3_000L)),
+      newDocForProject("issue1", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1_000L)),
+      newDocForProject("issue2", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 2_000L)),
+      newDocForProject("issue3", project1).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 3_000L)),
 
-      newDoc("issue4", project3).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 4_000L)),
-      newDoc("issue5", project3).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 5_000L)));
+      newDocForProject("issue4", project3).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 4_000L)),
+      newDocForProject("issue5", project3).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 5_000L)));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(
       asList(project1.uuid(), project2.uuid(), project3.uuid()),
@@ -215,9 +216,9 @@ public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
     String userUuid = randomAlphanumeric(40);
     long from = 1_111_234_567_890L;
     indexIssues(
-      newDoc("issue1", branch).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
-      newDoc("issue2", branch).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 2L)),
-      newDoc("issue3", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
+      newDoc("issue1", project.uuid(), branch).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)),
+      newDoc("issue2", project.uuid(), branch).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 2L)),
+      newDocForProject("issue3", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
 
     List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList(project.uuid()), singletonList(from), userUuid);
 
index ada7b0b97cce62da6cd19ec83359752821d1a0cc..ad521d7fb97bdddf9af63569e04847ec2cf51953 100644 (file)
@@ -31,6 +31,7 @@ import static java.util.Arrays.stream;
 import static java.util.stream.Collectors.toList;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.server.issue.IssueDocTesting.newDoc;
+import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
 
 public class IssueIndexSecurityCategoriesTest extends IssueIndexTestCommon {
 
@@ -39,9 +40,9 @@ public class IssueIndexSecurityCategoriesTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
 
     indexIssues(
-      newDoc("openvul1", project).setPciDss32(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project).setPciDss32(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project).setPciDss32(asList("3.3.2", "1.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project).setPciDss32(asList("3.3.2", "1.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR)
     );
 
@@ -55,11 +56,11 @@ public class IssueIndexSecurityCategoriesTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
 
     indexIssues(
-      newDoc("openvul1", project).setPciDss32(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project).setPciDss32(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project).setPciDss32(asList("3.3.2", "2.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project).setPciDss32(asList("3.3.2", "2.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("openvul3", project).setPciDss32(asList("4.1", "5.4")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul3", project).setPciDss32(asList("4.1", "5.4")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR)
     );
 
@@ -73,9 +74,9 @@ public class IssueIndexSecurityCategoriesTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
 
     indexIssues(
-      newDoc("openvul1", project).setPciDss40(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project).setPciDss40(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project).setPciDss40(asList("3.3.2", "1.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project).setPciDss40(asList("3.3.2", "1.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR)
     );
 
@@ -89,11 +90,11 @@ public class IssueIndexSecurityCategoriesTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
 
     indexIssues(
-      newDoc("openvul1", project).setPciDss40(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project).setPciDss40(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project).setPciDss40(asList("3.3.2", "2.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project).setPciDss40(asList("3.3.2", "2.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("openvul3", project).setPciDss40(asList("4.1", "5.4")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul3", project).setPciDss40(asList("4.1", "5.4")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR)
     );
 
@@ -107,11 +108,11 @@ public class IssueIndexSecurityCategoriesTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
 
     indexIssues(
-      newDoc("openvul1", project).setPciDss40(asList("1.2.0", "3.4.5")).setPciDss32(List.of("2.1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project).setPciDss40(asList("1.2.0", "3.4.5")).setPciDss32(List.of("2.1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project).setPciDss40(asList("3.3.2", "2.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project).setPciDss40(asList("3.3.2", "2.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("openvul3", project).setPciDss32(asList("4.1", "5.4")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul3", project).setPciDss32(asList("4.1", "5.4")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR)
     );
 
index 074014b1b904152f1af7529efe4d4c92c1971dff..40d490b31c92dad7fc41bf91b1fac5394181bc6a 100644 (file)
@@ -53,12 +53,12 @@ public class IssueIndexSecurityHotspotsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setType(BUG),
-      newDoc("I2", file).setType(CODE_SMELL),
-      newDoc("I3", file).setType(VULNERABILITY),
-      newDoc("I4", file).setType(VULNERABILITY),
-      newDoc("I5", file).setType(SECURITY_HOTSPOT),
-      newDoc("I6", file).setType(SECURITY_HOTSPOT));
+      newDoc("I1", project.uuid(), file).setType(BUG),
+      newDoc("I2", project.uuid(), file).setType(CODE_SMELL),
+      newDoc("I3", project.uuid(), file).setType(VULNERABILITY),
+      newDoc("I4", project.uuid(), file).setType(VULNERABILITY),
+      newDoc("I5", project.uuid(), file).setType(SECURITY_HOTSPOT),
+      newDoc("I6", project.uuid(), file).setType(SECURITY_HOTSPOT));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().types(singletonList(SECURITY_HOTSPOT.name())), "I5", "I6");
     assertThatSearchReturnsOnly(IssueQuery.builder().types(asList(SECURITY_HOTSPOT.name(), VULNERABILITY.name())), "I3", "I4", "I5", "I6");
@@ -71,12 +71,12 @@ public class IssueIndexSecurityHotspotsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setSeverity(Severity.INFO).setType(BUG),
-      newDoc("I2", file).setSeverity(Severity.MAJOR).setType(CODE_SMELL),
-      newDoc("I3", file).setSeverity(Severity.MAJOR).setType(VULNERABILITY),
-      newDoc("I4", file).setSeverity(Severity.CRITICAL).setType(VULNERABILITY),
+      newDoc("I1", project.uuid(), file).setSeverity(Severity.INFO).setType(BUG),
+      newDoc("I2", project.uuid(), file).setSeverity(Severity.MAJOR).setType(CODE_SMELL),
+      newDoc("I3", project.uuid(), file).setSeverity(Severity.MAJOR).setType(VULNERABILITY),
+      newDoc("I4", project.uuid(), file).setSeverity(Severity.CRITICAL).setType(VULNERABILITY),
       // This entry should be ignored
-      newDoc("I5", file).setSeverity(Severity.MAJOR).setType(SECURITY_HOTSPOT));
+      newDoc("I5", project.uuid(), file).setSeverity(Severity.MAJOR).setType(SECURITY_HOTSPOT));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().severities(asList(Severity.INFO, Severity.MAJOR)), "I1", "I2", "I3");
     assertThatSearchReturnsOnly(IssueQuery.builder().severities(asList(Severity.INFO, Severity.MAJOR)).types(singletonList(VULNERABILITY.name())), "I3");
@@ -89,13 +89,13 @@ public class IssueIndexSecurityHotspotsTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setSeverity(INFO).setType(BUG),
-      newDoc("I2", file).setSeverity(INFO).setType(CODE_SMELL),
-      newDoc("I3", file).setSeverity(INFO).setType(VULNERABILITY),
-      newDoc("I4", file).setSeverity(MAJOR).setType(VULNERABILITY),
+      newDoc("I1", project.uuid(), file).setSeverity(INFO).setType(BUG),
+      newDoc("I2", project.uuid(), file).setSeverity(INFO).setType(CODE_SMELL),
+      newDoc("I3", project.uuid(), file).setSeverity(INFO).setType(VULNERABILITY),
+      newDoc("I4", project.uuid(), file).setSeverity(MAJOR).setType(VULNERABILITY),
       // These 2 entries should be ignored
-      newDoc("I5", file).setSeverity(INFO).setType(SECURITY_HOTSPOT),
-      newDoc("I6", file).setSeverity(MAJOR).setType(SECURITY_HOTSPOT));
+      newDoc("I5", project.uuid(), file).setSeverity(INFO).setType(SECURITY_HOTSPOT),
+      newDoc("I6", project.uuid(), file).setSeverity(MAJOR).setType(SECURITY_HOTSPOT));
 
     assertThatFacetHasOnly(IssueQuery.builder(), "severities", entry("INFO", 3L), entry("MAJOR", 1L));
     assertThatFacetHasOnly(IssueQuery.builder().types(singletonList(VULNERABILITY.name())), "severities", entry("INFO", 1L), entry("MAJOR", 1L));
index 511993bb58afa3e1e0b4e04e981080458824584e..3f05442eae08300c8cd663af9a8a526f167197e0 100644 (file)
@@ -45,6 +45,7 @@ import static org.sonar.api.server.rule.RulesDefinition.OwaspTop10Version.Y2021;
 import static org.sonar.api.server.rule.RulesDefinition.PciDssVersion;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.server.issue.IssueDocTesting.newDoc;
+import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
 import static org.sonar.server.security.SecurityStandards.UNKNOWN_STANDARD;
 
 public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
@@ -54,10 +55,10 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     ComponentDto another = newPrivateProjectDto();
 
-    IssueDoc openVulDoc = newDoc("openvul1", project).setOwaspTop10(singletonList("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR);
+    IssueDoc openVulDoc = newDocForProject("openvul1", project).setOwaspTop10(singletonList("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR);
     openVulDoc.setOwaspTop10For2021(singletonList("a2")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR);
 
-    IssueDoc otherProjectDoc = newDoc("anotherProject", another).setOwaspTop10(singletonList("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL);
+    IssueDoc otherProjectDoc = newDocForProject("anotherProject", another).setOwaspTop10(singletonList("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL);
     otherProjectDoc.setOwaspTop10For2021(singletonList("a2")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL);
 
     indexIssues(openVulDoc, otherProjectDoc);
@@ -82,11 +83,11 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
   public void getOwaspTop10Report_dont_count_closed_vulnerabilities() {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
-      newDoc("openvul1", project).setOwaspTop10(List.of("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR),
-      newDoc("openvul12021", project).setOwaspTop10For2021(List.of("a2")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR),
-      newDoc("notopenvul", project).setOwaspTop10(List.of("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED)
+      newDocForProject("openvul1", project).setOwaspTop10(List.of("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR),
+      newDocForProject("openvul12021", project).setOwaspTop10For2021(List.of("a2")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR),
+      newDocForProject("notopenvul", project).setOwaspTop10(List.of("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED)
         .setSeverity(Severity.BLOCKER),
-      newDoc("notopenvul2021", project).setOwaspTop10For2021(List.of("a2")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED)
+      newDocForProject("notopenvul2021", project).setOwaspTop10For2021(List.of("a2")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED)
         .setSeverity(Severity.BLOCKER));
 
     List<SecurityStandardCategoryStatistics> owaspTop10Report = underTest.getOwaspTop10Report(project.uuid(), false, false, Y2017);
@@ -109,7 +110,7 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
       // Previous vulnerabilities in projects that are not reanalyzed will have no owasp nor cwe attributes (not even 'unknown')
-      newDoc("openvulNotReindexed", project).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR));
+      newDocForProject("openvulNotReindexed", project).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR));
 
     List<SecurityStandardCategoryStatistics> owaspTop10Report = underTest.getOwaspTop10Report(project.uuid(), false, false, Y2017);
     assertThat(owaspTop10Report)
@@ -131,10 +132,10 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     ComponentDto another = newPrivateProjectDto();
     indexIssues(
-      newDoc("openhotspot1", project).setOwaspTop10(List.of("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("openhotspot2021", project).setOwaspTop10For2021(List.of("a2")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("anotherProject", another).setOwaspTop10(List.of("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("anotherProject2021", another).setOwaspTop10For2021(List.of("a2")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
+      newDocForProject("openhotspot1", project).setOwaspTop10(List.of("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("openhotspot2021", project).setOwaspTop10For2021(List.of("a2")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("anotherProject", another).setOwaspTop10(List.of("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("anotherProject2021", another).setOwaspTop10For2021(List.of("a2")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
 
     List<SecurityStandardCategoryStatistics> owaspTop10Report = underTest.getOwaspTop10Report(project.uuid(), false, false, Y2017);
     assertThat(owaspTop10Report)
@@ -153,11 +154,11 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
   public void getOwaspTop10Report_dont_count_closed_hotspots() {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
-      newDoc("openhotspot1", project).setOwaspTop10(List.of("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("openhotspot2021", project).setOwaspTop10For2021(List.of("a2")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("closedHotspot", project).setOwaspTop10(List.of("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_CLOSED)
+      newDocForProject("openhotspot1", project).setOwaspTop10(List.of("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("openhotspot2021", project).setOwaspTop10For2021(List.of("a2")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("closedHotspot", project).setOwaspTop10(List.of("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_CLOSED)
         .setResolution(Issue.RESOLUTION_FIXED),
-      newDoc("closedHotspot2021", project).setOwaspTop10For2021(List.of("a2")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_CLOSED)
+      newDocForProject("closedHotspot2021", project).setOwaspTop10For2021(List.of("a2")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_CLOSED)
         .setResolution(Issue.RESOLUTION_FIXED));
 
     List<SecurityStandardCategoryStatistics> owaspTop10Report = underTest.getOwaspTop10Report(project.uuid(), false, false, Y2017);
@@ -246,15 +247,15 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
       .collect(Collectors.toMap(SecurityStandardCategoryStatistics::getCategory, SecurityStandardCategoryStatistics::getChildren));
 
     assertThat(cweByOwasp.get("a1")).extracting(SecurityStandardCategoryStatistics::getCategory, SecurityStandardCategoryStatistics::getVulnerabilities,
-      SecurityStandardCategoryStatistics::getVulnerabilityRating, SecurityStandardCategoryStatistics::getToReviewSecurityHotspots,
-      SecurityStandardCategoryStatistics::getReviewedSecurityHotspots, SecurityStandardCategoryStatistics::getSecurityReviewRating)
+        SecurityStandardCategoryStatistics::getVulnerabilityRating, SecurityStandardCategoryStatistics::getToReviewSecurityHotspots,
+        SecurityStandardCategoryStatistics::getReviewedSecurityHotspots, SecurityStandardCategoryStatistics::getSecurityReviewRating)
       .containsExactlyInAnyOrder(
         tuple("123", 1L /* openvul1 */, OptionalInt.of(3)/* MAJOR = C */, 0L, 0L, 1),
         tuple("456", 1L /* openvul1 */, OptionalInt.of(3)/* MAJOR = C */, 0L, 0L, 1),
         tuple("unknown", 0L, OptionalInt.empty(), 1L /* openhotspot1 */, 0L, 5));
     assertThat(cweByOwasp.get("a3")).extracting(SecurityStandardCategoryStatistics::getCategory, SecurityStandardCategoryStatistics::getVulnerabilities,
-      SecurityStandardCategoryStatistics::getVulnerabilityRating, SecurityStandardCategoryStatistics::getToReviewSecurityHotspots,
-      SecurityStandardCategoryStatistics::getReviewedSecurityHotspots, SecurityStandardCategoryStatistics::getSecurityReviewRating)
+        SecurityStandardCategoryStatistics::getVulnerabilityRating, SecurityStandardCategoryStatistics::getToReviewSecurityHotspots,
+        SecurityStandardCategoryStatistics::getReviewedSecurityHotspots, SecurityStandardCategoryStatistics::getSecurityReviewRating)
       .containsExactlyInAnyOrder(
         tuple("123", 2L /* openvul1, openvul2 */, OptionalInt.of(3)/* MAJOR = C */, 0L, 0L, 1),
         tuple("456", 1L /* openvul1 */, OptionalInt.of(3)/* MAJOR = C */, 0L, 0L, 1),
@@ -287,17 +288,17 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
   private List<SecurityStandardCategoryStatistics> indexIssuesAndAssertOwaspReport(boolean includeCwe) {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
-      newDoc("openvul1", project).setOwaspTop10(asList("a1", "a3")).setCwe(asList("123", "456")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project).setOwaspTop10(asList("a1", "a3")).setCwe(asList("123", "456")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project).setOwaspTop10(asList("a3", "a6")).setCwe(List.of("123")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project).setOwaspTop10(asList("a3", "a6")).setCwe(List.of("123")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("notowaspvul", project).setOwaspTop10(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
-      newDoc("toreviewhotspot1", project).setOwaspTop10(asList("a1", "a3")).setCwe(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT)
+      newDocForProject("notowaspvul", project).setOwaspTop10(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
+      newDocForProject("toreviewhotspot1", project).setOwaspTop10(asList("a1", "a3")).setCwe(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT)
         .setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("toreviewhotspot2", project).setOwaspTop10(asList("a3", "a6")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("reviewedHotspot", project).setOwaspTop10(asList("a3", "a8")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
+      newDocForProject("toreviewhotspot2", project).setOwaspTop10(asList("a3", "a6")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("reviewedHotspot", project).setOwaspTop10(asList("a3", "a8")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
         .setResolution(Issue.RESOLUTION_FIXED),
-      newDoc("notowasphotspot", project).setOwaspTop10(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
+      newDocForProject("notowasphotspot", project).setOwaspTop10(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
 
     List<SecurityStandardCategoryStatistics> owaspTop10Report = underTest.getOwaspTop10Report(project.uuid(), false, includeCwe, Y2017);
     assertThat(owaspTop10Report)
@@ -321,19 +322,19 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
   private List<SecurityStandardCategoryStatistics> indexIssuesAndAssertPciDss32Report() {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
-      newDoc("openvul1", project).setPciDss32(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project).setPciDss32(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project).setPciDss32(asList("3.3.2", "6.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project).setPciDss32(asList("3.3.2", "6.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("openvul3", project).setPciDss32(asList("10.1.2", "6.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul3", project).setPciDss32(asList("10.1.2", "6.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("notpcidssvul", project).setPciDss32(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
-      newDoc("toreviewhotspot1", project).setPciDss32(asList("1.3.0", "3.3.2")).setType(RuleType.SECURITY_HOTSPOT)
+      newDocForProject("notpcidssvul", project).setPciDss32(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
+      newDocForProject("toreviewhotspot1", project).setPciDss32(asList("1.3.0", "3.3.2")).setType(RuleType.SECURITY_HOTSPOT)
         .setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("toreviewhotspot2", project).setPciDss32(asList("3.5.6", "6.4.5")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("reviewedHotspot", project).setPciDss32(asList("3.1.1", "8.6")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
+      newDocForProject("toreviewhotspot2", project).setPciDss32(asList("3.5.6", "6.4.5")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("reviewedHotspot", project).setPciDss32(asList("3.1.1", "8.6")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
         .setResolution(Issue.RESOLUTION_FIXED),
-      newDoc("notpcidsshotspot", project).setPciDss32(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
+      newDocForProject("notpcidsshotspot", project).setPciDss32(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
 
     List<SecurityStandardCategoryStatistics> pciDssReport = underTest.getPciDssReport(project.uuid(), false, PciDssVersion.V3_2).stream()
       .sorted(comparing(s -> parseInt(s.getCategory())))
@@ -375,7 +376,7 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
         tuple("3", 2L /* openvul1,openvul2 */, OptionalInt.of(3)/* MAJOR = C */, 2L/* toreviewhotspot1,toreviewhotspot2 */, 1L /* reviewedHotspot */, 4),
         tuple("4", 0L, OptionalInt.empty(), 0L, 0L, 1),
         tuple("5", 0L, OptionalInt.empty(), 0L, 0L, 1),
-        tuple("6", 2L /* openvul2 */, OptionalInt.of(2) /* MINOR = B */, 0L , 0L, 1),
+        tuple("6", 2L /* openvul2 */, OptionalInt.of(2) /* MINOR = B */, 0L, 0L, 1),
         tuple("7", 0L /* openvul2 */, OptionalInt.empty() /* MINOR = B */, 1L /* toreviewhotspot2 */, 0L, 5),
         tuple("8", 0L, OptionalInt.empty(), 0L, 1L /* reviewedHotspot */, 1),
         tuple("9", 0L, OptionalInt.empty(), 0L, 0L, 1),
@@ -418,36 +419,36 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
   private ComponentDto getProjectWithOwaspAsvsIssuesIndexed() {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
-      newDoc("openvul1", project).setOwaspAsvs40(asList("2.4.1", "3.2.4")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project).setOwaspAsvs40(asList("2.4.1", "3.2.4")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project).setOwaspAsvs40(asList("3.4.5", "6.2.1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project).setOwaspAsvs40(asList("3.4.5", "6.2.1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("openvul3", project).setOwaspAsvs40(asList("10.2.4", "6.2.8")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul3", project).setOwaspAsvs40(asList("10.2.4", "6.2.8")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("notowaspasvsvul", project).setOwaspAsvs40(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
-      newDoc("toreviewhotspot1", project).setOwaspAsvs40(asList("2.2.5", "3.2.4")).setType(RuleType.SECURITY_HOTSPOT)
+      newDocForProject("notowaspasvsvul", project).setOwaspAsvs40(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
+      newDocForProject("toreviewhotspot1", project).setOwaspAsvs40(asList("2.2.5", "3.2.4")).setType(RuleType.SECURITY_HOTSPOT)
         .setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("toreviewhotspot2", project).setOwaspAsvs40(asList("3.6.1", "7.1.1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("reviewedHotspot", project).setOwaspAsvs40(asList("3.3.3", "8.3.7")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
+      newDocForProject("toreviewhotspot2", project).setOwaspAsvs40(asList("3.6.1", "7.1.1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("reviewedHotspot", project).setOwaspAsvs40(asList("3.3.3", "8.3.7")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
         .setResolution(Issue.RESOLUTION_FIXED),
-      newDoc("notowaspasvshotspot", project).setOwaspAsvs40(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
+      newDocForProject("notowaspasvshotspot", project).setOwaspAsvs40(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
     return project;
   }
 
   private List<SecurityStandardCategoryStatistics> indexIssuesAndAssertOwasp2021Report(boolean includeCwe) {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
-      newDoc("openvul1", project).setOwaspTop10For2021(asList("a1", "a3")).setCwe(asList("123", "456")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project).setOwaspTop10For2021(asList("a1", "a3")).setCwe(asList("123", "456")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project).setOwaspTop10For2021(asList("a3", "a6")).setCwe(List.of("123")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project).setOwaspTop10For2021(asList("a3", "a6")).setCwe(List.of("123")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("notowaspvul", project).setOwaspTop10For2021(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
-      newDoc("toreviewhotspot1", project).setOwaspTop10For2021(asList("a1", "a3")).setCwe(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT)
+      newDocForProject("notowaspvul", project).setOwaspTop10For2021(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
+      newDocForProject("toreviewhotspot1", project).setOwaspTop10For2021(asList("a1", "a3")).setCwe(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT)
         .setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("toreviewhotspot2", project).setOwaspTop10For2021(asList("a3", "a6")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("reviewedHotspot", project).setOwaspTop10For2021(asList("a3", "a8")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
+      newDocForProject("toreviewhotspot2", project).setOwaspTop10For2021(asList("a3", "a6")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("reviewedHotspot", project).setOwaspTop10For2021(asList("a3", "a8")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
         .setResolution(Issue.RESOLUTION_FIXED),
-      newDoc("notowasphotspot", project).setOwaspTop10For2021(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
+      newDocForProject("notowasphotspot", project).setOwaspTop10For2021(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
 
     List<SecurityStandardCategoryStatistics> owaspTop10Report = underTest.getOwaspTop10Report(project.uuid(), false, includeCwe, Y2021);
     assertThat(owaspTop10Report)
@@ -476,19 +477,19 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
     ComponentDto project2 = db.components().insertPrivateProject();
 
     indexIssues(
-      newDoc("openvul1", project1).setPciDss32(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project1).setPciDss32(asList("1.2.0", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project2).setPciDss32(asList("3.3.2", "6.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project2).setPciDss32(asList("3.3.2", "6.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("openvul3", project1).setPciDss32(asList("10.1.2", "6.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul3", project1).setPciDss32(asList("10.1.2", "6.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("notpcidssvul", project1).setPciDss32(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
-      newDoc("toreviewhotspot1", project2).setPciDss32(asList("1.3.0", "3.3.2")).setType(RuleType.SECURITY_HOTSPOT)
+      newDocForProject("notpcidssvul", project1).setPciDss32(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
+      newDocForProject("toreviewhotspot1", project2).setPciDss32(asList("1.3.0", "3.3.2")).setType(RuleType.SECURITY_HOTSPOT)
         .setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("toreviewhotspot2", project1).setPciDss32(asList("3.5.6", "6.4.5")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("reviewedHotspot", project2).setPciDss32(asList("3.1.1", "8.6")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
+      newDocForProject("toreviewhotspot2", project1).setPciDss32(asList("3.5.6", "6.4.5")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("reviewedHotspot", project2).setPciDss32(asList("3.1.1", "8.6")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
         .setResolution(Issue.RESOLUTION_FIXED),
-      newDoc("notpcidsshotspot", project1).setPciDss32(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
+      newDocForProject("notpcidsshotspot", project1).setPciDss32(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
 
     indexView(portfolio1.uuid(), singletonList(project1.uuid()));
     indexView(portfolio2.uuid(), singletonList(project2.uuid()));
@@ -523,19 +524,19 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
     ComponentDto project2 = db.components().insertPrivateProject();
 
     indexIssues(
-      newDoc("openvul1", project1).setOwaspAsvs40(asList("2.1.1", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project1).setOwaspAsvs40(asList("2.1.1", "3.4.5")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project2).setOwaspAsvs40(asList("3.3.2", "6.2.1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project2).setOwaspAsvs40(asList("3.3.2", "6.2.1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("openvul3", project1).setOwaspAsvs40(asList("10.3.2", "6.2.1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul3", project1).setOwaspAsvs40(asList("10.3.2", "6.2.1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("notowaspasvsvul", project1).setOwaspAsvs40(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
-      newDoc("toreviewhotspot1", project2).setOwaspAsvs40(asList("2.1.3", "3.3.2")).setType(RuleType.SECURITY_HOTSPOT)
+      newDocForProject("notowaspasvsvul", project1).setOwaspAsvs40(singletonList(UNKNOWN_STANDARD)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL),
+      newDocForProject("toreviewhotspot1", project2).setOwaspAsvs40(asList("2.1.3", "3.3.2")).setType(RuleType.SECURITY_HOTSPOT)
         .setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("toreviewhotspot2", project1).setOwaspAsvs40(asList("3.4.4", "6.2.1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("reviewedHotspot", project2).setOwaspAsvs40(asList("3.1.1", "8.3.1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
+      newDocForProject("toreviewhotspot2", project1).setOwaspAsvs40(asList("3.4.4", "6.2.1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
+      newDocForProject("reviewedHotspot", project2).setOwaspAsvs40(asList("3.1.1", "8.3.1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED)
         .setResolution(Issue.RESOLUTION_FIXED),
-      newDoc("notowaspasvshotspot", project1).setOwaspAsvs40(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
+      newDocForProject("notowaspasvshotspot", project1).setOwaspAsvs40(singletonList(UNKNOWN_STANDARD)).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW));
 
     indexView(portfolio1.uuid(), singletonList(project1.uuid()));
     indexView(portfolio2.uuid(), singletonList(project2.uuid()));
@@ -568,16 +569,16 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
   public void getCWETop25Report_aggregation() {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
-      newDoc("openvul", project).setCwe(List.of("119")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul", project).setCwe(List.of("119")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("notopenvul", project).setCwe(List.of("119")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_CLOSED)
+      newDocForProject("notopenvul", project).setCwe(List.of("119")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_CLOSED)
         .setResolution(Issue.RESOLUTION_FIXED)
         .setSeverity(Severity.BLOCKER),
-      newDoc("toreviewhotspot", project).setCwe(List.of("89")).setType(RuleType.SECURITY_HOTSPOT)
+      newDocForProject("toreviewhotspot", project).setCwe(List.of("89")).setType(RuleType.SECURITY_HOTSPOT)
         .setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("only2020", project).setCwe(List.of("862")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("only2020", project).setCwe(List.of("862")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("unknown", project).setCwe(List.of("999")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("unknown", project).setCwe(List.of("999")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR));
 
     List<SecurityStandardCategoryStatistics> cweTop25Reports = underTest.getCweTop25Reports(project.uuid(), false);
@@ -651,15 +652,15 @@ public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
     ComponentDto project2 = db.components().insertPrivateProject();
 
     indexIssues(
-      newDoc("openvul1", project1).setCwe(List.of("119")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
+      newDocForProject("openvul1", project1).setCwe(List.of("119")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
         .setSeverity(Severity.MAJOR),
-      newDoc("openvul2", project2).setCwe(List.of("119")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("openvul2", project2).setCwe(List.of("119")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("toreviewhotspot", project1).setCwe(List.of("89")).setType(RuleType.SECURITY_HOTSPOT)
+      newDocForProject("toreviewhotspot", project1).setCwe(List.of("89")).setType(RuleType.SECURITY_HOTSPOT)
         .setStatus(Issue.STATUS_TO_REVIEW),
-      newDoc("only2020", project2).setCwe(List.of("862")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("only2020", project2).setCwe(List.of("862")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR),
-      newDoc("unknown", project2).setCwe(List.of("999")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
+      newDocForProject("unknown", project2).setCwe(List.of("999")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_REOPENED)
         .setSeverity(Severity.MINOR));
 
     indexView(application.uuid(), asList(project1.uuid(), project2.uuid()));
index ab729fc57df4ca273023ce6b9cf69fb89dc421f6..db984cdb381ee92a0978f498c66fd01ecbaa2c81 100644 (file)
@@ -39,9 +39,9 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setStatus(Issue.STATUS_OPEN),
-      newDoc("I2", file).setStatus(Issue.STATUS_CLOSED),
-      newDoc("I3", file).setStatus(Issue.STATUS_REOPENED));
+      newDoc("I1", project.uuid(), file).setStatus(Issue.STATUS_OPEN),
+      newDoc("I2", project.uuid(), file).setStatus(Issue.STATUS_CLOSED),
+      newDoc("I3", project.uuid(), file).setStatus(Issue.STATUS_REOPENED));
 
     IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_STATUS).asc(true);
     assertThatSearchReturnsOnly(query, "I2", "I1", "I3");
@@ -56,11 +56,11 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setSeverity(Severity.BLOCKER),
-      newDoc("I2", file).setSeverity(Severity.INFO),
-      newDoc("I3", file).setSeverity(Severity.MINOR),
-      newDoc("I4", file).setSeverity(Severity.CRITICAL),
-      newDoc("I5", file).setSeverity(Severity.MAJOR));
+      newDoc("I1", project.uuid(), file).setSeverity(Severity.BLOCKER),
+      newDoc("I2", project.uuid(), file).setSeverity(Severity.INFO),
+      newDoc("I3", project.uuid(), file).setSeverity(Severity.MINOR),
+      newDoc("I4", project.uuid(), file).setSeverity(Severity.CRITICAL),
+      newDoc("I5", project.uuid(), file).setSeverity(Severity.MAJOR));
 
     IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_SEVERITY).asc(true);
     assertThatSearchReturnsOnly(query, "I2", "I3", "I5", "I4", "I1");
@@ -75,8 +75,8 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
-      newDoc("I2", file).setFuncCreationDate(parseDateTime("2014-09-24T00:00:00+0100")));
+      newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+      newDoc("I2", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-24T00:00:00+0100")));
 
     IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_CREATION_DATE).asc(true);
     SearchResponse result = underTest.search(query.build(), new SearchOptions());
@@ -92,8 +92,8 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setFuncUpdateDate(parseDateTime("2014-09-23T00:00:00+0100")),
-      newDoc("I2", file).setFuncUpdateDate(parseDateTime("2014-09-24T00:00:00+0100")));
+      newDoc("I1", project.uuid(), file).setFuncUpdateDate(parseDateTime("2014-09-23T00:00:00+0100")),
+      newDoc("I2", project.uuid(), file).setFuncUpdateDate(parseDateTime("2014-09-24T00:00:00+0100")));
 
     IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_UPDATE_DATE).asc(true);
     SearchResponse result = underTest.search(query.build(), new SearchOptions());
@@ -109,9 +109,9 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
     ComponentDto file = newFileDto(project, null);
 
     indexIssues(
-      newDoc("I1", file).setFuncCloseDate(parseDateTime("2014-09-23T00:00:00+0100")),
-      newDoc("I2", file).setFuncCloseDate(parseDateTime("2014-09-24T00:00:00+0100")),
-      newDoc("I3", file).setFuncCloseDate(null));
+      newDoc("I1", project.uuid(), file).setFuncCloseDate(parseDateTime("2014-09-23T00:00:00+0100")),
+      newDoc("I2", project.uuid(), file).setFuncCloseDate(parseDateTime("2014-09-24T00:00:00+0100")),
+      newDoc("I3", project.uuid(), file).setFuncCloseDate(null));
 
     IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_CLOSE_DATE).asc(true);
     SearchResponse result = underTest.search(query.build(), new SearchOptions());
@@ -129,15 +129,15 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
 
     indexIssues(
       // file F1
-      newDoc("F1_2", file1).setLine(20),
-      newDoc("F1_1", file1).setLine(null),
-      newDoc("F1_3", file1).setLine(25),
+      newDoc("F1_2", project.uuid(), file1).setLine(20),
+      newDoc("F1_1", project.uuid(), file1).setLine(null),
+      newDoc("F1_3", project.uuid(), file1).setLine(25),
 
       // file F2
-      newDoc("F2_1", file2).setLine(9),
-      newDoc("F2_2", file2).setLine(109),
+      newDoc("F2_1", project.uuid(), file2).setLine(9),
+      newDoc("F2_2", project.uuid(), file2).setLine(109),
       // two issues on the same line -> sort by key
-      newDoc("F2_3", file2).setLine(109));
+      newDoc("F2_3", project.uuid(), file2).setLine(109));
 
     // ascending sort -> F1 then F2. Line "0" first.
     IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_FILE_LINE).asc(true);
@@ -159,19 +159,19 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
 
     indexIssues(
       // file F1 from project P1
-      newDoc("F1_1", file1).setLine(20).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
-      newDoc("F1_2", file1).setLine(null).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
-      newDoc("F1_3", file1).setLine(25).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+      newDoc("F1_1", project1.uuid(), file1).setLine(20).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+      newDoc("F1_2", project1.uuid(), file1).setLine(null).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+      newDoc("F1_3", project1.uuid(), file1).setLine(25).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
 
       // file F2 from project P1
-      newDoc("F2_1", file2).setLine(9).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
-      newDoc("F2_2", file2).setLine(109).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+      newDoc("F2_1", project1.uuid(), file2).setLine(9).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+      newDoc("F2_2", project1.uuid(), file2).setLine(109).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
       // two issues on the same line -> sort by key
-      newDoc("F2_3", file2).setLine(109).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+      newDoc("F2_3", project1.uuid(), file2).setLine(109).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
 
       // file F3 from project P2
-      newDoc("F3_1", file3).setLine(20).setFuncCreationDate(parseDateTime("2014-09-24T00:00:00+0100")),
-      newDoc("F3_2", file3).setLine(20).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")));
+      newDoc("F3_1", project2.uuid(), file3).setLine(20).setFuncCreationDate(parseDateTime("2014-09-24T00:00:00+0100")),
+      newDoc("F3_2", project2.uuid(), file3).setLine(20).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")));
 
     assertThatSearchReturnsOnly(IssueQuery.builder(), "F3_1", "F1_2", "F1_1", "F1_3", "F2_1", "F2_2", "F2_3", "F3_2");
   }
index 81e817f40eb97c316cce240f01efec58268f2120..bac4e99a5886230298fd815ccb348b4869d1a390 100644 (file)
@@ -46,6 +46,7 @@ import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 import static org.sonar.db.user.UserTesting.newUserDto;
 import static org.sonar.server.issue.IssueDocTesting.newDoc;
+import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
 
 public class IssueIndexTest extends IssueIndexTestCommon {
 
@@ -54,7 +55,7 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     ComponentDto file = newFileDto(project, null);
     for (int i = 0; i < 12; i++) {
-      indexIssues(newDoc("I" + i, file));
+      indexIssues(newDoc("I" + i, project.uuid(), file));
     }
 
     IssueQuery.Builder query = IssueQuery.builder();
@@ -79,9 +80,9 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     List<IssueDoc> issues = new ArrayList<>();
     for (int i = 0; i < 500; i++) {
       String key = "I" + i;
-      issues.add(newDoc(key, file));
+      issues.add(newDoc(key, project.uuid(), file));
     }
-    indexIssues(issues.toArray(new IssueDoc[] {}));
+    indexIssues(issues.toArray(new IssueDoc[]{}));
 
     IssueQuery.Builder query = IssueQuery.builder();
     SearchResponse result = underTest.search(query.build(), new SearchOptions().setLimit(500));
@@ -96,9 +97,9 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     List<IssueDoc> issues = new ArrayList<>();
     for (int i = 0; i < 11_000; i++) {
       String key = "I" + i;
-      issues.add(newDoc(key, file));
+      issues.add(newDoc(key, project.uuid(), file));
     }
-    indexIssues(issues.toArray(new IssueDoc[] {}));
+    indexIssues(issues.toArray(new IssueDoc[]{}));
 
     IssueQuery.Builder query = IssueQuery.builder();
     SearchResponse result = underTest.search(query.build(), new SearchOptions().setLimit(500));
@@ -115,9 +116,9 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     // we are adding issues in reverse order to see if the sort is actually doing anything
     for (int i = 9; i >= 1; i--) {
       String key = "I" + i;
-      issues.add(newDoc(key, file));
+      issues.add(newDoc(key, project.uuid(), file));
     }
-    indexIssues(issues.toArray(new IssueDoc[] {}));
+    indexIssues(issues.toArray(new IssueDoc[]{}));
     IssueQuery.Builder query = IssueQuery.builder().asc(true);
 
     SearchResponse result = underTest.search(query.sort(IssueQuery.SORT_BY_CREATION_DATE).build(), new SearchOptions());
@@ -136,9 +137,9 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     // we are adding issues in reverse order to see if the sort is actually doing anything
     for (int i = 9; i >= 1; i--) {
       String key = "I" + i;
-      issues.add(newDoc(key, file));
+      issues.add(newDoc(key, project.uuid(), file));
     }
-    indexIssues(issues.toArray(new IssueDoc[] {}));
+    indexIssues(issues.toArray(new IssueDoc[]{}));
     IssueQuery.Builder query = IssueQuery.builder().asc(true);
 
     SearchResponse result = underTest.search(query.sort(IssueQuery.SORT_BY_CREATION_DATE).build(), new SearchOptions());
@@ -166,13 +167,13 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     GroupDto group2 = newGroupDto();
 
     // project1 can be seen by group1
-    indexIssue(newDoc("I1", file1));
+    indexIssue(newDoc("I1", project1.uuid(), file1));
     authorizationIndexer.allowOnlyGroup(project1, group1);
     // project2 can be seen by group2
-    indexIssue(newDoc("I2", file2));
+    indexIssue(newDoc("I2", project2.uuid(), file2));
     authorizationIndexer.allowOnlyGroup(project2, group2);
     // project3 can be seen by nobody but root
-    indexIssue(newDoc("I3", file3));
+    indexIssue(newDoc("I3", project3.uuid(), file3));
 
     userSessionRule.logIn().setGroups(group1);
     assertThatSearchReturnsOnly(IssueQuery.builder(), "I1");
@@ -203,11 +204,11 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     UserDto user2 = newUserDto();
 
     // project1 can be seen by john, project2 by max, project3 cannot be seen by anyone
-    indexIssue(newDoc("I1", file1));
+    indexIssue(newDoc("I1", project1.uuid(), file1));
     authorizationIndexer.allowOnlyUser(project1, user1);
-    indexIssue(newDoc("I2", file2));
+    indexIssue(newDoc("I2", project2.uuid(), file2));
     authorizationIndexer.allowOnlyUser(project2, user2);
-    indexIssue(newDoc("I3", file3));
+    indexIssue(newDoc("I3", project3.uuid(), file3));
 
     userSessionRule.logIn(user1);
     assertThatSearchReturnsOnly(IssueQuery.builder(), "I1");
@@ -229,11 +230,11 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
     ComponentDto file = newFileDto(project, null);
     indexIssues(
-      newDoc("I42", file).setRuleUuid(r1.getUuid()).setTags(of("another")),
-      newDoc("I1", file).setRuleUuid(r1.getUuid()).setTags(of("convention", "java8", "bug")),
-      newDoc("I2", file).setRuleUuid(r1.getUuid()).setTags(of("convention", "bug")),
-      newDoc("I3", file).setRuleUuid(r2.getUuid()),
-      newDoc("I4", file).setRuleUuid(r1.getUuid()).setTags(of("convention")));
+      newDoc("I42", project.uuid(), file).setRuleUuid(r1.getUuid()).setTags(of("another")),
+      newDoc("I1", project.uuid(), file).setRuleUuid(r1.getUuid()).setTags(of("convention", "java8", "bug")),
+      newDoc("I2", project.uuid(), file).setRuleUuid(r1.getUuid()).setTags(of("convention", "bug")),
+      newDoc("I3", project.uuid(), file).setRuleUuid(r2.getUuid()),
+      newDoc("I4", project.uuid(), file).setRuleUuid(r1.getUuid()).setTags(of("convention")));
 
     assertThat(underTest.searchTags(IssueQuery.builder().build(), null, 100)).containsExactlyInAnyOrder("convention", "java8", "bug", "another");
     assertThat(underTest.searchTags(IssueQuery.builder().build(), null, 2)).containsOnly("another", "bug");
@@ -246,10 +247,10 @@ public class IssueIndexTest extends IssueIndexTestCommon {
   public void list_authors() {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
-      newDoc("issue1", project).setAuthorLogin("luke.skywalker"),
-      newDoc("issue2", project).setAuthorLogin("luke@skywalker.name"),
-      newDoc("issue3", project).setAuthorLogin(null),
-      newDoc("issue4", project).setAuthorLogin("anakin@skywalker.name"));
+      newDocForProject("issue1", project).setAuthorLogin("luke.skywalker"),
+      newDocForProject("issue2", project).setAuthorLogin("luke@skywalker.name"),
+      newDocForProject("issue3", project).setAuthorLogin(null),
+      newDocForProject("issue4", project).setAuthorLogin("anakin@skywalker.name"));
     IssueQuery query = IssueQuery.builder().build();
 
     assertThat(underTest.searchAuthors(query, null, 5)).containsExactly("anakin@skywalker.name", "luke.skywalker", "luke@skywalker.name");
@@ -263,7 +264,7 @@ public class IssueIndexTest extends IssueIndexTestCommon {
   public void list_authors_escapes_regexp_special_characters() {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
-      newDoc("issue1", project).setAuthorLogin("name++"));
+      newDocForProject("issue1", project).setAuthorLogin("name++"));
     IssueQuery query = IssueQuery.builder().build();
 
     assertThat(underTest.searchAuthors(query, "invalidRegexp[", 5)).isEmpty();
@@ -276,11 +277,11 @@ public class IssueIndexTest extends IssueIndexTestCommon {
   public void countTags() {
     ComponentDto project = newPrivateProjectDto();
     indexIssues(
-      newDoc("issue1", project).setTags(ImmutableSet.of("convention", "java8", "bug")),
-      newDoc("issue2", project).setTags(ImmutableSet.of("convention", "bug")),
-      newDoc("issue3", project).setTags(emptyList()),
-      newDoc("issue4", project).setTags(ImmutableSet.of("convention", "java8", "bug")).setResolution(Issue.RESOLUTION_FIXED),
-      newDoc("issue5", project).setTags(ImmutableSet.of("convention")));
+      newDocForProject("issue1", project).setTags(ImmutableSet.of("convention", "java8", "bug")),
+      newDocForProject("issue2", project).setTags(ImmutableSet.of("convention", "bug")),
+      newDocForProject("issue3", project).setTags(emptyList()),
+      newDocForProject("issue4", project).setTags(ImmutableSet.of("convention", "java8", "bug")).setResolution(Issue.RESOLUTION_FIXED),
+      newDocForProject("issue5", project).setTags(ImmutableSet.of("convention")));
 
     assertThat(underTest.countTags(projectQuery(project.uuid()), 5)).containsOnly(entry("convention", 3L), entry("bug", 2L), entry("java8", 1L));
     assertThat(underTest.countTags(projectQuery(project.uuid()), 2)).contains(entry("convention", 3L), entry("bug", 2L)).doesNotContainEntry("java8", 1L);
index 4b82e4402103d807a18802672e5652da77e9fc86..d284e60e318825b8048ea4d74d4858c09d56ae57 100644 (file)
@@ -97,7 +97,7 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer {
     }
 
     BranchDto branch = loadBranch(dbSession, branchComponent);
-    Configuration config = projectConfigurationLoader.loadProjectConfiguration(dbSession, branchComponent);
+    Configuration config = projectConfigurationLoader.loadProjectConfiguration(dbSession, branch);
     ProjectDto project = loadProject(dbSession, branch.getProjectUuid());
     QualityGate qualityGate = qGateComputer.loadQualityGate(dbSession, project, branch);
     MeasureMatrix matrix = loadMeasureMatrix(dbSession, components.getAllUuids(), qualityGate);
index a5ce4c1cc06ff7d199d602afe6b735f1711979fb..5332a5280e321014f95601ad64c18398ab63a712 100644 (file)
@@ -319,7 +319,7 @@ public class SetAction implements SettingsWsAction {
     if (componentKey == null) {
       return Optional.empty();
     }
-    return Optional.of(componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, request.getBranch(), request.getPullRequest()));
+    return Optional.of(componentFinder.getByKey(dbSession, componentKey));
   }
 
   private PropertyDto toProperty(SetRequest request, Optional<ComponentDto> component) {
@@ -353,7 +353,6 @@ public class SetAction implements SettingsWsAction {
 
   private static class SetRequest {
 
-    private String branch;
     private String pullRequest;
     private String component;
     private List<String> fieldValues;
@@ -361,26 +360,6 @@ public class SetAction implements SettingsWsAction {
     private String value;
     private List<String> values;
 
-    public SetRequest setBranch(@Nullable String branch) {
-      this.branch = branch;
-      return this;
-    }
-
-    @CheckForNull
-    public String getBranch() {
-      return branch;
-    }
-
-    public SetRequest setPullRequest(@Nullable String pullRequest) {
-      this.pullRequest = pullRequest;
-      return this;
-    }
-
-    @CheckForNull
-    public String getPullRequest() {
-      return pullRequest;
-    }
-
     public SetRequest setComponent(@Nullable String component) {
       this.component = component;
       return this;
index 9950d08ef7e56a04774ad142c8ff80abe3414708..36813971f4f0b738b967acddd411dc54ae876472 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.setting;
 
 import org.sonar.api.config.Configuration;
 import org.sonar.db.DbSession;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
 
 public class TestProjectConfigurationLoader implements ProjectConfigurationLoader {
@@ -32,7 +33,7 @@ public class TestProjectConfigurationLoader implements ProjectConfigurationLoade
   }
 
   @Override
-  public Configuration loadProjectConfiguration(DbSession dbSession, ComponentDto project) {
+  public Configuration loadProjectConfiguration(DbSession dbSession, BranchDto branch) {
     return config;
   }
 }