aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-08-29 18:37:42 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-08-30 15:51:31 +0200
commit2e3c74b1b96f5a0475fc7c3482621412aa765192 (patch)
treee3fbda48fbe7e5c6af8a643c322393d7e294f363 /sonar-db
parent3588f94756e919d829cb2a44e0acffa1cc6f5b46 (diff)
downloadsonarqube-2e3c74b1b96f5a0475fc7c3482621412aa765192.tar.gz
sonarqube-2e3c74b1b96f5a0475fc7c3482621412aa765192.zip
SONAR-7975 Return parentValue, parentValues and parentFieldsValues
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/property/PropertyDbTester.java39
1 files changed, 39 insertions, 0 deletions
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 dfc451f4c56..bbef4a057f3 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
@@ -20,9 +20,19 @@
package org.sonar.db.property;
+import com.google.common.base.Joiner;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+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 org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
+import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto;
public class PropertyDbTester {
private final DbTester db;
@@ -43,9 +53,38 @@ public class PropertyDbTester {
}
public void insertProperties(PropertyDto... properties) {
+ insertProperties(asList(properties));
+ }
+
+ public void insertProperties(List<PropertyDto> properties) {
for (PropertyDto propertyDto : properties) {
dbClient.propertiesDao().insertProperty(dbSession, propertyDto);
}
dbSession.commit();
}
+
+ public void insertPropertySet(String settingBaseKey, @Nullable ComponentDto componentDto, Map<String, String>... fieldValues) {
+ int index = 1;
+ List<PropertyDto> propertyDtos = new ArrayList<>();
+ List<String> ids = new ArrayList<>();
+ for (Map<String, String> fieldValue : fieldValues) {
+ for (Map.Entry<String, String> entry : fieldValue.entrySet()) {
+ String key = settingBaseKey + "." + index + "." + entry.getKey();
+ if (componentDto != null) {
+ propertyDtos.add(newComponentPropertyDto(componentDto).setKey(key).setValue(entry.getValue()));
+ } else {
+ propertyDtos.add(newGlobalPropertyDto().setKey(key).setValue(entry.getValue()));
+ }
+ }
+ ids.add(Integer.toString(index));
+ index++;
+ }
+ String idsValue = Joiner.on(",").join(ids);
+ if (componentDto != null) {
+ propertyDtos.add(newComponentPropertyDto(componentDto).setKey(settingBaseKey).setValue(idsValue));
+ } else {
+ propertyDtos.add(newGlobalPropertyDto().setKey(settingBaseKey).setValue(idsValue));
+ }
+ insertProperties(propertyDtos);
+ }
}