|
|
@@ -20,34 +20,24 @@ |
|
|
|
package org.sonar.server.issue.ws; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.Test; |
|
|
|
import org.sonar.api.config.internal.MapSettings; |
|
|
|
import org.sonar.api.resources.Languages; |
|
|
|
import org.sonar.api.resources.Qualifiers; |
|
|
|
import org.sonar.api.rule.RuleStatus; |
|
|
|
import org.sonar.api.rule.RuleKey; |
|
|
|
import org.sonar.api.server.ws.WebService; |
|
|
|
import org.sonar.api.utils.DateUtils; |
|
|
|
import org.sonar.api.utils.Durations; |
|
|
|
import org.sonar.api.utils.System2; |
|
|
|
import org.sonar.db.DbClient; |
|
|
|
import org.sonar.db.DbSession; |
|
|
|
import org.sonar.db.DbTester; |
|
|
|
import org.sonar.db.component.ComponentDto; |
|
|
|
import org.sonar.db.component.ComponentTesting; |
|
|
|
import org.sonar.db.issue.IssueDto; |
|
|
|
import org.sonar.db.issue.IssueTesting; |
|
|
|
import org.sonar.db.organization.OrganizationDao; |
|
|
|
import org.sonar.db.organization.OrganizationDto; |
|
|
|
import org.sonar.db.organization.OrganizationTesting; |
|
|
|
import org.sonar.db.rule.RuleDto; |
|
|
|
import org.sonar.db.rule.RuleTesting; |
|
|
|
import org.sonar.db.rule.RuleDefinitionDto; |
|
|
|
import org.sonar.server.es.EsTester; |
|
|
|
import org.sonar.server.es.StartupIndexer; |
|
|
|
import org.sonar.server.issue.ActionFinder; |
|
|
|
import org.sonar.server.issue.IssueFieldsSetter; |
|
|
|
import org.sonar.server.issue.IssueQueryFactory; |
|
|
@@ -59,28 +49,29 @@ import org.sonar.server.issue.index.IssueIteratorFactory; |
|
|
|
import org.sonar.server.issue.workflow.FunctionExecutor; |
|
|
|
import org.sonar.server.issue.workflow.IssueWorkflow; |
|
|
|
import org.sonar.server.permission.index.AuthorizationTypeSupport; |
|
|
|
import org.sonar.server.permission.index.PermissionIndexer; |
|
|
|
import org.sonar.server.permission.index.PermissionIndexerTester; |
|
|
|
import org.sonar.server.tester.UserSessionRule; |
|
|
|
import org.sonar.server.view.index.ViewDoc; |
|
|
|
import org.sonar.server.view.index.ViewIndexDefinition; |
|
|
|
import org.sonar.server.view.index.ViewIndexer; |
|
|
|
import org.sonar.server.ws.WsActionTester; |
|
|
|
import org.sonar.server.ws.WsResponseCommonFormat; |
|
|
|
import org.sonarqube.ws.Issues.Component; |
|
|
|
import org.sonarqube.ws.Issues.Issue; |
|
|
|
import org.sonarqube.ws.Issues.SearchWsResponse; |
|
|
|
import org.sonarqube.ws.client.issue.IssuesWsParameters; |
|
|
|
|
|
|
|
import static com.google.common.collect.Lists.newArrayList; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.tuple; |
|
|
|
import static org.sonar.api.utils.DateUtils.addDays; |
|
|
|
import static org.sonar.api.utils.DateUtils.parseDateTime; |
|
|
|
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; |
|
|
|
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02; |
|
|
|
import static org.sonar.db.component.ComponentTesting.newDirectory; |
|
|
|
import static org.sonar.db.component.ComponentTesting.newFileDto; |
|
|
|
import static org.sonar.db.component.ComponentTesting.newModuleDto; |
|
|
|
import static org.sonar.db.component.ComponentTesting.newProjectCopy; |
|
|
|
import static org.sonar.db.component.SnapshotTesting.newAnalysis; |
|
|
|
import static org.sonar.db.component.ComponentTesting.newSubView; |
|
|
|
import static org.sonar.db.component.ComponentTesting.newView; |
|
|
|
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; |
|
|
|
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECT_KEYS; |
|
|
|
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SINCE_LEAK_PERIOD; |
|
|
@@ -95,83 +86,56 @@ public class SearchActionComponentsTest { |
|
|
|
public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()), new ViewIndexDefinition(new MapSettings().asConfig())); |
|
|
|
|
|
|
|
private DbClient dbClient = db.getDbClient(); |
|
|
|
private DbSession session = db.getSession(); |
|
|
|
private IssueIndex issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSession, new AuthorizationTypeSupport(userSession)); |
|
|
|
private IssueIndexer issueIndexer = new IssueIndexer(es.client(), dbClient, new IssueIteratorFactory(dbClient)); |
|
|
|
private ViewIndexer viewIndexer = new ViewIndexer(dbClient, es.client()); |
|
|
|
private IssueQueryFactory issueQueryFactory = new IssueQueryFactory(dbClient, System2.INSTANCE, userSession); |
|
|
|
private IssueFieldsSetter issueFieldsSetter = new IssueFieldsSetter(); |
|
|
|
private IssueWorkflow issueWorkflow = new IssueWorkflow(new FunctionExecutor(issueFieldsSetter), issueFieldsSetter); |
|
|
|
private SearchResponseLoader searchResponseLoader = new SearchResponseLoader(userSession, dbClient, new ActionFinder(userSession), new TransitionService(userSession, issueWorkflow)); |
|
|
|
private SearchResponseLoader searchResponseLoader = new SearchResponseLoader(userSession, dbClient, new ActionFinder(userSession), |
|
|
|
new TransitionService(userSession, issueWorkflow)); |
|
|
|
private Languages languages = new Languages(); |
|
|
|
private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), new WsResponseCommonFormat(languages), languages, new AvatarResolverImpl()); |
|
|
|
private WsActionTester ws = new WsActionTester(new SearchAction(userSession, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat)); |
|
|
|
private OrganizationDto defaultOrganization; |
|
|
|
private OrganizationDto otherOrganization1; |
|
|
|
private OrganizationDto otherOrganization2; |
|
|
|
private PermissionIndexerTester permissionIndexerTester = new PermissionIndexerTester(es, issueIndexer); |
|
|
|
private StartupIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client(), issueIndexer); |
|
|
|
|
|
|
|
@Before |
|
|
|
public void setUp() { |
|
|
|
session = dbClient.openSession(false); |
|
|
|
OrganizationDao organizationDao = dbClient.organizationDao(); |
|
|
|
this.defaultOrganization = db.getDefaultOrganization(); |
|
|
|
this.otherOrganization1 = OrganizationTesting.newOrganizationDto().setKey("my-org-1"); |
|
|
|
this.otherOrganization2 = OrganizationTesting.newOrganizationDto().setKey("my-org-2"); |
|
|
|
organizationDao.insert(session, this.otherOrganization1, false); |
|
|
|
organizationDao.insert(session, this.otherOrganization2, false); |
|
|
|
session.commit(); |
|
|
|
} |
|
|
|
private PermissionIndexerTester permissionIndexer = new PermissionIndexerTester(es, issueIndexer); |
|
|
|
|
|
|
|
@After |
|
|
|
public void after() { |
|
|
|
session.close(); |
|
|
|
} |
|
|
|
private WsActionTester ws = new WsActionTester(new SearchAction(userSession, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat)); |
|
|
|
|
|
|
|
@Test |
|
|
|
public void issues_on_different_projects() throws Exception { |
|
|
|
RuleDto rule = newRule(); |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization1, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
IssueDto issue = IssueTesting.newDto(rule, file, project) |
|
|
|
.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") |
|
|
|
.setStatus("OPEN").setResolution("OPEN") |
|
|
|
.setSeverity("MAJOR") |
|
|
|
.setIssueCreationDate(DateUtils.parseDateTime("2014-09-04T00:00:00+0100")) |
|
|
|
.setIssueUpdateDate(DateUtils.parseDateTime("2017-12-04T00:00:00+0100")); |
|
|
|
dbClient.issueDao().insert(session, issue); |
|
|
|
|
|
|
|
ComponentDto project2 = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization2, "P2").setDbKey("PK2")); |
|
|
|
ComponentDto file2 = insertComponent(newFileDto(project2, null, "F2").setDbKey("FK2")); |
|
|
|
IssueDto issue2 = IssueTesting.newDto(rule, file2, project2) |
|
|
|
.setKee("92fd47d4-b650-4037-80bc-7b112bd4eac2") |
|
|
|
.setStatus("OPEN").setResolution("OPEN") |
|
|
|
.setSeverity("MAJOR") |
|
|
|
.setIssueCreationDate(DateUtils.parseDateTime("2014-09-04T00:00:00+0100")) |
|
|
|
.setIssueUpdateDate(DateUtils.parseDateTime("2017-12-04T00:00:00+0100")); |
|
|
|
dbClient.issueDao().insert(session, issue2); |
|
|
|
session.commit(); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
OrganizationDto organization1 = db.organizations().insert(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(organization1); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project)); |
|
|
|
IssueDto issue1 = db.issues().insert(rule, project, file); |
|
|
|
OrganizationDto organization2 = db.organizations().insert(); |
|
|
|
ComponentDto project2 = db.components().insertPublicProject(organization2); |
|
|
|
ComponentDto file2 = db.components().insertComponent(newFileDto(project2)); |
|
|
|
IssueDto issue2 = db.issues().insert(rule, project2, file2); |
|
|
|
allowAnyoneOnProjects(project, project2); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.execute() |
|
|
|
.assertJson(this.getClass(), "issues_on_different_projects.json"); |
|
|
|
SearchWsResponse response = ws.newRequest().executeProtobuf(SearchWsResponse.class); |
|
|
|
|
|
|
|
assertThat(response.getIssuesList()) |
|
|
|
.extracting(Issue::getKey, Issue::getComponent, Issue::getProject) |
|
|
|
.containsExactlyInAnyOrder( |
|
|
|
tuple(issue1.getKey(), file.getKey(), project.getKey()), |
|
|
|
tuple(issue2.getKey(), file2.getKey(), project2.getKey())); |
|
|
|
assertThat(response.getComponentsList()) |
|
|
|
.extracting(Component::getKey, Component::getEnabled) |
|
|
|
.containsExactlyInAnyOrder(tuple(project.getKey(), true), tuple(file.getKey(), true), tuple(project2.getKey(), true), tuple(file2.getKey(), true)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void do_not_return_module_key_on_single_module_projects() throws IOException { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(defaultOrganization, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto module = insertComponent(newModuleDto("M1", project).setDbKey("MK1")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(module, null, "F1").setDbKey("FK1")); |
|
|
|
RuleDto newRule = newRule(); |
|
|
|
IssueDto issueInModule = IssueTesting.newDto(newRule, file, project).setKee("ISSUE_IN_MODULE"); |
|
|
|
IssueDto issueInRootModule = IssueTesting.newDto(newRule, project, project).setKee("ISSUE_IN_ROOT_MODULE"); |
|
|
|
dbClient.issueDao().insert(session, issueInModule, issueInRootModule); |
|
|
|
session.commit(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto module = db.components().insertComponent(newModuleDto("M1", project).setDbKey("MK1")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(module, null, "F1").setDbKey("FK1")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
db.issues().insert(rule, project, file, i -> i.setKee("ISSUE_IN_MODULE")); |
|
|
|
db.issues().insert(rule, project, project, i -> i.setKee("ISSUE_IN_ROOT_MODULE")); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
SearchWsResponse searchResponse = ws.newRequest().executeProtobuf(SearchWsResponse.class); |
|
|
|
assertThat(searchResponse.getIssuesCount()).isEqualTo(2); |
|
|
@@ -188,13 +152,12 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_by_project_uuid() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization1, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); |
|
|
|
dbClient.issueDao().insert(session, issue); |
|
|
|
session.commit(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_PROJECT_UUIDS, project.uuid()) |
|
|
@@ -219,24 +182,18 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_since_leak_period_on_project() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization2, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
dbClient.snapshotDao().insert(session, |
|
|
|
newAnalysis(project) |
|
|
|
.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime())); |
|
|
|
RuleDto rule = newRule(); |
|
|
|
IssueDto issueAfterLeak = IssueTesting.newDto(rule, file, project) |
|
|
|
.setKee(UUID_EXAMPLE_01) |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime())); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
IssueDto issueAfterLeak = db.issues().insert(rule, project, file, i -> i.setKee(UUID_EXAMPLE_01) |
|
|
|
.setIssueCreationDate(parseDateTime("2015-09-04T00:00:00+0100")) |
|
|
|
.setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")); |
|
|
|
IssueDto issueBeforeLeak = IssueTesting.newDto(rule, file, project) |
|
|
|
.setKee(UUID_EXAMPLE_02) |
|
|
|
.setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100"))); |
|
|
|
IssueDto issueBeforeLeak = db.issues().insert(rule, project, file, i -> i.setKee(UUID_EXAMPLE_02) |
|
|
|
.setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) |
|
|
|
.setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")); |
|
|
|
dbClient.issueDao().insert(session, issueAfterLeak, issueBeforeLeak); |
|
|
|
session.commit(); |
|
|
|
.setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100"))); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, project.uuid()) |
|
|
@@ -247,24 +204,19 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_since_leak_period_on_file_in_module_project() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(defaultOrganization, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto module = insertComponent(newModuleDto(project)); |
|
|
|
ComponentDto file = insertComponent(newFileDto(module, null, "F1").setDbKey("FK1")); |
|
|
|
dbClient.snapshotDao().insert(session, |
|
|
|
newAnalysis(project).setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime())); |
|
|
|
RuleDto rule = newRule(); |
|
|
|
IssueDto issueAfterLeak = IssueTesting.newDto(rule, file, project) |
|
|
|
.setKee(UUID_EXAMPLE_01) |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto module = db.components().insertComponent(newModuleDto(project)); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(module, null, "F1").setDbKey("FK1")); |
|
|
|
db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime())); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
IssueDto issueAfterLeak = db.issues().insert(rule, project, file, i -> i.setKee(UUID_EXAMPLE_01) |
|
|
|
.setIssueCreationDate(parseDateTime("2015-09-04T00:00:00+0100")) |
|
|
|
.setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")); |
|
|
|
IssueDto issueBeforeLeak = IssueTesting.newDto(rule, file, project) |
|
|
|
.setKee(UUID_EXAMPLE_02) |
|
|
|
.setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100"))); |
|
|
|
IssueDto issueBeforeLeak = db.issues().insert(rule, project, file, i -> i.setKee(UUID_EXAMPLE_02) |
|
|
|
.setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) |
|
|
|
.setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")); |
|
|
|
dbClient.issueDao().insert(session, issueAfterLeak, issueBeforeLeak); |
|
|
|
session.commit(); |
|
|
|
.setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100"))); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, project.uuid()) |
|
|
@@ -276,20 +228,21 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void project_facet_is_sticky() throws Exception { |
|
|
|
ComponentDto project1 = insertComponent(ComponentTesting.newPublicProjectDto(defaultOrganization, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto project2 = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization1, "P2").setDbKey("PK2")); |
|
|
|
ComponentDto project3 = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization2, "P3").setDbKey("PK3")); |
|
|
|
ComponentDto file1 = insertComponent(newFileDto(project1, null, "F1").setDbKey("FK1")); |
|
|
|
ComponentDto file2 = insertComponent(newFileDto(project2, null, "F2").setDbKey("FK2")); |
|
|
|
ComponentDto file3 = insertComponent(newFileDto(project3, null, "F3").setDbKey("FK3")); |
|
|
|
RuleDto rule = newRule(); |
|
|
|
IssueDto issue1 = IssueTesting.newDto(rule, file1, project1).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); |
|
|
|
IssueDto issue2 = IssueTesting.newDto(rule, file2, project2).setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4"); |
|
|
|
IssueDto issue3 = IssueTesting.newDto(rule, file3, project3).setKee("7b1182fd-b650-4037-80bc-82fd47d4eac2"); |
|
|
|
dbClient.issueDao().insert(session, issue1, issue2, issue3); |
|
|
|
session.commit(); |
|
|
|
OrganizationDto organization1 = db.organizations().insert(); |
|
|
|
OrganizationDto organization2 = db.organizations().insert(); |
|
|
|
OrganizationDto organization3 = db.organizations().insert(); |
|
|
|
ComponentDto project1 = db.components().insertPublicProject(organization1, "P1"); |
|
|
|
ComponentDto project2 = db.components().insertPublicProject(organization2, "P2"); |
|
|
|
ComponentDto project3 = db.components().insertPublicProject(organization3, "P3"); |
|
|
|
ComponentDto file1 = db.components().insertComponent(newFileDto(project1, null, "F1").setDbKey("FK1")); |
|
|
|
ComponentDto file2 = db.components().insertComponent(newFileDto(project2, null, "F2").setDbKey("FK2")); |
|
|
|
ComponentDto file3 = db.components().insertComponent(newFileDto(project3, null, "F3").setDbKey("FK3")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
db.issues().insert(rule, project1, file1, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
db.issues().insert(rule, project2, file2, i -> i.setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4")); |
|
|
|
db.issues().insert(rule, project3, file3, i -> i.setKee("7b1182fd-b650-4037-80bc-82fd47d4eac2")); |
|
|
|
allowAnyoneOnProjects(project1, project2, project3); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_PROJECT_UUIDS, project1.uuid()) |
|
|
@@ -300,13 +253,12 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_by_file_uuid() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(defaultOrganization, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); |
|
|
|
dbClient.issueDao().insert(session, issue); |
|
|
|
session.commit(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_FILE_UUIDS, file.uuid()) |
|
|
@@ -331,16 +283,14 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_by_file_key() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization1, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
ComponentDto unitTest = insertComponent(newFileDto(project, null, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setDbKey("FK2")); |
|
|
|
RuleDto rule = newRule(); |
|
|
|
IssueDto issueOnFile = IssueTesting.newDto(rule, file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); |
|
|
|
IssueDto issueOnTest = IssueTesting.newDto(rule, unitTest, project).setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4"); |
|
|
|
dbClient.issueDao().insert(session, issueOnFile, issueOnTest); |
|
|
|
session.commit(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
ComponentDto unitTest = db.components().insertComponent(newFileDto(project, null, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setDbKey("FK2")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
IssueDto issueOnFile = db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
IssueDto issueOnTest = db.issues().insert(rule, project, unitTest, i -> i.setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4")); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_COMPONENTS, file.getDbKey()) |
|
|
@@ -355,17 +305,15 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void display_file_facet() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization2, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto file1 = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
ComponentDto file2 = insertComponent(newFileDto(project, null, "F2").setDbKey("FK2")); |
|
|
|
ComponentDto file3 = insertComponent(newFileDto(project, null, "F3").setDbKey("FK3")); |
|
|
|
RuleDto newRule = newRule(); |
|
|
|
IssueDto issue1 = IssueTesting.newDto(newRule, file1, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); |
|
|
|
IssueDto issue2 = IssueTesting.newDto(newRule, file2, project).setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4"); |
|
|
|
dbClient.issueDao().insert(session, issue1, issue2); |
|
|
|
session.commit(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "F2").setDbKey("FK2")); |
|
|
|
ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "F3").setDbKey("FK3")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
db.issues().insert(rule, project, file1, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
db.issues().insert(rule, project, file2, i -> i.setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4")); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, project.uuid()) |
|
|
@@ -377,14 +325,13 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_by_directory_path() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(defaultOrganization, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto directory = insertComponent(ComponentTesting.newDirectory(project, "D1", "src/main/java/dir")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1").setPath(directory.path() + "/MyComponent.java")); |
|
|
|
IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); |
|
|
|
dbClient.issueDao().insert(session, issue); |
|
|
|
session.commit(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto directory = db.components().insertComponent(newDirectory(project, "D1", "src/main/java/dir")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1").setPath(directory.path() + "/MyComponent.java")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, directory.uuid()) |
|
|
@@ -409,19 +356,17 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_by_directory_path_in_different_modules() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization1, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto module1 = insertComponent(newModuleDto("M1", project).setDbKey("MK1")); |
|
|
|
ComponentDto module2 = insertComponent(newModuleDto("M2", project).setDbKey("MK2")); |
|
|
|
ComponentDto directory1 = insertComponent(ComponentTesting.newDirectory(module1, "D1", "src/main/java/dir")); |
|
|
|
ComponentDto directory2 = insertComponent(ComponentTesting.newDirectory(module2, "D2", "src/main/java/dir")); |
|
|
|
ComponentDto file1 = insertComponent(newFileDto(module1, directory1, "F1").setDbKey("FK1").setPath(directory1.path() + "/MyComponent.java")); |
|
|
|
insertComponent(newFileDto(module2, directory2, "F2").setDbKey("FK2").setPath(directory2.path() + "/MyComponent.java")); |
|
|
|
RuleDto rule = newRule(); |
|
|
|
IssueDto issue1 = IssueTesting.newDto(rule, file1, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); |
|
|
|
dbClient.issueDao().insert(session, issue1); |
|
|
|
session.commit(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto module1 = db.components().insertComponent(newModuleDto("M1", project).setDbKey("MK1")); |
|
|
|
ComponentDto module2 = db.components().insertComponent(newModuleDto("M2", project).setDbKey("MK2")); |
|
|
|
ComponentDto directory1 = db.components().insertComponent(newDirectory(module1, "D1", "src/main/java/dir")); |
|
|
|
ComponentDto directory2 = db.components().insertComponent(newDirectory(module2, "D2", "src/main/java/dir")); |
|
|
|
ComponentDto file1 = db.components().insertComponent(newFileDto(module1, directory1, "F1").setDbKey("FK1").setPath(directory1.path() + "/MyComponent.java")); |
|
|
|
db.components().insertComponent(newFileDto(module2, directory2, "F2").setDbKey("FK2").setPath(directory2.path() + "/MyComponent.java")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
db.issues().insert(rule, project, file1, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, directory1.uuid()) |
|
|
@@ -458,20 +403,18 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void display_module_facet() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization2, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto module = insertComponent(newModuleDto("M1", project).setDbKey("MK1")); |
|
|
|
ComponentDto subModule1 = insertComponent(newModuleDto("SUBM1", module).setDbKey("SUBMK1")); |
|
|
|
ComponentDto subModule2 = insertComponent(newModuleDto("SUBM2", module).setDbKey("SUBMK2")); |
|
|
|
ComponentDto subModule3 = insertComponent(newModuleDto("SUBM3", module).setDbKey("SUBMK3")); |
|
|
|
ComponentDto file1 = insertComponent(newFileDto(subModule1, null, "F1").setDbKey("FK1")); |
|
|
|
ComponentDto file2 = insertComponent(newFileDto(subModule2, null, "F2").setDbKey("FK2")); |
|
|
|
RuleDto newRule = newRule(); |
|
|
|
IssueDto issue1 = IssueTesting.newDto(newRule, file1, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); |
|
|
|
IssueDto issue2 = IssueTesting.newDto(newRule, file2, project).setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4"); |
|
|
|
dbClient.issueDao().insert(session, issue1, issue2); |
|
|
|
session.commit(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto module = db.components().insertComponent(newModuleDto("M1", project).setDbKey("MK1")); |
|
|
|
ComponentDto subModule1 = db.components().insertComponent(newModuleDto("SUBM1", module).setDbKey("SUBMK1")); |
|
|
|
ComponentDto subModule2 = db.components().insertComponent(newModuleDto("SUBM2", module).setDbKey("SUBMK2")); |
|
|
|
ComponentDto subModule3 = db.components().insertComponent(newModuleDto("SUBM3", module).setDbKey("SUBMK3")); |
|
|
|
ComponentDto file1 = db.components().insertComponent(newFileDto(subModule1, null, "F1").setDbKey("FK1")); |
|
|
|
ComponentDto file2 = db.components().insertComponent(newFileDto(subModule2, null, "F2").setDbKey("FK2")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
IssueDto issue1 = db.issues().insert(rule, project, file1, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
IssueDto issue2 = db.issues().insert(rule, project, file2, i -> i.setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4")); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, module.uuid()) |
|
|
@@ -483,14 +426,13 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void display_directory_facet() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(defaultOrganization, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto directory = insertComponent(ComponentTesting.newDirectory(project, "D1", "src/main/java/dir")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, directory, "F1").setDbKey("FK1").setPath(directory.path() + "/MyComponent.java")); |
|
|
|
IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); |
|
|
|
dbClient.issueDao().insert(session, issue); |
|
|
|
session.commit(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto directory = db.components().insertComponent(newDirectory(project, "D1", "src/main/java/dir")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project, directory, "F1").setDbKey("FK1").setPath(directory.path() + "/MyComponent.java")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
userSession.logIn("john"); |
|
|
|
ws.newRequest() |
|
|
@@ -502,16 +444,14 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_by_view_uuid() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization1, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
ComponentDto view = insertComponent(ComponentTesting.newView(defaultOrganization, "V1").setDbKey("MyView")); |
|
|
|
indexView(view.uuid(), newArrayList(project.uuid())); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
|
|
|
|
userSession.logIn("john") |
|
|
|
.registerComponents(project, file, view); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "V1").setDbKey("MyView")); |
|
|
|
db.components().insertComponent(newProjectCopy(project, view)); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
allowAnyoneOnProjects(project, view); |
|
|
|
indexIssuesAndViews(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, view.uuid()) |
|
|
@@ -521,18 +461,16 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_by_sub_view_uuid() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(defaultOrganization, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
|
|
|
|
ComponentDto view = insertComponent(ComponentTesting.newView(otherOrganization1, "V1").setDbKey("MyView")); |
|
|
|
indexView(view.uuid(), newArrayList(project.uuid())); |
|
|
|
ComponentDto subView = insertComponent(ComponentTesting.newSubView(view, "SV1", "MySubView")); |
|
|
|
indexView(subView.uuid(), newArrayList(project.uuid())); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
userSession.logIn("john") |
|
|
|
.registerComponents(project, file, view, subView); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "V1").setDbKey("MyView")); |
|
|
|
ComponentDto subView = db.components().insertComponent(newSubView(view, "SV1", "MySubView")); |
|
|
|
db.components().insertComponent(newProjectCopy(project, subView)); |
|
|
|
allowAnyoneOnProjects(project, view, subView); |
|
|
|
indexIssuesAndViews(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, subView.uuid()) |
|
|
|
.execute() |
|
|
@@ -541,18 +479,16 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_by_sub_view_uuid_return_only_authorized_view() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(defaultOrganization, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
|
|
|
|
ComponentDto view = insertComponent(ComponentTesting.newView(otherOrganization1, "V1").setDbKey("MyView")); |
|
|
|
indexView(view.uuid(), newArrayList(project.uuid())); |
|
|
|
ComponentDto subView = insertComponent(ComponentTesting.newSubView(view, "SV1", "MySubView")); |
|
|
|
indexView(subView.uuid(), newArrayList(project.uuid())); |
|
|
|
|
|
|
|
// User has wrong permission on the view, no issue will be returned |
|
|
|
userSession.logIn("john") |
|
|
|
.registerComponents(project, file, view, subView); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "V1").setDbKey("MyView")); |
|
|
|
ComponentDto subView = db.components().insertComponent(newSubView(view, "SV1", "MySubView")); |
|
|
|
db.components().insertComponent(newProjectCopy(project, subView)); |
|
|
|
// User has no permission on the view, no issue will be returned |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssuesAndViews(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, subView.uuid()) |
|
|
@@ -562,15 +498,12 @@ public class SearchActionComponentsTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_by_author() throws Exception { |
|
|
|
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(defaultOrganization, "P1").setDbKey("PK1")); |
|
|
|
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
RuleDto newRule = newRule(); |
|
|
|
IssueDto issue1 = IssueTesting.newDto(newRule, file, project).setAuthorLogin("leia").setKee("2bd4eac2-b650-4037-80bc-7b112bd4eac2"); |
|
|
|
IssueDto issue2 = IssueTesting.newDto(newRule, file, project).setAuthorLogin("luke@skywalker.name").setKee("82fd47d4-b650-4037-80bc-7b1182fd47d4"); |
|
|
|
indexPermissions(); |
|
|
|
|
|
|
|
dbClient.issueDao().insert(session, issue1, issue2); |
|
|
|
session.commit(); |
|
|
|
ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); |
|
|
|
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); |
|
|
|
RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); |
|
|
|
db.issues().insert(rule, project, file, i -> i.setAuthorLogin("leia").setKee("2bd4eac2-b650-4037-80bc-7b112bd4eac2")); |
|
|
|
db.issues().insert(rule, project, file, i -> i.setAuthorLogin("luke@skywalker.name").setKee("82fd47d4-b650-4037-80bc-7b1182fd47d4")); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssues(); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
@@ -584,6 +517,7 @@ public class SearchActionComponentsTest { |
|
|
|
.execute() |
|
|
|
.assertJson(this.getClass(), "no_issue.json"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void search_by_application_key() throws Exception { |
|
|
|
ComponentDto project1 = db.components().insertPublicProject(); |
|
|
@@ -593,9 +527,7 @@ public class SearchActionComponentsTest { |
|
|
|
db.components().insertComponents(newProjectCopy("PC2", project2, application)); |
|
|
|
IssueDto issue1 = db.issues().insertIssue(i -> i.setProject(project1)); |
|
|
|
IssueDto issue2 = db.issues().insertIssue(i -> i.setProject(project2)); |
|
|
|
userSession.registerComponents(application, project1, project2); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project1); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project2); |
|
|
|
allowAnyoneOnProjects(project1, project2, application); |
|
|
|
indexIssuesAndViews(); |
|
|
|
|
|
|
|
SearchWsResponse result = ws.newRequest() |
|
|
@@ -612,8 +544,7 @@ public class SearchActionComponentsTest { |
|
|
|
ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); |
|
|
|
db.components().insertComponents(newProjectCopy("PC1", project, application)); |
|
|
|
db.issues().insertIssue(i -> i.setProject(project)); |
|
|
|
userSession.registerComponents(project); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project); |
|
|
|
allowAnyoneOnProjects(project); |
|
|
|
indexIssuesAndViews(); |
|
|
|
|
|
|
|
SearchWsResponse result = ws.newRequest() |
|
|
@@ -628,8 +559,7 @@ public class SearchActionComponentsTest { |
|
|
|
ComponentDto project = db.components().insertPublicProject(); |
|
|
|
ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); |
|
|
|
db.issues().insertIssue(i -> i.setProject(project)); |
|
|
|
userSession.registerComponents(application, project); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project); |
|
|
|
allowAnyoneOnProjects(project, application); |
|
|
|
indexIssuesAndViews(); |
|
|
|
|
|
|
|
SearchWsResponse result = ws.newRequest() |
|
|
@@ -656,9 +586,7 @@ public class SearchActionComponentsTest { |
|
|
|
IssueDto project2Issue1 = db.issues().insertIssue(i -> i.setProject(project2).setIssueCreationDate(addDays(now, -15))); |
|
|
|
IssueDto project2Issue2 = db.issues().insertIssue(i -> i.setProject(project2).setIssueCreationDate(addDays(now, -30))); |
|
|
|
// Permissions and index |
|
|
|
userSession.registerComponents(application, project1, project2); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project1); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project2); |
|
|
|
allowAnyoneOnProjects(project1, project2, application); |
|
|
|
indexIssuesAndViews(); |
|
|
|
|
|
|
|
SearchWsResponse result = ws.newRequest() |
|
|
@@ -680,9 +608,7 @@ public class SearchActionComponentsTest { |
|
|
|
db.components().insertComponents(newProjectCopy("PC2", project2, application)); |
|
|
|
IssueDto issue1 = db.issues().insertIssue(i -> i.setProject(project1)); |
|
|
|
IssueDto issue2 = db.issues().insertIssue(i -> i.setProject(project2)); |
|
|
|
userSession.registerComponents(application, project1, project2); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project1); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project2); |
|
|
|
allowAnyoneOnProjects(project1, project2, application); |
|
|
|
indexIssuesAndViews(); |
|
|
|
|
|
|
|
SearchWsResponse result = ws.newRequest() |
|
|
@@ -712,9 +638,7 @@ public class SearchActionComponentsTest { |
|
|
|
IssueDto project2Issue1 = db.issues().insertIssue(i -> i.setProject(project2).setIssueCreationDate(addDays(now, -15))); |
|
|
|
IssueDto project2Issue2 = db.issues().insertIssue(i -> i.setProject(project2).setIssueCreationDate(addDays(now, -30))); |
|
|
|
// Permissions and index |
|
|
|
userSession.registerComponents(application, project1, project2); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project1); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project2); |
|
|
|
allowAnyoneOnProjects(project1, project2, application); |
|
|
|
indexIssuesAndViews(); |
|
|
|
|
|
|
|
SearchWsResponse result = ws.newRequest() |
|
|
@@ -745,9 +669,7 @@ public class SearchActionComponentsTest { |
|
|
|
IssueDto project2Issue1 = db.issues().insertIssue(i -> i.setProject(project2).setIssueCreationDate(addDays(now, -15))); |
|
|
|
IssueDto project2Issue2 = db.issues().insertIssue(i -> i.setProject(project2).setIssueCreationDate(addDays(now, -30))); |
|
|
|
// Permissions and index |
|
|
|
userSession.registerComponents(application, project1, project2); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project1); |
|
|
|
permissionIndexerTester.allowOnlyAnyone(project2); |
|
|
|
allowAnyoneOnProjects(project1, project2, application); |
|
|
|
indexIssuesAndViews(); |
|
|
|
|
|
|
|
SearchWsResponse result = ws.newRequest() |
|
|
@@ -760,43 +682,17 @@ public class SearchActionComponentsTest { |
|
|
|
.doesNotContain(project1Issue2.getKey(), project2Issue1.getKey(), project2Issue2.getKey()); |
|
|
|
} |
|
|
|
|
|
|
|
private RuleDto newRule() { |
|
|
|
RuleDto rule = RuleTesting.newXooX1() |
|
|
|
.setName("Rule name") |
|
|
|
.setDescription("Rule desc") |
|
|
|
.setStatus(RuleStatus.READY); |
|
|
|
db.rules().insert(rule.getDefinition()); |
|
|
|
session.commit(); |
|
|
|
return rule; |
|
|
|
} |
|
|
|
|
|
|
|
private void indexPermissions() { |
|
|
|
permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes()); |
|
|
|
} |
|
|
|
|
|
|
|
private IssueDto insertIssue(IssueDto issue) { |
|
|
|
dbClient.issueDao().insert(session, issue); |
|
|
|
session.commit(); |
|
|
|
indexIssues(); |
|
|
|
return issue; |
|
|
|
} |
|
|
|
|
|
|
|
private ComponentDto insertComponent(ComponentDto component) { |
|
|
|
dbClient.componentDao().insert(session, component); |
|
|
|
session.commit(); |
|
|
|
return component; |
|
|
|
private void allowAnyoneOnProjects(ComponentDto... projects) { |
|
|
|
userSession.registerComponents(projects); |
|
|
|
Arrays.stream(projects).forEach(p -> permissionIndexer.allowOnlyAnyone(p)); |
|
|
|
} |
|
|
|
|
|
|
|
private void indexIssues() { |
|
|
|
issueIndexer.indexOnStartup(issueIndexer.getIndexTypes()); |
|
|
|
} |
|
|
|
|
|
|
|
private void indexView(String viewUuid, List<String> projects) { |
|
|
|
viewIndexer.index(new ViewDoc().setUuid(viewUuid).setProjects(projects)); |
|
|
|
issueIndexer.indexOnStartup(null); |
|
|
|
} |
|
|
|
|
|
|
|
private void indexIssuesAndViews() { |
|
|
|
issueIndexer.indexOnStartup(null); |
|
|
|
indexIssues(); |
|
|
|
viewIndexer.indexOnStartup(null); |
|
|
|
} |
|
|
|
} |