* Inserts an issue or a security hotspot.
*/
@SafeVarargs
- public final IssueDto insert(OrganizationDto organizationDto, Consumer<IssueDto>... populators) {
+ public final IssueDto insert(Consumer<IssueDto>... populators) {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPublicProject(organizationDto);
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = newIssue(rule, project, file);
stream(populators).forEach(p -> p.accept(issue));
private Boolean onComponentOnly;
private String branch;
private String pullRequest;
- private String organization;
private int page;
private int pageSize;
private List<String> projects;
return this;
}
- @CheckForNull
- public String getOrganization() {
- return organization;
- }
-
- public SearchRequest setOrganization(@Nullable String s) {
- this.organization = s;
- return this;
- }
-
public int getPage() {
return page;
}
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_DIRECTORY_PATH);
}
- @CheckForNull
- public String organizationUuid() {
- return getNullableField(IssueIndexDefinition.FIELD_ISSUE_ORGANIZATION_UUID);
- }
-
public IssueDoc setKey(@Nullable String s) {
setField(IssueIndexDefinition.FIELD_ISSUE_KEY, s);
return this;
return this;
}
- public IssueDoc setOrganizationUuid(String s) {
- setField(IssueIndexDefinition.FIELD_ISSUE_ORGANIZATION_UUID, s);
- return this;
- }
-
@CheckForNull
public Collection<String> getOwaspTop10() {
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_OWASP_TOP_10);
public static final String FIELD_ISSUE_LINE = "line";
public static final String FIELD_ISSUE_MODULE_UUID = "module";
public static final String FIELD_ISSUE_MODULE_PATH = "modulePath";
- public static final String FIELD_ISSUE_ORGANIZATION_UUID = "organization";
/**
* The (real) project, equivalent of projects.main_branch_project_uuid | projects.project_uuid, so
mapping.createIntegerField(FIELD_ISSUE_LINE);
mapping.keywordFieldBuilder(FIELD_ISSUE_MODULE_UUID).disableNorms().build();
mapping.createUuidPathField(FIELD_ISSUE_MODULE_PATH);
- mapping.keywordFieldBuilder(FIELD_ISSUE_ORGANIZATION_UUID).disableNorms().build();
mapping.keywordFieldBuilder(FIELD_ISSUE_PROJECT_UUID).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
mapping.keywordFieldBuilder(FIELD_ISSUE_BRANCH_UUID).disableNorms().build();
mapping.createBooleanField(FIELD_ISSUE_IS_MAIN_BRANCH);
"c.module_uuid_path",
"c.path",
"c.scope",
- "c.organization_uuid",
"c.project_uuid",
"c.main_branch_project_uuid",
String filePath = extractFilePath(rs.getString(16), scope);
doc.setFilePath(filePath);
doc.setDirectoryPath(extractDirPath(doc.filePath(), scope));
- doc.setOrganizationUuid(rs.getString(18));
- String branchUuid = rs.getString(19);
- String mainBranchProjectUuid = DatabaseUtils.getString(rs, 20);
+ String branchUuid = rs.getString(18);
+ String mainBranchProjectUuid = DatabaseUtils.getString(rs, 19);
doc.setBranchUuid(branchUuid);
if (mainBranchProjectUuid == null) {
doc.setProjectUuid(branchUuid);
doc.setProjectUuid(mainBranchProjectUuid);
doc.setIsMainBranch(false);
}
- String tags = rs.getString(21);
+ String tags = rs.getString(20);
doc.setTags(IssueIteratorForSingleChunk.TAGS_SPLITTER.splitToList(tags == null ? "" : tags));
- doc.setType(RuleType.valueOf(rs.getInt(22)));
+ doc.setType(RuleType.valueOf(rs.getInt(21)));
- SecurityStandards securityStandards = fromSecurityStandards(deserializeSecurityStandardsString(rs.getString(23)));
+ SecurityStandards securityStandards = fromSecurityStandards(deserializeSecurityStandardsString(rs.getString(22)));
SecurityStandards.SQCategory sqCategory = securityStandards.getSqCategory();
doc.setOwaspTop10(securityStandards.getOwaspTop10());
doc.setCwe(securityStandards.getCwe());
doc.setSonarSourceSecurityCategory(sqCategory);
doc.setVulnerabilityProbability(sqCategory.getVulnerability());
- doc.setScope(Qualifiers.UNIT_TEST_FILE.equals(rs.getString(24)) ? IssueScope.TEST : IssueScope.MAIN);
+ doc.setScope(Qualifiers.UNIT_TEST_FILE.equals(rs.getString(23)) ? IssueScope.TEST : IssueScope.MAIN);
return doc;
}
.setScopes(asList("MAIN", "TEST"))
.setLanguages(singletonList("xoo"))
.setTags(asList("tag1", "tag2"))
- .setOrganization("org-a")
.setAssigned(true)
.setCreatedAfter("2013-04-16T09:08:24+0200")
.setCreatedBefore("2013-04-17T09:08:24+0200")
assertThat(underTest.getScopes()).containsExactly("MAIN", "TEST");
assertThat(underTest.getLanguages()).containsExactly("xoo");
assertThat(underTest.getTags()).containsExactly("tag1", "tag2");
- assertThat(underTest.getOrganization()).isEqualTo("org-a");
assertThat(underTest.getAssigned()).isTrue();
assertThat(underTest.getCreatedAfter()).isEqualTo("2013-04-16T09:08:24+0200");
assertThat(underTest.getCreatedBefore()).isEqualTo("2013-04-17T09:08:24+0200");
import java.util.stream.Collectors;
import org.assertj.core.api.Assertions;
import org.elasticsearch.search.SearchHit;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.es.EsQueueDto;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.IssueTesting;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.IndexingResult;
@Rule
public LogTester logTester = new LogTester();
- private OrganizationDto organization;
- private IssueIndexer underTest = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null);
-
- @Before
- public void setUp() {
- organization = db.organizations().insert();
- }
+ private final IssueIndexer underTest = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null);
@Test
public void test_getIndexTypes() {
@Test
public void indexOnStartup_scrolls_db_and_adds_all_issues_to_index() {
- IssueDto issue1 = db.issues().insert(organization);
- IssueDto issue2 = db.issues().insert(organization);
+ IssueDto issue1 = db.issues().insert();
+ IssueDto issue2 = db.issues().insert();
underTest.indexAllIssues();
@Test
public void verify_indexed_fields() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo"));
ComponentDto file = db.components().insertComponent(newFileDto(project, dir, "F1"));
IssueDto issue = db.issues().insert(rule, project, file);
IssueDoc doc = es.getDocuments(TYPE_ISSUE, IssueDoc.class).get(0);
assertThat(doc.getId()).isEqualTo(issue.getKey());
- assertThat(doc.organizationUuid()).isEqualTo(organization.getUuid());
assertThat(doc.assigneeUuid()).isEqualTo(issue.getAssigneeUuid());
assertThat(doc.authorLogin()).isEqualTo(issue.getAuthorLogin());
assertThat(doc.componentUuid()).isEqualTo(file.uuid());
@Test
public void verify_security_standards_indexation() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setSecurityStandards(new HashSet<>(Arrays.asList("cwe:123", "owaspTop10:a3", "cwe:863"))));
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo"));
ComponentDto file = db.components().insertComponent(newFileDto(project, dir, "F1"));
IssueDto issue = db.issues().insert(rule, project, file);
@Test
public void indexOnStartup_does_not_fail_on_errors_and_does_enable_recovery_mode() {
es.lockWrites(TYPE_ISSUE);
- db.issues().insert(organization);
+ db.issues().insert();
try {
// FIXME : test also message
@Test
public void indexOnAnalysis_indexes_the_issues_of_project() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = db.issues().insert(rule, project, file);
- ComponentDto otherProject = db.components().insertPrivateProject(organization);
+ ComponentDto otherProject = db.components().insertPrivateProject();
ComponentDto fileOnOtherProject = db.components().insertComponent(newFileDto(otherProject));
underTest.indexOnAnalysis(project.uuid());
@Test
public void indexOnAnalysis_does_not_delete_orphan_docs() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = db.issues().insert(rule, project, file);
@Test
public void indexOnAnalysis_does_not_fail_on_errors_and_does_not_enable_recovery_mode() {
es.lockWrites(TYPE_ISSUE);
- IssueDto issue = db.issues().insert(organization);
+ IssueDto issue = db.issues().insert();
try {
// FIXME : test also message
// it's impossible to already have an issue on a project
// that is being created, but it's just to verify that
// indexing is disabled
- IssueDto issue = db.issues().insert(organization);
+ IssueDto issue = db.issues().insert();
IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_CREATION);
assertThat(result.getTotal()).isEqualTo(0L);
@Test
public void index_is_not_updated_when_updating_project_key() {
// issue is inserted to verify that indexing of project is not triggered
- IssueDto issue = db.issues().insert(organization);
+ IssueDto issue = db.issues().insert();
IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE);
assertThat(result.getTotal()).isEqualTo(0L);
@Test
public void index_is_not_updated_when_updating_tags() {
// issue is inserted to verify that indexing of project is not triggered
- IssueDto issue = db.issues().insert(organization);
+ IssueDto issue = db.issues().insert();
IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_TAGS_UPDATE);
assertThat(result.getTotal()).isEqualTo(0L);
@Test
public void commitAndIndexIssues_commits_db_transaction_and_adds_issues_to_index() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
// insert issues in db without committing
public void commitAndIndexIssues_removes_issue_from_index_if_it_does_not_exist_in_db() {
IssueDto issue1 = new IssueDto().setKee("I1").setProjectUuid("P1");
addIssueToIndex(issue1.getProjectUuid(), issue1.getKey());
- IssueDto issue2 = db.issues().insert(organization);
+ IssueDto issue2 = db.issues().insert();
underTest.commitAndIndexIssues(db.getSession(), asList(issue1, issue2));
@Test
public void indexing_errors_during_commitAndIndexIssues_are_recovered() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
// insert issues in db without committing
@Test
public void indexing_recovers_multiple_errors_on_the_same_issue() {
es.lockWrites(TYPE_ISSUE);
- IssueDto issue = db.issues().insert(organization);
+ IssueDto issue = db.issues().insert();
// three changes on the same issue
- underTest.commitAndIndexIssues(db.getSession(), asList(issue));
- underTest.commitAndIndexIssues(db.getSession(), asList(issue));
- underTest.commitAndIndexIssues(db.getSession(), asList(issue));
+ underTest.commitAndIndexIssues(db.getSession(), singletonList(issue));
+ underTest.commitAndIndexIssues(db.getSession(), singletonList(issue));
+ underTest.commitAndIndexIssues(db.getSession(), singletonList(issue));
assertThatIndexHasSize(0);
// three attempts of indexing are stored in es_queue recovery table
@Test
public void indexing_recovers_multiple_errors_on_the_same_project() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue1 = db.issues().insert(rule, project, file);
IssueDto issue2 = db.issues().insert(rule, project, file);
issueDoc.setKey("key");
issueDoc.setProjectUuid("parent-does-not-exist");
new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null)
- .index(asList(issueDoc).iterator());
+ .index(singletonList(issueDoc).iterator());
assertThat(es.countDocuments(TYPE_ISSUE)).isEqualTo(1L);
}
@Test
public void index_issue_in_non_main_branch() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo"));
ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(branch, "src/main/java/foo"));
ComponentDto file = db.components().insertComponent(newFileDto(branch, dir, "F1"));
IssueDoc doc = es.getDocuments(TYPE_ISSUE, IssueDoc.class).get(0);
assertThat(doc.getId()).isEqualTo(issue.getKey());
- assertThat(doc.organizationUuid()).isEqualTo(organization.getUuid());
assertThat(doc.componentUuid()).isEqualTo(file.uuid());
assertThat(doc.projectUuid()).isEqualTo(branch.getMainBranchProjectUuid());
assertThat(doc.branchUuid()).isEqualTo(branch.uuid());
@Test
public void issue_on_test_file_has_test_scope() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo"));
ComponentDto file = db.components().insertComponent(newFileDto(project, dir, "F1").setQualifier("UTS"));
IssueDto issue = db.issues().insert(rule, project, file);
IssueDoc doc = es.getDocuments(TYPE_ISSUE, IssueDoc.class).get(0);
assertThat(doc.getId()).isEqualTo(issue.getKey());
- assertThat(doc.organizationUuid()).isEqualTo(organization.getUuid());
assertThat(doc.componentUuid()).isEqualTo(file.uuid());
assertThat(doc.scope()).isEqualTo(IssueScope.TEST);
}
@Test
public void issue_on_directory_has_main_code_scope() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo"));
IssueDto issue = db.issues().insert(rule, project, dir);
IssueDoc doc = es.getDocuments(TYPE_ISSUE, IssueDoc.class).get(0);
assertThat(doc.getId()).isEqualTo(issue.getKey());
- assertThat(doc.organizationUuid()).isEqualTo(organization.getUuid());
assertThat(doc.componentUuid()).isEqualTo(dir.uuid());
assertThat(doc.scope()).isEqualTo(IssueScope.MAIN);
}
@Test
public void issue_on_project_has_main_code_scope() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
IssueDto issue = db.issues().insert(rule, project, project);
underTest.indexAllIssues();
IssueDoc doc = es.getDocuments(TYPE_ISSUE, IssueDoc.class).get(0);
assertThat(doc.getId()).isEqualTo(issue.getKey());
- assertThat(doc.organizationUuid()).isEqualTo(organization.getUuid());
assertThat(doc.componentUuid()).isEqualTo(project.uuid());
assertThat(doc.scope()).isEqualTo(IssueScope.MAIN);
}
.setModuleUuid(!componentDto.scope().equals(Scopes.PROJECT) ? componentDto.moduleUuid() : componentDto.uuid())
.setModuleUuidPath(componentDto.moduleUuidPath())
.setProjectUuid(mainBranchProjectUuid == null ? componentDto.projectUuid() : mainBranchProjectUuid)
- .setOrganizationUuid(componentDto.getOrganizationUuid())
// File path make no sens on modules and projects
.setFilePath(!componentDto.scope().equals(Scopes.PROJECT) ? componentDto.path() : null)
.setIsMainBranch(mainBranchProjectUuid == null);
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_LINE;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_MODULE_UUID;
-import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_ORGANIZATION_UUID;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_OWASP_TOP_10;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_RESOLUTION;
FIELD_ISSUE_RULE_UUID,
query.rules().stream().map(RuleDefinitionDto::getUuid).collect(toList())));
filters.addFilter(FIELD_ISSUE_STATUS, STATUSES.getFilterScope(), createTermsFilter(FIELD_ISSUE_STATUS, query.statuses()));
- filters.addFilter(
- FIELD_ISSUE_ORGANIZATION_UUID, new SimpleFieldFilterScope(FIELD_ISSUE_ORGANIZATION_UUID),
- createTermFilter(FIELD_ISSUE_ORGANIZATION_UUID, query.organizationUuid()));
// security category
addSecurityCategoryFilter(FIELD_ISSUE_OWASP_TOP_10, OWASP_TOP_10, query.owaspTop10(), filters);
private final String sort;
private final Boolean asc;
private final String facetMode;
- private final String organizationUuid;
private final String branchUuid;
private final boolean mainBranch;
private final ZoneId timeZone;
this.sort = builder.sort;
this.asc = builder.asc;
this.facetMode = builder.facetMode;
- this.organizationUuid = builder.organizationUuid;
this.branchUuid = builder.branchUuid;
this.mainBranch = builder.mainBranch;
this.timeZone = builder.timeZone;
return asc;
}
- @CheckForNull
- public String organizationUuid() {
- return organizationUuid;
- }
-
@CheckForNull
public String branchUuid() {
return branchUuid;
private String sort;
private Boolean asc = false;
private String facetMode;
- private String organizationUuid;
private String branchUuid;
private boolean mainBranch = true;
private ZoneId timeZone;
return this;
}
- public Builder organizationUuid(String s) {
- this.organizationUuid = s;
- return this;
- }
-
public Builder branchUuid(@Nullable String s) {
this.branchUuid = s;
return this;
.createdAt(parseStartingDateOrDateTime(request.getCreatedAt(), timeZone))
.createdBefore(parseEndingDateOrDateTime(request.getCreatedBefore(), timeZone))
.facetMode(request.getFacetMode())
- .organizationUuid(convertOrganizationKeyToUuid(dbSession, request.getOrganization()))
.timeZone(timeZone);
List<ComponentDto> allComponents = new ArrayList<>();
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchOptions;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
import static org.sonar.db.rule.RuleTesting.newRule;
import static org.sonar.server.issue.IssueDocTesting.newDoc;
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Rule
public ExpectedException expectedException = none();
- private System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(getTimeZone("GMT-01:00"));
+ private final System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(getTimeZone("GMT-01:00"));
@Rule
public DbTester db = DbTester.create(system2);
- private IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null);
- private ViewIndexer viewIndexer = new ViewIndexer(db.getDbClient(), es.client());
- private PermissionIndexerTester authorizationIndexer = new PermissionIndexerTester(es, issueIndexer);
-
- private IssueIndex underTest = new IssueIndex(es.client(), system2, userSessionRule, new WebAuthorizationTypeSupport(userSessionRule));
+ private final IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null);
+ private final ViewIndexer viewIndexer = new ViewIndexer(db.getDbClient(), es.client());
+ private final PermissionIndexerTester authorizationIndexer = new PermissionIndexerTester(es, issueIndexer);
+ private final IssueIndex underTest = new IssueIndex(es.client(), system2, userSessionRule, new WebAuthorizationTypeSupport(userSessionRule));
@Test
public void filter_by_keys() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
indexIssues(
newDoc("I1", newFileDto(project, null)),
@Test
public void filter_by_projects() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto module = newModuleDto(project);
ComponentDto subModule = newModuleDto(module);
@Test
public void filter_by_modules() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto module = newModuleDto(project);
ComponentDto subModule = newModuleDto(module);
ComponentDto file = newFileDto(subModule, null);
@Test
public void filter_by_components_on_contextualized_search() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto module = newModuleDto(project);
ComponentDto subModule = newModuleDto(module);
ComponentDto file1 = newFileDto(project, null);
ComponentDto file2 = newFileDto(module, null);
ComponentDto file3 = newFileDto(subModule, null);
String view = "ABCD";
- indexView(view, asList(project.uuid()));
+ indexView(view, singletonList(project.uuid()));
indexIssues(
newDoc("I1", project),
@Test
public void filter_by_components_on_non_contextualized_search() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto(), "project");
+ ComponentDto project = newPrivateProjectDto("project");
ComponentDto file1 = newFileDto(project, null, "file1");
ComponentDto module = newModuleDto(project).setUuid("module");
ComponentDto file2 = newFileDto(module, null, "file2");
ComponentDto subModule = newModuleDto(module).setUuid("subModule");
ComponentDto file3 = newFileDto(subModule, null, "file3");
String view = "ABCD";
- indexView(view, asList(project.uuid()));
+ indexView(view, singletonList(project.uuid()));
indexIssues(
newDoc("I1", project),
@Test
public void filter_by_directories() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file1 = newFileDto(project, null).setPath("src/main/xoo/F1.xoo");
ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo");
@Test
public void filter_by_portfolios() {
- ComponentDto portfolio1 = db.components().insertPrivateApplication(db.getDefaultOrganization());
- ComponentDto portfolio2 = db.components().insertPrivateApplication(db.getDefaultOrganization());
+ ComponentDto portfolio1 = db.components().insertPrivateApplication();
+ ComponentDto portfolio2 = db.components().insertPrivateApplication();
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project1));
ComponentDto project2 = db.components().insertPrivateProject();
@Test
public void filter_by_portfolios_not_having_projects() {
- OrganizationDto organizationDto = newOrganizationDto();
- ComponentDto project1 = newPrivateProjectDto(organizationDto);
+ ComponentDto project1 = newPrivateProjectDto();
ComponentDto file1 = newFileDto(project1, null);
indexIssues(newDoc("I2", file1));
String view1 = "ABCD";
@Test
public void do_not_return_issues_from_project_branch_when_filtering_by_portfolios() {
- ComponentDto portfolio = db.components().insertPrivateApplication(db.getDefaultOrganization());
+ ComponentDto portfolio = db.components().insertPrivateApplication();
ComponentDto project = db.components().insertPublicProject();
ComponentDto projectBranch = db.components().insertProjectBranch(project);
ComponentDto fileOnProjectBranch = db.components().insertComponent(newFileDto(projectBranch));
@Test
public void filter_by_main_application() {
- ComponentDto application1 = db.components().insertPrivateApplication(db.getDefaultOrganization());
- ComponentDto application2 = db.components().insertPrivateApplication(db.getDefaultOrganization());
+ ComponentDto application1 = db.components().insertPrivateApplication();
+ ComponentDto application2 = db.components().insertPrivateApplication();
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project1));
ComponentDto project2 = db.components().insertPrivateProject();
@Test
public void filter_by_created_after_by_projects() {
Date now = new Date();
- OrganizationDto organizationDto = newOrganizationDto();
- ComponentDto project1 = newPrivateProjectDto(organizationDto);
+ ComponentDto project1 = newPrivateProjectDto();
IssueDoc project1Issue1 = newDoc(project1).setFuncCreationDate(addDays(now, -10));
IssueDoc project1Issue2 = newDoc(project1).setFuncCreationDate(addDays(now, -20));
- ComponentDto project2 = newPrivateProjectDto(organizationDto);
+ ComponentDto project2 = newPrivateProjectDto();
IssueDoc project2Issue1 = newDoc(project2).setFuncCreationDate(addDays(now, -15));
IssueDoc project2Issue2 = newDoc(project2).setFuncCreationDate(addDays(now, -30));
indexIssues(project1Issue1, project1Issue2, project2Issue1, project2Issue2);
@Test
public void filter_by_created_after_by_project_branches() {
Date now = new Date();
- OrganizationDto organizationDto = newOrganizationDto();
- ComponentDto project1 = newPrivateProjectDto(organizationDto);
+ ComponentDto project1 = newPrivateProjectDto();
IssueDoc project1Issue1 = newDoc(project1).setFuncCreationDate(addDays(now, -10));
IssueDoc project1Issue2 = newDoc(project1).setFuncCreationDate(addDays(now, -20));
IssueDoc project1Branch1Issue1 = newDoc(project1Branch1).setFuncCreationDate(addDays(now, -10));
IssueDoc project1Branch1Issue2 = newDoc(project1Branch1).setFuncCreationDate(addDays(now, -20));
- ComponentDto project2 = newPrivateProjectDto(organizationDto);
+ ComponentDto project2 = newPrivateProjectDto();
IssueDoc project2Issue1 = newDoc(project2).setFuncCreationDate(addDays(now, -15));
IssueDoc project2Issue2 = newDoc(project2).setFuncCreationDate(addDays(now, -30));
@Test
public void filter_by_severities() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_statuses() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_resolutions() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_resolved() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_rules() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
RuleDefinitionDto ruleDefinitionDto = newRule();
db.rules().insert(ruleDefinitionDto);
@Test
public void filter_by_languages() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
RuleDefinitionDto ruleDefinitionDto = newRule();
db.rules().insert(ruleDefinitionDto);
@Test
public void filter_by_assignees() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_assigned() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_authors() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_created_after() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_created_before() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_created_after_and_before() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_created_after_and_before_take_into_account_timezone() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_created_at() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(newDoc("I1", file).setFuncCreationDate(parseDate("2014-09-20")));
assertThatSearchReturnsEmpty(IssueQuery.builder().createdAt(parseDate("2014-09-21")));
}
- @Test
- public void filter_by_organization() {
- OrganizationDto org1 = newOrganizationDto();
- ComponentDto projectInOrg1 = newPrivateProjectDto(org1);
- OrganizationDto org2 = newOrganizationDto();
- ComponentDto projectInOrg2 = newPrivateProjectDto(org2);
-
- indexIssues(newDoc("issueInOrg1", projectInOrg1), newDoc("issue1InOrg2", projectInOrg2), newDoc("issue2InOrg2", projectInOrg2));
-
- verifyOrganizationFilter(org1.getUuid(), "issueInOrg1");
- verifyOrganizationFilter(org2.getUuid(), "issue1InOrg2", "issue2InOrg2");
- verifyOrganizationFilter("does_not_exist");
- }
-
- @Test
- public void filter_by_organization_and_project() {
- OrganizationDto org1 = newOrganizationDto();
- ComponentDto projectInOrg1 = newPrivateProjectDto(org1);
- OrganizationDto org2 = newOrganizationDto();
- ComponentDto projectInOrg2 = newPrivateProjectDto(org2);
-
- indexIssues(newDoc("issueInOrg1", projectInOrg1), newDoc("issue1InOrg2", projectInOrg2), newDoc("issue2InOrg2", projectInOrg2));
-
- // no conflict
- IssueQuery.Builder query = IssueQuery.builder().organizationUuid(org1.getUuid()).projectUuids(singletonList(projectInOrg1.uuid()));
- assertThatSearchReturnsOnly(query, "issueInOrg1");
-
- // conflict
- query = IssueQuery.builder().organizationUuid(org1.getUuid()).projectUuids(singletonList(projectInOrg2.uuid()));
- assertThatSearchReturnsEmpty(query);
- }
-
@Test
public void filter_by_cwe() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
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("I2", file).setType(RuleType.VULNERABILITY).setCwe(singletonList("943")),
newDoc("I3", file));
- assertThatSearchReturnsOnly(IssueQuery.builder().cwe(asList("20")), "I1");
+ assertThatSearchReturnsOnly(IssueQuery.builder().cwe(singletonList("20")), "I1");
}
@Test
public void filter_by_owaspTop10() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
newDoc("I2", file).setType(RuleType.VULNERABILITY).setCwe(singletonList("a3")),
newDoc("I3", file));
- assertThatSearchReturnsOnly(IssueQuery.builder().owaspTop10(asList("a1")), "I1");
+ assertThatSearchReturnsOnly(IssueQuery.builder().owaspTop10(singletonList("a1")), "I1");
}
@Test
public void filter_by_sansTop25() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
newDoc("I2", file).setType(RuleType.VULNERABILITY).setSansTop25(singletonList("porous-defenses")),
newDoc("I3", file));
- assertThatSearchReturnsOnly(IssueQuery.builder().sansTop25(asList("risky-resource")), "I1");
+ assertThatSearchReturnsOnly(IssueQuery.builder().sansTop25(singletonList("risky-resource")), "I1");
}
@Test
public void filter_by_sonarSecurity() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
assertThatSearchReturnsOnly(IssueQuery.builder().sonarsourceSecurity(singletonList("buffer-overflow")), "I1");
}
- private void verifyOrganizationFilter(String organizationUuid, String... expectedIssueKeys) {
- IssueQuery.Builder query = IssueQuery.builder().organizationUuid(organizationUuid);
- assertThatSearchReturnsOnly(query, expectedIssueKeys);
- }
-
private void indexIssues(IssueDoc... issues) {
issueIndexer.index(asList(issues).iterator());
authorizationIndexer.allow(stream(issues).map(issue -> new IndexPermissions(issue.projectUuid(), PROJECT).allowAnyone()).collect(toList()));
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.tuple;
import static org.junit.rules.ExpectedException.none;
+import static org.mockito.Mockito.mock;
import static org.sonar.api.issue.Issue.RESOLUTION_FIXED;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.rules.RuleType.BUG;
import static org.sonar.api.rules.RuleType.VULNERABILITY;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
import static org.sonar.db.user.GroupTesting.newGroupDto;
import static org.sonar.db.user.UserTesting.newUserDto;
import static org.sonar.server.issue.IssueDocTesting.newDoc;
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Rule
public ExpectedException expectedException = none();
- private System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(getTimeZone("GMT-01:00"));
+ private final System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(getTimeZone("GMT-01:00"));
@Rule
public DbTester db = DbTester.create(system2);
- private IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null);
- private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
- private PermissionIndexerTester authorizationIndexer = new PermissionIndexerTester(es, issueIndexer);
+ private final AsyncIssueIndexing asyncIssueIndexing = mock(AsyncIssueIndexing.class);
+ private final IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), asyncIssueIndexing);
+ private final RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
+ private final PermissionIndexerTester authorizationIndexer = new PermissionIndexerTester(es, issueIndexer);
- private IssueIndex underTest = new IssueIndex(es.client(), system2, userSessionRule, new WebAuthorizationTypeSupport(userSessionRule));
+ private final IssueIndex underTest = new IssueIndex(es.client(), system2, userSessionRule, new WebAuthorizationTypeSupport(userSessionRule));
@Test
public void paging() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
for (int i = 0; i < 12; i++) {
indexIssues(newDoc("I" + i, file));
@Test
public void search_with_max_limit() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
List<IssueDoc> issues = new ArrayList<>();
for (int i = 0; i < 500; i++) {
// SONAR-14224
@Test
public void search_exceeding_default_index_max_window() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
List<IssueDoc> issues = new ArrayList<>();
for (int i = 0; i < 11_000; i++) {
@Test
public void authorized_issues_on_groups() {
- OrganizationDto org = newOrganizationDto();
- ComponentDto project1 = newPrivateProjectDto(org);
- ComponentDto project2 = newPrivateProjectDto(org);
- ComponentDto project3 = newPrivateProjectDto(org);
+ ComponentDto project1 = newPrivateProjectDto();
+ ComponentDto project2 = newPrivateProjectDto();
+ ComponentDto project3 = newPrivateProjectDto();
ComponentDto file1 = newFileDto(project1, null);
ComponentDto file2 = newFileDto(project2, null);
ComponentDto file3 = newFileDto(project3, null);
@Test
public void authorized_issues_on_user() {
- OrganizationDto org = newOrganizationDto();
- ComponentDto project1 = newPrivateProjectDto(org);
- ComponentDto project2 = newPrivateProjectDto(org);
- ComponentDto project3 = newPrivateProjectDto(org);
+ ComponentDto project1 = newPrivateProjectDto();
+ ComponentDto project2 = newPrivateProjectDto();
+ ComponentDto project3 = newPrivateProjectDto();
ComponentDto file1 = newFileDto(project1, null);
ComponentDto file2 = newFileDto(project2, null);
ComponentDto file3 = newFileDto(project3, null);
userSessionRule.logIn(user1);
assertThatSearchReturnsOnly(IssueQuery.builder(), "I1");
- assertThatSearchReturnsEmpty(IssueQuery.builder().projectUuids(asList(project3.getDbKey())));
+ assertThatSearchReturnsEmpty(IssueQuery.builder().projectUuids(singletonList(project3.getDbKey())));
userSessionRule.logIn(user2);
assertThatSearchReturnsOnly(IssueQuery.builder(), "I2");
@Test
public void root_user_is_authorized_to_access_all_issues() {
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
indexIssue(newDoc("I1", project));
userSessionRule.logIn().setRoot();
RuleDefinitionDto r1 = db.rules().insert();
RuleDefinitionDto r2 = db.rules().insert();
ruleIndexer.commitAndIndex(db.getSession(), asList(r1.getUuid(), r2.getUuid()));
-
- OrganizationDto org = db.organizations().insert();
- OrganizationDto anotherOrg = db.organizations().insert();
- ComponentDto project = newPrivateProjectDto(newOrganizationDto());
+ ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
indexIssues(
- newDoc("I42", file).setOrganizationUuid(anotherOrg.getUuid()).setRuleUuid(r1.getUuid()).setTags(of("another")),
- newDoc("I1", file).setOrganizationUuid(org.getUuid()).setRuleUuid(r1.getUuid()).setTags(of("convention", "java8", "bug")),
- newDoc("I2", file).setOrganizationUuid(org.getUuid()).setRuleUuid(r1.getUuid()).setTags(of("convention", "bug")),
- newDoc("I3", file).setOrganizationUuid(org.getUuid()).setRuleUuid(r2.getUuid()),
- newDoc("I4", file).setOrganizationUuid(org.getUuid()).setRuleUuid(r1.getUuid()).setTags(of("convention")));
-
- assertThat(underTest.searchTags(IssueQuery.builder().organizationUuid(org.getUuid()).build(), null, 100)).containsOnly("convention", "java8", "bug");
- assertThat(underTest.searchTags(IssueQuery.builder().organizationUuid(org.getUuid()).build(), null, 2)).containsOnly("bug", "convention");
- assertThat(underTest.searchTags(IssueQuery.builder().organizationUuid(org.getUuid()).build(), "vent", 100)).containsOnly("convention");
- assertThat(underTest.searchTags(IssueQuery.builder().organizationUuid(org.getUuid()).build(), null, 1)).containsOnly("bug");
- assertThat(underTest.searchTags(IssueQuery.builder().organizationUuid(org.getUuid()).build(), null, 100)).containsOnly("convention", "java8", "bug");
- assertThat(underTest.searchTags(IssueQuery.builder().organizationUuid(org.getUuid()).build(), "invalidRegexp[", 100)).isEmpty();
- assertThat(underTest.searchTags(IssueQuery.builder().build(), null, 100)).containsExactlyInAnyOrder("another", "convention", "java8", "bug");
+ 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")));
+
+ assertThat(underTest.searchTags(IssueQuery.builder().build(), null, 100)).containsExactlyInAnyOrder("convention", "java8", "bug", "another");
+ assertThat(underTest.searchTags(IssueQuery.builder().build(), null, 2)).containsOnly("another", "bug");
+ assertThat(underTest.searchTags(IssueQuery.builder().build(), "vent", 100)).containsOnly("convention");
+ assertThat(underTest.searchTags(IssueQuery.builder().build(), null, 1)).containsOnly("another");
+ assertThat(underTest.searchTags(IssueQuery.builder().build(), "invalidRegexp[", 100)).isEmpty();
}
@Test
public void list_authors() {
- OrganizationDto org = newOrganizationDto();
- ComponentDto project = newPrivateProjectDto(org);
+ ComponentDto project = newPrivateProjectDto();
indexIssues(
newDoc("issue1", project).setAuthorLogin("luke.skywalker"),
newDoc("issue2", project).setAuthorLogin("luke@skywalker.name"),
@Test
public void list_authors_escapes_regexp_special_characters() {
- OrganizationDto org = newOrganizationDto();
- ComponentDto project = newPrivateProjectDto(org);
+ ComponentDto project = newPrivateProjectDto();
indexIssues(
newDoc("issue1", project).setAuthorLogin("name++"));
IssueQuery query = IssueQuery.builder().build();
@Test
public void countTags() {
- OrganizationDto org = newOrganizationDto();
- ComponentDto project = newPrivateProjectDto(org);
+ ComponentDto project = newPrivateProjectDto();
indexIssues(
newDoc("issue1", project).setTags(ImmutableSet.of("convention", "java8", "bug")),
newDoc("issue2", project).setTags(ImmutableSet.of("convention", "bug")),
IntStream.range(0, bugs).forEach(b -> issues.add(newDoc(component).setType(BUG).setResolution(null)));
IntStream.range(0, vulnerabilities).forEach(v -> issues.add(newDoc(component).setType(VULNERABILITY).setResolution(null)));
IntStream.range(0, codeSmelles).forEach(c -> issues.add(newDoc(component).setType(CODE_SMELL).setResolution(null)));
- indexIssues(issues.toArray(new IssueDoc[issues.size()]));
+ indexIssues(issues.toArray(new IssueDoc[0]));
}
private IssueQuery projectQuery(String projectUuid) {
.setScopes(asList("MAIN", "TEST"))
.setLanguages(asList("xoo"))
.setTags(asList("tag1", "tag2"))
- .setOrganization(organization.getKey())
.setAssigned(true)
.setCreatedAfter("2013-04-16T09:08:24+0200")
.setCreatedBefore("2013-04-17T09:08:24+0200")
assertThat(query.scopes()).containsOnly("TEST", "MAIN");
assertThat(query.languages()).containsOnly("xoo");
assertThat(query.tags()).containsOnly("tag1", "tag2");
- assertThat(query.organizationUuid()).isEqualTo(organization.getUuid());
assertThat(query.onComponentOnly()).isFalse();
assertThat(query.assigned()).isTrue();
assertThat(query.rules()).hasSize(2);
assertThat(query.directories()).isEmpty();
assertThat(query.files()).isEmpty();
assertThat(query.viewUuids()).isEmpty();
- assertThat(query.organizationUuid()).isNull();
assertThat(query.branchUuid()).isNull();
}
.setCreatedAfter("unknown-date"));
}
- @Test
- public void return_empty_results_if_organization_with_specified_key_does_not_exist() {
- SearchRequest request = new SearchRequest()
- .setOrganization("does_not_exist");
-
- IssueQuery query = underTest.create(request);
-
- assertThat(query.organizationUuid()).isEqualTo("<UNKNOWN>");
- }
-
}
.owaspTop10(newArrayList("a1", "a2"))
.sansTop25(newArrayList("insecure-interaction", "porous-defenses"))
.cwe(newArrayList("12", "125"))
- .organizationUuid("orga")
.branchUuid("my_branch")
.createdAfterByProjectUuids(ImmutableMap.of("PROJECT", filterDate))
.assigned(true)
assertThat(query.owaspTop10()).containsOnly("a1", "a2");
assertThat(query.sansTop25()).containsOnly("insecure-interaction", "porous-defenses");
assertThat(query.cwe()).containsOnly("12", "125");
- assertThat(query.organizationUuid()).isEqualTo("orga");
assertThat(query.branchUuid()).isEqualTo("my_branch");
assertThat(query.createdAfterByProjectUuids()).containsOnly(entry("PROJECT", filterDate));
assertThat(query.assigned()).isTrue();
assertThat(query.languages()).isEmpty();
assertThat(query.tags()).isEmpty();
assertThat(query.types()).isEmpty();
- assertThat(query.organizationUuid()).isNull();
assertThat(query.branchUuid()).isNull();
assertThat(query.assigned()).isNull();
assertThat(query.createdAfter()).isNull();
package org.sonar.server.hotspot.ws;
import org.sonar.db.component.ComponentDto;
-import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonarqube.ws.Hotspots;
import static java.util.Optional.ofNullable;
public class HotspotWsResponseFormatter {
- private final DefaultOrganizationProvider defaultOrganizationProvider;
- public HotspotWsResponseFormatter(DefaultOrganizationProvider defaultOrganizationProvider) {
- this.defaultOrganizationProvider = defaultOrganizationProvider;
+ public HotspotWsResponseFormatter() {
+ // nothing to do here
}
Hotspots.Component formatComponent(Hotspots.Component.Builder builder, ComponentDto component) {
builder
.clear()
- .setOrganization(defaultOrganizationProvider.get().getKey())
.setKey(component.getKey())
.setQualifier(component.qualifier())
.setName(component.name())
.statuses(wsRequest.getStatus().map(Collections::singletonList).orElse(STATUSES));
if (project != null) {
- builder.organizationUuid(project.getOrganizationUuid());
String projectUuid = firstNonNull(project.getMainBranchProjectUuid(), project.uuid());
if (Qualifiers.APP.equals(project.qualifier())) {
builder.viewUuids(singletonList(projectUuid));
checkIfComponentNeedIssueSync(dbSession, request.param(PARAM_PROJECT));
Optional<ComponentDto> project = getProject(dbSession, organization, request.param(PARAM_PROJECT));
- List<String> authors = getAuthors(organization, project, request);
+ List<String> authors = getAuthors(project.orElse(null), request);
AuthorsResponse wsResponse = AuthorsResponse.newBuilder().addAllAuthors(authors).build();
writeProtobuf(wsResponse, request, response);
}
return Optional.of(project);
}
- private List<String> getAuthors(OrganizationDto organization, Optional<ComponentDto> project, Request request) {
- IssueQuery.Builder issueQueryBuilder = IssueQuery.builder()
- .organizationUuid(organization.getUuid());
- project.ifPresent(p -> {
+ private List<String> getAuthors(@Nullable ComponentDto project, Request request) {
+ IssueQuery.Builder issueQueryBuilder = IssueQuery.builder();
+ ofNullable(project).ifPresent(p -> {
switch (p.qualifier()) {
case Qualifiers.PROJECT:
issueQueryBuilder.projectUuids(ImmutableSet.of(p.uuid()));
PARAM_SONARSOURCE_SECURITY);
private static final String INTERNAL_PARAMETER_DISCLAIMER = "This parameter is mostly used by the Issues page, please prefer usage of the componentKeys parameter. ";
- private static final Set<String> FACETS_REQUIRING_PROJECT_OR_ORGANIZATION = newHashSet(PARAM_MODULE_UUIDS, PARAM_FILES, PARAM_DIRECTORIES);
+ private static final Set<String> FACETS_REQUIRING_PROJECT = newHashSet(PARAM_MODULE_UUIDS, PARAM_FILES, PARAM_DIRECTORIES);
private final UserSession userSession;
private final IssueIndex issueIndex;
private final DbClient dbClient;
public SearchAction(UserSession userSession, IssueIndex issueIndex, IssueQueryFactory issueQueryFactory, IssueIndexSyncProgressChecker issueIndexSyncProgressChecker,
- SearchResponseLoader searchResponseLoader, SearchResponseFormat searchResponseFormat, System2 system2, DbClient dbClient) {
+ SearchResponseLoader searchResponseLoader, SearchResponseFormat searchResponseFormat, System2 system2, DbClient dbClient) {
this.userSession = userSession;
this.issueIndex = issueIndex;
this.issueQueryFactory = issueQueryFactory;
.setBooleanPossibleValues()
.setDefaultValue("false");
action.createParam(PARAM_TIMEZONE)
- .setDescription("To resolve dates passed to '" + PARAM_CREATED_AFTER + "' or '" + PARAM_CREATED_BEFORE + "' (does not apply to datetime) and to compute creation date histogram")
+ .setDescription(
+ "To resolve dates passed to '" + PARAM_CREATED_AFTER + "' or '" + PARAM_CREATED_BEFORE + "' (does not apply to datetime) and to compute creation date histogram")
.setRequired(false)
.setExampleValue("'Europe/Paris', 'Z' or '+02:00'")
.setSince("8.6");
EnumSet<SearchAdditionalField> additionalFields = SearchAdditionalField.getFromRequest(request);
IssueQuery query = issueQueryFactory.create(request);
- Set<String> facetsRequiringProjectOrOrganizationParameter = options.getFacets().stream()
- .filter(FACETS_REQUIRING_PROJECT_OR_ORGANIZATION::contains)
+ Set<String> facetsRequiringProjectParameter = options.getFacets().stream()
+ .filter(FACETS_REQUIRING_PROJECT::contains)
.collect(toSet());
- checkArgument(facetsRequiringProjectOrOrganizationParameter.isEmpty() ||
- (!query.projectUuids().isEmpty()) || query.organizationUuid() != null, "Facet(s) '%s' require to also filter by project or organization",
- String.join(",", facetsRequiringProjectOrOrganizationParameter));
+ checkArgument(facetsRequiringProjectParameter.isEmpty() ||
+ (!query.projectUuids().isEmpty()), "Facet(s) '%s' require to also filter by project",
+ String.join(",", facetsRequiringProjectParameter));
// execute request
SearchResponse result = issueIndex.search(query, options);
.setOnComponentOnly(request.paramAsBoolean(PARAM_ON_COMPONENT_ONLY))
.setBranch(request.param(PARAM_BRANCH))
.setPullRequest(request.param(PARAM_PULL_REQUEST))
- .setOrganization(request.param(PARAM_ORGANIZATION))
.setPage(request.mandatoryParamAsInt(Param.PAGE))
.setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE))
.setProjects(request.paramAsStrings(PARAM_PROJECTS))
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.issue.index.IssueIndex;
import org.sonar.server.issue.index.IssueIndexSyncProgressChecker;
import org.sonarqube.ws.Issues;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Optional.ofNullable;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
-import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional;
import static org.sonar.server.issue.index.IssueQueryFactory.ISSUE_TYPE_NAMES;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
* @since 5.1
*/
public class TagsAction implements IssuesWsAction {
-
- private static final String PARAM_ORGANIZATION = "organization";
private static final String PARAM_PROJECT = "project";
private final IssueIndex issueIndex;
.setChangelog(new Change("7.4", "Result doesn't include rules tags anymore"));
action.createSearchQuery("misra", "tags");
action.createPageSize(10, 100);
- action.createParam(PARAM_ORGANIZATION)
- .setDescription("Organization key")
- .setRequired(false)
- .setInternal(true)
- .setExampleValue("my-org")
- .setSince("6.4");
action.createParam(PARAM_PROJECT)
.setDescription("Project key")
.setRequired(false)
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
String projectKey = request.param(PARAM_PROJECT);
- String organizatioKey = request.param(PARAM_ORGANIZATION);
checkIfAnyComponentsNeedIssueSync(dbSession, projectKey);
- Optional<OrganizationDto> organization = getOrganization(dbSession, organizatioKey);
- Optional<ComponentDto> project = getProject(dbSession, organization, projectKey);
- List<String> tags = searchTags(organization, project, request);
+ Optional<ComponentDto> project = getProject(dbSession, projectKey);
+ List<String> tags = searchTags(project.orElse(null), request);
Issues.TagsResponse.Builder tagsResponseBuilder = Issues.TagsResponse.newBuilder();
tags.forEach(tagsResponseBuilder::addTags);
writeProtobuf(tagsResponseBuilder.build(), request, response);
}
}
- private Optional<OrganizationDto> getOrganization(DbSession dbSession, @Nullable String organizationKey) {
- return organizationKey == null ? Optional.empty()
- : Optional.of(checkFoundWithOptional(dbClient.organizationDao().selectByKey(dbSession, organizationKey), "No organization with key '%s'", organizationKey));
- }
-
- private Optional<ComponentDto> getProject(DbSession dbSession, Optional<OrganizationDto> organization, @Nullable String projectKey) {
+ private Optional<ComponentDto> getProject(DbSession dbSession, @Nullable String projectKey) {
if (projectKey == null) {
return Optional.empty();
}
ComponentDto project = componentFinder.getByKey(dbSession, projectKey);
checkArgument(project.scope().equals(Scopes.PROJECT), "Component '%s' must be a project", projectKey);
- organization.ifPresent(o -> checkArgument(project.getOrganizationUuid().equals(o.getUuid()), "Project '%s' is not part of the organization '%s'", projectKey, o.getKey()));
return Optional.of(project);
}
}
}
- private List<String> searchTags(Optional<OrganizationDto> organization, Optional<ComponentDto> project, Request request) {
+ private List<String> searchTags(@Nullable ComponentDto project, Request request) {
IssueQuery.Builder issueQueryBuilder = IssueQuery.builder()
.types(ISSUE_TYPE_NAMES);
- organization.ifPresent(o -> issueQueryBuilder.organizationUuid(o.getUuid()));
- project.ifPresent(p -> {
+ ofNullable(project).ifPresent(p -> {
switch (p.qualifier()) {
case Qualifiers.PROJECT:
issueQueryBuilder.projectUuids(ImmutableSet.of(p.uuid()));
],
"components": [
{
- "organization": "default-organization",
"key": "com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java",
"qualifier": "FIL",
"name": "FourthClass.java",
"path": "src/main/java/com/sonarsource/FourthClass.java"
},
{
- "organization": "default-organization",
"key": "com.sonarsource:test-project",
"qualifier": "TRK",
"name": "test-project",
{
"key": "AW9mgJw6eFC3pGl94Wrf",
"component": {
- "organization": "default-organization",
"key": "com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java",
"qualifier": "FIL",
"name": "FourthClass.java",
"path": "src/main/java/com/sonarsource/FourthClass.java"
},
"project": {
- "organization": "default-organization",
"key": "com.sonarsource:test-project",
"qualifier": "TRK",
"name": "test-project",
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
- private DbClient dbClient = dbTester.getDbClient();
- private IssueUpdater issueUpdater = mock(IssueUpdater.class);
- private System2 system2 = mock(System2.class);
- private IssueFieldsSetter issueFieldsSetter = mock(IssueFieldsSetter.class);
- private HotspotWsSupport hotspotWsSupport = new HotspotWsSupport(dbClient, userSessionRule, system2);
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final IssueUpdater issueUpdater = mock(IssueUpdater.class);
+ private final System2 system2 = mock(System2.class);
+ private final IssueFieldsSetter issueFieldsSetter = mock(IssueFieldsSetter.class);
+ private final HotspotWsSupport hotspotWsSupport = new HotspotWsSupport(dbClient, userSessionRule, system2);
- private AssignAction underTest = new AssignAction(dbClient, hotspotWsSupport, issueFieldsSetter, issueUpdater);
- private WsActionTester actionTester = new WsActionTester(underTest);
+ private final AssignAction underTest = new AssignAction(dbClient, hotspotWsSupport, issueFieldsSetter, issueUpdater);
+ private final WsActionTester actionTester = new WsActionTester(underTest);
@Test
public void ws_definition_check() {
assertThat(wsDefinition.isPost()).isTrue();
assertThat(wsDefinition.isInternal()).isTrue();
assertThat(wsDefinition.params()).hasSize(3);
- assertThat(wsDefinition.param("hotspot").isRequired()).isTrue();
- assertThat(wsDefinition.param("assignee").isRequired()).isTrue();
- assertThat(wsDefinition.param("comment").isRequired()).isFalse();
+ WebService.Param hotspotParam = wsDefinition.param("hotspot");
+ assertThat(hotspotParam).isNotNull();
+ assertThat(hotspotParam.isRequired()).isTrue();
+ WebService.Param assigneeParam = wsDefinition.param("assignee");
+ assertThat(assigneeParam).isNotNull();
+ assertThat(assigneeParam.isRequired()).isTrue();
+ WebService.Param commentParam = wsDefinition.param("comment");
+ assertThat(commentParam).isNotNull();
+ assertThat(commentParam.isRequired()).isFalse();
assertThat(wsDefinition.since()).isEqualTo("8.2");
}
}
private UserDto insertUser(String login) {
- UserDto user = dbTester.users().insertUser(login);
- dbTester.organizations().addMember(dbTester.getDefaultOrganization(), user);
- return user;
+ return dbTester.users().insertUser(login);
}
private UserDto insertUserWithProjectPermission(String login, ComponentDto project, String permission) {
UserDto user = dbTester.users().insertUser(login);
- dbTester.organizations().addMember(dbTester.getDefaultOrganization(), user);
dbTester.users().insertProjectPermissionOnUser(user, permission, project);
return user;
}
import org.sonar.server.issue.index.IssueIndexSyncProgressChecker;
import org.sonar.server.issue.index.IssueIndexer;
import org.sonar.server.issue.index.IssueIteratorFactory;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.permission.index.PermissionIndexer;
import org.sonar.server.permission.index.WebAuthorizationTypeSupport;
import org.sonar.server.security.SecurityStandards;
private final TestSystem2 system2 = new TestSystem2();
private final DbClient dbClient = dbTester.getDbClient();
- private final TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
private final IssueIndex issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSessionRule, new WebAuthorizationTypeSupport(userSessionRule));
private final IssueIndexer issueIndexer = new IssueIndexer(es.client(), dbClient, new IssueIteratorFactory(dbClient), mock(AsyncIssueIndexing.class));
private final ViewIndexer viewIndexer = new ViewIndexer(dbClient, es.client());
private final PermissionIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client(), issueIndexer);
- private final HotspotWsResponseFormatter responseFormatter = new HotspotWsResponseFormatter(defaultOrganizationProvider);
+ private final HotspotWsResponseFormatter responseFormatter = new HotspotWsResponseFormatter();
private final IssueIndexSyncProgressChecker issueIndexSyncProgressChecker = mock(IssueIndexSyncProgressChecker.class);
private final SearchAction underTest = new SearchAction(dbClient, userSessionRule, issueIndex,
issueIndexSyncProgressChecker, responseFormatter, system2);
.extracting(SearchWsResponse.Hotspot::getKey)
.containsOnly(fileHotspot.getKey(), dirHotspot.getKey(), projectHotspot.getKey());
assertThat(response.getComponentsList()).hasSize(3);
- assertThat(response.getComponentsList())
- .extracting(Component::getOrganization)
- .containsOnly(defaultOrganizationProvider.get().getKey());
assertThat(response.getComponentsList())
.extracting(Component::getKey)
.containsOnly(project.getKey(), directory.getKey(), file.getKey());
.toArray(IssueDto[]::new);
indexIssues();
+ assertThat(actionTester.getDef().responseExampleAsString()).isNotNull();
newRequest(project)
.execute()
- .assertJson(actionTester.getDef().responseExampleAsString()
- .replaceAll("default-organization", dbTester.getDefaultOrganization().getKey()));
+ .assertJson(actionTester.getDef().responseExampleAsString());
}
private IssueDto insertHotspot(ComponentDto project, ComponentDto file, RuleDefinitionDto rule) {
import org.sonar.server.issue.IssueChangeWSSupport.Load;
import org.sonar.server.issue.TextRangeResponseFormatter;
import org.sonar.server.issue.ws.UserResponseFormatter;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.security.SecurityStandards;
import org.sonar.server.security.SecurityStandards.SQCategory;
import org.sonar.server.tester.UserSessionRule;
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
- private DbClient dbClient = dbTester.getDbClient();
- private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
-
- private MacroInterpreter macroInterpreter = mock(MacroInterpreter.class);
-
- private AvatarResolver avatarResolver = new AvatarResolverImpl();
- private HotspotWsResponseFormatter responseFormatter = new HotspotWsResponseFormatter(defaultOrganizationProvider);
- private IssueChangeWSSupport issueChangeSupport = Mockito.mock(IssueChangeWSSupport.class);
- private HotspotWsSupport hotspotWsSupport = new HotspotWsSupport(dbClient, userSessionRule, System2.INSTANCE);
- private UserResponseFormatter userFormatter = new UserResponseFormatter(new AvatarResolverImpl());
- private TextRangeResponseFormatter textRangeFormatter = new TextRangeResponseFormatter();
-
- private ShowAction underTest = new ShowAction(dbClient, hotspotWsSupport, responseFormatter, textRangeFormatter, userFormatter, issueChangeSupport, macroInterpreter);
- private WsActionTester actionTester = new WsActionTester(underTest);
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final MacroInterpreter macroInterpreter = mock(MacroInterpreter.class);
+ private final AvatarResolver avatarResolver = new AvatarResolverImpl();
+ private final HotspotWsResponseFormatter responseFormatter = new HotspotWsResponseFormatter();
+ private final IssueChangeWSSupport issueChangeSupport = Mockito.mock(IssueChangeWSSupport.class);
+ private final HotspotWsSupport hotspotWsSupport = new HotspotWsSupport(dbClient, userSessionRule, System2.INSTANCE);
+ private final UserResponseFormatter userFormatter = new UserResponseFormatter(new AvatarResolverImpl());
+ private final TextRangeResponseFormatter textRangeFormatter = new TextRangeResponseFormatter();
+ private final ShowAction underTest = new ShowAction(dbClient, hotspotWsSupport, responseFormatter, textRangeFormatter, userFormatter, issueChangeSupport, macroInterpreter);
+ private final WsActionTester actionTester = new WsActionTester(underTest);
@Before
public void before() {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT,
r -> r.setTemplateUuid("123")
.setDescription(description)
- .setDescriptionFormat(MARKDOWN)
- );
+ .setDescriptionFormat(MARKDOWN));
doReturn(resultingDescription).when(macroInterpreter).interpret(parsedDescription);
when(issueChangeSupport.formatChangelog(any(), any())).thenReturn(changelog.stream());
when(issueChangeSupport.formatComments(any(), any(), any())).thenReturn(comments.stream());
+ assertThat(actionTester.getDef().responseExampleAsString()).isNotNull();
newRequest(hotspot)
.execute()
- .assertJson(actionTester.getDef().responseExampleAsString()
- .replaceAll("default-organization", dbTester.getDefaultOrganization().getKey()));
+ .assertJson(actionTester.getDef().responseExampleAsString());
}
private FormattingContext mockChangelogAndCommentsFormattingContext() {
.doesNotContain(luke);
}
- @Test
- public void search_authors_by_organization() {
- String leia = "leia.organa";
- String luke = "luke.skywalker";
- OrganizationDto organization1 = db.organizations().insert();
- OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization1);
- ComponentDto project2 = db.components().insertPrivateProject(organization2);
- permissionIndexer.allowOnlyAnyone(project1, project2);
- RuleDefinitionDto rule = db.rules().insertIssueRule();
- db.issues().insertIssue(rule, project1, project1, issue -> issue.setAuthorLogin(leia));
- db.issues().insertIssue(rule, project2, project2, issue -> issue.setAuthorLogin(luke));
- indexIssues();
- userSession.logIn();
-
- assertThat(ws.newRequest()
- .setParam("organization", organization1.getKey())
- .executeProtobuf(AuthorsResponse.class).getAuthorsList())
- .containsExactlyInAnyOrder(leia);
- assertThat(ws.newRequest()
- .setParam("organization", organization1.getKey())
- .setParam(TEXT_QUERY, "eia")
- .executeProtobuf(AuthorsResponse.class).getAuthorsList())
- .containsExactlyInAnyOrder(leia);
- assertThat(ws.newRequest()
- .setParam("organization", organization1.getKey())
- .setParam(TEXT_QUERY, "luke")
- .executeProtobuf(AuthorsResponse.class).getAuthorsList())
- .isEmpty();
- }
-
@Test
public void search_authors_by_project() {
String leia = "leia.organa";
.setParam("organization", organization.getKey())
.setParam("project", project1.getKey())
.executeProtobuf(AuthorsResponse.class).getAuthorsList())
- .containsExactlyInAnyOrder(leia);
+ .containsExactlyInAnyOrder(leia);
assertThat(ws.newRequest()
.setParam("organization", organization.getKey())
.setParam("project", project1.getKey())
.setParam(TEXT_QUERY, "eia")
.executeProtobuf(AuthorsResponse.class).getAuthorsList())
- .containsExactlyInAnyOrder(leia);
+ .containsExactlyInAnyOrder(leia);
assertThat(ws.newRequest()
.setParam("organization", organization.getKey())
.setParam("project", project1.getKey())
.setParam(TEXT_QUERY, "luke")
.executeProtobuf(AuthorsResponse.class).getAuthorsList())
- .isEmpty();
+ .isEmpty();
verify(issueIndexSyncProgressChecker, times(3)).checkIfComponentNeedIssueSync(any(), eq(project1.getKey()));
}
assertThat(ws.newRequest()
.setParam("project", portfolio.getKey())
.executeProtobuf(AuthorsResponse.class).getAuthorsList())
- .containsExactlyInAnyOrder(leia);
+ .containsExactlyInAnyOrder(leia);
}
@Test
assertThat(ws.newRequest()
.setParam("project", application.getKey())
.executeProtobuf(AuthorsResponse.class).getAuthorsList())
- .containsExactlyInAnyOrder(leia);
- }
-
- @Test
- public void default_organization_is_used_when_no_organization_parameter_set() {
- String leia = "leia.organa";
- String luke = "luke.skywalker";
- ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization());
- OrganizationDto otherOrganization = db.organizations().insert();
- ComponentDto project2 = db.components().insertPrivateProject(otherOrganization);
- permissionIndexer.allowOnlyAnyone(project1, project2);
- RuleDefinitionDto rule = db.rules().insertIssueRule();
- db.issues().insertIssue(rule, project1, project1, issue -> issue.setAuthorLogin(leia));
- db.issues().insertIssue(rule, project2, project2, issue -> issue.setAuthorLogin(luke));
- indexIssues();
- userSession.logIn();
-
- AuthorsResponse result = ws.newRequest().executeProtobuf(AuthorsResponse.class);
-
- assertThat(result.getAuthorsList())
- .containsExactlyInAnyOrder(leia)
- .doesNotContain(luke);
+ .containsExactlyInAnyOrder(leia);
}
@Test
}
@Test
- public void display_module_facet_using_organization() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPublicProject(organization);
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto subModule1 = db.components().insertComponent(newModuleDto(module));
- ComponentDto subModule2 = db.components().insertComponent(newModuleDto(module));
- ComponentDto subModule3 = db.components().insertComponent(newModuleDto(module));
- ComponentDto file1 = db.components().insertComponent(newFileDto(subModule1));
- ComponentDto file2 = db.components().insertComponent(newFileDto(subModule2));
- RuleDefinitionDto rule = db.rules().insertIssueRule();
- db.issues().insertIssue(rule, project, file1);
- db.issues().insertIssue(rule, project, file2);
- indexPermissions();
- indexIssues();
-
- SearchWsResponse response = ws.newRequest()
- .setParam(PARAM_ORGANIZATION, organization.getKey())
- .setParam(PARAM_COMPONENT_UUIDS, module.uuid())
- .setParam(PARAM_MODULE_UUIDS, subModule1.uuid() + "," + subModule2.uuid())
- .setParam(WebService.Param.FACETS, "moduleUuids")
- .executeProtobuf(SearchWsResponse.class);
-
- assertThat(response.getFacets().getFacetsList())
- .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount)))
- .containsExactlyInAnyOrder(tuple("moduleUuids", of(subModule1.uuid(), 1L, subModule2.uuid(), 1L)));
- }
-
- @Test
- public void fail_to_display_module_facet_when_no_organization_or_project_is_set() {
+ public void fail_to_display_module_facet_when_no_project_is_set() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto module = db.components().insertComponent(newModuleDto(project));
ComponentDto file = db.components().insertComponent(newFileDto(module, null));
indexIssues();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Facet(s) 'moduleUuids' require to also filter by project or organization");
+ expectedException.expectMessage("Facet(s) 'moduleUuids' require to also filter by project");
ws.newRequest()
.setParam(PARAM_COMPONENT_UUIDS, module.uuid())
}
@Test
- public void display_directory_facet_using_organization() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPublicProject(organization);
- ComponentDto directory = db.components().insertComponent(newDirectory(project, "src/main/java/dir"));
- ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
- RuleDefinitionDto rule = db.rules().insertIssueRule();
- db.issues().insertIssue(rule, project, file);
- indexPermissions();
- indexIssues();
-
- SearchWsResponse response = ws.newRequest()
- .setParam("resolved", "false")
- .setParam(PARAM_ORGANIZATION, organization.getKey())
- .setParam(WebService.Param.FACETS, "directories")
- .executeProtobuf(SearchWsResponse.class);
-
- assertThat(response.getFacets().getFacetsList())
- .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount)))
- .containsExactlyInAnyOrder(tuple("directories", of(directory.path(), 1L)));
- }
-
- @Test
- public void fail_to_display_directory_facet_when_no_organization_or_project_is_set() {
+ public void fail_to_display_directory_facet_when_no_project_is_set() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto directory = db.components().insertComponent(newDirectory(project, "src"));
ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
indexIssues();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Facet(s) 'directories' require to also filter by project or organization");
+ expectedException.expectMessage("Facet(s) 'directories' require to also filter by project");
ws.newRequest()
.setParam(WebService.Param.FACETS, "directories")
}
@Test
- public void display_fileUuids_facet_with_organization() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPublicProject(organization);
- ComponentDto file1 = db.components().insertComponent(newFileDto(project));
- ComponentDto file2 = db.components().insertComponent(newFileDto(project));
- ComponentDto file3 = db.components().insertComponent(newFileDto(project));
- RuleDefinitionDto rule = db.rules().insertIssueRule();
- db.issues().insertIssue(rule, project, file1);
- db.issues().insertIssue(rule, project, file2);
- indexPermissions();
- indexIssues();
-
- SearchWsResponse response = ws.newRequest()
- .setParam(PARAM_ORGANIZATION, organization.getKey())
- .setParam(PARAM_FILES, file1.path())
- .setParam(WebService.Param.FACETS, "files")
- .executeProtobuf(SearchWsResponse.class);
-
- assertThat(response.getFacets().getFacetsList())
- .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount)))
- .containsExactlyInAnyOrder(tuple("files", of(file1.path(), 1L, file2.path(), 1L)));
- }
-
- @Test
- public void fail_to_display_fileUuids_facet_when_no_organization_or_project_is_set() {
+ public void fail_to_display_fileUuids_facet_when_no_project_is_set() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = db.rules().insertIssueRule();
indexIssues();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Facet(s) 'files' require to also filter by project or organization");
+ expectedException.expectMessage("Facet(s) 'files' require to also filter by project");
ws.newRequest()
.setParam(PARAM_FILES, file.path())
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.issue.IssueDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.es.EsTester;
assertThat(tagListOf(testRequest.setParam("q", "ag5"))).isEmpty();
}
- @Test
- public void search_tags_by_organization() {
- RuleDefinitionDto rule = db.rules().insertIssueRule();
- // Tags on issues of organization 1
- OrganizationDto organization1 = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization1);
- db.issues().insertIssue(rule, project1, project1, issue -> issue.setTags(asList("tag1", "tag2")));
- // Tags on issues of organization 2
- OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project2 = db.components().insertPrivateProject(organization2);
- db.issues().insertIssue(rule, project2, project2, issue -> issue.setTags(singletonList("tag3")));
- indexIssues();
- permissionIndexer.allowOnlyAnyone(project1, project2);
-
- assertThat(tagListOf(ws.newRequest().setParam("organization", organization1.getKey()))).containsExactly("tag1", "tag2");
- }
-
- @Test
- public void search_tags_by_organization_ignores_hotspots() {
- RuleDefinitionDto issueRule = db.rules().insertIssueRule();
- RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule();
- // Tags on issues of organization 1
- OrganizationDto organization1 = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization1);
- db.issues().insertIssue(issueRule, project1, project1, issue -> issue.setTags(asList("tag1", "tag2")));
- db.issues().insertHotspot(hotspotRule, project1, project1, issue -> issue.setTags(asList("tag3", "tag4")));
- // Tags on issues of organization 2
- OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project2 = db.components().insertPrivateProject(organization2);
- db.issues().insertIssue(issueRule, project2, project2, issue -> issue.setTags(singletonList("tag5")));
- db.issues().insertHotspot(hotspotRule, project2, project2, issue -> issue.setTags(singletonList("tag6")));
- indexIssues();
- permissionIndexer.allowOnlyAnyone(project1, project2);
-
- assertThat(tagListOf(ws.newRequest().setParam("organization", organization1.getKey()))).containsExactly("tag1", "tag2");
- }
-
@Test
public void search_tags_by_project() {
RuleDefinitionDto rule = db.rules().insertIssueRule();
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization);
- ComponentDto project2 = db.components().insertPrivateProject(organization);
+ ComponentDto project1 = db.components().insertPrivateProject();
+ ComponentDto project2 = db.components().insertPrivateProject();
db.issues().insertIssue(rule, project1, project1, issue -> issue.setTags(singletonList("tag1")));
db.issues().insertIssue(rule, project2, project2, issue -> issue.setTags(singletonList("tag2")));
indexIssues();
permissionIndexer.allowOnlyAnyone(project1, project2);
assertThat(tagListOf(ws.newRequest()
- .setParam("organization", organization.getKey())
.setParam("project", project1.getKey()))).containsExactly("tag1");
verify(issueIndexSyncProgressChecker).checkIfComponentNeedIssueSync(any(), eq(project1.getKey()));
}
public void search_tags_by_project_ignores_hotspots() {
RuleDefinitionDto issueRule = db.rules().insertIssueRule();
RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule();
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization);
- ComponentDto project2 = db.components().insertPrivateProject(organization);
+ ComponentDto project1 = db.components().insertPrivateProject();
+ ComponentDto project2 = db.components().insertPrivateProject();
db.issues().insertHotspot(hotspotRule, project1, project1, issue -> issue.setTags(singletonList("tag1")));
db.issues().insertIssue(issueRule, project1, project1, issue -> issue.setTags(singletonList("tag2")));
db.issues().insertHotspot(hotspotRule, project2, project2, issue -> issue.setTags(singletonList("tag3")));
permissionIndexer.allowOnlyAnyone(project1, project2);
assertThat(tagListOf(ws.newRequest()
- .setParam("organization", organization.getKey())
.setParam("project", project1.getKey()))).containsExactly("tag2");
}
@Test
public void search_tags_by_portfolio() {
- OrganizationDto organization = db.getDefaultOrganization();
- ComponentDto portfolio = db.components().insertPrivatePortfolio(organization);
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto portfolio = db.components().insertPrivatePortfolio();
+ ComponentDto project = db.components().insertPrivateProject();
db.components().insertComponent(newProjectCopy(project, portfolio));
permissionIndexer.allowOnlyAnyone(project);
RuleDefinitionDto rule = db.rules().insertIssueRule();
@Test
public void search_tags_by_portfolio_ignores_hotspots() {
- OrganizationDto organization = db.getDefaultOrganization();
- ComponentDto portfolio = db.components().insertPrivatePortfolio(organization);
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto portfolio = db.components().insertPrivatePortfolio();
+ ComponentDto project = db.components().insertPrivateProject();
db.components().insertComponent(newProjectCopy(project, portfolio));
permissionIndexer.allowOnlyAnyone(project);
RuleDefinitionDto issueRule = db.rules().insertIssueRule();
@Test
public void search_tags_by_application() {
- OrganizationDto organization = db.getDefaultOrganization();
- ComponentDto application = db.components().insertPrivateApplication(organization);
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto application = db.components().insertPrivateApplication();
+ ComponentDto project = db.components().insertPrivateProject();
db.components().insertComponent(newProjectCopy(project, application));
permissionIndexer.allowOnlyAnyone(project);
RuleDefinitionDto rule = db.rules().insertIssueRule();
@Test
public void search_tags_by_application_ignores_hotspots() {
- OrganizationDto organization = db.getDefaultOrganization();
- ComponentDto application = db.components().insertPrivateApplication(organization);
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto application = db.components().insertPrivateApplication();
+ ComponentDto project = db.components().insertPrivateProject();
db.components().insertComponent(newProjectCopy(project, application));
permissionIndexer.allowOnlyAnyone(project);
RuleDefinitionDto issueRule = db.rules().insertIssueRule();
assertThat(result.getTagsList()).containsExactly("tag1", "tag2");
}
- @Test
- public void without_organization_parameter_is_cross_organization() {
- RuleDefinitionDto rule = db.rules().insertIssueRule();
- // Tags on issues of organization 1
- OrganizationDto organization1 = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization1);
- db.issues().insertIssue(rule, project1, project1, issue -> issue.setTags(asList("tag1", "tag2")));
- // Tags on issues of organization 2
- OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project2 = db.components().insertPrivateProject(organization2);
- db.issues().insertIssue(rule, project2, project2, issue -> issue.setTags(singletonList("tag3")));
- indexIssues();
- permissionIndexer.allowOnlyAnyone(project1, project2);
-
- TagsResponse result = ws.newRequest().executeProtobuf(TagsResponse.class);
-
- assertThat(result.getTagsList()).containsExactly("tag1", "tag2", "tag3");
- }
-
@Test
public void empty_list() {
TagsResponse result = ws.newRequest().executeProtobuf(TagsResponse.class);
assertThat(result.getTagsList()).isEmpty();
}
- @Test
- public void fail_when_project_does_not_belong_to_organization() {
- OrganizationDto organization = db.organizations().insert();
- OrganizationDto otherOrganization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(otherOrganization);
- indexIssues();
- permissionIndexer.allowOnlyAnyone(project, project);
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage(format("Project '%s' is not part of the organization '%s'", project.getKey(), organization.getKey()));
-
- ws.newRequest()
- .setParam("organization", organization.getKey())
- .setParam("project", project.getKey())
- .execute();
- }
-
private void indexIssues() {
issueIndexer.indexAllIssues();
}
@Test
public void fail_when_project_parameter_does_not_match_a_project() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
indexIssues();
permissionIndexer.allowOnlyAnyone(project, project);
expectedException.expectMessage(format("Component '%s' must be a project", file.getKey()));
ws.newRequest()
- .setParam("organization", organization.getKey())
.setParam("project", file.getKey())
.execute();
}
String result = ws.newRequest().execute().getInput();
+ assertThat(ws.getDef().responseExampleAsString()).isNotNull();
assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString());
}
.containsExactlyInAnyOrder(
tuple("q", null, null, false, false),
tuple("ps", "10", null, false, false),
- tuple("organization", null, "6.4", false, true),
tuple("project", null, "7.4", false, false));
}
}
message Component {
- optional string organization = 1;
- optional string key = 2;
- optional string qualifier = 3;
- optional string name = 4;
- optional string longName = 5;
- optional string path = 6;
- optional string branch = 7;
- optional string pullRequest = 8;
+ optional string key = 1;
+ optional string qualifier = 2;
+ optional string name = 3;
+ optional string longName = 4;
+ optional string path = 5;
+ optional string branch = 6;
+ optional string pullRequest = 7;
}
message Rule {