@@ -66,9 +66,9 @@ public class IssueDbTester { | |||
* 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)); |
@@ -50,7 +50,6 @@ public class SearchRequest { | |||
private Boolean onComponentOnly; | |||
private String branch; | |||
private String pullRequest; | |||
private String organization; | |||
private int page; | |||
private int pageSize; | |||
private List<String> projects; | |||
@@ -273,16 +272,6 @@ public class SearchRequest { | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getOrganization() { | |||
return organization; | |||
} | |||
public SearchRequest setOrganization(@Nullable String s) { | |||
this.organization = s; | |||
return this; | |||
} | |||
public int getPage() { | |||
return page; | |||
} |
@@ -158,11 +158,6 @@ public class IssueDoc extends BaseDoc { | |||
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; | |||
@@ -290,11 +285,6 @@ public class IssueDoc extends BaseDoc { | |||
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); |
@@ -62,7 +62,6 @@ public class IssueIndexDefinition implements IndexDefinition { | |||
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 | |||
@@ -148,7 +147,6 @@ public class IssueIndexDefinition implements IndexDefinition { | |||
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); |
@@ -74,7 +74,6 @@ class IssueIteratorForSingleChunk implements IssueIterator { | |||
"c.module_uuid_path", | |||
"c.path", | |||
"c.scope", | |||
"c.organization_uuid", | |||
"c.project_uuid", | |||
"c.main_branch_project_uuid", | |||
@@ -215,9 +214,8 @@ class IssueIteratorForSingleChunk implements IssueIterator { | |||
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); | |||
@@ -226,11 +224,11 @@ class IssueIteratorForSingleChunk implements IssueIterator { | |||
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()); | |||
@@ -238,7 +236,7 @@ class IssueIteratorForSingleChunk implements IssueIterator { | |||
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; | |||
} | |||
@@ -43,7 +43,6 @@ public class SearchRequestTest { | |||
.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") | |||
@@ -64,7 +63,6 @@ public class SearchRequestTest { | |||
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"); |
@@ -28,7 +28,6 @@ import java.util.function.Predicate; | |||
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; | |||
@@ -42,7 +41,6 @@ import org.sonar.db.component.ComponentTesting; | |||
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; | |||
@@ -77,13 +75,7 @@ public class IssueIndexerTest { | |||
@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() { | |||
@@ -105,8 +97,8 @@ public class IssueIndexerTest { | |||
@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(); | |||
@@ -116,7 +108,7 @@ public class IssueIndexerTest { | |||
@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); | |||
@@ -125,7 +117,6 @@ public class IssueIndexerTest { | |||
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()); | |||
@@ -151,7 +142,7 @@ public class IssueIndexerTest { | |||
@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); | |||
@@ -167,7 +158,7 @@ public class IssueIndexerTest { | |||
@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 | |||
@@ -183,10 +174,10 @@ public class IssueIndexerTest { | |||
@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()); | |||
@@ -197,7 +188,7 @@ public class IssueIndexerTest { | |||
@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); | |||
@@ -218,7 +209,7 @@ public class IssueIndexerTest { | |||
@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 | |||
@@ -236,7 +227,7 @@ public class IssueIndexerTest { | |||
// 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); | |||
@@ -246,7 +237,7 @@ public class IssueIndexerTest { | |||
@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); | |||
@@ -256,7 +247,7 @@ public class IssueIndexerTest { | |||
@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); | |||
@@ -302,7 +293,7 @@ public class IssueIndexerTest { | |||
@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 | |||
@@ -322,7 +313,7 @@ public class IssueIndexerTest { | |||
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)); | |||
@@ -335,7 +326,7 @@ public class IssueIndexerTest { | |||
@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 | |||
@@ -382,12 +373,12 @@ public class IssueIndexerTest { | |||
@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 | |||
@@ -403,7 +394,7 @@ public class IssueIndexerTest { | |||
@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); | |||
@@ -485,7 +476,7 @@ public class IssueIndexerTest { | |||
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); | |||
} | |||
@@ -493,7 +484,7 @@ public class IssueIndexerTest { | |||
@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")); | |||
@@ -503,7 +494,6 @@ public class IssueIndexerTest { | |||
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()); | |||
@@ -514,7 +504,7 @@ public class IssueIndexerTest { | |||
@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); | |||
@@ -523,7 +513,6 @@ public class IssueIndexerTest { | |||
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); | |||
} | |||
@@ -531,7 +520,7 @@ public class IssueIndexerTest { | |||
@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); | |||
@@ -539,7 +528,6 @@ public class IssueIndexerTest { | |||
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); | |||
} | |||
@@ -547,14 +535,13 @@ public class IssueIndexerTest { | |||
@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); | |||
} |
@@ -48,7 +48,6 @@ public class IssueDocTesting { | |||
.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); |
@@ -150,7 +150,6 @@ import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_LANG | |||
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; | |||
@@ -438,9 +437,6 @@ public class IssueIndex { | |||
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); |
@@ -94,7 +94,6 @@ public class IssueQuery { | |||
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; | |||
@@ -132,7 +131,6 @@ public class IssueQuery { | |||
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; | |||
@@ -270,11 +268,6 @@ public class IssueQuery { | |||
return asc; | |||
} | |||
@CheckForNull | |||
public String organizationUuid() { | |||
return organizationUuid; | |||
} | |||
@CheckForNull | |||
public String branchUuid() { | |||
return branchUuid; | |||
@@ -335,7 +328,6 @@ public class IssueQuery { | |||
private String sort; | |||
private Boolean asc = false; | |||
private String facetMode; | |||
private String organizationUuid; | |||
private String branchUuid; | |||
private boolean mainBranch = true; | |||
private ZoneId timeZone; | |||
@@ -531,11 +523,6 @@ public class IssueQuery { | |||
return this; | |||
} | |||
public Builder organizationUuid(String s) { | |||
this.organizationUuid = s; | |||
return this; | |||
} | |||
public Builder branchUuid(@Nullable String s) { | |||
this.branchUuid = s; | |||
return this; |
@@ -131,7 +131,6 @@ public class IssueQueryFactory { | |||
.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<>(); |
@@ -36,7 +36,6 @@ import org.sonar.api.rules.RuleType; | |||
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; | |||
@@ -64,7 +63,6 @@ import static org.sonar.api.utils.DateUtils.parseDateTime; | |||
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; | |||
@@ -76,19 +74,18 @@ public class IssueIndexFiltersTest { | |||
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)), | |||
@@ -101,7 +98,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_projects() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto module = newModuleDto(project); | |||
ComponentDto subModule = newModuleDto(module); | |||
@@ -119,7 +116,7 @@ public class IssueIndexFiltersTest { | |||
@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); | |||
@@ -138,14 +135,14 @@ public class IssueIndexFiltersTest { | |||
@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), | |||
@@ -166,14 +163,14 @@ public class IssueIndexFiltersTest { | |||
@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), | |||
@@ -194,7 +191,7 @@ public class IssueIndexFiltersTest { | |||
@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"); | |||
@@ -209,8 +206,8 @@ public class IssueIndexFiltersTest { | |||
@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(); | |||
@@ -234,8 +231,7 @@ public class IssueIndexFiltersTest { | |||
@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"; | |||
@@ -246,7 +242,7 @@ public class IssueIndexFiltersTest { | |||
@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)); | |||
@@ -337,8 +333,8 @@ public class IssueIndexFiltersTest { | |||
@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(); | |||
@@ -421,11 +417,10 @@ public class IssueIndexFiltersTest { | |||
@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); | |||
@@ -458,9 +453,8 @@ public class IssueIndexFiltersTest { | |||
@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)); | |||
@@ -468,7 +462,7 @@ public class IssueIndexFiltersTest { | |||
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)); | |||
@@ -511,7 +505,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_severities() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto file = newFileDto(project, null); | |||
indexIssues( | |||
@@ -525,7 +519,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_statuses() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto file = newFileDto(project, null); | |||
indexIssues( | |||
@@ -539,7 +533,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_resolutions() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto file = newFileDto(project, null); | |||
indexIssues( | |||
@@ -553,7 +547,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_resolved() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto file = newFileDto(project, null); | |||
indexIssues( | |||
@@ -568,7 +562,7 @@ public class IssueIndexFiltersTest { | |||
@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); | |||
@@ -581,7 +575,7 @@ public class IssueIndexFiltersTest { | |||
@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); | |||
@@ -594,7 +588,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_assignees() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto file = newFileDto(project, null); | |||
indexIssues( | |||
@@ -609,7 +603,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_assigned() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto file = newFileDto(project, null); | |||
indexIssues( | |||
@@ -624,7 +618,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_authors() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto file = newFileDto(project, null); | |||
indexIssues( | |||
@@ -639,7 +633,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_created_after() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto file = newFileDto(project, null); | |||
indexIssues( | |||
@@ -655,7 +649,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_created_before() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto file = newFileDto(project, null); | |||
indexIssues( | |||
@@ -671,7 +665,7 @@ public class IssueIndexFiltersTest { | |||
@Test | |||
public void filter_by_created_after_and_before() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto project = newPrivateProjectDto(); | |||
ComponentDto file = newFileDto(project, null); | |||
indexIssues( | |||
@@ -711,7 +705,7 @@ public class IssueIndexFiltersTest { | |||
@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( | |||
@@ -755,7 +749,7 @@ public class IssueIndexFiltersTest { | |||
@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"))); | |||
@@ -764,54 +758,22 @@ public class IssueIndexFiltersTest { | |||
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( | |||
@@ -819,12 +781,12 @@ public class IssueIndexFiltersTest { | |||
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( | |||
@@ -832,12 +794,12 @@ public class IssueIndexFiltersTest { | |||
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( | |||
@@ -848,11 +810,6 @@ public class IssueIndexFiltersTest { | |||
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())); |
@@ -39,7 +39,6 @@ import org.sonar.api.issue.Issue; | |||
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; | |||
@@ -62,6 +61,7 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
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; | |||
@@ -69,7 +69,6 @@ import static org.sonar.api.rules.RuleType.CODE_SMELL; | |||
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; | |||
@@ -82,19 +81,20 @@ public class IssueIndexTest { | |||
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)); | |||
@@ -117,7 +117,7 @@ public class IssueIndexTest { | |||
@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++) { | |||
@@ -134,7 +134,7 @@ public class IssueIndexTest { | |||
// 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++) { | |||
@@ -152,10 +152,9 @@ public class IssueIndexTest { | |||
@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); | |||
@@ -193,10 +192,9 @@ public class IssueIndexTest { | |||
@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); | |||
@@ -212,7 +210,7 @@ public class IssueIndexTest { | |||
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"); | |||
@@ -227,7 +225,7 @@ public class IssueIndexTest { | |||
@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(); | |||
@@ -239,31 +237,25 @@ public class IssueIndexTest { | |||
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"), | |||
@@ -280,8 +272,7 @@ public class IssueIndexTest { | |||
@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(); | |||
@@ -294,8 +285,7 @@ public class IssueIndexTest { | |||
@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")), | |||
@@ -362,7 +352,7 @@ public class IssueIndexTest { | |||
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) { |
@@ -97,7 +97,6 @@ public class IssueQueryFactoryTest { | |||
.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") | |||
@@ -119,7 +118,6 @@ public class IssueQueryFactoryTest { | |||
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); | |||
@@ -233,7 +231,6 @@ public class IssueQueryFactoryTest { | |||
assertThat(query.directories()).isEmpty(); | |||
assertThat(query.files()).isEmpty(); | |||
assertThat(query.viewUuids()).isEmpty(); | |||
assertThat(query.organizationUuid()).isNull(); | |||
assertThat(query.branchUuid()).isNull(); | |||
} | |||
@@ -585,14 +582,4 @@ public class IssueQueryFactoryTest { | |||
.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>"); | |||
} | |||
} |
@@ -56,7 +56,6 @@ public class IssueQueryTest { | |||
.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) | |||
@@ -81,7 +80,6 @@ public class IssueQueryTest { | |||
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(); | |||
@@ -173,7 +171,6 @@ public class IssueQueryTest { | |||
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(); |
@@ -20,22 +20,19 @@ | |||
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()) |
@@ -317,7 +317,6 @@ public class SearchAction implements HotspotsWsAction { | |||
.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)); |
@@ -115,7 +115,7 @@ public class AuthorsAction implements IssuesWsAction { | |||
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); | |||
} | |||
@@ -146,10 +146,9 @@ public class AuthorsAction implements IssuesWsAction { | |||
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())); |
@@ -162,7 +162,7 @@ public class SearchAction implements IssuesWsAction { | |||
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; | |||
@@ -174,7 +174,7 @@ public class SearchAction implements IssuesWsAction { | |||
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; | |||
@@ -324,7 +324,8 @@ public class SearchAction implements IssuesWsAction { | |||
.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"); | |||
@@ -404,12 +405,12 @@ public class SearchAction implements IssuesWsAction { | |||
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); | |||
@@ -541,7 +542,6 @@ public class SearchAction implements IssuesWsAction { | |||
.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)) |
@@ -34,7 +34,6 @@ import org.sonar.api.server.ws.WebService.NewAction; | |||
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; | |||
@@ -42,9 +41,9 @@ import org.sonar.server.issue.index.IssueQuery; | |||
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; | |||
@@ -54,8 +53,6 @@ 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; | |||
@@ -82,12 +79,6 @@ public class TagsAction implements IssuesWsAction { | |||
.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) | |||
@@ -99,29 +90,21 @@ public class TagsAction implements IssuesWsAction { | |||
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); | |||
} | |||
@@ -133,11 +116,10 @@ public class TagsAction implements IssuesWsAction { | |||
} | |||
} | |||
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())); |
@@ -50,7 +50,6 @@ | |||
], | |||
"components": [ | |||
{ | |||
"organization": "default-organization", | |||
"key": "com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java", | |||
"qualifier": "FIL", | |||
"name": "FourthClass.java", | |||
@@ -58,7 +57,6 @@ | |||
"path": "src/main/java/com/sonarsource/FourthClass.java" | |||
}, | |||
{ | |||
"organization": "default-organization", | |||
"key": "com.sonarsource:test-project", | |||
"qualifier": "TRK", | |||
"name": "test-project", |
@@ -1,7 +1,6 @@ | |||
{ | |||
"key": "AW9mgJw6eFC3pGl94Wrf", | |||
"component": { | |||
"organization": "default-organization", | |||
"key": "com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java", | |||
"qualifier": "FIL", | |||
"name": "FourthClass.java", | |||
@@ -9,7 +8,6 @@ | |||
"path": "src/main/java/com/sonarsource/FourthClass.java" | |||
}, | |||
"project": { | |||
"organization": "default-organization", | |||
"key": "com.sonarsource:test-project", | |||
"qualifier": "TRK", | |||
"name": "test-project", |
@@ -79,14 +79,14 @@ public class AssignActionTest { | |||
@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() { | |||
@@ -95,9 +95,15 @@ public class AssignActionTest { | |||
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"); | |||
} | |||
@@ -466,14 +472,11 @@ public class AssignActionTest { | |||
} | |||
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; | |||
} |
@@ -61,7 +61,6 @@ import org.sonar.server.issue.index.IssueIndex; | |||
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; | |||
@@ -114,12 +113,11 @@ public class SearchActionTest { | |||
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); | |||
@@ -1015,9 +1013,6 @@ public class SearchActionTest { | |||
.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()); | |||
@@ -1535,10 +1530,10 @@ public class SearchActionTest { | |||
.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) { |
@@ -67,7 +67,6 @@ import org.sonar.server.issue.IssueChangeWSSupport.FormattingContext; | |||
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; | |||
@@ -109,20 +108,16 @@ public class ShowActionTest { | |||
@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() { | |||
@@ -399,8 +394,7 @@ public class ShowActionTest { | |||
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT, | |||
r -> r.setTemplateUuid("123") | |||
.setDescription(description) | |||
.setDescriptionFormat(MARKDOWN) | |||
); | |||
.setDescriptionFormat(MARKDOWN)); | |||
doReturn(resultingDescription).when(macroInterpreter).interpret(parsedDescription); | |||
@@ -942,10 +936,10 @@ public class ShowActionTest { | |||
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() { |
@@ -122,37 +122,6 @@ public class AuthorsActionTest { | |||
.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"; | |||
@@ -171,19 +140,19 @@ public class AuthorsActionTest { | |||
.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())); | |||
} | |||
@@ -205,7 +174,7 @@ public class AuthorsActionTest { | |||
assertThat(ws.newRequest() | |||
.setParam("project", portfolio.getKey()) | |||
.executeProtobuf(AuthorsResponse.class).getAuthorsList()) | |||
.containsExactlyInAnyOrder(leia); | |||
.containsExactlyInAnyOrder(leia); | |||
} | |||
@Test | |||
@@ -225,28 +194,7 @@ public class AuthorsActionTest { | |||
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 |
@@ -249,35 +249,7 @@ public class SearchActionFacetsTest { | |||
} | |||
@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)); | |||
@@ -287,7 +259,7 @@ public class SearchActionFacetsTest { | |||
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()) | |||
@@ -317,29 +289,7 @@ public class SearchActionFacetsTest { | |||
} | |||
@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)); | |||
@@ -349,7 +299,7 @@ public class SearchActionFacetsTest { | |||
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") | |||
@@ -381,31 +331,7 @@ public class SearchActionFacetsTest { | |||
} | |||
@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(); | |||
@@ -414,7 +340,7 @@ public class SearchActionFacetsTest { | |||
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()) |
@@ -31,7 +31,6 @@ import org.sonar.db.DbTester; | |||
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; | |||
@@ -142,56 +141,17 @@ public class TagsActionTest { | |||
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())); | |||
} | |||
@@ -200,9 +160,8 @@ public class TagsActionTest { | |||
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"))); | |||
@@ -211,15 +170,13 @@ public class TagsActionTest { | |||
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(); | |||
@@ -232,9 +189,8 @@ public class TagsActionTest { | |||
@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(); | |||
@@ -249,9 +205,8 @@ public class TagsActionTest { | |||
@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(); | |||
@@ -264,9 +219,8 @@ public class TagsActionTest { | |||
@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(); | |||
@@ -311,25 +265,6 @@ public class TagsActionTest { | |||
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); | |||
@@ -337,31 +272,13 @@ public class TagsActionTest { | |||
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); | |||
@@ -370,7 +287,6 @@ public class TagsActionTest { | |||
expectedException.expectMessage(format("Component '%s' must be a project", file.getKey())); | |||
ws.newRequest() | |||
.setParam("organization", organization.getKey()) | |||
.setParam("project", file.getKey()) | |||
.execute(); | |||
} | |||
@@ -386,6 +302,7 @@ public class TagsActionTest { | |||
String result = ws.newRequest().execute().getInput(); | |||
assertThat(ws.getDef().responseExampleAsString()).isNotNull(); | |||
assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString()); | |||
} | |||
@@ -402,7 +319,6 @@ public class TagsActionTest { | |||
.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)); | |||
} | |||
@@ -72,14 +72,13 @@ message ShowWsResponse { | |||
} | |||
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 { |