From 645d874eda971f79a0927aa6370adb9489f148b7 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Wed, 3 Aug 2016 15:36:53 +0200 Subject: SONAR-7928 SONAR-4770 Create WS api/components/update_key --- .../main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java | 2 +- .../src/test/java/org/sonar/db/component/ComponentDbTester.java | 9 +++++++++ .../java/org/sonar/db/component/ResourceKeyUpdaterDaoTest.java | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'sonar-db') 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"); } -- cgit v1.2.3