aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Marion <steve.marion@sonarsource.com>2024-07-31 11:26:30 +0200
committersonartech <sonartech@sonarsource.com>2024-08-12 20:02:45 +0000
commitd989ded179b6997b5814459b2e57447a197c0ade (patch)
tree044b17c8a7a4f330f0bc83d2d621c73799c528e6
parentb9f79022490910dc8b3ba4ea21b2b001479c7a47 (diff)
downloadsonarqube-d989ded179b6997b5814459b2e57447a197c0ade.tar.gz
sonarqube-d989ded179b6997b5814459b2e57447a197c0ade.zip
SONAR-22649 remove caching of dbSession in tester. This enables centralised session management.
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/audit/AuditDbTester.java5
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java49
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectLinkDbTester.java5
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/event/EventDbTester.java9
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java13
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java17
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java9
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java19
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/plugin/PluginDbTester.java9
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/InternalComponentPropertyDbTester.java7
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyDbTester.java12
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java27
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java41
13 files changed, 98 insertions, 124 deletions
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/audit/AuditDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/audit/AuditDbTester.java
index 3c3a5e5164a..7afa5fe8908 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/audit/AuditDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/audit/AuditDbTester.java
@@ -20,24 +20,21 @@
package org.sonar.db.audit;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
public class AuditDbTester {
private final DbTester db;
private final DbClient dbClient;
- private final DbSession dbSession;
public AuditDbTester(DbTester db) {
this.db = db;
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
}
public final void insertRandomAuditEntry(long createdAt) {
AuditDto auditDto = AuditTesting.newAuditDto(createdAt);
- dbClient.auditDao().insert(dbSession, auditDto);
+ dbClient.auditDao().insert(db.getSession(), auditDto);
db.commit();
}
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
index 34317e908dd..afeaad2f40e 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
@@ -25,7 +25,6 @@ import javax.annotation.Nullable;
import org.sonar.api.resources.Qualifiers;
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.portfolio.PortfolioDto;
import org.sonar.db.portfolio.PortfolioProjectDto;
@@ -40,12 +39,10 @@ import static org.sonar.db.portfolio.PortfolioDto.SelectionMode.NONE;
public class ComponentDbTester {
private final DbTester db;
private final DbClient dbClient;
- private final DbSession dbSession;
public ComponentDbTester(DbTester db) {
this.db = db;
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
}
public SnapshotDto insertProjectAndSnapshot(ComponentDto component) {
@@ -54,7 +51,7 @@ public class ComponentDbTester {
}
public SnapshotDto insertPortfolioAndSnapshot(ComponentDto component) {
- dbClient.componentDao().insert(dbSession, component);
+ dbClient.componentDao().insert(db.getSession(), component);
return insertSnapshot(component);
}
@@ -68,17 +65,17 @@ public class ComponentDbTester {
}
public ProjectDto getProjectDto(ComponentDto project) {
- return db.getDbClient().projectDao().selectByUuid(dbSession, project.uuid())
+ return db.getDbClient().projectDao().selectByUuid(db.getSession(), project.uuid())
.orElseThrow(() -> new IllegalStateException("Project has invalid configuration"));
}
public ComponentDto getComponentDto(ProjectDto project) {
- return db.getDbClient().componentDao().selectByUuid(dbSession, project.getUuid())
+ return db.getDbClient().componentDao().selectByUuid(db.getSession(), project.getUuid())
.orElseThrow(() -> new IllegalStateException("Can't find project"));
}
public ComponentDto getComponentDto(BranchDto branch) {
- return db.getDbClient().componentDao().selectByUuid(dbSession, branch.getUuid())
+ return db.getDbClient().componentDao().selectByUuid(db.getSession(), branch.getUuid())
.orElseThrow(() -> new IllegalStateException("Can't find branch"));
}
@@ -168,6 +165,10 @@ public class ComponentDbTester {
return insertComponent(ComponentTesting.newFileDto(projectComponent));
}
+ public final ComponentDto insertFile(ComponentDto projectComponent) {
+ return insertComponent(ComponentTesting.newFileDto(projectComponent));
+ }
+
public final ComponentDto insertPrivateProject(String uuid, Consumer<ComponentDto> dtoPopulator) {
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(uuid), true, defaults(), dtoPopulator);
}
@@ -255,7 +256,7 @@ public class ComponentDbTester {
}
public PortfolioDto getPortfolioDto(ComponentDto portfolio) {
- return db.getDbClient().portfolioDao().selectByUuid(dbSession, portfolio.uuid())
+ return db.getDbClient().portfolioDao().selectByUuid(db.getSession(), portfolio.uuid())
.orElseThrow(() -> new IllegalStateException("Portfolio has invalid configuration"));
}
@@ -265,7 +266,7 @@ public class ComponentDbTester {
PortfolioDto portfolioDto = toPortfolioDto(componentDto, System2.INSTANCE.now());
portfolioPopulator.accept(portfolioDto);
- dbClient.portfolioDao().insert(dbSession, portfolioDto);
+ dbClient.portfolioDao().insert(db.getSession(), portfolioDto);
db.commit();
return componentDto;
}
@@ -288,7 +289,7 @@ public class ComponentDbTester {
public void addPortfolioReference(String portfolioUuid, String... referencerUuids) {
for (String uuid : referencerUuids) {
- dbClient.portfolioDao().addReference(dbSession, portfolioUuid, uuid);
+ dbClient.portfolioDao().addReference(db.getSession(), portfolioUuid, uuid);
}
db.commit();
}
@@ -307,7 +308,7 @@ public class ComponentDbTester {
public void addPortfolioProject(String portfolioUuid, String... projectUuids) {
for (String uuid : projectUuids) {
- dbClient.portfolioDao().addProject(dbSession, portfolioUuid, uuid);
+ dbClient.portfolioDao().addProject(db.getSession(), portfolioUuid, uuid);
}
db.commit();
}
@@ -322,7 +323,7 @@ public class ComponentDbTester {
public void addPortfolioProject(PortfolioDto portfolioDto, ProjectDto... projects) {
for (ProjectDto project : projects) {
- dbClient.portfolioDao().addProject(dbSession, portfolioDto.getUuid(), project.getUuid());
+ dbClient.portfolioDao().addProject(db.getSession(), portfolioDto.getUuid(), project.getUuid());
}
db.commit();
}
@@ -336,7 +337,7 @@ public class ComponentDbTester {
}
public void addPortfolioProjectBranch(String portfolioUuid, String projectUuid, String branchUuid) {
- PortfolioProjectDto portfolioProject = dbClient.portfolioDao().selectPortfolioProjectOrFail(dbSession, portfolioUuid, projectUuid);
+ PortfolioProjectDto portfolioProject = dbClient.portfolioDao().selectPortfolioProjectOrFail(db.getSession(), portfolioUuid, projectUuid);
dbClient.portfolioDao().addBranch(db.getSession(), portfolioProject.getUuid(), branchUuid);
db.commit();
}
@@ -400,12 +401,12 @@ public class ComponentDbTester {
ProjectDto projectDto = toProjectDto(component, System2.INSTANCE.now());
projectDtoPopulator.accept(projectDto);
- dbClient.projectDao().insert(dbSession, projectDto);
+ dbClient.projectDao().insert(db.getSession(), projectDto);
BranchDto branchDto = ComponentTesting.newBranchDto(component, BRANCH);
branchDto.setExcludeFromPurge(true);
branchPopulator.accept(branchDto);
- dbClient.branchDao().insert(dbSession, branchDto);
+ dbClient.branchDao().insert(db.getSession(), branchDto);
db.commit();
return component;
@@ -413,21 +414,21 @@ public class ComponentDbTester {
public void addApplicationProject(ComponentDto application, ComponentDto... projects) {
for (ComponentDto project : projects) {
- dbClient.applicationProjectsDao().addProject(dbSession, application.uuid(), project.uuid());
+ dbClient.applicationProjectsDao().addProject(db.getSession(), application.uuid(), project.uuid());
}
db.commit();
}
public void addApplicationProject(ProjectDto application, ProjectDto... projects) {
for (ProjectDto project : projects) {
- dbClient.applicationProjectsDao().addProject(dbSession, application.getUuid(), project.getUuid());
+ dbClient.applicationProjectsDao().addProject(db.getSession(), application.getUuid(), project.getUuid());
}
db.commit();
}
public void addProjectBranchToApplicationBranch(BranchDto applicationBranch, BranchDto... projectBranches) {
for (BranchDto projectBranch : projectBranches) {
- dbClient.applicationProjectsDao().addProjectBranchToAppBranch(dbSession, applicationBranch, projectBranch);
+ dbClient.applicationProjectsDao().addProjectBranchToAppBranch(db.getSession(), applicationBranch, projectBranch);
}
db.commit();
}
@@ -448,19 +449,19 @@ public class ComponentDbTester {
private ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate, Consumer<ComponentDto> dtoPopulator) {
dtoPopulator.accept(component);
checkState(isPrivate == null || component.isPrivate() == isPrivate, "Illegal modification of private flag");
- dbClient.componentDao().insert(dbSession, component);
+ dbClient.componentDao().insert(db.getSession(), component);
db.commit();
return component;
}
public void insertComponents(ComponentDto... components) {
- dbClient.componentDao().insert(dbSession, asList(components));
+ dbClient.componentDao().insert(db.getSession(), asList(components));
db.commit();
}
public SnapshotDto insertSnapshot(SnapshotDto snapshotDto) {
- SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, snapshotDto);
+ SnapshotDto snapshot = dbClient.snapshotDao().insert(db.getSession(), snapshotDto);
db.commit();
return snapshot;
}
@@ -496,7 +497,7 @@ public class ComponentDbTester {
}
public void insertSnapshots(SnapshotDto... snapshotDtos) {
- dbClient.snapshotDao().insert(dbSession, asList(snapshotDtos));
+ dbClient.snapshotDao().insert(db.getSession(), asList(snapshotDtos));
db.commit();
}
@@ -520,7 +521,7 @@ public class ComponentDbTester {
checkArgument(branchDto.getProjectUuid().equals(project.getUuid()));
ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto);
insertComponent(branch);
- dbClient.branchDao().insert(dbSession, branchDto);
+ dbClient.branchDao().insert(db.getSession(), branchDto);
db.commit();
return branch;
}
@@ -530,7 +531,7 @@ public class ComponentDbTester {
checkArgument(branchDto.getProjectUuid().equals(firstNonNull(project.getMainBranchProjectUuid(), project.branchUuid())));
ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto);
insertComponent(branch);
- dbClient.branchDao().insert(dbSession, branchDto);
+ dbClient.branchDao().insert(db.getSession(), branchDto);
db.commit();
return branch;
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectLinkDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectLinkDbTester.java
index 2218f2020cf..b68b971ac07 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectLinkDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectLinkDbTester.java
@@ -22,7 +22,6 @@ package org.sonar.db.component;
import java.util.Arrays;
import java.util.function.Consumer;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import static org.sonar.db.component.ProjectLinkTesting.newCustomLinkDto;
@@ -31,12 +30,10 @@ import static org.sonar.db.component.ProjectLinkTesting.newProvidedLinkDto;
public class ProjectLinkDbTester {
private final DbTester db;
private final DbClient dbClient;
- private final DbSession dbSession;
public ProjectLinkDbTester(DbTester db) {
this.db = db;
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
}
@SafeVarargs
@@ -52,7 +49,7 @@ public class ProjectLinkDbTester {
@SafeVarargs
private final ProjectLinkDto insertLink(ComponentDto project, ProjectLinkDto componentLink, Consumer<ProjectLinkDto>... dtoPopulators) {
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(componentLink));
- dbClient.projectLinkDao().insert(dbSession, componentLink.setProjectUuid(project.uuid()));
+ dbClient.projectLinkDao().insert(db.getSession(), componentLink.setProjectUuid(project.uuid()));
db.commit();
return componentLink;
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/event/EventDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/event/EventDbTester.java
index 80689e0e6b5..ef3ceeda7f6 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/event/EventDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/event/EventDbTester.java
@@ -23,7 +23,6 @@ import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.core.util.UuidFactoryFast;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
@@ -33,16 +32,14 @@ import org.sonar.db.event.EventComponentChangeDto.ChangeCategory;
public class EventDbTester {
private final DbTester db;
private final DbClient dbClient;
- private final DbSession dbSession;
public EventDbTester(DbTester db) {
this.db = db;
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
}
public EventDto insertEvent(EventDto event) {
- dbClient.eventDao().insert(dbSession, event);
+ dbClient.eventDao().insert(db.getSession(), event);
db.commit();
return event;
@@ -50,7 +47,7 @@ public class EventDbTester {
public EventDto insertEvent(SnapshotDto analysis) {
EventDto event = EventTesting.newEvent(analysis);
- dbClient.eventDao().insert(dbSession, event);
+ dbClient.eventDao().insert(db.getSession(), event);
db.commit();
return event;
@@ -69,7 +66,7 @@ public class EventDbTester {
.setComponentBranchKey(Optional.ofNullable(branch).map(BranchDto::getKey).orElse(null));
EventPurgeData eventPurgeData = new EventPurgeData(analysis.getComponentUuid(), analysis.getUuid());
- dbClient.eventComponentChangeDao().insert(dbSession, eventComponentChange, eventPurgeData);
+ dbClient.eventComponentChangeDao().insert(db.getSession(), eventComponentChange, eventPurgeData);
db.commit();
return eventComponentChange;
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java
index 64a0636281f..e45aa7dad16 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java
@@ -21,7 +21,6 @@ package org.sonar.db.favorite;
import java.util.List;
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.property.PropertyDto;
@@ -31,20 +30,20 @@ public class FavoriteDbTester {
private static final String PROP_FAVORITE_KEY = "favourite";
private final DbClient dbClient;
- private final DbSession dbSession;
+ private final DbTester db;
public FavoriteDbTester(DbTester db) {
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
+ this.db = db;
}
public void add(ComponentDto componentDto, String userUuid, String userLogin) {
- dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
+ dbClient.propertiesDao().saveProperty(db.getSession(), new PropertyDto()
.setKey(PROP_FAVORITE_KEY)
.setUserUuid(userUuid)
.setComponentUuid(componentDto.uuid()),
userLogin, componentDto.getKey(), componentDto.name(), componentDto.qualifier());
- dbSession.commit();
+ db.commit();
}
public boolean hasFavorite(ComponentDto componentDto, String userUuid) {
@@ -52,7 +51,7 @@ public class FavoriteDbTester {
.setKey(PROP_FAVORITE_KEY)
.setComponentUuid(componentDto.uuid())
.setUserUuid(userUuid)
- .build(), dbSession);
+ .build(), db.getSession());
return !result.isEmpty();
}
@@ -61,7 +60,7 @@ public class FavoriteDbTester {
List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setKey(PROP_FAVORITE_KEY)
.setComponentUuid(componentDto.uuid())
- .build(), dbSession);
+ .build(), db.getSession());
return result.isEmpty();
}
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
index 8ef64639888..1580ce3e7e2 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
@@ -22,7 +22,6 @@ package org.sonar.db.measure;
import java.util.Arrays;
import java.util.function.Consumer;
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.SnapshotDto;
@@ -34,19 +33,19 @@ import static org.sonar.db.metric.MetricTesting.newMetricDto;
public class MeasureDbTester {
private final DbClient dbClient;
- private final DbSession dbSession;
+ private final DbTester db;
public MeasureDbTester(DbTester db) {
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
+ this.db = db;
}
@SafeVarargs
public final MeasureDto insertMeasure(ComponentDto component, SnapshotDto analysis, MetricDto metricDto, Consumer<MeasureDto>... consumers) {
MeasureDto measureDto = newMeasureDto(metricDto, component, analysis);
Arrays.stream(consumers).forEach(c -> c.accept(measureDto));
- dbClient.measureDao().insert(dbSession, measureDto);
- dbSession.commit();
+ dbClient.measureDao().insert(db.getSession(), measureDto);
+ db.commit();
return measureDto;
}
@@ -54,8 +53,8 @@ public class MeasureDbTester {
public final LiveMeasureDto insertLiveMeasure(ComponentDto component, MetricDto metric, Consumer<LiveMeasureDto>... consumers) {
LiveMeasureDto dto = newLiveMeasure(component, metric);
Arrays.stream(consumers).forEach(c -> c.accept(dto));
- dbClient.liveMeasureDao().insert(dbSession, dto);
- dbSession.commit();
+ dbClient.liveMeasureDao().insert(db.getSession(), dto);
+ db.commit();
return dto;
}
@@ -63,8 +62,8 @@ public class MeasureDbTester {
public final MetricDto insertMetric(Consumer<MetricDto>... consumers) {
MetricDto metricDto = newMetricDto();
Arrays.stream(consumers).forEach(c -> c.accept(metricDto));
- dbClient.metricDao().insert(dbSession, metricDto);
- dbSession.commit();
+ dbClient.metricDao().insert(db.getSession(), metricDto);
+ db.commit();
return metricDto;
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java
index f1c4c3afdf0..b60703284cd 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java
@@ -23,7 +23,6 @@ import java.util.List;
import javax.annotation.Nullable;
import org.sonar.core.util.stream.MoreCollectors;
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.property.PropertyDto;
@@ -35,11 +34,11 @@ public class NotificationDbTester {
private static final String PROP_NOTIFICATION_PREFIX = "notification";
private final DbClient dbClient;
- private final DbSession dbSession;
+ private final DbTester db;
public NotificationDbTester(DbTester db) {
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
+ this.db = db;
}
public void assertExists(String channel, String dispatcher, String userUuid, @Nullable ComponentDto component) {
@@ -47,7 +46,7 @@ public class NotificationDbTester {
.setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
.setComponentUuid(component == null ? null : component.uuid())
.setUserUuid(userUuid)
- .build(), dbSession).stream()
+ .build(), db.getSession()).stream()
.filter(prop -> component == null ? prop.getComponentUuid() == null : prop.getComponentUuid() != null)
.collect(MoreCollectors.toList());
assertThat(result).hasSize(1);
@@ -59,7 +58,7 @@ public class NotificationDbTester {
.setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
.setComponentUuid(component == null ? null : component.uuid())
.setUserUuid(userUuid)
- .build(), dbSession);
+ .build(), db.getSession());
assertThat(result).isEmpty();
}
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java
index 1cc5d189af6..b426756ae10 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java
@@ -22,7 +22,6 @@ package org.sonar.db.permission.template;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
@@ -34,23 +33,21 @@ import static org.sonar.db.permission.template.PermissionTemplateTesting.newPerm
public class PermissionTemplateDbTester {
private final DbTester db;
private final DbClient dbClient;
- private final DbSession dbSession;
public PermissionTemplateDbTester(DbTester db) {
this.db = db;
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
}
public void setDefaultTemplates(String projectDefaultTemplateUuid, @Nullable String applicationDefaultTemplateUuid, @Nullable String portfoliosDefaultTemplateUuid) {
- db.getDbClient().internalPropertiesDao().save(dbSession, "defaultTemplate.prj", projectDefaultTemplateUuid);
+ db.getDbClient().internalPropertiesDao().save(db.getSession(), "defaultTemplate.prj", projectDefaultTemplateUuid);
if (applicationDefaultTemplateUuid != null) {
- db.getDbClient().internalPropertiesDao().save(dbSession, "defaultTemplate.app", applicationDefaultTemplateUuid);
+ db.getDbClient().internalPropertiesDao().save(db.getSession(), "defaultTemplate.app", applicationDefaultTemplateUuid);
}
if (portfoliosDefaultTemplateUuid != null) {
- db.getDbClient().internalPropertiesDao().save(dbSession, "defaultTemplate.port", portfoliosDefaultTemplateUuid);
+ db.getDbClient().internalPropertiesDao().save(db.getSession(), "defaultTemplate.port", portfoliosDefaultTemplateUuid);
}
- dbSession.commit();
+ db.commit();
}
public void setDefaultTemplates(PermissionTemplateDto projectDefaultTemplate, @Nullable PermissionTemplateDto applicationDefaultTemplate,
@@ -66,7 +63,7 @@ public class PermissionTemplateDbTester {
}
public PermissionTemplateDto insertTemplate(PermissionTemplateDto template) {
- PermissionTemplateDto templateInDb = dbClient.permissionTemplateDao().insert(dbSession, template);
+ PermissionTemplateDto templateInDb = dbClient.permissionTemplateDao().insert(db.getSession(), template);
db.commit();
return templateInDb;
}
@@ -76,7 +73,7 @@ public class PermissionTemplateDbTester {
}
public void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission, String templateName, @Nullable String groupName) {
- dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateUuid, groupUuid, permission, templateName, groupName);
+ dbClient.permissionTemplateDao().insertGroupPermission(db.getSession(), templateUuid, groupUuid, permission, templateName, groupName);
db.commit();
}
@@ -89,7 +86,7 @@ public class PermissionTemplateDbTester {
}
public void addUserToTemplate(String templateUuid, String userUuid, String permission, String templateName, String userLogin) {
- dbClient.permissionTemplateDao().insertUserPermission(dbSession, templateUuid, userUuid, permission, templateName, userLogin);
+ dbClient.permissionTemplateDao().insertUserPermission(db.getSession(), templateUuid, userUuid, permission, templateName, userLogin);
db.commit();
}
@@ -98,7 +95,7 @@ public class PermissionTemplateDbTester {
}
public void addProjectCreatorToTemplate(String templateUuid, String permission, String templateName) {
- dbClient.permissionTemplateCharacteristicDao().insert(dbSession, newPermissionTemplateCharacteristicDto()
+ dbClient.permissionTemplateCharacteristicDao().insert(db.getSession(), newPermissionTemplateCharacteristicDto()
.setWithProjectCreator(true)
.setTemplateUuid(templateUuid)
.setPermission(permission),
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/plugin/PluginDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/plugin/PluginDbTester.java
index 8b3c7f6ad03..fc24a81181b 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/plugin/PluginDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/plugin/PluginDbTester.java
@@ -22,24 +22,23 @@ package org.sonar.db.plugin;
import java.util.Arrays;
import java.util.function.Consumer;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
public class PluginDbTester {
private final DbClient dbClient;
- private final DbSession dbSession;
+ private final DbTester db;
public PluginDbTester(DbTester db) {
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
+ this.db = db;
}
@SafeVarargs
public final PluginDto insertPlugin(Consumer<PluginDto>... consumers) {
PluginDto pluginDto = PluginTesting.newPluginDto();
Arrays.stream(consumers).forEach(c -> c.accept(pluginDto));
- dbClient.pluginDao().insert(dbSession, pluginDto);
- dbSession.commit();
+ dbClient.pluginDao().insert(db.getSession(), pluginDto);
+ db.commit();
return pluginDto;
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/InternalComponentPropertyDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/InternalComponentPropertyDbTester.java
index 227179d52bd..7b5230c8039 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/InternalComponentPropertyDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/InternalComponentPropertyDbTester.java
@@ -21,26 +21,23 @@ package org.sonar.db.property;
import java.util.Optional;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
public class InternalComponentPropertyDbTester {
private final DbTester db;
private final DbClient dbClient;
- private final DbSession dbSession;
public InternalComponentPropertyDbTester(DbTester db) {
this.db = db;
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
}
public void insertProperty(String componentUuid, String key, String value) {
- dbClient.internalComponentPropertiesDao().insertOrUpdate(dbSession, componentUuid, key, value);
+ dbClient.internalComponentPropertiesDao().insertOrUpdate(db.getSession(), componentUuid, key, value);
db.commit();
}
public Optional<InternalComponentPropertyDto> getProperty(String componentUuid, String key) {
- return dbClient.internalComponentPropertiesDao().selectByComponentUuidAndKey(dbSession, componentUuid, key);
+ return dbClient.internalComponentPropertiesDao().selectByComponentUuidAndKey(db.getSession(), componentUuid, key);
}
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyDbTester.java
index e175e2f77b3..32e4c35ed6a 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyDbTester.java
@@ -26,30 +26,26 @@ import java.util.Map;
import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
-import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto;
public class PropertyDbTester {
private final DbTester db;
private final DbClient dbClient;
- private final DbSession dbSession;
public PropertyDbTester(DbTester db) {
this.db = db;
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
}
public PropertyDto insertProperty(PropertyDto property, @Nullable String componentKey,
@Nullable String componentName, @Nullable String qualifier, @Nullable String userLogin) {
- dbClient.propertiesDao().saveProperty(dbSession, property, userLogin, componentKey, componentName, qualifier);
+ dbClient.propertiesDao().saveProperty(db.getSession(), property, userLogin, componentKey, componentName, qualifier);
db.commit();
return property;
@@ -63,9 +59,9 @@ public class PropertyDbTester {
public void insertProperties(List<PropertyDto> properties, @Nullable String userLogin, @Nullable String projectKey,
@Nullable String projectName, @Nullable String qualifier) {
for (PropertyDto propertyDto : properties) {
- dbClient.propertiesDao().saveProperty(dbSession, propertyDto, userLogin, projectKey, projectName, qualifier);
+ dbClient.propertiesDao().saveProperty(db.getSession(), propertyDto, userLogin, projectKey, projectName, qualifier);
}
- dbSession.commit();
+ db.commit();
}
public void insertProperty(String propKey, String propValue, @Nullable String componentUuid) {
@@ -110,6 +106,6 @@ public class PropertyDbTester {
.setKey(key)
.build();
- return dbClient.propertiesDao().selectByQuery(query, dbSession).stream().findFirst();
+ return dbClient.propertiesDao().selectByQuery(query, db.getSession()).stream().findFirst();
}
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java
index 5dd05f6799e..7fa0247977b 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java
@@ -25,7 +25,6 @@ import java.util.Optional;
import java.util.function.Consumer;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.project.ProjectDto;
@@ -41,21 +40,19 @@ public class QualityGateDbTester {
private final DbTester db;
private final DbClient dbClient;
- private final DbSession dbSession;
public QualityGateDbTester(DbTester db) {
this.db = db;
this.dbClient = db.getDbClient();
- this.dbSession = db.getSession();
}
public QualityGateDto insertBuiltInQualityGate() {
- QualityGateDto builtin = dbClient.qualityGateDao().insert(dbSession, new QualityGateDto()
+ QualityGateDto builtin = dbClient.qualityGateDao().insert(db.getSession(), new QualityGateDto()
.setName("Sonar way")
.setUuid(Uuids.createFast())
.setBuiltIn(true)
.setCreatedAt(new Date()));
- dbSession.commit();
+ db.commit();
return builtin;
}
@@ -66,13 +63,13 @@ public class QualityGateDbTester {
.setUuid(Uuids.createFast())
.setBuiltIn(false);
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(qualityGate));
- dbClient.qualityGateDao().insert(dbSession, qualityGate);
+ dbClient.qualityGateDao().insert(db.getSession(), qualityGate);
db.commit();
- return dbClient.qualityGateDao().selectByUuid(dbSession, qualityGate.getUuid());
+ return dbClient.qualityGateDao().selectByUuid(db.getSession(), qualityGate.getUuid());
}
public void associateProjectToQualityGate(ProjectDto project, QualityGateDto qualityGate) {
- dbClient.projectQgateAssociationDao().insertProjectQGateAssociation(dbSession, project.getUuid(), qualityGate.getUuid());
+ dbClient.projectQgateAssociationDao().insertProjectQGateAssociation(db.getSession(), project.getUuid(), qualityGate.getUuid());
db.commit();
}
@@ -85,7 +82,7 @@ public class QualityGateDbTester {
public void setDefaultQualityGate(QualityGateDto qualityGate) {
dbClient.propertiesDao().saveProperty(new PropertyDto().setKey(DEFAULT_QUALITY_GATE_PROPERTY_NAME).setValue(qualityGate.getUuid()));
- dbSession.commit();
+ db.commit();
}
@SafeVarargs
@@ -96,33 +93,33 @@ public class QualityGateDbTester {
.setOperator("GT")
.setErrorThreshold(randomNumeric(10));
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(condition));
- dbClient.gateConditionDao().insert(condition, dbSession);
+ dbClient.gateConditionDao().insert(condition, db.getSession());
db.commit();
return condition;
}
public Optional<String> selectQGateUuidByComponentUuid(String componentUuid) {
- return dbClient.projectQgateAssociationDao().selectQGateUuidByProjectUuid(dbSession, componentUuid);
+ return dbClient.projectQgateAssociationDao().selectQGateUuidByProjectUuid(db.getSession(), componentUuid);
}
public void addGroupPermission(QualityGateDto qualityGateDto, GroupDto group) {
- dbClient.qualityGateGroupPermissionsDao().insert(dbSession, new QualityGateGroupPermissionsDto()
+ dbClient.qualityGateGroupPermissionsDao().insert(db.getSession(), new QualityGateGroupPermissionsDto()
.setUuid(Uuids.createFast())
.setGroupUuid(group.getUuid())
.setQualityGateUuid(qualityGateDto.getUuid()),
qualityGateDto.getName(),
group.getName()
);
- dbSession.commit();
+ db.commit();
}
public void addUserPermission(QualityGateDto qualityGateDto, UserDto user) {
- dbClient.qualityGateUserPermissionDao().insert(dbSession, new QualityGateUserPermissionsDto()
+ dbClient.qualityGateUserPermissionDao().insert(db.getSession(), new QualityGateUserPermissionsDto()
.setUuid(Uuids.createFast())
.setUserUuid(user.getUuid())
.setQualityGateUuid(qualityGateDto.getUuid()),
qualityGateDto.getName(),
user.getLogin());
- dbSession.commit();
+ db.commit();
}
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java
index 8f2bf0a2632..ff7eba6e9a1 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java
@@ -25,7 +25,6 @@ import java.util.function.Consumer;
import org.sonar.api.rule.Severity;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDto;
@@ -39,15 +38,15 @@ import static org.sonar.db.qualityprofile.ActiveRuleDto.createFor;
public class QualityProfileDbTester {
private final DbClient dbClient;
- private final DbSession dbSession;
+ private final DbTester db;
public QualityProfileDbTester(DbTester dbTester) {
this.dbClient = dbTester.getDbClient();
- this.dbSession = dbTester.getSession();
+ this.db = dbTester;
}
public Optional<QProfileDto> selectByUuid(String uuid) {
- return Optional.ofNullable(dbClient.qualityProfileDao().selectByUuid(dbSession, uuid));
+ return Optional.ofNullable(dbClient.qualityProfileDao().selectByUuid(db.getSession(), uuid));
}
/**
@@ -66,24 +65,24 @@ public class QualityProfileDbTester {
QProfileDto profile = QualityProfileTesting.newQualityProfileDto();
consumer.accept(profile);
- dbClient.qualityProfileDao().insert(dbSession, profile);
- dbSession.commit();
+ dbClient.qualityProfileDao().insert(db.getSession(), profile);
+ db.commit();
return profile;
}
public QualityProfileDbTester insert(QProfileDto profile, QProfileDto... others) {
- dbClient.qualityProfileDao().insert(dbSession, profile);
- Arrays.stream(others).forEach(p -> dbClient.qualityProfileDao().insert(dbSession, p));
- dbSession.commit();
+ dbClient.qualityProfileDao().insert(db.getSession(), profile);
+ Arrays.stream(others).forEach(p -> dbClient.qualityProfileDao().insert(db.getSession(), p));
+ db.commit();
return this;
}
public QualityProfileDbTester associateWithProject(ProjectDto project, QProfileDto profile, QProfileDto... otherProfiles) {
- dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, profile);
+ dbClient.qualityProfileDao().insertProjectProfileAssociation(db.getSession(), project, profile);
for (QProfileDto p : otherProfiles) {
- dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, p);
+ dbClient.qualityProfileDao().insertProjectProfileAssociation(db.getSession(), project, p);
}
- dbSession.commit();
+ db.commit();
return this;
}
@@ -98,38 +97,38 @@ public class QualityProfileDbTester {
.setCreatedAt(nextLong())
.setUpdatedAt(nextLong());
consumer.accept(activeRule);
- dbClient.activeRuleDao().insert(dbSession, activeRule);
- dbSession.commit();
+ dbClient.activeRuleDao().insert(db.getSession(), activeRule);
+ db.commit();
return activeRule;
}
public QualityProfileDbTester setAsDefault(QProfileDto profile, QProfileDto... others) {
- dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profile));
+ dbClient.defaultQProfileDao().insertOrUpdate(db.getSession(), DefaultQProfileDto.from(profile));
for (QProfileDto other : others) {
- dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(other));
+ dbClient.defaultQProfileDao().insertOrUpdate(db.getSession(), DefaultQProfileDto.from(other));
}
- dbSession.commit();
+ db.commit();
return this;
}
public void addUserPermission(QProfileDto profile, UserDto user) {
checkArgument(!profile.isBuiltIn(), "Built-In profile cannot be used");
- dbClient.qProfileEditUsersDao().insert(dbSession, new QProfileEditUsersDto()
+ dbClient.qProfileEditUsersDao().insert(db.getSession(), new QProfileEditUsersDto()
.setUuid(Uuids.createFast())
.setUserUuid(user.getUuid())
.setQProfileUuid(profile.getKee()),
profile.getName(), user.getLogin()
);
- dbSession.commit();
+ db.commit();
}
public void addGroupPermission(QProfileDto profile, GroupDto group) {
checkArgument(!profile.isBuiltIn(), "Built-In profile cannot be used");
- dbClient.qProfileEditGroupsDao().insert(dbSession, new QProfileEditGroupsDto()
+ dbClient.qProfileEditGroupsDao().insert(db.getSession(), new QProfileEditGroupsDto()
.setUuid(Uuids.createFast())
.setGroupUuid(group.getUuid())
.setQProfileUuid(profile.getKee()),
profile.getName(), group.getName());
- dbSession.commit();
+ db.commit();
}
}