]> source.dussan.org Git - sonarqube.git/commitdiff
Add and complete DbTester#properties()
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 8 Feb 2017 20:14:10 +0000 (21:14 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 10 Feb 2017 21:49:09 +0000 (22:49 +0100)
sonar-db/src/test/java/org/sonar/db/DbTester.java
sonar-db/src/test/java/org/sonar/db/property/PropertyDbTester.java

index 7f48f1242c33f9774f37620936be2bccdaab75b6..17651fa8bd5f6589f5d046a2a90586e501589253 100644 (file)
@@ -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;
   }
index 14473e6e6dd4c81cd745637ac6b0c28e2f61f8f2..b2bb7b7c5a45842af92f5960ea8dcc5cd0a6dd13 100644 (file)
@@ -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<String> 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;
+  }
 }