aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-08-03 15:36:53 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-08-05 14:31:15 +0200
commit645d874eda971f79a0927aa6370adb9489f148b7 (patch)
tree242f65e73652307ae524312427d00722555735a2 /sonar-db
parent982927e716d5e6a0659c7a7157c3793bef761e76 (diff)
downloadsonarqube-645d874eda971f79a0927aa6370adb9489f148b7.tar.gz
sonarqube-645d874eda971f79a0927aa6370adb9489f148b7.zip
SONAR-7928 SONAR-4770 Create WS api/components/update_key
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java2
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java9
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ResourceKeyUpdaterDaoTest.java4
3 files changed, 12 insertions, 3 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java
index c675163fc76..4c0fb971c34 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java
@@ -49,7 +49,7 @@ public class ResourceKeyUpdaterDao implements Dao {
ResourceKeyUpdaterMapper mapper = session.getMapper(ResourceKeyUpdaterMapper.class);
try {
if (mapper.countResourceByKey(newKey) > 0) {
- throw new IllegalStateException("Impossible to update key: a resource with \"" + newKey + "\" key already exists.");
+ throw new IllegalArgumentException("Impossible to update key: a component with key \"" + newKey + "\" already exists.");
}
// must SELECT first everything
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
index ebee0a46a45..4e1fab7a094 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
@@ -26,6 +26,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import static java.util.Arrays.asList;
+import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
public class ComponentDbTester {
@@ -69,6 +70,14 @@ public class ComponentDbTester {
return component;
}
+ public ComponentDto insertProject() {
+ ComponentDto project = newProjectDto();
+ dbClient.componentDao().insert(dbSession, project);
+ db.commit();
+
+ return project;
+ }
+
public void insertComponents(ComponentDto... components) {
dbClient.componentDao().insert(dbSession, asList(components));
db.commit();
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceKeyUpdaterDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceKeyUpdaterDaoTest.java
index 971aab92c4d..df673897e46 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ResourceKeyUpdaterDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ResourceKeyUpdaterDaoTest.java
@@ -57,8 +57,8 @@ public class ResourceKeyUpdaterDaoTest {
public void shouldNotUpdateKey() {
db.prepareDbUnit(getClass(), "shared.xml");
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Impossible to update key: a resource with \"org.struts:struts-ui\" key already exists.");
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Impossible to update key: a component with key \"org.struts:struts-ui\" already exists.");
underTest.updateKey("B", "org.struts:struts-ui");
}