diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-07-18 13:16:09 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-07-22 00:31:16 +0200 |
commit | b18e284c549f4e46d0ad806cfbcc76e348027bd7 (patch) | |
tree | 6307bd9576529584bb45e4510471ad626b448ad0 /server/sonar-db-dao | |
parent | 7e87812f0c2a3000368e76b2965360c476f8ec10 (diff) | |
download | sonarqube-b18e284c549f4e46d0ad806cfbcc76e348027bd7.tar.gz sonarqube-b18e284c549f4e46d0ad806cfbcc76e348027bd7.zip |
SONAR-9516 add integration tests on api/projects/update_key
including ES resiliency tests
Diffstat (limited to 'server/sonar-db-dao')
4 files changed, 10 insertions, 11 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java index 357732fa08c..b954a67e27f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java @@ -48,22 +48,20 @@ public class ComponentKeyUpdaterDao implements Dao { private static final Set<String> PROJECT_OR_MODULE_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.MODULE); - public void updateKey(DbSession dbSession, String projectUuid, String newKey) { + public void updateKey(DbSession dbSession, String projectOrModuleUuid, String newKey) { ComponentKeyUpdaterMapper mapper = dbSession.getMapper(ComponentKeyUpdaterMapper.class); if (mapper.countResourceByKey(newKey) > 0) { throw new IllegalArgumentException("Impossible to update key: a component with key \"" + newKey + "\" already exists."); } // must SELECT first everything - ResourceDto project = mapper.selectProject(projectUuid); + ResourceDto project = mapper.selectProject(projectOrModuleUuid); String projectOldKey = project.getKey(); - List<ResourceDto> resources = mapper.selectProjectResources(projectUuid); + List<ResourceDto> resources = mapper.selectProjectResources(projectOrModuleUuid); resources.add(project); // and then proceed with the batch UPDATE at once runBatchUpdateForAllResources(resources, projectOldKey, newKey, mapper); - - dbSession.commit(); } public static void checkIsProjectOrModule(ComponentDto component) { diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml index b47e6f46b44..d7189fdb1ec 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml @@ -21,15 +21,15 @@ <select id="selectProject" parameterType="String" resultMap="resourceResultMap"> select * from projects - where uuid=#{uuid,jdbcType=VARCHAR} + where uuid = #{uuid,jdbcType=VARCHAR} </select> <select id="selectProjectResources" parameterType="String" resultMap="resourceResultMap"> select * from projects where - root_uuid=#{rootUuid,jdbcType=VARCHAR} - and scope!='PRJ' - and enabled=${_true} + root_uuid = #{rootUuid,jdbcType=VARCHAR} + and scope != 'PRJ' + and enabled = ${_true} </select> <select id="selectDescendantProjects" parameterType="String" resultMap="resourceResultMap"> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index f9a99818714..fecf8cf8715 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -425,7 +425,7 @@ p.enabled=${_true} and p.copy_component_uuid is null <if test="projectUuid != null"> - and p.project_uuid=#{projectUuid,jdbcType=VARCHAR} + and p.project_uuid = #{projectUuid,jdbcType=VARCHAR} </if> </select> diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java index 8dd4bbcadce..f8305553ee9 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java @@ -56,6 +56,7 @@ public class ComponentKeyUpdaterDaoTest { db.prepareDbUnit(getClass(), "shared.xml"); underTest.updateKey(dbSession, "B", "struts:core"); + dbSession.commit(); db.assertDbUnit(getClass(), "shouldUpdateKey-result.xml", "projects"); } @@ -70,7 +71,7 @@ public class ComponentKeyUpdaterDaoTest { db.components().insertComponent(newFileDto(project, inactiveDirectory).setKey("my_project:inactive_directory/file").setEnabled(false)); underTest.updateKey(dbSession, "A", "your_project"); - db.commit(); + dbSession.commit(); List<ComponentDto> result = dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, "your_project"); assertThat(result).hasSize(5).extracting(ComponentDto::getKey) |