aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-08-12 10:39:32 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-08-12 10:39:37 +0200
commit105831419ee487a9d1ab1f8a9338d275e5be82fd (patch)
treedbcc07f6bb5c6d6bead39582b1a72cea917b523b /sonar-db
parentafdf3ba619eb80c7475afb0b69c1cabfcdd08833 (diff)
downloadsonarqube-105831419ee487a9d1ab1f8a9338d275e5be82fd.tar.gz
sonarqube-105831419ee487a9d1ab1f8a9338d275e5be82fd.zip
SONAR-7930 WS api/components/bulk_update_key dry run fails when invalid key
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java7
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java11
2 files changed, 17 insertions, 1 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java
index 1eb408af1f1..4248788692d 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java
@@ -37,6 +37,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import static com.google.common.base.Preconditions.checkArgument;
+import static org.sonar.core.component.ComponentKeys.checkModuleKey;
import static org.sonar.core.component.ComponentKeys.isValidModuleKey;
/**
@@ -109,7 +110,11 @@ public class ComponentKeyUpdaterDao implements Dao {
.stream()
.collect(Collectors.toMap(
ResourceDto::getKey,
- component -> computeNewKey(component.getKey(), stringToReplace, replacementString)));
+ component -> {
+ String newKey = computeNewKey(component.getKey(), stringToReplace, replacementString);
+ checkModuleKey(newKey);
+ return newKey;
+ }));
}
/**
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java
index eb74073d6b7..10621fe5a77 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java
@@ -222,6 +222,17 @@ public class ComponentKeyUpdaterDaoTest {
}
@Test
+ public void simulate_bulk_update_key_fails_if_invalid_componentKey() {
+ ComponentDto project = componentDb.insertComponent(newProjectDto("A").setKey("project"));
+ componentDb.insertComponent(newModuleDto(project).setKey("project:enabled-module"));
+ componentDb.insertComponent(newModuleDto(project).setKey("project:disabled-module").setEnabled(false));
+
+ thrown.expect(IllegalArgumentException.class);
+
+ underTest.simulateBulkUpdateKey(dbSession, "A", "project", "project?");
+ }
+
+ @Test
public void compute_new_key() {
assertThat(computeNewKey("my_project", "my_", "your_")).isEqualTo("your_project");
assertThat(computeNewKey("my_project", "my_", "$()_")).isEqualTo("$()_project");