aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-es
diff options
context:
space:
mode:
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>2023-06-30 11:42:57 +0200
committersonartech <sonartech@sonarsource.com>2023-07-03 20:03:13 +0000
commitebece82669c46e8657d10407ee1d5dc957af3a6c (patch)
tree1569745006df20ebcea3f565597ddd3610dd649d /server/sonar-webserver-es
parentb819971ea23f4d63feed5147608a570f026d7906 (diff)
downloadsonarqube-ebece82669c46e8657d10407ee1d5dc957af3a6c.tar.gz
sonarqube-ebece82669c46e8657d10407ee1d5dc957af3a6c.zip
SONAR-19558 Update rest of tests for other modules
Diffstat (limited to 'server/sonar-webserver-es')
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java64
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/es/RecoveryIndexerTest.java2
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java81
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTestCommon.java2
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java70
5 files changed, 118 insertions, 101 deletions
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java
index 7d32bcd743d..9f0414d5e4b 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java
@@ -28,6 +28,9 @@ import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.entity.EntityDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchIdResult;
import org.sonar.server.es.SearchOptions;
@@ -43,7 +46,7 @@ public class ComponentIndexSearchTest {
@Rule
public EsTester es = EsTester.create();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone().logIn();
@Rule
@@ -55,79 +58,84 @@ public class ComponentIndexSearchTest {
@Test
public void filter_by_name() {
- ComponentDto ignoredProject = db.components().insertPrivateProject(p -> p.setName("ignored project")).getMainBranchComponent();
- ComponentDto project = db.components().insertPrivateProject(p -> p.setName("Project Shiny name")).getMainBranchComponent();
- index(ignoredProject, project);
+ ProjectData ignoredProject = db.components().insertPrivateProject(p -> p.setName("ignored project"));
+ ProjectData project = db.components().insertPrivateProject(p -> p.setName("Project Shiny name"));
+ index(ignoredProject.getProjectDto(), project.getProjectDto());
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setQuery("shiny").build(), new SearchOptions());
- assertThat(result.getUuids()).containsExactlyInAnyOrder(project.uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(project.projectUuid());
}
@Test
public void filter_by_key_with_exact_match() {
- ComponentDto ignoredProject = db.components().insertPrivateProject(p -> p.setKey("ignored-project")).getMainBranchComponent();
- ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("shiny-project")).getMainBranchComponent();
+ ProjectData ignoredProject = db.components().insertPrivateProject(p -> p.setKey("ignored-project"));
+ ProjectData project = db.components().insertPrivateProject(p -> p.setKey("shiny-project"));
db.components().insertPrivateProject(p -> p.setKey("another-shiny-project")).getMainBranchComponent();
- index(ignoredProject, project);
+ index(ignoredProject.getProjectDto(), project.getProjectDto());
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setQuery("shiny-project").build(), new SearchOptions());
- assertThat(result.getUuids()).containsExactlyInAnyOrder(project.uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(project.projectUuid());
}
@Test
public void filter_by_qualifier() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData project = db.components().insertPrivateProject();
ComponentDto portfolio = db.components().insertPrivatePortfolio();
- index(project);
- index(portfolio);
+ index(project.getProjectDto());
+ index(db.components().getPortfolioDto(portfolio));
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setQualifiers(singleton(Qualifiers.PROJECT)).build(), new SearchOptions());
- assertThat(result.getUuids()).containsExactlyInAnyOrder(project.uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(project.projectUuid());
}
@Test
public void order_by_name_case_insensitive() {
- ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("PROJECT 2")).getMainBranchComponent();
- ComponentDto project3 = db.components().insertPrivateProject(p -> p.setName("project 3")).getMainBranchComponent();
- ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("Project 1")).getMainBranchComponent();
- index(project1, project2, project3);
+ ProjectData project2 = db.components().insertPrivateProject(p -> p.setName("PROJECT 2"));
+ ProjectData project3 = db.components().insertPrivateProject(p -> p.setName("project 3"));
+ ProjectData project1 = db.components().insertPrivateProject(p -> p.setName("Project 1"));
+ index(project1.getProjectDto(), project2.getProjectDto(), project3.getProjectDto());
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().build(), new SearchOptions());
- assertThat(result.getUuids()).containsExactly(project1.uuid(), project2.uuid(), project3.uuid());
+ assertThat(result.getUuids()).containsExactly(project1.projectUuid(),
+ project2.projectUuid(),
+ project3.projectUuid());
}
@Test
public void paginate_results() {
- List<ComponentDto> projects = IntStream.range(0, 9)
- .mapToObj(i -> db.components().insertPrivateProject(p -> p.setName("project " + i)).getMainBranchComponent())
+ List<ProjectData> projects = IntStream.range(0, 9)
+ .mapToObj(i -> db.components().insertPrivateProject(p -> p.setName("project " + i)))
.toList();
- index(projects.toArray(new ComponentDto[0]));
+ ProjectDto[] projectDtos = projects.stream().map(p -> p.getProjectDto()).toArray(ProjectDto[]::new);
+ index(projectDtos);
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().build(), new SearchOptions().setPage(2, 3));
- assertThat(result.getUuids()).containsExactlyInAnyOrder(projects.get(3).uuid(), projects.get(4).uuid(), projects.get(5).uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(projects.get(3).projectUuid(),
+ projects.get(4).projectUuid(),
+ projects.get(5).projectUuid());
}
@Test
public void filter_unauthorized_components() {
- ComponentDto unauthorizedProject = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectDto unauthorizedProject = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
indexer.indexAll();
authorizationIndexerTester.allowOnlyAnyone(project1);
authorizationIndexerTester.allowOnlyAnyone(project2);
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().build(), new SearchOptions());
- assertThat(result.getUuids()).containsExactlyInAnyOrder(project1.uuid(), project2.uuid())
- .doesNotContain(unauthorizedProject.uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(project1.getUuid(), project2.getUuid())
+ .doesNotContain(unauthorizedProject.getUuid());
}
- private void index(ComponentDto... components) {
+ private void index(EntityDto... components) {
indexer.indexAll();
Arrays.stream(components).forEach(authorizationIndexerTester::allowOnlyAnyone);
}
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/es/RecoveryIndexerTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/es/RecoveryIndexerTest.java
index a87e495aa10..44d133b3b3f 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/es/RecoveryIndexerTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/es/RecoveryIndexerTest.java
@@ -67,7 +67,7 @@ public class RecoveryIndexerTest {
@Rule
public EsTester es = EsTester.createCustom();
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, true);
@Rule
public LogTester logTester = new LogTester().setLevel(TRACE);
@Rule
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java
index c9adbb2cede..2e888fdb0ef 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java
@@ -37,6 +37,7 @@ import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeQueueDto.Status;
import org.sonar.db.ce.CeTaskTypes;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.es.EsIndexSyncInProgressException;
@@ -51,7 +52,7 @@ public class IssueIndexSyncProgressCheckerTest {
private final System2 system2 = new System2();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private final IssueIndexSyncProgressChecker underTest = new IssueIndexSyncProgressChecker(db.getDbClient());
@@ -82,16 +83,16 @@ public class IssueIndexSyncProgressCheckerTest {
public void return_has_failure_true_if_exists_task() {
assertThat(underTest.getIssueSyncProgress(db.getSession()).hasFailures()).isFalse();
- ProjectDto projectDto1 = insertProjectWithBranches(false, 0);
- insertCeActivity("TASK_1", projectDto1, SUCCESS);
+ ProjectData projectData1 = insertProjectWithBranches(false, 0);
+ insertCeActivity("TASK_1", projectData1, SUCCESS);
- ProjectDto projectDto2 = insertProjectWithBranches(false, 0);
- insertCeActivity("TASK_2", projectDto2, SUCCESS);
+ ProjectData projectData2 = insertProjectWithBranches(false, 0);
+ insertCeActivity("TASK_2", projectData2, SUCCESS);
assertThat(underTest.getIssueSyncProgress(db.getSession()).hasFailures()).isFalse();
- ProjectDto projectDto3 = insertProjectWithBranches(true, 0);
- insertCeActivity("TASK_3", projectDto3, FAILED);
+ ProjectData projectData3 = insertProjectWithBranches(true, 0);
+ insertCeActivity("TASK_3", projectData3, FAILED);
assertThat(underTest.getIssueSyncProgress(db.getSession()).hasFailures()).isTrue();
}
@@ -205,10 +206,10 @@ public class IssueIndexSyncProgressCheckerTest {
@Test
public void checkIfAnyComponentsNeedIssueSync_throws_exception_if_all_components_have_need_issue_sync_TRUE() {
- ProjectDto projectDto1 = insertProjectWithBranches(true, 0);
- ProjectDto projectDto2 = insertProjectWithBranches(true, 0);
+ ProjectData projectData1 = insertProjectWithBranches(true, 0);
+ ProjectData projectData2 = insertProjectWithBranches(true, 0);
DbSession session = db.getSession();
- List<String> projectKeys = Arrays.asList(projectDto1.getKey(), projectDto2.getKey());
+ List<String> projectKeys = Arrays.asList(projectData1.getProjectDto().getKey(), projectData2.getProjectDto().getKey());
assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session, projectKeys))
.isInstanceOf(EsIndexSyncInProgressException.class)
.hasFieldOrPropertyWithValue("httpCode", 503)
@@ -218,18 +219,18 @@ public class IssueIndexSyncProgressCheckerTest {
@Test
public void checkIfAnyComponentsNeedIssueSync_does_not_throw_exception_if_all_components_have_need_issue_sync_FALSE() {
underTest.checkIfAnyComponentsNeedIssueSync(db.getSession(), Collections.emptyList());
- ProjectDto projectDto1 = insertProjectWithBranches(false, 0);
- ProjectDto projectDto2 = insertProjectWithBranches(false, 0);
- underTest.checkIfAnyComponentsNeedIssueSync(db.getSession(), Arrays.asList(projectDto1.getKey(), projectDto2.getKey()));
+ ProjectData projectData1 = insertProjectWithBranches(false, 0);
+ ProjectData projectData2 = insertProjectWithBranches(false, 0);
+ underTest.checkIfAnyComponentsNeedIssueSync(db.getSession(), Arrays.asList(projectData1.getProjectDto().getKey(), projectData2.getProjectDto().getKey()));
}
@Test
public void checkIfAnyComponentsNeedIssueSync_throws_exception_if_at_least_one_component_has_need_issue_sync_TRUE() {
- ProjectDto projectDto1 = insertProjectWithBranches(false, 0);
- ProjectDto projectDto2 = insertProjectWithBranches(true, 0);
+ ProjectData projectData1 = insertProjectWithBranches(false, 0);
+ ProjectData projectData2 = insertProjectWithBranches(true, 0);
DbSession session = db.getSession();
- List<String> projectKeys = Arrays.asList(projectDto1.getKey(), projectDto2.getKey());
+ List<String> projectKeys = Arrays.asList(projectData1.getProjectDto().getKey(), projectData2.getProjectDto().getKey());
assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session, projectKeys))
.isInstanceOf(EsIndexSyncInProgressException.class)
.hasFieldOrPropertyWithValue("httpCode", 503)
@@ -238,15 +239,15 @@ public class IssueIndexSyncProgressCheckerTest {
@Test
public void checkIfComponentNeedIssueSync_single_component() {
- ProjectDto projectDto1 = insertProjectWithBranches(true, 0);
- ProjectDto projectDto2 = insertProjectWithBranches(false, 0);
+ ProjectData projectData1 = insertProjectWithBranches(true, 0);
+ ProjectData projectData2 = insertProjectWithBranches(false, 0);
DbSession session = db.getSession();
// do nothing when need issue sync false
- underTest.checkIfComponentNeedIssueSync(session, projectDto2.getKey());
+ underTest.checkIfComponentNeedIssueSync(session, projectData2.getProjectDto().getKey());
// throws if flag set to TRUE
- String key = projectDto1.getKey();
+ String key = projectData1.getProjectDto().getKey();
assertThatThrownBy(() -> underTest.checkIfComponentNeedIssueSync(session, key))
.isInstanceOf(EsIndexSyncInProgressException.class)
.hasFieldOrPropertyWithValue("httpCode", 503)
@@ -255,14 +256,14 @@ public class IssueIndexSyncProgressCheckerTest {
@Test
public void checkIfAnyComponentsNeedIssueSync_single_view_subview_or_app() {
- ProjectDto projectDto1 = insertProjectWithBranches(true, 0);
+ ProjectData projectData1 = insertProjectWithBranches(true, 0);
ComponentDto app = db.components().insertPublicApplication().getMainBranchComponent();
ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subview = db.components().insertSubView(view);
DbSession session = db.getSession();
- List<String> appViewOrSubviewKeys = Arrays.asList(projectDto1.getKey(), app.getKey(), view.getKey(), subview.getKey());
+ List<String> appViewOrSubviewKeys = Arrays.asList(projectData1.getProjectDto().getKey(), app.getKey(), view.getKey(), subview.getKey());
// throws if flag set to TRUE
assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session,
@@ -287,32 +288,32 @@ public class IssueIndexSyncProgressCheckerTest {
@Test
public void doProjectNeedIssueSync() {
- ProjectDto projectDto1 = insertProjectWithBranches(false, 0);
- assertThat(underTest.doProjectNeedIssueSync(db.getSession(), projectDto1.getUuid())).isFalse();
- ProjectDto projectDto2 = insertProjectWithBranches(true, 0);
- assertThat(underTest.doProjectNeedIssueSync(db.getSession(), projectDto2.getUuid())).isTrue();
+ ProjectData projectData1 = insertProjectWithBranches(false, 0);
+ assertThat(underTest.doProjectNeedIssueSync(db.getSession(), projectData1.getProjectDto().getUuid())).isFalse();
+ ProjectData projectData2 = insertProjectWithBranches(true, 0);
+ assertThat(underTest.doProjectNeedIssueSync(db.getSession(), projectData2.getProjectDto().getUuid())).isTrue();
}
@Test
public void findProjectUuidsWithIssuesSyncNeed() {
- ProjectDto projectDto1 = insertProjectWithBranches(false, 0);
- ProjectDto projectDto2 = insertProjectWithBranches(false, 0);
- ProjectDto projectDto3 = insertProjectWithBranches(true, 0);
- ProjectDto projectDto4 = insertProjectWithBranches(true, 0);
+ ProjectData projectData1 = insertProjectWithBranches(false, 0);
+ ProjectData projectData2 = insertProjectWithBranches(false, 0);
+ ProjectData projectData3 = insertProjectWithBranches(true, 0);
+ ProjectData projectData4 = insertProjectWithBranches(true, 0);
assertThat(underTest.findProjectUuidsWithIssuesSyncNeed(db.getSession(),
- Arrays.asList(projectDto1.getUuid(), projectDto2.getUuid(), projectDto3.getUuid(), projectDto4.getUuid())))
- .containsOnly(projectDto3.getUuid(), projectDto4.getUuid());
+ Arrays.asList(projectData1.getProjectDto().getUuid(), projectData2.getProjectDto().getUuid(), projectData3.getProjectDto().getUuid(), projectData4.getProjectDto().getUuid())))
+ .containsOnly(projectData3.getProjectDto().getUuid(), projectData4.getProjectDto().getUuid());
}
- private ProjectDto insertProjectWithBranches(boolean needIssueSync, int numberOfBranches) {
- ProjectDto projectDto = db.components()
+ private ProjectData insertProjectWithBranches(boolean needIssueSync, int numberOfBranches) {
+ ProjectData projectData = db.components()
.insertPrivateProject(branchDto -> branchDto.setNeedIssueSync(needIssueSync), c -> {
}, p -> {
- }).getProjectDto();
+ });
IntStream.range(0, numberOfBranches).forEach(
- i -> db.components().insertProjectBranch(projectDto, branchDto -> branchDto.setNeedIssueSync(needIssueSync)));
- return projectDto;
+ i -> db.components().insertProjectBranch(projectData.getProjectDto(), branchDto -> branchDto.setNeedIssueSync(needIssueSync)));
+ return projectData;
}
private CeQueueDto insertCeQueue(String uuid, CeQueueDto.Status status) {
@@ -324,14 +325,14 @@ public class IssueIndexSyncProgressCheckerTest {
return queueDto;
}
- private CeActivityDto insertCeActivity(String uuid, ProjectDto projectDto, CeActivityDto.Status status) {
+ private CeActivityDto insertCeActivity(String uuid, ProjectData projectData, CeActivityDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setUuid(uuid);
queueDto.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC);
CeActivityDto dto = new CeActivityDto(queueDto);
- dto.setComponentUuid(projectDto.getUuid());
- dto.setEntityUuid(projectDto.getUuid());
+ dto.setComponentUuid(projectData.getMainBranchComponent().uuid());
+ dto.setEntityUuid(projectData.projectUuid());
dto.setStatus(status);
dto.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC);
dto.setAnalysisUuid(uuid + "_AA");
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTestCommon.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTestCommon.java
index 4fea3b36ef9..762cf3ddfd4 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTestCommon.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTestCommon.java
@@ -52,7 +52,7 @@ public class IssueIndexTestCommon {
public UserSessionRule userSessionRule = UserSessionRule.standalone();
protected final System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(getTimeZone("GMT-01:00"));
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, true);
private final AsyncIssueIndexing asyncIssueIndexing = mock(AsyncIssueIndexing.class);
protected final IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), asyncIssueIndexing);
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
index fbd161d712e..9a95f7fb319 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
@@ -69,7 +69,7 @@ public class IssueQueryFactoryTest {
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
@Rule
public LogTester logTester = new LogTester();
@@ -81,7 +81,8 @@ public class IssueQueryFactoryTest {
public void create_from_parameters() {
String ruleAdHocName = "New Name";
UserDto user = db.users().insertUser(u -> u.setLogin("joanna"));
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
RuleDto rule1 = ruleDbTester.insert(r -> r.setAdHocName(ruleAdHocName));
@@ -115,7 +116,7 @@ public class IssueQueryFactoryTest {
assertThat(query.statuses()).containsOnly("CLOSED");
assertThat(query.resolutions()).containsOnly("FALSE-POSITIVE");
assertThat(query.resolved()).isTrue();
- assertThat(query.projectUuids()).containsOnly(project.uuid());
+ assertThat(query.projectUuids()).containsOnly(projectData.projectUuid());
assertThat(query.files()).containsOnly(file.uuid());
assertThat(query.assignees()).containsOnly(user.getUuid());
assertThat(query.scopes()).containsOnly("TEST", "MAIN");
@@ -316,15 +317,16 @@ public class IssueQueryFactoryTest {
ProjectData projectData2 = db.components().insertPublicProject();
ComponentDto project2 = projectData2.getMainBranchComponent();
ProjectData applicationData = db.components().insertPublicApplication();
- ComponentDto application = applicationData.getMainBranchComponent();
- db.components().insertComponents(newProjectCopy("PC1", project1, application));
- db.components().insertComponents(newProjectCopy("PC2", project2, application));
+ ComponentDto applicationMainBranch = applicationData.getMainBranchComponent();
+ db.components().insertComponents(newProjectCopy("PC1", project1, applicationMainBranch));
+ db.components().insertComponents(newProjectCopy("PC2", project2, applicationMainBranch));
userSession.registerApplication(applicationData.getProjectDto())
- .registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto());
+ .registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto())
+ .registerBranches(applicationData.getMainBranchDto());
- IssueQuery result = underTest.create(new SearchRequest().setComponentUuids(singletonList(application.uuid())));
+ IssueQuery result = underTest.create(new SearchRequest().setComponentUuids(singletonList(applicationMainBranch.uuid())));
- assertThat(result.viewUuids()).containsExactlyInAnyOrder(application.uuid());
+ assertThat(result.viewUuids()).containsExactlyInAnyOrder(applicationMainBranch.uuid());
}
@Test
@@ -364,7 +366,8 @@ public class IssueQueryFactoryTest {
db.components().insertComponents(newProjectCopy("PC2", project2, application));
db.components().insertComponents(newProjectCopy("PC3", project3, application));
db.components().insertComponents(newProjectCopy("PC4", project4, application));
- userSession.registerApplication(applicationData.getProjectDto());
+ userSession.registerApplication(applicationData.getProjectDto())
+ .registerBranches(applicationData.getMainBranchDto());
userSession.registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto(), projectData3.getProjectDto(), projectData4.getProjectDto());
IssueQuery result = underTest.create(new SearchRequest()
@@ -393,12 +396,13 @@ public class IssueQueryFactoryTest {
@Test
public void param_componentUuids_enables_search_on_project_tree_by_default() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
SearchRequest request = new SearchRequest()
- .setComponentUuids(asList(project.uuid()));
+ .setComponentUuids(asList(mainBranch.uuid()));
IssueQuery query = underTest.create(request);
- assertThat(query.projectUuids()).containsExactly(project.uuid());
+ assertThat(query.projectUuids()).containsExactly(projectData.projectUuid());
assertThat(query.onComponentOnly()).isFalse();
}
@@ -455,21 +459,22 @@ public class IssueQueryFactoryTest {
@Test
public void search_issue_from_branch() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
String branchName = randomAlphanumeric(248);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey(branchName));
assertThat(underTest.create(new SearchRequest()
.setProjectKeys(singletonList(branch.getKey()))
.setBranch(branchName)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
- .containsOnly(branch.uuid(), singletonList(project.uuid()), false);
+ .containsOnly(branch.uuid(), singletonList(projectData.projectUuid()), false);
assertThat(underTest.create(new SearchRequest()
.setComponentKeys(singletonList(branch.getKey()))
.setBranch(branchName)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
- .containsOnly(branch.uuid(), singletonList(project.uuid()), false);
+ .containsOnly(branch.uuid(), singletonList(projectData.projectUuid()), false);
}
@Test
@@ -517,19 +522,20 @@ public class IssueQueryFactoryTest {
@Test
public void search_issues_from_main_branch() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- db.components().insertProjectBranch(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.components().insertProjectBranch(mainBranch);
assertThat(underTest.create(new SearchRequest()
- .setProjectKeys(singletonList(project.getKey()))
+ .setProjectKeys(singletonList(projectData.projectKey()))
.setBranch(DEFAULT_MAIN_BRANCH_NAME)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
- .containsOnly(project.uuid(), singletonList(project.uuid()), true);
+ .containsOnly(mainBranch.uuid(), singletonList(projectData.projectUuid()), true);
assertThat(underTest.create(new SearchRequest()
- .setComponentKeys(singletonList(project.getKey()))
+ .setComponentKeys(singletonList(mainBranch.getKey()))
.setBranch(DEFAULT_MAIN_BRANCH_NAME)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
- .containsOnly(project.uuid(), singletonList(project.uuid()), true);
+ .containsOnly(mainBranch.uuid(), singletonList(projectData.projectUuid()), true);
}
@Test
@@ -546,11 +552,12 @@ public class IssueQueryFactoryTest {
.registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto())
.addProjectPermission(USER, applicationData.getProjectDto())
.addProjectPermission(USER, projectData1.getProjectDto())
- .addProjectPermission(USER, projectData2.getProjectDto());
+ .addProjectPermission(USER, projectData2.getProjectDto())
+ .registerBranches(applicationData.getMainBranchDto());
assertThat(underTest.create(new SearchRequest()
.setComponentKeys(singletonList(application.getKey())))
- .viewUuids()).containsExactly(application.uuid());
+ .viewUuids()).containsExactly(applicationData.getMainBranchComponent().uuid());
}
@Test
@@ -560,10 +567,11 @@ public class IssueQueryFactoryTest {
String branchName2 = "app-branch2";
ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey(branchName1));
ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey(branchName2));
- ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1")).getMainBranchComponent();
- ComponentDto project1Branch1 = db.components().insertProjectBranch(project1);
- db.components().insertComponent(newFileDto(project1Branch1, project1.uuid()));
- ComponentDto project1Branch2 = db.components().insertProjectBranch(project1);
+ ProjectData projectData1 = db.components().insertPrivateProject(p -> p.setKey("prj1"));
+ ComponentDto mainBranch1 = projectData1.getMainBranchComponent();
+ ComponentDto project1Branch1 = db.components().insertProjectBranch(mainBranch1);
+ db.components().insertComponent(newFileDto(project1Branch1, mainBranch1.uuid()));
+ ComponentDto project1Branch2 = db.components().insertProjectBranch(mainBranch1);
ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2")).getMainBranchComponent();
db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1));
db.components().insertComponents(newProjectCopy(project2, applicationBranch1));
@@ -579,10 +587,10 @@ public class IssueQueryFactoryTest {
// Search on project1Branch1
assertThat(underTest.create(new SearchRequest()
.setComponentKeys(singletonList(applicationBranch1.getKey()))
- .setProjectKeys(singletonList(project1.getKey()))
+ .setProjectKeys(singletonList(mainBranch1.getKey()))
.setBranch(branchName1)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
- .containsOnly(applicationBranch1.uuid(), singletonList(project1.uuid()), false);
+ .containsOnly(applicationBranch1.uuid(), singletonList(projectData1.projectUuid()), false);
}
@Test