diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-05-19 10:46:46 +0200 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-06-09 08:26:48 +0200 |
commit | b6ad5cfbba96fd03e03ec12a2fd45b96874368c3 (patch) | |
tree | 7bbb8f68ef347af7322936e45a198fe1a5cb730b /server/sonar-db-dao | |
parent | 67045c090faf055cea3946b888929f84df52b03d (diff) | |
download | sonarqube-b6ad5cfbba96fd03e03ec12a2fd45b96874368c3.tar.gz sonarqube-b6ad5cfbba96fd03e03ec12a2fd45b96874368c3.zip |
SONAR-9245 Make SearchProjectsActionTest more stable
Do not directly insert documents into ES but insert data in db then calls indexer
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r-- | server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java | 7 | ||||
-rw-r--r-- | server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDbTester.java | 63 |
2 files changed, 70 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java b/server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java index 31ab11a427a..ff078a73d2d 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java @@ -32,6 +32,7 @@ import org.sonar.db.component.ComponentDbTester; import org.sonar.db.event.EventDbTester; import org.sonar.db.favorite.FavoriteDbTester; import org.sonar.db.issue.IssueDbTester; +import org.sonar.db.measure.MeasureDbTester; import org.sonar.db.notification.NotificationDbTester; import org.sonar.db.organization.OrganizationDbTester; import org.sonar.db.organization.OrganizationDto; @@ -74,6 +75,7 @@ public class DbTester extends AbstractDbTester<TestDb> { private final NotificationDbTester notificationDbTester; private final RootFlagAssertions rootFlagAssertions; private final QualityProfileDbTester qualityProfileDbTester; + private final MeasureDbTester measureDbTester; public DbTester(System2 system2, @Nullable String schemaPath) { super(TestDb.create(schemaPath)); @@ -93,6 +95,7 @@ public class DbTester extends AbstractDbTester<TestDb> { this.notificationDbTester = new NotificationDbTester(this); this.rootFlagAssertions = new RootFlagAssertions(this); this.qualityProfileDbTester = new QualityProfileDbTester(this); + this.measureDbTester = new MeasureDbTester(this); } public static DbTester create() { @@ -219,6 +222,10 @@ public class DbTester extends AbstractDbTester<TestDb> { return qualityProfileDbTester; } + public MeasureDbTester measureDbTester() { + return measureDbTester; + } + @Override protected void after() { if (session != null) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDbTester.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDbTester.java new file mode 100644 index 00000000000..b1d45914ec3 --- /dev/null +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDbTester.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +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; +import org.sonar.db.metric.MetricDto; + +import static org.sonar.db.measure.MeasureTesting.newMeasureDto; +import static org.sonar.db.metric.MetricTesting.newMetricDto; + +public class MeasureDbTester { + private final DbTester db; + private final DbClient dbClient; + private final DbSession dbSession; + + public MeasureDbTester(DbTester db) { + this.db = db; + this.dbClient = db.getDbClient(); + this.dbSession = db.getSession(); + } + + @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(); + return measureDto; + } + + @SafeVarargs + 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(); + return metricDto; + } + +} |