]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17412 minor fixes on log and tests (#6812)
authorLéo Geoffroy <99647462+leo-geoffroy-sonarsource@users.noreply.github.com>
Tue, 11 Oct 2022 07:23:16 +0000 (09:23 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 12 Oct 2022 20:03:44 +0000 (20:03 +0000)
server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java
server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java

index 2e27ce531f5a7998177f658f8689f1b705b8b4ac..261bd7fee94cd1c54976de1c6f2e0e12505597fa 100644 (file)
@@ -51,7 +51,7 @@ public class FavoriteUpdater {
       .setUserUuid(userUuid)
       .setComponentUuid(componentDto.uuid())
       .build(), dbSession);
-    checkArgument(existingFavoriteOnComponent.isEmpty(), "Component '%s' is already a favorite", componentDto.getKey());
+    checkArgument(existingFavoriteOnComponent.isEmpty(), "Component '%s' (uuid: %s) is already a favorite", componentDto.getKey(), componentDto.uuid());
 
     List<PropertyDto> existingFavorites = dbClient.propertiesDao().selectByKeyAndUserUuidAndComponentQualifier(dbSession, PROP_FAVORITE_KEY, userUuid, componentDto.qualifier());
     if (existingFavorites.size() >= 100) {
@@ -81,6 +81,6 @@ public class FavoriteUpdater {
         .setComponentUuid(component.uuid())
         .setUserUuid(userUuid),
       userLogin, component.getKey(), component.name(), component.qualifier());
-    checkArgument(result == 1, "Component '%s' is not a favorite", component.getKey());
+    checkArgument(result == 1, "Component '%s' (uuid: %s) is not a favorite", component.getKey(), component.uuid());
   }
 }
index 3678a2656eb9f302c8cb721d19fa54838c74d374..8bcd228f662adaeb291f0f0ccdef8bc2b095aeb8 100644 (file)
@@ -118,7 +118,7 @@ public class FavoriteUpdaterTest {
 
     assertThatThrownBy(() -> underTest.add(dbSession, project, user.getUuid(), user.getLogin(), true))
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage(String.format("Component '%s' is already a favorite", project.getKey()));
+      .hasMessage(String.format("Component '%s' (uuid: %s) is already a favorite", project.getKey(), project.uuid()));
   }
 
   private void assertFavorite(ComponentDto project, UserDto user) {
index 35e910cfba7251a2f5875faa0bdbd40fa0a98a4a..ff8cb14dcc33546756b87336c99c29cfbc2734bc 100644 (file)
@@ -78,7 +78,8 @@ public class LiveMeasureTreeUpdaterImpl implements LiveMeasureTreeUpdater {
           try {
             formula.computeHierarchy(context);
           } catch (RuntimeException e) {
-            throw new IllegalStateException("Fail to compute " + formula.getMetric().getKey() + " on " + context.getComponent().getKey(), e);
+            throw new IllegalStateException("Fail to compute " + formula.getMetric().getKey() + " on "
+              + context.getComponent().getKey() + " (uuid: " + context.getComponent().uuid() + ")", e);
           }
         }
       }
@@ -98,7 +99,8 @@ public class LiveMeasureTreeUpdaterImpl implements LiveMeasureTreeUpdater {
           try {
             formula.compute(context, issueCounter);
           } catch (RuntimeException e) {
-            throw new IllegalStateException("Fail to compute " + formula.getMetric().getKey() + " on " + context.getComponent().getKey(), e);
+            throw new IllegalStateException("Fail to compute " + formula.getMetric().getKey() + " on "
+              + context.getComponent().getKey() + " (uuid: " + context.getComponent().uuid() + ")", e);
           }
         }
       }
index 109205b4b7f39fabde458907973b2fecc01b668c..9696837f1645dffaa658e05902140914a7eb19fe 100644 (file)
@@ -146,7 +146,8 @@ public class LinesAction implements SourcesWsAction {
       int from = request.mandatoryParamAsInt(PARAM_FROM);
       int to = MoreObjects.firstNonNull(request.paramAsInt(PARAM_TO), Integer.MAX_VALUE);
 
-      Iterable<DbFileSources.Line> lines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "No source found for file '%s'", file.getKey());
+      Iterable<DbFileSources.Line> lines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to),
+        "No source found for file '%s' (uuid: %s)", file.getKey(), file.uuid());
       try (JsonWriter json = response.newJsonWriter()) {
         json.beginObject();
         linesJsonWriter.writeSource(lines, json, periodDateSupplier);
index f71292b5740acf82e7d51176d4c2ea8a7b1875aa..aa613ea067a4f16aebe344e74db236d7f016dbbf 100644 (file)
@@ -270,12 +270,14 @@ public class DuplicationsParserTest {
     Duplication duplication1 = duplications.get(0);
     assertThat(duplication1.componentDto()).isEqualTo(file1);
     assertThat(duplication1.componentDto().getKey()).isEqualTo(file1.getKey());
+    assertThat(duplication1.componentDto().branchUuid()).isEqualTo(branch.uuid());
     assertThat(duplication1.from()).isEqualTo(31);
     assertThat(duplication1.size()).isEqualTo(5);
 
     Duplication duplication2 = duplications.get(1);
     assertThat(duplication2.componentDto()).isEqualTo(file2);
     assertThat(duplication2.componentDto().getKey()).isEqualTo(file2.getKey());
+    assertThat(duplication1.componentDto().branchUuid()).isEqualTo(branch.uuid());
     assertThat(duplication2.from()).isEqualTo(20);
     assertThat(duplication2.size()).isEqualTo(5);
   }
@@ -303,12 +305,14 @@ public class DuplicationsParserTest {
     Duplication duplication1 = duplications.get(0);
     assertThat(duplication1.componentDto()).isEqualTo(file1);
     assertThat(duplication1.componentDto().getKey()).isEqualTo(file1.getKey());
+    assertThat(duplication1.componentDto().branchUuid()).isEqualTo(pullRequest.uuid());
     assertThat(duplication1.from()).isEqualTo(31);
     assertThat(duplication1.size()).isEqualTo(5);
 
     Duplication duplication2 = duplications.get(1);
     assertThat(duplication2.componentDto()).isEqualTo(file2);
     assertThat(duplication2.componentDto().getKey()).isEqualTo(file2.getKey());
+    assertThat(duplication1.componentDto().branchUuid()).isEqualTo(pullRequest.uuid());
     assertThat(duplication2.from()).isEqualTo(20);
     assertThat(duplication2.size()).isEqualTo(5);
   }
index d8a5b32a3528c05de2f0e30f63350b2425827638..39d77aecff0b9fdc4fddc6850105a01023a1b7b6 100644 (file)
@@ -82,11 +82,11 @@ public class RemoveActionTest {
 
   @Test
   public void fail_if_not_already_a_favorite() {
-    insertProjectAndPermissions();
+    ComponentDto componentDto = insertProjectAndPermissions();
 
     assertThatThrownBy(() -> call(PROJECT_KEY))
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Component '" + PROJECT_KEY + "' is not a favorite");
+      .hasMessage("Component '" + PROJECT_KEY + "' (uuid: "+componentDto.uuid()+") is not a favorite");
   }
 
   @Test