From f4b595f075588f33a9b955758f36536104330663 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 8 Feb 2017 21:14:10 +0100 Subject: [PATCH] Add and complete DbTester#properties() --- .../src/test/java/org/sonar/db/DbTester.java | 7 +++++++ .../sonar/db/property/PropertyDbTester.java | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/sonar-db/src/test/java/org/sonar/db/DbTester.java b/sonar-db/src/test/java/org/sonar/db/DbTester.java index 7f48f1242c3..17651fa8bd5 100644 --- a/sonar-db/src/test/java/org/sonar/db/DbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/DbTester.java @@ -72,6 +72,7 @@ import org.sonar.db.organization.OrganizationDbTester; import org.sonar.db.organization.OrganizationDto; import org.sonar.db.organization.OrganizationTesting; import org.sonar.db.permission.template.PermissionTemplateDbTester; +import org.sonar.db.property.PropertyDbTester; import org.sonar.db.qualitygate.QualityGateDbTester; import org.sonar.db.qualityprofile.QualityProfileDbTester; import org.sonar.db.rule.RuleDbTester; @@ -111,6 +112,7 @@ public class DbTester extends ExternalResource { private final EventDbTester eventTester; private final OrganizationDbTester organizationTester; private final PermissionTemplateDbTester permissionTemplateTester; + private final PropertyDbTester propertyTester; private final QualityGateDbTester qualityGateDbTester; private final IssueDbTester issueDbTester; private final RuleDbTester ruleDbTester; @@ -128,6 +130,7 @@ public class DbTester extends ExternalResource { this.eventTester = new EventDbTester(this); this.organizationTester = new OrganizationDbTester(this); this.permissionTemplateTester = new PermissionTemplateDbTester(this); + this.propertyTester = new PropertyDbTester(this); this.qualityGateDbTester = new QualityGateDbTester(this); this.issueDbTester = new IssueDbTester(this); this.ruleDbTester = new RuleDbTester(this); @@ -223,6 +226,10 @@ public class DbTester extends ExternalResource { return permissionTemplateTester; } + public PropertyDbTester properties() { + return propertyTester; + } + public QualityGateDbTester qualityGates() { return qualityGateDbTester; } diff --git a/sonar-db/src/test/java/org/sonar/db/property/PropertyDbTester.java b/sonar-db/src/test/java/org/sonar/db/property/PropertyDbTester.java index 14473e6e6dd..b2bb7b7c5a4 100644 --- a/sonar-db/src/test/java/org/sonar/db/property/PropertyDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/property/PropertyDbTester.java @@ -23,6 +23,7 @@ import com.google.common.base.Joiner; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import javax.annotation.Nullable; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -30,6 +31,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto; import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto; @@ -86,4 +88,20 @@ public class PropertyDbTester { } insertProperties(propertyDtos); } + + public PropertyDbTester verifyInternal(String key, @Nullable String expectedValue) { + Optional value = dbClient.internalPropertiesDao().selectByKey(dbSession, key); + if (expectedValue == null) { + assertThat(value).isEmpty(); + } else { + assertThat(value).hasValue(expectedValue); + } + return this; + } + + public PropertyDbTester insertInternal(String key, String value) { + dbClient.internalPropertiesDao().save(dbSession, key, value); + dbSession.commit(); + return this; + } } -- 2.39.5