@DataProvider
public static Object[][] nullOrEmpty() {
- return new Object[][] {
+ return new Object[][]{
{null},
{""}
};
public static Object[][] oldAndNewValuesCombinations() {
String value1 = randomAlphabetic(10);
String value2 = randomAlphabetic(20);
- return new Object[][] {
+ return new Object[][]{
{null, value1},
{"", value1},
{value1, null},
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
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()));
}
assertThat(underTest.selectProjectUuidsWithIssuesNeedSync(db.getSession(),
Sets.newHashSet(project1Dto.getUuid(), project2Dto.getUuid(), project3Dto.getUuid(), project4Dto.getUuid())))
- .containsOnly(project1.uuid());
+ .containsOnly(project1.uuid());
}
@Test
@DataProvider
public static Object[][] booleanValues() {
- return new Object[][] {
+ return new Object[][]{
{true},
{false}
};
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();
+ }
}
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();
}
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;
short doAnyOfComponentsNeedIssueSync(@Param("componentKeys") List<String> components);
+ Optional<BranchDto> selectMainBranchByProjectUuid(String projectUuid);
}
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,
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;
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);
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);
*/
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;
@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;
}
+
}
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 {
* <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);
}
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 {
}
@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) {
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)));
}
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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 {
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));
}
@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);
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));
}
@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);
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));
}
@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);
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),
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),
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),
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),
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),
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),
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),
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),
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),
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));
}
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);
}
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));
}
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);
}
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));
}
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);
}
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));
}
@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);
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));
}
@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);
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));
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));
}
@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);
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);
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 {
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");
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")));
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");
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");
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");
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()));
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());
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());
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());
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");
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());
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());
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());
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),
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),
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
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);
@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
@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);
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");
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");
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");
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");
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")));
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")));
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");
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");
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");
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
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
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")),
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");
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")));
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");
}
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");
}
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");
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");
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));
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");
}
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");
}
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");
}
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 {
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);
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);
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);
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);
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);
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);
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);
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);
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()),
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()),
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);
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 {
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)
);
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)
);
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)
);
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)
);
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)
);
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");
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");
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));
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 {
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);
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);
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)
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)
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);
.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),
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)
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())))
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),
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)
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()));
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()));
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);
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()));
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");
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");
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());
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());
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());
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);
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");
}
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 {
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();
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));
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));
// 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());
// 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());
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");
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");
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");
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");
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();
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);
}
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);
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) {
private static class SetRequest {
- private String branch;
private String pullRequest;
private String component;
private List<String> fieldValues;
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;
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 {
}
@Override
- public Configuration loadProjectConfiguration(DbSession dbSession, ComponentDto project) {
+ public Configuration loadProjectConfiguration(DbSession dbSession, BranchDto branch) {
return config;
}
}