From 0d4b2cabcf45adc9faec4a08e205abd3e327f9ad Mon Sep 17 00:00:00 2001 From: Tobias Hahnen Date: Mon, 26 Aug 2024 16:13:02 +0200 Subject: [PATCH] SLE-923,SLE-927: PR feedback + additional IT This incorporates feedback regarding the phrasing. Additionally, another IT was added featuring a fix suggestion with two changes with the second one being outside of the file range. And only the first one can be accepted. --- .../sc/SonarCloudConnectedModeTest.java | 109 +++++++++++++++--- .../ConfirmConnectionCreationDialog.java | 2 +- ...irmSonarCloudConnectionCreationDialog.java | 2 +- .../ui/internal/util/MessageDialogUtils.java | 2 +- 4 files changed, 98 insertions(+), 17 deletions(-) diff --git a/its/org.sonarlint.eclipse.its.connected.sc/src/org/sonarlint/eclipse/its/connected/sc/SonarCloudConnectedModeTest.java b/its/org.sonarlint.eclipse.its.connected.sc/src/org/sonarlint/eclipse/its/connected/sc/SonarCloudConnectedModeTest.java index 128ac273c..d954a6250 100644 --- a/its/org.sonarlint.eclipse.its.connected.sc/src/org/sonarlint/eclipse/its/connected/sc/SonarCloudConnectedModeTest.java +++ b/its/org.sonarlint.eclipse.its.connected.sc/src/org/sonarlint/eclipse/its/connected/sc/SonarCloudConnectedModeTest.java @@ -73,7 +73,7 @@ public class SonarCloudConnectedModeTest extends AbstractSonarLintTest { private static final String SONARCLOUD_PASSWORD = System.getenv("SONARCLOUD_IT_PASSWORD"); private static final String TOKEN_NAME = "SLE-IT-" + TIMESTAMP; private static final String CONNECTION_NAME = "connection"; - private static final String SAMPLE_JAVA_ISSUES_KEY = "sonarlint-its-sample-java-issues"; + private static final String SAMPLE_JAVA_ISSUES_PROJECT_KEY = "sonarlint-its-sample-java-issues"; private static WsClient adminWsClient; private static String token; @@ -180,7 +180,7 @@ public void configureServerWithTokenAndOrganization() throws InterruptedExceptio @Test public void fixSuggestion_with_ConnectionSetup_noProject() throws InterruptedException, IOException { - triggerOpenFixSuggestion(firstSonarCloudProjectKey, + triggerOpenFixSuggestionWithOneChange(firstSonarCloudProjectKey, firstSonarCloudIssueKey, "NotExisting.txt", "fixSuggestion_with_ConnectionSetup_noProject", @@ -199,9 +199,9 @@ public void fixSuggestion_with_ConnectionSetup_noProject() throws InterruptedExc @Test public void fixSuggestion_with_ConnectionSetup_fileNotFound() throws InterruptedException, IOException { - importExistingProjectIntoWorkspace("connected-sc/" + SAMPLE_JAVA_ISSUES_KEY, SAMPLE_JAVA_ISSUES_KEY); + importExistingProjectIntoWorkspace("connected-sc/" + SAMPLE_JAVA_ISSUES_PROJECT_KEY, SAMPLE_JAVA_ISSUES_PROJECT_KEY); - triggerOpenFixSuggestion(firstSonarCloudProjectKey, + triggerOpenFixSuggestionWithOneChange(firstSonarCloudProjectKey, firstSonarCloudIssueKey, "NotExisting.txt", "fixSuggestion_with_ConnectionSetup_fileNotFound", @@ -220,7 +220,7 @@ public void fixSuggestion_with_ConnectionSetup_fileNotFound() throws Interrupted } @Test - public void fixSuggestion_with_fixes() throws InterruptedException, IOException { + public void fixSuggestion_with_fix() throws InterruptedException, IOException { final var file = "FileExists.txt"; final var explanation = "This is common knowledge!"; final var before = "Eclipse IDE is the best!"; @@ -228,10 +228,10 @@ public void fixSuggestion_with_fixes() throws InterruptedException, IOException final var startLine = 0; final var endLine = 1; - importExistingProjectIntoWorkspace("connected-sc/" + SAMPLE_JAVA_ISSUES_KEY, SAMPLE_JAVA_ISSUES_KEY); + importExistingProjectIntoWorkspace("connected-sc/" + SAMPLE_JAVA_ISSUES_PROJECT_KEY, SAMPLE_JAVA_ISSUES_PROJECT_KEY); // 1) Cancel the suggestion (available) - triggerOpenFixSuggestion(firstSonarCloudProjectKey, firstSonarCloudIssueKey, file, explanation, before, after, startLine, endLine); + triggerOpenFixSuggestionWithOneChange(firstSonarCloudProjectKey, firstSonarCloudIssueKey, file, explanation, before, after, startLine, endLine); new WaitUntil(new ConfirmConnectionCreationDialogOpened(true)); new ConfirmConnectionCreationDialog(true).trust(); @@ -243,30 +243,68 @@ public void fixSuggestion_with_fixes() throws InterruptedException, IOException new FixSuggestionAvailableDialog(0, 1).cancel(); // 2) Decline the suggestion - triggerOpenFixSuggestion(firstSonarCloudProjectKey, firstSonarCloudIssueKey, file, explanation, before, after, startLine, endLine); + triggerOpenFixSuggestionWithOneChange(firstSonarCloudProjectKey, firstSonarCloudIssueKey, file, explanation, before, after, startLine, endLine); new WaitUntil(new FixSuggestionAvailableDialogOpened(0, 1)); new FixSuggestionAvailableDialog(0, 1).declineTheChange(); // 3) Apply the suggestion - triggerOpenFixSuggestion(firstSonarCloudProjectKey, firstSonarCloudIssueKey, file, explanation, before, after, startLine, endLine); + triggerOpenFixSuggestionWithOneChange(firstSonarCloudProjectKey, firstSonarCloudIssueKey, file, explanation, before, after, startLine, endLine); new WaitUntil(new FixSuggestionAvailableDialogOpened(0, 1)); new FixSuggestionAvailableDialog(0, 1).applyTheChange(); // 4) Cancel the suggestion (unavailable) - triggerOpenFixSuggestion(firstSonarCloudProjectKey, firstSonarCloudIssueKey, file, explanation, before, after, startLine, endLine); + triggerOpenFixSuggestionWithOneChange(firstSonarCloudProjectKey, firstSonarCloudIssueKey, file, explanation, before, after, startLine, endLine); new WaitUntil(new FixSuggestionUnavailableDialogOpened(0, 1)); new FixSuggestionUnavailableDialog(0, 1).cancel(); // 5) Suggestion not found - triggerOpenFixSuggestion(firstSonarCloudProjectKey, firstSonarCloudIssueKey, file, explanation, before, after, startLine, endLine); + triggerOpenFixSuggestionWithOneChange(firstSonarCloudProjectKey, firstSonarCloudIssueKey, file, explanation, before, after, startLine, endLine); new WaitUntil(new FixSuggestionUnavailableDialogOpened(0, 1)); new FixSuggestionUnavailableDialog(0, 1).proceed(); } + @Test + public void fixSuggestion_with_multipleFixes() throws InterruptedException, IOException { + final var file = "FileExists.txt"; + final var explanation = "We need to change this!"; + final var before = "Eclipse IDE is the best!"; + final var firstAfter = "IntelliJ IDEA is not the best!"; + final var secondAfter = "PyCharm CE is also quite okey!"; + final var firstStartLine = 0; + final var firstEndLine = 1; + final var secondStartLine = 1107; + final var secondEndLine = 1108; + + importExistingProjectIntoWorkspace("connected-sc/" + SAMPLE_JAVA_ISSUES_PROJECT_KEY, SAMPLE_JAVA_ISSUES_PROJECT_KEY); + + // 1) Cancel the suggestion (available) + triggerOpenFixSuggestionWithTwoChanges( + firstSonarCloudProjectKey, + firstSonarCloudIssueKey, + file, + explanation, + before, firstAfter, firstStartLine, firstEndLine, + firstAfter, secondAfter, secondStartLine, secondEndLine); + + new WaitUntil(new ConfirmConnectionCreationDialogOpened(true)); + new ConfirmConnectionCreationDialog(true).trust(); + + new WaitUntil(new ProjectSelectionDialogOpened()); + new ProjectSelectionDialog().ok(); + + // 1) Accept first suggestion + new WaitUntil(new FixSuggestionAvailableDialogOpened(0, 2)); + new FixSuggestionAvailableDialog(0, 2).applyTheChange(); + + // 2) Proceed with second suggestion (way out of range of the file) + new WaitUntil(new FixSuggestionUnavailableDialogOpened(1, 2)); + new FixSuggestionUnavailableDialog(1, 2).proceed(); + } + private static List getProjectKeys() throws InterruptedException, IOException { assertThat(hotspotServerPort).isNotEqualTo(-1); @@ -286,7 +324,7 @@ private static List getProjectKeys() throws InterruptedException, IOExce var projectsList = jsonObject.get("components").getAsJsonArray(); for (var project : projectsList) { var key = project.getAsJsonObject().get("key").getAsString(); - if (key.contains(SAMPLE_JAVA_ISSUES_KEY)) { + if (key.contains(SAMPLE_JAVA_ISSUES_PROJECT_KEY)) { projectKeys.add(key); } } @@ -320,8 +358,9 @@ private static Branch getFirstBranch(String projectKey) { return response.getBranches(0); } - private void triggerOpenFixSuggestion(String projectKey, String issueKey, String relativePath, String explanation, - String before, String after, int startLine, int endLine) throws InterruptedException, IOException { + private void triggerOpenFixSuggestionWithOneChange(String projectKey, String issueKey, String relativePath, + String explanation, String before, String after, int startLine, int endLine) + throws InterruptedException, IOException { assertThat(hotspotServerPort).isNotEqualTo(-1); var body = "{" @@ -342,6 +381,48 @@ private void triggerOpenFixSuggestion(String projectKey, String issueKey, String + "}" + "}"; + triggerOpenFixSuggestion(projectKey, issueKey, body); + } + + private void triggerOpenFixSuggestionWithTwoChanges(String projectKey, String issueKey, String relativePath, + String explanation, String firstBefore, String firstAfter, int firstStartLine, int firstEndLine, + String secondBefore, String secondAfter, int secondStartLine, int secondEndLine) + throws InterruptedException, IOException { + assertThat(hotspotServerPort).isNotEqualTo(-1); + + var body = "{" + + "\"suggestionId\":\"9689b623-708e-4128-ae90-8432206c61fe\"," + + "\"explanation\":\"" + explanation + "\"," + + "\"fileEdit\":{" + + "\"path\":\"" + relativePath + "\"," + + "\"changes\":[" + + "{" + + "\"before\":\"" + firstBefore + "\"," + + "\"after\":\"" + firstAfter + "\"," + + "\"beforeLineRange\":{" + + "\"startLine\":" + firstStartLine + "," + + "\"endLine\":" + firstEndLine + + "}" + + "}," + + "{" + + "\"before\":\"" + secondBefore + "\"," + + "\"after\":\"" + secondAfter + "\"," + + "\"beforeLineRange\":{" + + "\"startLine\":" + secondStartLine + "," + + "\"endLine\":" + secondEndLine + + "}" + + "}" + + "]" + + "}" + + "}"; + + triggerOpenFixSuggestion(projectKey, issueKey, body); + } + + private void triggerOpenFixSuggestion(String projectKey, String issueKey, String body) + throws InterruptedException, IOException { + assertThat(hotspotServerPort).isNotEqualTo(-1); + var request = HttpRequest.newBuilder() .uri(URI.create("http://localhost:" + hotspotServerPort + "/sonarlint/api/fix/show" diff --git a/its/org.sonarlint.eclipse.its.shared/src/org/sonarlint/eclipse/its/shared/reddeer/dialogs/ConfirmConnectionCreationDialog.java b/its/org.sonarlint.eclipse.its.shared/src/org/sonarlint/eclipse/its/shared/reddeer/dialogs/ConfirmConnectionCreationDialog.java index 3cf8e30f0..bc5f53ce5 100644 --- a/its/org.sonarlint.eclipse.its.shared/src/org/sonarlint/eclipse/its/shared/reddeer/dialogs/ConfirmConnectionCreationDialog.java +++ b/its/org.sonarlint.eclipse.its.shared/src/org/sonarlint/eclipse/its/shared/reddeer/dialogs/ConfirmConnectionCreationDialog.java @@ -26,7 +26,7 @@ public class ConfirmConnectionCreationDialog extends DefaultShell { public ConfirmConnectionCreationDialog(boolean isSonarCloud) { super(isSonarCloud - ? "Do you trust SonarCloud?" + ? "Do you trust this SonarCloud organization?" : "Do you trust this SonarQube server?"); this.isSonarCloud = isSonarCloud; } diff --git a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/binding/assist/ConfirmSonarCloudConnectionCreationDialog.java b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/binding/assist/ConfirmSonarCloudConnectionCreationDialog.java index de3141e15..4d7e817d6 100644 --- a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/binding/assist/ConfirmSonarCloudConnectionCreationDialog.java +++ b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/binding/assist/ConfirmSonarCloudConnectionCreationDialog.java @@ -24,7 +24,7 @@ public class ConfirmSonarCloudConnectionCreationDialog extends AbstractConfirmConnectionCreationDialog { public ConfirmSonarCloudConnectionCreationDialog(Shell parentShell, String organization, boolean automaticSetUp) { super(parentShell, - "Do you trust SonarCloud?", + "Do you trust this SonarCloud organization?", "SonarCloud is attempting to set up a connection for the organization '" + organization + "' with SonarLint.", "Connect to SonarCloud", automaticSetUp); diff --git a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/util/MessageDialogUtils.java b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/util/MessageDialogUtils.java index 024d83274..ea9a535ff 100644 --- a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/util/MessageDialogUtils.java +++ b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/util/MessageDialogUtils.java @@ -46,7 +46,7 @@ public static void dialogCancelled(String message) { } public static void branchMismatch(String message) { - showError("Branch not matching", message); + showError("Branch does not match", message); } public static void openInEclipseFailed(String message) {