From 2bf2395c57dd82e6e2557e7497f8854d755479bc Mon Sep 17 00:00:00 2001 From: Lukasz Jarocki Date: Wed, 14 Dec 2022 11:16:17 +0100 Subject: [PATCH] SONAR-17254 added coverage for renaming the main branch of the application --- .../src/main/java/org/sonar/db/component/BranchDao.java | 4 ++-- .../src/main/java/org/sonar/db/component/BranchMapper.java | 2 +- .../main/resources/org/sonar/db/component/BranchMapper.xml | 4 ++-- .../src/test/java/org/sonar/db/component/BranchDaoTest.java | 2 +- .../main/java/org/sonar/server/branch/ws/RenameAction.java | 2 +- .../test/java/org/sonar/server/branch/ws/ListActionTest.java | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java index 1dff7ccc75b..65f60177741 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java @@ -53,9 +53,9 @@ public class BranchDao implements Dao { } } - public int updateMainBranchName(DbSession dbSession, String projectUuid, String newBranchKey) { + public int updateBranchName(DbSession dbSession, String branchUuid, String newBranchKey) { long now = system2.now(); - return mapper(dbSession).updateMainBranchName(projectUuid, newBranchKey, now); + return mapper(dbSession).updateBranchName(branchUuid, newBranchKey, now); } public int updateExcludeFromPurge(DbSession dbSession, String branchUuid, boolean excludeFromPurge) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java index eebd797906a..a840d00be87 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java @@ -32,7 +32,7 @@ public interface BranchMapper { int update(@Param("dto") BranchDto dto, @Param("now") long now); - int updateMainBranchName(@Param("projectUuid") String projectUuid, @Param("newBranchName") String newBranchName, @Param("now") long now); + int updateBranchName(@Param("branchUuid") String branchUuid, @Param("newBranchName") String newBranchName, @Param("now") long now); int updateExcludeFromPurge(@Param("uuid") String uuid, @Param("excludeFromPurge") boolean excludeFromPurge, @Param("now") long now); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml index ab077238c9f..fc6074dd865 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml @@ -39,13 +39,13 @@ ) - + update project_branches set kee = #{newBranchName, jdbcType=VARCHAR}, updated_at = #{now, jdbcType=BIGINT} where - uuid = #{projectUuid, jdbcType=VARCHAR} + uuid = #{branchUuid, jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java index 1c6589f3190..be3f1d37711 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java @@ -106,7 +106,7 @@ public class BranchDaoTest { dto2.setKey("branch"); underTest.insert(dbSession, dto2); - underTest.updateMainBranchName(dbSession, "U1", "master"); + underTest.updateBranchName(dbSession, "U1", "master"); BranchDto loaded = underTest.selectByBranchKey(dbSession, "U1", "master").get(); assertThat(loaded.getMergeBranchUuid()).isNull(); assertThat(loaded.getProjectUuid()).isEqualTo("U1"); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/RenameAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/RenameAction.java index 4dae323f237..a255db1aaed 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/RenameAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/RenameAction.java @@ -81,7 +81,7 @@ public class RenameAction implements BranchWsAction { checkArgument(!existingBranch.filter(b -> !b.isMain()).isPresent(), "Impossible to update branch name: a branch with name \"%s\" already exists in the project.", newBranchName); - dbClient.branchDao().updateMainBranchName(dbSession, project.getUuid(), newBranchName); + dbClient.branchDao().updateBranchName(dbSession, project.getUuid(), newBranchName); dbSession.commit(); response.noContent(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java index 80ac0430697..dbf16947590 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java @@ -168,7 +168,7 @@ public class ListActionTest { @Test public void main_branch_with_specified_name() { ComponentDto project = db.components().insertPrivateProject(); - db.getDbClient().branchDao().updateMainBranchName(db.getSession(), project.uuid(), "head"); + db.getDbClient().branchDao().updateBranchName(db.getSession(), project.uuid(), "head"); db.commit(); userSession.logIn().addProjectPermission(USER, project); -- 2.39.5