]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17254 added coverage for renaming the main branch of the application
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Wed, 14 Dec 2022 10:16:17 +0000 (11:16 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 15 Dec 2022 20:03:33 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/RenameAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java

index 1dff7ccc75bed838be3f345695898421358d51f9..65f6017774150017de4f95a8def6428bd16ac0ed 100644 (file)
@@ -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) {
index eebd797906abbe2e4ddab97c4cc79c7be830f839..a840d00be87e0fa06649fde1a119779ef397120c 100644 (file)
@@ -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);
index ab077238c9f81e9269cd9af58a9dd3c446ab61b2..fc6074dd8650c9ecc7238a146f419c6381171241 100644 (file)
     )
   </insert>
 
-  <update id="updateMainBranchName" parameterType="map">
+  <update id="updateBranchName" parameterType="map">
     update project_branches
     set
       kee = #{newBranchName, jdbcType=VARCHAR},
       updated_at = #{now, jdbcType=BIGINT}
     where
-      uuid = #{projectUuid, jdbcType=VARCHAR}
+      uuid = #{branchUuid, jdbcType=VARCHAR}
   </update>
 
   <update id="updateExcludeFromPurge">
index 1c6589f3190506101156f8426f5b7ed7479a9957..be3f1d37711b648520654ed4ab4ba0a887ea5701 100644 (file)
@@ -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");
index 4dae323f237a02e2d03deca86eda2d036104d50b..a255db1aaed74041cd6c5a6916940034e3c5a80a 100644 (file)
@@ -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();
     }
index 80ac0430697f4ffbb059b30d6ba3a9fe264260e3..dbf169475904eaad28ce6cacf19ef0188dedcbe4 100644 (file)
@@ -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);