diff options
author | Julien Camus <julien.camus@sonarsource.com> | 2024-12-19 14:14:10 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-12-19 20:03:04 +0000 |
commit | 8fe712960e07591f6cc2f8aa2e164a6eb9ad67fa (patch) | |
tree | 2dc4a7534b311092542ebacdbd22af13c47b823e | |
parent | 1b2aa4e56280456d456ef960671423f543dba283 (diff) | |
download | sonarqube-8fe712960e07591f6cc2f8aa2e164a6eb9ad67fa.tar.gz sonarqube-8fe712960e07591f6cc2f8aa2e164a6eb9ad67fa.zip |
SONAR-23990 Replace with text block
36 files changed, 1527 insertions, 1291 deletions
diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java index c240799a9f7..d95ccb08e10 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java @@ -63,17 +63,19 @@ public class AzureDevOpsHttpClientTest { @Test public void check_pat() throws InterruptedException { - enqueueResponse(200, " { \"count\": 1,\n" + - " \"value\": [\n" + - " {\n" + - " \"id\": \"3311cd05-3f00-4a5e-b47f-df94a9982b6e\",\n" + - " \"name\": \"Project\",\n" + - " \"description\": \"Project Description\",\n" + - " \"url\": \"https://ado.sonarqube.com/DefaultCollection/_apis/projects/3311cd05-3f00-4a5e-b47f-df94a9982b6e\",\n" + - " \"state\": \"wellFormed\",\n" + - " \"revision\": 63,\n" + - " \"visibility\": \"private\"\n" + - " }]}"); + enqueueResponse(200, """ + { "count": 1, + "value": [ + { + "id": "3311cd05-3f00-4a5e-b47f-df94a9982b6e", + "name": "Project", + "description": "Project Description", + "url": "https://ado.sonarqube.com/DefaultCollection/_apis/projects/3311cd05-3f00-4a5e-b47f-df94a9982b6e", + "state": "wellFormed", + "revision": 63, + "visibility": "private" + }]}\ + """); underTest.checkPAT(server.url("").toString(), "token"); @@ -108,25 +110,26 @@ public class AzureDevOpsHttpClientTest { @Test public void get_projects() throws InterruptedException { - enqueueResponse(200, " { \"count\": 2,\n" + - " \"value\": [\n" + - " {\n" + - " \"id\": \"3311cd05-3f00-4a5e-b47f-df94a9982b6e\",\n" + - " \"name\": \"Project 1\",\n" + - " \"description\": \"Project Description\",\n" + - " \"url\": \"https://ado.sonarqube.com/DefaultCollection/_apis/projects/3311cd05-3f00-4a5e-b47f-df94a9982b6e\",\n" + - " \"state\": \"wellFormed\",\n" + - " \"revision\": 63,\n" + - " \"visibility\": \"private\"\n" + - " }," + - "{\n" + - " \"id\": \"3be0f34d-c931-4ff8-8d37-18a83663bd3c\",\n" + - " \"name\": \"Project 2\",\n" + - " \"url\": \"https://ado.sonarqube.com/DefaultCollection/_apis/projects/3be0f34d-c931-4ff8-8d37-18a83663bd3c\",\n" + - " \"state\": \"wellFormed\",\n" + - " \"revision\": 52,\n" + - " \"visibility\": \"private\"\n" + - " }]}"); + enqueueResponse(200, """ + { "count": 2, + "value": [ + { + "id": "3311cd05-3f00-4a5e-b47f-df94a9982b6e", + "name": "Project 1", + "description": "Project Description", + "url": "https://ado.sonarqube.com/DefaultCollection/_apis/projects/3311cd05-3f00-4a5e-b47f-df94a9982b6e", + "state": "wellFormed", + "revision": 63, + "visibility": "private" + },\ + { + "id": "3be0f34d-c931-4ff8-8d37-18a83663bd3c", + "name": "Project 2", + "url": "https://ado.sonarqube.com/DefaultCollection/_apis/projects/3be0f34d-c931-4ff8-8d37-18a83663bd3c", + "state": "wellFormed", + "revision": 52, + "visibility": "private" + }]}"""); GsonAzureProjectList projects = underTest.getProjects(server.url("").toString(), "token"); @@ -197,26 +200,27 @@ public class AzureDevOpsHttpClientTest { @Test public void get_repos_with_project_name() throws InterruptedException { - enqueueResponse(200, "{\n" + - " \"value\": [\n" + - " {\n" + - " \"id\": \"741248a4-285e-4a6d-af52-1a49d8070638\",\n" + - " \"name\": \"Repository 1\",\n" + - " \"url\": \"https://ado.sonarqube.com/repositories/\",\n" + - " \"project\": {\n" + - " \"id\": \"c88ddb32-ced8-420d-ab34-764133038b34\",\n" + - " \"name\": \"projectName\",\n" + - " \"url\": \"https://ado.sonarqube.com/DefaultCollection/_apis/projects/c88ddb32-ced8-420d-ab34-764133038b34\",\n" + - " \"state\": \"wellFormed\",\n" + - " \"revision\": 29,\n" + - " \"visibility\": \"private\",\n" + - " \"lastUpdateTime\": \"2020-11-11T09:38:03.3Z\"\n" + - " },\n" + - " \"size\": 0\n" + - " }\n" + - " ],\n" + - " \"count\": 1\n" + - "}"); + enqueueResponse(200, """ + { + "value": [ + { + "id": "741248a4-285e-4a6d-af52-1a49d8070638", + "name": "Repository 1", + "url": "https://ado.sonarqube.com/repositories/", + "project": { + "id": "c88ddb32-ced8-420d-ab34-764133038b34", + "name": "projectName", + "url": "https://ado.sonarqube.com/DefaultCollection/_apis/projects/c88ddb32-ced8-420d-ab34-764133038b34", + "state": "wellFormed", + "revision": 29, + "visibility": "private", + "lastUpdateTime": "2020-11-11T09:38:03.3Z" + }, + "size": 0 + } + ], + "count": 1 + }"""); GsonAzureRepoList repos = underTest.getRepos(server.url("").toString(), "token", "projectName"); @@ -257,18 +261,19 @@ public class AzureDevOpsHttpClientTest { @Test public void get_repo() throws InterruptedException { - enqueueResponse(200, "{ " + - " \"id\": \"Repo-Id-1\",\n" + - " \"name\": \"Repo-Name-1\",\n" + - " \"url\": \"https://ado.sonarqube.com/DefaultCollection/Repo-Id-1\",\n" + - " \"project\": {\n" + - " \"id\": \"84ea9d51-0c8a-44ad-be92-b2af7fe2c299\",\n" + - " \"name\": \"Project-Name\",\n" + - " \"description\": \"Project's description\" \n" + - " },\n" + - " \"defaultBranch\": \"refs/heads/default-branch\",\n" + - " \"size\": 0" + - "}"); + enqueueResponse(200, """ + { \ + "id": "Repo-Id-1", + "name": "Repo-Name-1", + "url": "https://ado.sonarqube.com/DefaultCollection/Repo-Id-1", + "project": { + "id": "84ea9d51-0c8a-44ad-be92-b2af7fe2c299", + "name": "Project-Name", + "description": "Project's description"\s + }, + "defaultBranch": "refs/heads/default-branch", + "size": 0\ + }"""); GsonAzureRepo repo = underTest.getRepo(server.url("").toString(), "token", "Project-Name", "Repo-Name-1"); diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java index 1a4ce443110..86e3d33e489 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java @@ -82,30 +82,31 @@ public class BitbucketCloudRestClientTest { public void get_repos() { server.enqueue(new MockResponse() .setHeader("Content-Type", "application/json;charset=UTF-8") - .setBody("{\n" + - " \"values\": [\n" + - " {\n" + - " \"slug\": \"banana\",\n" + - " \"uuid\": \"BANANA-UUID\",\n" + - " \"name\": \"banana\",\n" + - " \"project\": {\n" + - " \"key\": \"HOY\",\n" + - " \"uuid\": \"BANANA-PROJECT-UUID\",\n" + - " \"name\": \"hoy\"\n" + - " }\n" + - " },\n" + - " {\n" + - " \"slug\": \"potato\",\n" + - " \"uuid\": \"POTATO-UUID\",\n" + - " \"name\": \"potato\",\n" + - " \"project\": {\n" + - " \"key\": \"HEY\",\n" + - " \"uuid\": \"POTATO-PROJECT-UUID\",\n" + - " \"name\": \"hey\"\n" + - " }\n" + - " }\n" + - " ]\n" + - "}")); + .setBody(""" + { + "values": [ + { + "slug": "banana", + "uuid": "BANANA-UUID", + "name": "banana", + "project": { + "key": "HOY", + "uuid": "BANANA-PROJECT-UUID", + "name": "hoy" + } + }, + { + "slug": "potato", + "uuid": "POTATO-UUID", + "name": "potato", + "project": { + "key": "HEY", + "uuid": "POTATO-PROJECT-UUID", + "name": "hey" + } + } + ] + }""")); RepositoryList repositoryList = underTest.searchRepos("user:apppwd", "", null, 1, 100); assertThat(repositoryList.getNext()).isNull(); @@ -122,21 +123,22 @@ public class BitbucketCloudRestClientTest { public void get_repo() { server.enqueue(new MockResponse() .setHeader("Content-Type", "application/json;charset=UTF-8") - .setBody( - " {\n" + - " \"slug\": \"banana\",\n" + - " \"uuid\": \"BANANA-UUID\",\n" + - " \"name\": \"banana\",\n" + - " \"mainbranch\": {\n" + - " \"type\": \"branch\",\n" + - " \"name\": \"develop\"\n" + - " }," + - " \"project\": {\n" + - " \"key\": \"HOY\",\n" + - " \"uuid\": \"BANANA-PROJECT-UUID\",\n" + - " \"name\": \"hoy\"\n" + - " }\n" + - " }")); + .setBody(""" + { + "slug": "banana", + "uuid": "BANANA-UUID", + "name": "banana", + "mainbranch": { + "type": "branch", + "name": "develop" + },\ + "project": { + "key": "HOY", + "uuid": "BANANA-PROJECT-UUID", + "name": "hoy" + } + }\ + """)); Repository repository = underTest.getRepo("user:apppwd", "workspace", "rep"); assertThat(repository.getUuid()).isEqualTo("BANANA-UUID"); @@ -279,11 +281,12 @@ public class BitbucketCloudRestClientTest { @Test public void validate_app_password_success() throws Exception { - String reposResponse = "{\"pagelen\": 10,\n" + - "\"values\": [],\n" + - "\"page\": 1,\n" + - "\"size\": 0\n" + - "}"; + String reposResponse = """ + {"pagelen": 10, + "values": [], + "page": 1, + "size": 0 + }"""; server.enqueue(new MockResponse().setBody(reposResponse)); server.enqueue(new MockResponse().setBody("OK")); @@ -357,14 +360,14 @@ public class BitbucketCloudRestClientTest { @Test public void validate_fails_when_ssl_verification_failed() throws IOException { - //GIVEN + // GIVEN OkHttpClient okHttpClient = mock(OkHttpClient.class); Call call = mock(Call.class); underTest = new BitbucketCloudRestClient(okHttpClient, serverURL, serverURL); when(okHttpClient.newCall(any())).thenReturn(call); when(call.execute()).thenThrow(new SSLHandshakeException("SSL verification failed")); - //WHEN - //THEN + // WHEN + // THEN assertThatIllegalArgumentException() .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage(UNABLE_TO_CONTACT_BBC_SERVERS); diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationClientImplTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationClientImplTest.java index 15c2747e6a9..848dfc49b27 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationClientImplTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationClientImplTest.java @@ -644,9 +644,10 @@ public class GithubApplicationClientImplTest { public void listRepositories_returns_empty_results() throws IOException { String appUrl = "https://github.sonarsource.com"; AccessToken accessToken = new UserAccessToken(secure().nextAlphanumeric(10)); - String responseJson = "{\n" - + " \"total_count\": 0\n" - + "}"; + String responseJson = """ + { + "total_count": 0 + }"""; when(githubApplicationHttpClient.get(appUrl, accessToken, format("/search/repositories?q=%s&page=%s&per_page=%s", "fork:true+org:github", 1, 100))) .thenReturn(new OkGetResponse(responseJson)); @@ -851,143 +852,144 @@ public class GithubApplicationClientImplTest { public void getRepository_returns_repository() throws IOException { String appUrl = "https://github.sonarsource.com"; AccessToken accessToken = new UserAccessToken(secure().nextAlphanumeric(10)); - String responseJson = "{\n" - + " \"id\": 1296269,\n" - + " \"node_id\": \"MDEwOlJlcG9zaXRvcnkxMjk2MjY5\",\n" - + " \"name\": \"Hello-World\",\n" - + " \"full_name\": \"octocat/Hello-World\",\n" - + " \"owner\": {\n" - + " \"login\": \"octocat\",\n" - + " \"id\": 1,\n" - + " \"node_id\": \"MDQ6VXNlcjE=\",\n" - + " \"avatar_url\": \"https://github.sonarsource.com/images/error/octocat_happy.gif\",\n" - + " \"gravatar_id\": \"\",\n" - + " \"url\": \"https://github.sonarsource.com/api/v3/users/octocat\",\n" - + " \"html_url\": \"https://github.com/octocat\",\n" - + " \"followers_url\": \"https://github.sonarsource.com/api/v3/users/octocat/followers\",\n" - + " \"following_url\": \"https://github.sonarsource.com/api/v3/users/octocat/following{/other_user}\",\n" - + " \"gists_url\": \"https://github.sonarsource.com/api/v3/users/octocat/gists{/gist_id}\",\n" - + " \"starred_url\": \"https://github.sonarsource.com/api/v3/users/octocat/starred{/owner}{/repo}\",\n" - + " \"subscriptions_url\": \"https://github.sonarsource.com/api/v3/users/octocat/subscriptions\",\n" - + " \"organizations_url\": \"https://github.sonarsource.com/api/v3/users/octocat/orgs\",\n" - + " \"repos_url\": \"https://github.sonarsource.com/api/v3/users/octocat/repos\",\n" - + " \"events_url\": \"https://github.sonarsource.com/api/v3/users/octocat/events{/privacy}\",\n" - + " \"received_events_url\": \"https://github.sonarsource.com/api/v3/users/octocat/received_events\",\n" - + " \"type\": \"User\",\n" - + " \"site_admin\": false\n" - + " },\n" - + " \"private\": false,\n" - + " \"html_url\": \"https://github.com/octocat/Hello-World\",\n" - + " \"description\": \"This your first repo!\",\n" - + " \"fork\": false,\n" - + " \"url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World\",\n" - + " \"archive_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/{archive_format}{/ref}\",\n" - + " \"assignees_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/assignees{/user}\",\n" - + " \"blobs_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/git/blobs{/sha}\",\n" - + " \"branches_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/branches{/branch}\",\n" - + " \"collaborators_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/collaborators{/collaborator}\",\n" - + " \"comments_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/comments{/number}\",\n" - + " \"commits_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/commits{/sha}\",\n" - + " \"compare_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/compare/{base}...{head}\",\n" - + " \"contents_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/contents/{+path}\",\n" - + " \"contributors_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/contributors\",\n" - + " \"deployments_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/deployments\",\n" - + " \"downloads_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/downloads\",\n" - + " \"events_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/events\",\n" - + " \"forks_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/forks\",\n" - + " \"git_commits_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/git/commits{/sha}\",\n" - + " \"git_refs_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/git/refs{/sha}\",\n" - + " \"git_tags_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/git/tags{/sha}\",\n" - + " \"git_url\": \"git:github.com/octocat/Hello-World.git\",\n" - + " \"issue_comment_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/issues/comments{/number}\",\n" - + " \"issue_events_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/issues/events{/number}\",\n" - + " \"issues_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/issues{/number}\",\n" - + " \"keys_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/keys{/key_id}\",\n" - + " \"labels_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/labels{/name}\",\n" - + " \"languages_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/languages\",\n" - + " \"merges_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/merges\",\n" - + " \"milestones_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/milestones{/number}\",\n" - + " \"notifications_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/notifications{?since,all,participating}\",\n" - + " \"pulls_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/pulls{/number}\",\n" - + " \"releases_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/releases{/id}\",\n" - + " \"ssh_url\": \"git@github.com:octocat/Hello-World.git\",\n" - + " \"stargazers_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/stargazers\",\n" - + " \"statuses_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/statuses/{sha}\",\n" - + " \"subscribers_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/subscribers\",\n" - + " \"subscription_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/subscription\",\n" - + " \"tags_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/tags\",\n" - + " \"teams_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/teams\",\n" - + " \"trees_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/git/trees{/sha}\",\n" - + " \"clone_url\": \"https://github.com/octocat/Hello-World.git\",\n" - + " \"mirror_url\": \"git:git.example.com/octocat/Hello-World\",\n" - + " \"hooks_url\": \"https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/hooks\",\n" - + " \"svn_url\": \"https://svn.github.com/octocat/Hello-World\",\n" - + " \"homepage\": \"https://github.com\",\n" - + " \"language\": null,\n" - + " \"forks_count\": 9,\n" - + " \"stargazers_count\": 80,\n" - + " \"watchers_count\": 80,\n" - + " \"size\": 108,\n" - + " \"default_branch\": \"master\",\n" - + " \"open_issues_count\": 0,\n" - + " \"is_template\": true,\n" - + " \"topics\": [\n" - + " \"octocat\",\n" - + " \"atom\",\n" - + " \"electron\",\n" - + " \"api\"\n" - + " ],\n" - + " \"has_issues\": true,\n" - + " \"has_projects\": true,\n" - + " \"has_wiki\": true,\n" - + " \"has_pages\": false,\n" - + " \"has_downloads\": true,\n" - + " \"archived\": false,\n" - + " \"disabled\": false,\n" - + " \"visibility\": \"public\",\n" - + " \"pushed_at\": \"2011-01-26T19:06:43Z\",\n" - + " \"created_at\": \"2011-01-26T19:01:12Z\",\n" - + " \"updated_at\": \"2011-01-26T19:14:43Z\",\n" - + " \"permissions\": {\n" - + " \"admin\": false,\n" - + " \"push\": false,\n" - + " \"pull\": true\n" - + " },\n" - + " \"allow_rebase_merge\": true,\n" - + " \"template_repository\": null,\n" - + " \"allow_squash_merge\": true,\n" - + " \"allow_merge_commit\": true,\n" - + " \"subscribers_count\": 42,\n" - + " \"network_count\": 0,\n" - + " \"anonymous_access_enabled\": false,\n" - + " \"license\": {\n" - + " \"key\": \"mit\",\n" - + " \"name\": \"MIT License\",\n" - + " \"spdx_id\": \"MIT\",\n" - + " \"url\": \"https://github.sonarsource.com/api/v3/licenses/mit\",\n" - + " \"node_id\": \"MDc6TGljZW5zZW1pdA==\"\n" - + " },\n" - + " \"organization\": {\n" - + " \"login\": \"octocat\",\n" - + " \"id\": 1,\n" - + " \"node_id\": \"MDQ6VXNlcjE=\",\n" - + " \"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\",\n" - + " \"gravatar_id\": \"\",\n" - + " \"url\": \"https://github.sonarsource.com/api/v3/users/octocat\",\n" - + " \"html_url\": \"https://github.com/octocat\",\n" - + " \"followers_url\": \"https://github.sonarsource.com/api/v3/users/octocat/followers\",\n" - + " \"following_url\": \"https://github.sonarsource.com/api/v3/users/octocat/following{/other_user}\",\n" - + " \"gists_url\": \"https://github.sonarsource.com/api/v3/users/octocat/gists{/gist_id}\",\n" - + " \"starred_url\": \"https://github.sonarsource.com/api/v3/users/octocat/starred{/owner}{/repo}\",\n" - + " \"subscriptions_url\": \"https://github.sonarsource.com/api/v3/users/octocat/subscriptions\",\n" - + " \"organizations_url\": \"https://github.sonarsource.com/api/v3/users/octocat/orgs\",\n" - + " \"repos_url\": \"https://github.sonarsource.com/api/v3/users/octocat/repos\",\n" - + " \"events_url\": \"https://github.sonarsource.com/api/v3/users/octocat/events{/privacy}\",\n" - + " \"received_events_url\": \"https://github.sonarsource.com/api/v3/users/octocat/received_events\",\n" - + " \"type\": \"Organization\",\n" - + " \"site_admin\": false\n" - + " }" - + "}"; + String responseJson = """ + { + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "owner": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.sonarsource.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://github.sonarsource.com/api/v3/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://github.sonarsource.com/api/v3/users/octocat/followers", + "following_url": "https://github.sonarsource.com/api/v3/users/octocat/following{/other_user}", + "gists_url": "https://github.sonarsource.com/api/v3/users/octocat/gists{/gist_id}", + "starred_url": "https://github.sonarsource.com/api/v3/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://github.sonarsource.com/api/v3/users/octocat/subscriptions", + "organizations_url": "https://github.sonarsource.com/api/v3/users/octocat/orgs", + "repos_url": "https://github.sonarsource.com/api/v3/users/octocat/repos", + "events_url": "https://github.sonarsource.com/api/v3/users/octocat/events{/privacy}", + "received_events_url": "https://github.sonarsource.com/api/v3/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/octocat/Hello-World", + "description": "This your first repo!", + "fork": false, + "url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World", + "archive_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/{archive_format}{/ref}", + "assignees_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/assignees{/user}", + "blobs_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/git/blobs{/sha}", + "branches_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/branches{/branch}", + "collaborators_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/collaborators{/collaborator}", + "comments_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/comments{/number}", + "commits_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/commits{/sha}", + "compare_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/compare/{base}...{head}", + "contents_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/contents/{+path}", + "contributors_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/contributors", + "deployments_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/deployments", + "downloads_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/downloads", + "events_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/events", + "forks_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/forks", + "git_commits_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/git/commits{/sha}", + "git_refs_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/git/refs{/sha}", + "git_tags_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/git/tags{/sha}", + "git_url": "git:github.com/octocat/Hello-World.git", + "issue_comment_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/issues/comments{/number}", + "issue_events_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/issues/events{/number}", + "issues_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/issues{/number}", + "keys_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/keys{/key_id}", + "labels_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/labels{/name}", + "languages_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/languages", + "merges_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/merges", + "milestones_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/milestones{/number}", + "notifications_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/notifications{?since,all,participating}", + "pulls_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/pulls{/number}", + "releases_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/releases{/id}", + "ssh_url": "git@github.com:octocat/Hello-World.git", + "stargazers_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/stargazers", + "statuses_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/statuses/{sha}", + "subscribers_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/subscribers", + "subscription_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/subscription", + "tags_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/tags", + "teams_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/teams", + "trees_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/git/trees{/sha}", + "clone_url": "https://github.com/octocat/Hello-World.git", + "mirror_url": "git:git.example.com/octocat/Hello-World", + "hooks_url": "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World/hooks", + "svn_url": "https://svn.github.com/octocat/Hello-World", + "homepage": "https://github.com", + "language": null, + "forks_count": 9, + "stargazers_count": 80, + "watchers_count": 80, + "size": 108, + "default_branch": "master", + "open_issues_count": 0, + "is_template": true, + "topics": [ + "octocat", + "atom", + "electron", + "api" + ], + "has_issues": true, + "has_projects": true, + "has_wiki": true, + "has_pages": false, + "has_downloads": true, + "archived": false, + "disabled": false, + "visibility": "public", + "pushed_at": "2011-01-26T19:06:43Z", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "allow_rebase_merge": true, + "template_repository": null, + "allow_squash_merge": true, + "allow_merge_commit": true, + "subscribers_count": 42, + "network_count": 0, + "anonymous_access_enabled": false, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://github.sonarsource.com/api/v3/licenses/mit", + "node_id": "MDc6TGljZW5zZW1pdA==" + }, + "organization": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://github.sonarsource.com/api/v3/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://github.sonarsource.com/api/v3/users/octocat/followers", + "following_url": "https://github.sonarsource.com/api/v3/users/octocat/following{/other_user}", + "gists_url": "https://github.sonarsource.com/api/v3/users/octocat/gists{/gist_id}", + "starred_url": "https://github.sonarsource.com/api/v3/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://github.sonarsource.com/api/v3/users/octocat/subscriptions", + "organizations_url": "https://github.sonarsource.com/api/v3/users/octocat/orgs", + "repos_url": "https://github.sonarsource.com/api/v3/users/octocat/repos", + "events_url": "https://github.sonarsource.com/api/v3/users/octocat/events{/privacy}", + "received_events_url": "https://github.sonarsource.com/api/v3/users/octocat/received_events", + "type": "Organization", + "site_admin": false + }\ + }"""; when(githubApplicationHttpClient.get(appUrl, accessToken, "/repos/octocat/Hello-World")) .thenReturn(new GetResponse() { diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java index 90bda331610..d68949469bd 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java @@ -41,9 +41,9 @@ import org.sonar.alm.client.ConstantTimeoutConfiguration; import org.sonar.alm.client.TimeoutConfiguration; import org.sonar.api.testfixtures.log.LogTester; import org.sonar.auth.gitlab.GsonGroup; +import org.sonar.auth.gitlab.GsonMemberRole; import org.sonar.auth.gitlab.GsonProjectMember; import org.sonar.auth.gitlab.GsonUser; -import org.sonar.auth.gitlab.GsonMemberRole; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; @@ -167,21 +167,21 @@ public class GitlabApplicationClientTest { public void get_branches() { MockResponse response = new MockResponse() .setResponseCode(200) - .setBody("[{\n" - + " \"name\": \"main\",\n" - + " \"default\": true\n" - + "},{\n" - + " \"name\": \"other\",\n" - + " \"default\": false\n" - + "}]"); + .setBody(""" + [{ + "name": "main", + "default": true + },{ + "name": "other", + "default": false + }]"""); server.enqueue(response); assertThat(underTest.getBranches(gitlabUrl, "pat", 12345L)) .extracting(GitLabBranch::getName, GitLabBranch::isDefault) .containsExactly( tuple("main", true), - tuple("other", false) - ); + tuple("other", false)); } @Test @@ -211,32 +211,33 @@ public class GitlabApplicationClientTest { public void search_projects() throws InterruptedException { MockResponse projects = new MockResponse() .setResponseCode(200) - .setBody("[\n" - + " {\n" - + " \"id\": 1,\n" - + " \"name\": \"SonarQube example 1\",\n" - + " \"name_with_namespace\": \"SonarSource / SonarQube / SonarQube example 1\",\n" - + " \"path\": \"sonarqube-example-1\",\n" - + " \"path_with_namespace\": \"sonarsource/sonarqube/sonarqube-example-1\",\n" - + " \"web_url\": \"https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1\"\n" - + " },\n" - + " {\n" - + " \"id\": 2,\n" - + " \"name\": \"SonarQube example 2\",\n" - + " \"name_with_namespace\": \"SonarSource / SonarQube / SonarQube example 2\",\n" - + " \"path\": \"sonarqube-example-2\",\n" - + " \"path_with_namespace\": \"sonarsource/sonarqube/sonarqube-example-2\",\n" - + " \"web_url\": \"https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-2\"\n" - + " },\n" - + " {\n" - + " \"id\": 3,\n" - + " \"name\": \"SonarQube example 3\",\n" - + " \"name_with_namespace\": \"SonarSource / SonarQube / SonarQube example 3\",\n" - + " \"path\": \"sonarqube-example-3\",\n" - + " \"path_with_namespace\": \"sonarsource/sonarqube/sonarqube-example-3\",\n" - + " \"web_url\": \"https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-3\"\n" - + " }\n" - + "]"); + .setBody(""" + [ + { + "id": 1, + "name": "SonarQube example 1", + "name_with_namespace": "SonarSource / SonarQube / SonarQube example 1", + "path": "sonarqube-example-1", + "path_with_namespace": "sonarsource/sonarqube/sonarqube-example-1", + "web_url": "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1" + }, + { + "id": 2, + "name": "SonarQube example 2", + "name_with_namespace": "SonarSource / SonarQube / SonarQube example 2", + "path": "sonarqube-example-2", + "path_with_namespace": "sonarsource/sonarqube/sonarqube-example-2", + "web_url": "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-2" + }, + { + "id": 3, + "name": "SonarQube example 3", + "name_with_namespace": "SonarSource / SonarQube / SonarQube example 3", + "path": "sonarqube-example-3", + "path_with_namespace": "sonarsource/sonarqube/sonarqube-example-3", + "web_url": "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-3" + } + ]"""); projects.addHeader("X-Page", 1); projects.addHeader("X-Per-Page", 10); projects.addHeader("X-Total", 3); @@ -251,12 +252,12 @@ public class GitlabApplicationClientTest { assertThat(projectList.getProjects()).hasSize(3); assertThat(projectList.getProjects()).extracting( Project::getId, Project::getName, Project::getNameWithNamespace, Project::getPath, Project::getPathWithNamespace, Project::getWebUrl).containsExactly( - tuple(1L, "SonarQube example 1", "SonarSource / SonarQube / SonarQube example 1", "sonarqube-example-1", "sonarsource/sonarqube/sonarqube-example-1", - "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1"), - tuple(2L, "SonarQube example 2", "SonarSource / SonarQube / SonarQube example 2", "sonarqube-example-2", "sonarsource/sonarqube/sonarqube-example-2", - "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-2"), - tuple(3L, "SonarQube example 3", "SonarSource / SonarQube / SonarQube example 3", "sonarqube-example-3", "sonarsource/sonarqube/sonarqube-example-3", - "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-3")); + tuple(1L, "SonarQube example 1", "SonarSource / SonarQube / SonarQube example 1", "sonarqube-example-1", "sonarsource/sonarqube/sonarqube-example-1", + "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1"), + tuple(2L, "SonarQube example 2", "SonarSource / SonarQube / SonarQube example 2", "sonarqube-example-2", "sonarsource/sonarqube/sonarqube-example-2", + "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-2"), + tuple(3L, "SonarQube example 3", "SonarSource / SonarQube / SonarQube example 3", "sonarqube-example-3", "sonarsource/sonarqube/sonarqube-example-3", + "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-3")); RecordedRequest projectGitlabRequest = server.takeRequest(10, TimeUnit.SECONDS); String gitlabUrlCall = projectGitlabRequest.getRequestUrl().toString(); @@ -268,16 +269,17 @@ public class GitlabApplicationClientTest { public void search_projects_dont_fail_if_no_x_total() throws InterruptedException { MockResponse projects = new MockResponse() .setResponseCode(200) - .setBody("[\n" - + " {\n" - + " \"id\": 1,\n" - + " \"name\": \"SonarQube example 1\",\n" - + " \"name_with_namespace\": \"SonarSource / SonarQube / SonarQube example 1\",\n" - + " \"path\": \"sonarqube-example-1\",\n" - + " \"path_with_namespace\": \"sonarsource/sonarqube/sonarqube-example-1\",\n" - + " \"web_url\": \"https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1\"\n" - + " }" - + "]"); + .setBody(""" + [ + { + "id": 1, + "name": "SonarQube example 1", + "name_with_namespace": "SonarSource / SonarQube / SonarQube example 1", + "path": "sonarqube-example-1", + "path_with_namespace": "sonarsource/sonarqube/sonarqube-example-1", + "web_url": "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1" + }\ + ]"""); projects.addHeader("X-Page", 1); projects.addHeader("X-Per-Page", 10); server.enqueue(projects); @@ -291,8 +293,8 @@ public class GitlabApplicationClientTest { assertThat(projectList.getProjects()).hasSize(1); assertThat(projectList.getProjects()).extracting( Project::getId, Project::getName, Project::getNameWithNamespace, Project::getPath, Project::getPathWithNamespace, Project::getWebUrl).containsExactly( - tuple(1L, "SonarQube example 1", "SonarSource / SonarQube / SonarQube example 1", "sonarqube-example-1", "sonarsource/sonarqube/sonarqube-example-1", - "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1")); + tuple(1L, "SonarQube example 1", "SonarSource / SonarQube / SonarQube example 1", "sonarqube-example-1", "sonarsource/sonarqube/sonarqube-example-1", + "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1")); RecordedRequest projectGitlabRequest = server.takeRequest(10, TimeUnit.SECONDS); String gitlabUrlCall = projectGitlabRequest.getRequestUrl().toString(); @@ -304,16 +306,17 @@ public class GitlabApplicationClientTest { public void search_projects_with_case_insensitive_pagination_headers() throws InterruptedException { MockResponse projects1 = new MockResponse() .setResponseCode(200) - .setBody("[\n" - + " {\n" - + " \"id\": 1,\n" - + " \"name\": \"SonarQube example 1\",\n" - + " \"name_with_namespace\": \"SonarSource / SonarQube / SonarQube example 1\",\n" - + " \"path\": \"sonarqube-example-1\",\n" - + " \"path_with_namespace\": \"sonarsource/sonarqube/sonarqube-example-1\",\n" - + " \"web_url\": \"https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1\"\n" - + " }" - + "]"); + .setBody(""" + [ + { + "id": 1, + "name": "SonarQube example 1", + "name_with_namespace": "SonarSource / SonarQube / SonarQube example 1", + "path": "sonarqube-example-1", + "path_with_namespace": "sonarsource/sonarqube/sonarqube-example-1", + "web_url": "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1" + }\ + ]"""); projects1.addHeader("x-page", 1); projects1.addHeader("x-Per-page", 1); projects1.addHeader("X-Total", 2); @@ -328,8 +331,8 @@ public class GitlabApplicationClientTest { assertThat(projectList.getProjects()).hasSize(1); assertThat(projectList.getProjects()).extracting( Project::getId, Project::getName, Project::getNameWithNamespace, Project::getPath, Project::getPathWithNamespace, Project::getWebUrl).containsExactly( - tuple(1L, "SonarQube example 1", "SonarSource / SonarQube / SonarQube example 1", "sonarqube-example-1", "sonarsource/sonarqube/sonarqube-example-1", - "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1")); + tuple(1L, "SonarQube example 1", "SonarSource / SonarQube / SonarQube example 1", "sonarqube-example-1", "sonarsource/sonarqube/sonarqube-example-1", + "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1")); RecordedRequest projectGitlabRequest = server.takeRequest(10, TimeUnit.SECONDS); String gitlabUrlCall = projectGitlabRequest.getRequestUrl().toString(); diff --git a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonEmailTest.java b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonEmailTest.java index b4964e926fc..85bf88609ba 100644 --- a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonEmailTest.java +++ b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonEmailTest.java @@ -28,19 +28,19 @@ public class GsonEmailTest { @Test public void parse() { - List<GsonEmail> underTest = GsonEmail.parse( - "[\n" + - " {\n" + - " \"email\": \"octocat@github.com\",\n" + - " \"verified\": true,\n" + - " \"primary\": true\n" + - " },\n" + - " {\n" + - " \"email\": \"support@github.com\",\n" + - " \"verified\": false,\n" + - " \"primary\": false\n" + - " }\n" + - "]"); + List<GsonEmail> underTest = GsonEmail.parse(""" + [ + { + "email": "octocat@github.com", + "verified": true, + "primary": true + }, + { + "email": "support@github.com", + "verified": false, + "primary": false + } + ]"""); assertThat(underTest).hasSize(2); assertThat(underTest.get(0).getEmail()).isEqualTo("octocat@github.com"); diff --git a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonTeamTest.java b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonTeamTest.java index 5f9d3040215..3ca30d49965 100644 --- a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonTeamTest.java +++ b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonTeamTest.java @@ -28,16 +28,16 @@ public class GsonTeamTest { @Test public void parse_one_team() { - List<GsonTeam> underTest = GsonTeam.parse( - "[\n" + - " {\n" + - " \"name\": \"Developers\",\n" + - " \"slug\": \"developers\",\n" + - " \"organization\": {\n" + - " \"login\": \"SonarSource\"\n" + - " }\n" + - " }\n" + - "]"); + List<GsonTeam> underTest = GsonTeam.parse(""" + [ + { + "name": "Developers", + "slug": "developers", + "organization": { + "login": "SonarSource" + } + } + ]"""); assertThat(underTest).hasSize(1); assertThat(underTest.get(0).getId()).isEqualTo("developers"); @@ -46,22 +46,22 @@ public class GsonTeamTest { @Test public void parse_two_teams() { - List<GsonTeam> underTest = GsonTeam.parse( - "[\n" + - " {\n" + - " \"name\": \"Developers\",\n" + - " \"slug\": \"developers\",\n" + - " \"organization\": {\n" + - " \"login\": \"SonarSource\"\n" + - " }\n" + - " },\n" + - " {\n" + - " \"login\": \"SonarSource Developers\",\n" + - " \"organization\": {\n" + - " \"login\": \"SonarQubeCommunity\"\n" + - " }\n" + - " }\n" + - "]"); + List<GsonTeam> underTest = GsonTeam.parse(""" + [ + { + "name": "Developers", + "slug": "developers", + "organization": { + "login": "SonarSource" + } + }, + { + "login": "SonarSource Developers", + "organization": { + "login": "SonarQubeCommunity" + } + } + ]"""); assertThat(underTest).hasSize(2); } diff --git a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonUserTest.java b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonUserTest.java index 3f34d99a841..97bd0a70a0b 100644 --- a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonUserTest.java +++ b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonUserTest.java @@ -27,13 +27,13 @@ public class GsonUserTest { @Test public void parse_json() { - GsonUser user = GsonUser.parse( - "{\n" + - " \"login\": \"octocat\",\n" + - " \"id\": 1,\n" + - " \"name\": \"monalisa octocat\",\n" + - " \"email\": \"octocat@github.com\"\n" + - "}"); + GsonUser user = GsonUser.parse(""" + { + "login": "octocat", + "id": 1, + "name": "monalisa octocat", + "email": "octocat@github.com" + }"""); assertThat(user.getId()).isEqualTo("1"); assertThat(user.getLogin()).isEqualTo("octocat"); assertThat(user.getName()).isEqualTo("monalisa octocat"); diff --git a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/IntegrationTest.java b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/IntegrationTest.java index dbfa4df93b7..8662be1ce76 100644 --- a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/IntegrationTest.java +++ b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/IntegrationTest.java @@ -165,19 +165,19 @@ public class IntegrationTest { // response of api.github.com/orgs/first_org/members/user github.enqueue(new MockResponse().setResponseCode(204)); // response of api.github.com/user/emails - github.enqueue(new MockResponse().setBody( - "[\n" + - " {\n" + - " \"email\": \"support@github.com\",\n" + - " \"verified\": false,\n" + - " \"primary\": false\n" + - " },\n" + - " {\n" + - " \"email\": \"octocat@github.com\",\n" + - " \"verified\": true,\n" + - " \"primary\": true\n" + - " },\n" + - "]")); + github.enqueue(new MockResponse().setBody(""" + [ + { + "email": "support@github.com", + "verified": false, + "primary": false + }, + { + "email": "octocat@github.com", + "verified": true, + "primary": true + }, + ]""")); HttpServletRequest request = newRequest("the-verifier-code"); DumbCallbackContext callbackContext = new DumbCallbackContext(request); @@ -203,7 +203,6 @@ public class IntegrationTest { // response of api.github.com/user/emails github.enqueue(new MockResponse().setBody("[]")); - HttpServletRequest request = newRequest("the-verifier-code"); DumbCallbackContext callbackContext = new DumbCallbackContext(request); mockInstallations(); @@ -243,14 +242,15 @@ public class IntegrationTest { // response of api.github.com/orgs/first_org/members/user github.enqueue(new MockResponse().setResponseCode(204)); // response of api.github.com/user/teams - github.enqueue(new MockResponse().setBody("[\n" + - " {\n" + - " \"slug\": \"developers\",\n" + - " \"organization\": {\n" + - " \"login\": \"SonarSource\"\n" + - " }\n" + - " }\n" + - "]")); + github.enqueue(new MockResponse().setBody(""" + [ + { + "slug": "developers", + "organization": { + "login": "SonarSource" + } + } + ]""")); HttpServletRequest request = newRequest("the-verifier-code"); DumbCallbackContext callbackContext = new DumbCallbackContext(request); @@ -273,24 +273,26 @@ public class IntegrationTest { // responses of api.github.com/user/teams github.enqueue(new MockResponse() .setHeader("Link", "<" + gitHubUrl + "/user/teams?per_page=100&page=2>; rel=\"next\", <" + gitHubUrl + "/user/teams?per_page=100&page=2>; rel=\"last\"") - .setBody("[\n" + - " {\n" + - " \"slug\": \"developers\",\n" + - " \"organization\": {\n" + - " \"login\": \"SonarSource\"\n" + - " }\n" + - " }\n" + - "]")); + .setBody(""" + [ + { + "slug": "developers", + "organization": { + "login": "SonarSource" + } + } + ]""")); github.enqueue(new MockResponse() .setHeader("Link", "<" + gitHubUrl + "/user/teams?per_page=100&page=1>; rel=\"prev\", <" + gitHubUrl + "/user/teams?per_page=100&page=1>; rel=\"first\"") - .setBody("[\n" + - " {\n" + - " \"slug\": \"sonarsource-developers\",\n" + - " \"organization\": {\n" + - " \"login\": \"SonarQubeCommunity\"\n" + - " }\n" + - " }\n" + - "]")); + .setBody(""" + [ + { + "slug": "sonarsource-developers", + "organization": { + "login": "SonarQubeCommunity" + } + } + ]""")); HttpServletRequest request = newRequest("the-verifier-code"); DumbCallbackContext callbackContext = new DumbCallbackContext(request); diff --git a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonGroupTest.java b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonGroupTest.java index d9dbf7d0240..5fcfa448dea 100644 --- a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonGroupTest.java +++ b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonGroupTest.java @@ -28,22 +28,23 @@ public class GsonGroupTest { @Test public void test_parse() { - List<GsonGroup> groups = GsonGroup.parse("[{\n" + - "\"id\": 123456789,\n" + - "\"web_url\": \"https://gitlab.com/groups/my-awesome-group/my-project\",\n" + - "\"name\": \"my-project\",\n" + - "\"path\": \"my-project\",\n" + - "\"description\": \"toto\",\n" + - "\"visibility\": \"private\",\n" + - "\"lfs_enabled\": true,\n" + - "\"avatar_url\": null,\n" + - "\"request_access_enabled\": false,\n" + - "\"full_name\": \"my-awesome-group / my-project\",\n" + - "\"full_path\": \"my-awesome-group/my-project\",\n" + - "\"parent_id\": 987654321,\n" + - "\"ldap_cn\": null,\n" + - "\"ldap_access\": null\n" + - "}]"); + List<GsonGroup> groups = GsonGroup.parse(""" + [{ + "id": 123456789, + "web_url": "https://gitlab.com/groups/my-awesome-group/my-project", + "name": "my-project", + "path": "my-project", + "description": "toto", + "visibility": "private", + "lfs_enabled": true, + "avatar_url": null, + "request_access_enabled": false, + "full_name": "my-awesome-group / my-project", + "full_path": "my-awesome-group/my-project", + "parent_id": 987654321, + "ldap_cn": null, + "ldap_access": null + }]"""); assertThat(groups).isNotNull(); assertThat(groups.size()).isOne(); diff --git a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonUserTest.java b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonUserTest.java index d65b100ee15..63e99cc418a 100644 --- a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonUserTest.java +++ b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonUserTest.java @@ -27,45 +27,46 @@ public class GsonUserTest { @Test public void test_parse() { - GsonUser gsonUser = GsonUser.parse("{\n" + - "\"id\": 4418804,\n" + - "\"name\": \"Pierre Guillot\",\n" + - "\"username\": \"pierre-guillot-sonarsource\",\n" + - "\"state\": \"active\",\n" + - "\"avatar_url\": \"https://secure.gravatar.com/avatar/fe075537af1b94fd1cea160e5359e178?s=80&d=identicon\",\n" + - "\"web_url\": \"https://gitlab.com/pierre-guillot-sonarsource\",\n" + - "\"created_at\": \"2019-08-06T08:36:09.031Z\",\n" + - "\"bio\": null,\n" + - "\"location\": null,\n" + - "\"public_email\": \"\",\n" + - "\"skype\": \"\",\n" + - "\"linkedin\": \"\",\n" + - "\"twitter\": \"\",\n" + - "\"website_url\": \"\",\n" + - "\"organization\": null,\n" + - "\"last_sign_in_at\": \"2019-08-19T11:53:15.041Z\",\n" + - "\"confirmed_at\": \"2019-08-06T08:36:08.246Z\",\n" + - "\"last_activity_on\": \"2019-08-23\",\n" + - "\"email\": \"pierre.guillot@sonarsource.com\",\n" + - "\"theme_id\": 1,\n" + - "\"color_scheme_id\": 1,\n" + - "\"projects_limit\": 100000,\n" + - "\"current_sign_in_at\": \"2019-08-23T09:27:42.853Z\",\n" + - "\"identities\": [\n" + - "{\n" + - "\"provider\": \"github\",\n" + - "\"extern_uid\": \"50145663\",\n" + - "\"saml_provider_id\": null\n" + - "}\n" + - "],\n" + - "\"can_create_group\": true,\n" + - "\"can_create_project\": true,\n" + - "\"two_factor_enabled\": false,\n" + - "\"external\": false,\n" + - "\"private_profile\": false,\n" + - "\"shared_runners_minutes_limit\": 50000,\n" + - "\"extra_shared_runners_minutes_limit\": null\n" + - "}"); + GsonUser gsonUser = GsonUser.parse(""" + { + "id": 4418804, + "name": "Pierre Guillot", + "username": "pierre-guillot-sonarsource", + "state": "active", + "avatar_url": "https://secure.gravatar.com/avatar/fe075537af1b94fd1cea160e5359e178?s=80&d=identicon", + "web_url": "https://gitlab.com/pierre-guillot-sonarsource", + "created_at": "2019-08-06T08:36:09.031Z", + "bio": null, + "location": null, + "public_email": "", + "skype": "", + "linkedin": "", + "twitter": "", + "website_url": "", + "organization": null, + "last_sign_in_at": "2019-08-19T11:53:15.041Z", + "confirmed_at": "2019-08-06T08:36:08.246Z", + "last_activity_on": "2019-08-23", + "email": "pierre.guillot@sonarsource.com", + "theme_id": 1, + "color_scheme_id": 1, + "projects_limit": 100000, + "current_sign_in_at": "2019-08-23T09:27:42.853Z", + "identities": [ + { + "provider": "github", + "extern_uid": "50145663", + "saml_provider_id": null + } + ], + "can_create_group": true, + "can_create_project": true, + "two_factor_enabled": false, + "external": false, + "private_profile": false, + "shared_runners_minutes_limit": 50000, + "extra_shared_runners_minutes_limit": null + }"""); assertThat(gsonUser).isNotNull(); assertThat(gsonUser.getUsername()).isEqualTo("pierre-guillot-sonarsource"); diff --git a/server/sonar-auth-saml/src/it/java/org/sonar/auth/saml/SamlIdentityProviderIT.java b/server/sonar-auth-saml/src/it/java/org/sonar/auth/saml/SamlIdentityProviderIT.java index 547b856c718..86c2aee8577 100644 --- a/server/sonar-auth-saml/src/it/java/org/sonar/auth/saml/SamlIdentityProviderIT.java +++ b/server/sonar-auth-saml/src/it/java/org/sonar/auth/saml/SamlIdentityProviderIT.java @@ -19,6 +19,8 @@ */ package org.sonar.auth.saml; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -26,12 +28,11 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.slf4j.event.Level; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.server.authentication.OAuth2IdentityProvider; @@ -39,7 +40,6 @@ import org.sonar.api.server.authentication.UnauthorizedException; import org.sonar.api.server.authentication.UserIdentity; import org.sonar.api.server.http.HttpRequest; import org.sonar.api.server.http.HttpResponse; -import org.sonar.api.testfixtures.log.LogAndArguments; import org.sonar.api.testfixtures.log.LogTester; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; @@ -53,13 +53,12 @@ import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.sonar.api.utils.log.LoggerLevel.ERROR; public class SamlIdentityProviderIT { private static final String SQ_CALLBACK_URL = "http://localhost:9000/oauth2/callback/saml"; - /* IDP private key (keep here for future tests with signature) ------BEGIN PRIVATE KEY-----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-----END PRIVATE KEY----- + /** IDP private key (keep here for future tests with signature) + -----BEGIN PRIVATE KEY-----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-----END PRIVATE KEY----- */ private static final String IDP_CERTIFICATE = "-----BEGIN CERTIFICATE-----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-----END CERTIFICATE-----"; @@ -229,16 +228,14 @@ public class SamlIdentityProviderIT { @Test public void log_clear_error_when_private_key_is_not_pkcs8() { - var WRONG_FORMAT_PRIVATE_KEY = "MIIEpAIBAAKCAQEA0haE9+9QtP5JWbj4LymxiLZJk2n+QsHjVy/Lt/PXffGjl0aQ0O5mk13Vf1vlXC/L1FoPMhup5/AkcMHmJxkzXZ/VAHYYJJ78UHt6atxMDicpbOBaYqumE4fg0H4mVEIs4xYwzq/xhuTtpTb00ZCOF2Y/151o0alWcLbYgObZtbCpLxncjkJY8J+CY2v1WyE3VfBgErpseugYpf8GpkrKiM5tkY7DjhkrH+VY2FD8A6G6bkn/o+Ay7Vo3pv/byMyNsHBN9LgvCwQIDtyQJSEvTUK3IY0vcYTCUaITqIrWkj5qrDsuw9gR9Ie11+kzYL/1mE5AWOHmT2qNz7C9gOgJoQIDAQABAoIBAQCY9dRyQEfev5XgQZBRpmWgSDhhoDaDnG9Nt3r3wA4RoLGfHr2poSoF+bfMNrhT2mjpf3i43vNh77JYdpR/uxVvAUQwRctmPmsunfiPfT3SwCilIOQuGxOb/L5ujqqRhmzwGeQHWIrd0ChGtjChtEIAP24UKoN6w3QwNLCFiY7RfTC7+yyO05tKoIhzirCNDBARZPmaIm4ClmIf3Z3xg0Vsgtz7qntd63UoXjSWFA0f9EDJHfxCTaS1r9OrpPsPMNpVOEYDek4le+mWVCBmQABxYDBCycrILQUwpDkGOa6D7tezpjGYyn8Z4HiHzcneNqt/0+g5lG28DWHz9h0TKIjBAoGBAOklXNZmeMpMrQvTOta2cE/ts17SSrnUFWtKqU7ZH9Gs50ZpwzrnNWy+3sCiCCKfa+RylbXjukioKR5qz/qpr28GdD8+dWYNDHraEpk/ZtOfff7TlNpOjiNPXb0OF2t3HDeQs5etUPx5DHgCA58vDK4RlQcIWpZROCeH5vzo7lStAoGBAOauiFYKmbX3FdWsyBerjhbem5X59eNs68KtHxd/Y6INn/uI12gSsOi+Gj9B7yC/N1AKxqaWGN9fPeGy2+mC+BI0tiTWwATNlZyaSXeKBqKThONhgmZWUaX++dczqbWADdtzRUroy5X2lHzG8q6iG0RQtgwnczU1OdBk+UgF1/NFAoGBAJcr0Lx8CQozGWk3d0lNVhmdaNasyCMh7xl4ebtUcZtE31j6rsn8rNlsEYcaCOhaMl0YJxafKGSAFNlSLLS9XbFBoBJ57ylSgKsPx0tynrvNCKc4jaXXlbYzefZhsrHNs5Ab1Tcd/AsYegs+UxbeLPyZDeZXdlVNKHoJVq7aYd6pAoGAC7M2fwaynSQXG2tUCr9MyaQoyAaRjiNsIceeGBcB+qouPxfFtSWdi3B47FRvyH1qVMj3ImPihxHRlaz4snNOGb5KrrulqZizyemZaFK722sYBmBfuMkQAxdXnK6mIOqJyWOjVBVSnhyPk3STwn++WkytrxghI8W7VPKKIjkJpvECgYBBnvWXa8Ez/azEN+Y2Lc1PnU9OpNa/QRPUPApq15dB8Cu9e2Vm6F+CdGKBY8WQvDw7DJd6eOjCfN6ymy1O9vLiooNQJGaO/znncU1r3s42dfpQ8owthILl24GNXnEgth2yYfYPr/EVLoVsbgO0WKFvdsVbSo/upeLzGnVT+DMqfA=="; + var wrongFormatPrivateKey = "MIIEpAIBAAKCAQEA0haE9+9QtP5JWbj4LymxiLZJk2n+QsHjVy/Lt/PXffGjl0aQ0O5mk13Vf1vlXC/L1FoPMhup5/AkcMHmJxkzXZ/VAHYYJJ78UHt6atxMDicpbOBaYqumE4fg0H4mVEIs4xYwzq/xhuTtpTb00ZCOF2Y/151o0alWcLbYgObZtbCpLxncjkJY8J+CY2v1WyE3VfBgErpseugYpf8GpkrKiM5tkY7DjhkrH+VY2FD8A6G6bkn/o+Ay7Vo3pv/byMyNsHBN9LgvCwQIDtyQJSEvTUK3IY0vcYTCUaITqIrWkj5qrDsuw9gR9Ie11+kzYL/1mE5AWOHmT2qNz7C9gOgJoQIDAQABAoIBAQCY9dRyQEfev5XgQZBRpmWgSDhhoDaDnG9Nt3r3wA4RoLGfHr2poSoF+bfMNrhT2mjpf3i43vNh77JYdpR/uxVvAUQwRctmPmsunfiPfT3SwCilIOQuGxOb/L5ujqqRhmzwGeQHWIrd0ChGtjChtEIAP24UKoN6w3QwNLCFiY7RfTC7+yyO05tKoIhzirCNDBARZPmaIm4ClmIf3Z3xg0Vsgtz7qntd63UoXjSWFA0f9EDJHfxCTaS1r9OrpPsPMNpVOEYDek4le+mWVCBmQABxYDBCycrILQUwpDkGOa6D7tezpjGYyn8Z4HiHzcneNqt/0+g5lG28DWHz9h0TKIjBAoGBAOklXNZmeMpMrQvTOta2cE/ts17SSrnUFWtKqU7ZH9Gs50ZpwzrnNWy+3sCiCCKfa+RylbXjukioKR5qz/qpr28GdD8+dWYNDHraEpk/ZtOfff7TlNpOjiNPXb0OF2t3HDeQs5etUPx5DHgCA58vDK4RlQcIWpZROCeH5vzo7lStAoGBAOauiFYKmbX3FdWsyBerjhbem5X59eNs68KtHxd/Y6INn/uI12gSsOi+Gj9B7yC/N1AKxqaWGN9fPeGy2+mC+BI0tiTWwATNlZyaSXeKBqKThONhgmZWUaX++dczqbWADdtzRUroy5X2lHzG8q6iG0RQtgwnczU1OdBk+UgF1/NFAoGBAJcr0Lx8CQozGWk3d0lNVhmdaNasyCMh7xl4ebtUcZtE31j6rsn8rNlsEYcaCOhaMl0YJxafKGSAFNlSLLS9XbFBoBJ57ylSgKsPx0tynrvNCKc4jaXXlbYzefZhsrHNs5Ab1Tcd/AsYegs+UxbeLPyZDeZXdlVNKHoJVq7aYd6pAoGAC7M2fwaynSQXG2tUCr9MyaQoyAaRjiNsIceeGBcB+qouPxfFtSWdi3B47FRvyH1qVMj3ImPihxHRlaz4snNOGb5KrrulqZizyemZaFK722sYBmBfuMkQAxdXnK6mIOqJyWOjVBVSnhyPk3STwn++WkytrxghI8W7VPKKIjkJpvECgYBBnvWXa8Ez/azEN+Y2Lc1PnU9OpNa/QRPUPApq15dB8Cu9e2Vm6F+CdGKBY8WQvDw7DJd6eOjCfN6ymy1O9vLiooNQJGaO/znncU1r3s42dfpQ8owthILl24GNXnEgth2yYfYPr/EVLoVsbgO0WKFvdsVbSo/upeLzGnVT+DMqfA=="; setSettings(true); - settings.setProperty("sonar.auth.saml.sp.privateKey.secured", WRONG_FORMAT_PRIVATE_KEY); + settings.setProperty("sonar.auth.saml.sp.privateKey.secured", wrongFormatPrivateKey); DumbCallbackContext callbackContext = new DumbCallbackContext(request, response, "encoded_minimal_response.txt", SQ_CALLBACK_URL); underTest.callback(callbackContext); - assertThat(log.getLogs(ERROR)) - .extracting(LogAndArguments::getFormattedMsg) - .contains("Error in parsing service provider private key, please make sure that it is in PKCS 8 format."); + assertThat(log.logs(Level.ERROR)).contains("Error in parsing service provider private key, please make sure that it is in PKCS 8 format."); } @Test @@ -289,31 +286,33 @@ public class SamlIdentityProviderIT { @Test public void fail_to_callback_when_using_wrong_certificate() { setSettings(true); - settings.setProperty("sonar.auth.saml.certificate.secured", "-----BEGIN CERTIFICATE-----\n" + - "MIIEIzCCAwugAwIBAgIUHUzPjy5E2TmnsmTRT2sIUBRXFF8wDQYJKoZIhvcNAQEF\n" + - "BQAwXDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC1NvbmFyU291cmNlMRUwEwYDVQQL\n" + - "DAxPbmVMb2dpbiBJZFAxIDAeBgNVBAMMF09uZUxvZ2luIEFjY291bnQgMTMxMTkx\n" + - "MB4XDTE4MDcxOTA4NDUwNVoXDTIzMDcxOTA4NDUwNVowXDELMAkGA1UEBhMCVVMx\n" + - "FDASBgNVBAoMC1NvbmFyU291cmNlMRUwEwYDVQQLDAxPbmVMb2dpbiBJZFAxIDAe\n" + - "BgNVBAMMF09uZUxvZ2luIEFjY291bnQgMTMxMTkxMIIBIjANBgkqhkiG9w0BAQEF\n" + - "AAOCAQ8AMIIBCgKCAQEArlpKHm4EkJiQyy+4GtZBixcy7fWnreB96T7cOoWLmWkK\n" + - "05FM5M/boWHZsvaNAuHsoCAMzIY3/l+55WbORzAxsloH7rvDaDrdPYQN+sU9bzsD\n" + - "ZkmDGDmA3QBSm/h/p5SiMkWU5Jg34toDdM0rmzUStIOMq6Gh/Ykx3fRRSjswy48x\n" + - "wfZLy+0wU7lasHqdfk54dVbb7mCm9J3iHZizvOt2lbtzGbP6vrrjpzvZm43ZRgP8\n" + - "FapYA8G3lczdIaG4IaLW6kYIRORd0UwI7IAwkao3uIo12rh1T6DLVyzjOs9PdIkb\n" + - "HbICN2EehB/ut3wohuPwmwp2UmqopIMVVaBSsmSlYwIDAQABo4HcMIHZMAwGA1Ud\n" + - "EwEB/wQCMAAwHQYDVR0OBBYEFAXGFMKYgtpzCpfpBUPQ1H/9AeDrMIGZBgNVHSME\n" + - "gZEwgY6AFAXGFMKYgtpzCpfpBUPQ1H/9AeDroWCkXjBcMQswCQYDVQQGEwJVUzEU\n" + - "MBIGA1UECgwLU29uYXJTb3VyY2UxFTATBgNVBAsMDE9uZUxvZ2luIElkUDEgMB4G\n" + - "A1UEAwwXT25lTG9naW4gQWNjb3VudCAxMzExOTGCFB1Mz48uRNk5p7Jk0U9rCFAU\n" + - "VxRfMA4GA1UdDwEB/wQEAwIHgDANBgkqhkiG9w0BAQUFAAOCAQEAPHgi9IdDaTxD\n" + - "R5R8KHMdt385Uq8XC5pd0Li6y5RR2k6SKjThCt+eQU7D0Y2CyYU27vfCa2DQV4hJ\n" + - "4v4UfQv3NR/fYfkVSsNpxjBXBI3YWouxt2yg7uwdZBdgGYd37Yv3g9PdIZenjOhr\n" + - "Ck6WjdleMAWHRgJpocmB4IOESSyTfUul3jFupWnkbnn8c0ue6zwXd7LA1/yjVT2l\n" + - "Yh45+lz25aIOlyyo7OUw2TD15LIl8OOIuWRS4+UWy5+VdhXMbmpSEQH+Byod90g6\n" + - "A1bKpOFhRBzcxaZ6B2hB4SqjTBzS9zdmJyyFs/WNJxHri3aorcdqG9oUakjJJqqX\n" + - "E13skIMV2g==\n" + - "-----END CERTIFICATE-----\n"); + settings.setProperty("sonar.auth.saml.certificate.secured", """ + -----BEGIN CERTIFICATE----- + MIIEIzCCAwugAwIBAgIUHUzPjy5E2TmnsmTRT2sIUBRXFF8wDQYJKoZIhvcNAQEF + BQAwXDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC1NvbmFyU291cmNlMRUwEwYDVQQL + DAxPbmVMb2dpbiBJZFAxIDAeBgNVBAMMF09uZUxvZ2luIEFjY291bnQgMTMxMTkx + MB4XDTE4MDcxOTA4NDUwNVoXDTIzMDcxOTA4NDUwNVowXDELMAkGA1UEBhMCVVMx + FDASBgNVBAoMC1NvbmFyU291cmNlMRUwEwYDVQQLDAxPbmVMb2dpbiBJZFAxIDAe + BgNVBAMMF09uZUxvZ2luIEFjY291bnQgMTMxMTkxMIIBIjANBgkqhkiG9w0BAQEF + AAOCAQ8AMIIBCgKCAQEArlpKHm4EkJiQyy+4GtZBixcy7fWnreB96T7cOoWLmWkK + 05FM5M/boWHZsvaNAuHsoCAMzIY3/l+55WbORzAxsloH7rvDaDrdPYQN+sU9bzsD + ZkmDGDmA3QBSm/h/p5SiMkWU5Jg34toDdM0rmzUStIOMq6Gh/Ykx3fRRSjswy48x + wfZLy+0wU7lasHqdfk54dVbb7mCm9J3iHZizvOt2lbtzGbP6vrrjpzvZm43ZRgP8 + FapYA8G3lczdIaG4IaLW6kYIRORd0UwI7IAwkao3uIo12rh1T6DLVyzjOs9PdIkb + HbICN2EehB/ut3wohuPwmwp2UmqopIMVVaBSsmSlYwIDAQABo4HcMIHZMAwGA1Ud + EwEB/wQCMAAwHQYDVR0OBBYEFAXGFMKYgtpzCpfpBUPQ1H/9AeDrMIGZBgNVHSME + gZEwgY6AFAXGFMKYgtpzCpfpBUPQ1H/9AeDroWCkXjBcMQswCQYDVQQGEwJVUzEU + MBIGA1UECgwLU29uYXJTb3VyY2UxFTATBgNVBAsMDE9uZUxvZ2luIElkUDEgMB4G + A1UEAwwXT25lTG9naW4gQWNjb3VudCAxMzExOTGCFB1Mz48uRNk5p7Jk0U9rCFAU + VxRfMA4GA1UdDwEB/wQEAwIHgDANBgkqhkiG9w0BAQUFAAOCAQEAPHgi9IdDaTxD + R5R8KHMdt385Uq8XC5pd0Li6y5RR2k6SKjThCt+eQU7D0Y2CyYU27vfCa2DQV4hJ + 4v4UfQv3NR/fYfkVSsNpxjBXBI3YWouxt2yg7uwdZBdgGYd37Yv3g9PdIZenjOhr + Ck6WjdleMAWHRgJpocmB4IOESSyTfUul3jFupWnkbnn8c0ue6zwXd7LA1/yjVT2l + Yh45+lz25aIOlyyo7OUw2TD15LIl8OOIuWRS4+UWy5+VdhXMbmpSEQH+Byod90g6 + A1bKpOFhRBzcxaZ6B2hB4SqjTBzS9zdmJyyFs/WNJxHri3aorcdqG9oUakjJJqqX + E13skIMV2g== + -----END CERTIFICATE----- + """); DumbCallbackContext callbackContext = new DumbCallbackContext(request, response, "encoded_full_response.txt", SQ_CALLBACK_URL); assertThatThrownBy(() -> underTest.callback(callbackContext)) @@ -363,6 +362,7 @@ public class SamlIdentityProviderIT { @Override public void redirectTo(String url) { + // Do nothing } @Override @@ -396,11 +396,10 @@ public class SamlIdentityProviderIT { this.response = response; this.expectedCallbackUrl = expectedCallbackUrl; Map<String, String[]> parameterMap = new HashMap<>(); - parameterMap.put("SAMLResponse", new String[]{loadResponse(encodedResponseFile)}); + parameterMap.put("SAMLResponse", new String[] {loadResponse(encodedResponseFile)}); when(((JakartaHttpRequest) getHttpRequest()).getDelegate().getParameterMap()).thenReturn(parameterMap); } - private String loadResponse(String file) { try (InputStream json = getClass().getResourceAsStream(SamlIdentityProviderIT.class.getSimpleName() + "/" + file)) { return IOUtils.toString(json, StandardCharsets.UTF_8); diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepIT.java index 8cbe08cc260..4d044e31d0c 100644 --- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepIT.java +++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepIT.java @@ -94,6 +94,9 @@ public class PersistScannerContextStepIT { underTest.execute(new TestComputationStepContext()); assertThat(dbClient.ceScannerContextDao().selectScannerContext(dbTester.getSession(), ANALYSIS_UUID)) - .contains("1" + '\n' + "2" + '\n' + "3"); + .contains(""" + 1 + 2 + 3"""); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java index 1c48fc28d4f..810eccb9323 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java @@ -33,7 +33,10 @@ class LogsIteratorInputStreamTest { @Test void read_from_ClosableIterator_with_several_lines() throws IOException { - assertThat(read(create("line1", "line2", "line3"))).isEqualTo("line1" + '\n' + "line2" + '\n' + "line3"); + assertThat(read(create("line1", "line2", "line3"))).isEqualTo(""" + line1 + line2 + line3"""); } @Test @@ -49,7 +52,16 @@ class LogsIteratorInputStreamTest { @Test void read_from_ClosableIterator_with_several_empty_lines() throws IOException { assertThat(read(create("", "line2", "", "line4", "", "", "", "line8", ""))) - .isEqualTo('\n' + "line2" + '\n' + '\n' + "line4" + '\n' + '\n' + '\n' + '\n' + "line8" + '\n'); + .isEqualTo(""" + + line2 + + line4 + + + + line8 + """); } @Test diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropTableBuilderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropTableBuilderTest.java index 2d7c4cc52bf..821eec84c34 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropTableBuilderTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropTableBuilderTest.java @@ -50,31 +50,31 @@ public class DropTableBuilderTest { @Test public void drop_columns_on_oracle() { assertThat(new DropTableBuilder(new Oracle(), "issues") - .build()).containsExactly( - "BEGIN\n" + - "EXECUTE IMMEDIATE 'DROP SEQUENCE issues_seq';\n" + - "EXCEPTION\n" + - "WHEN OTHERS THEN\n" + - " IF SQLCODE != -2289 THEN\n" + - " RAISE;\n" + - " END IF;\n" + - "END;", - "BEGIN\n" + - "EXECUTE IMMEDIATE 'DROP TRIGGER issues_idt';\n" + - "EXCEPTION\n" + - "WHEN OTHERS THEN\n" + - " IF SQLCODE != -4080 THEN\n" + - " RAISE;\n" + - " END IF;\n" + - "END;", - "BEGIN\n" + - "EXECUTE IMMEDIATE 'DROP TABLE issues';\n" + - "EXCEPTION\n" + - "WHEN OTHERS THEN\n" + - " IF SQLCODE != -942 THEN\n" + - " RAISE;\n" + - " END IF;\n" + - "END;"); + .build()).containsExactly(""" + BEGIN + EXECUTE IMMEDIATE 'DROP SEQUENCE issues_seq'; + EXCEPTION + WHEN OTHERS THEN + IF SQLCODE != -2289 THEN + RAISE; + END IF; + END;""", """ + BEGIN + EXECUTE IMMEDIATE 'DROP TRIGGER issues_idt'; + EXCEPTION + WHEN OTHERS THEN + IF SQLCODE != -4080 THEN + RAISE; + END IF; + END;""", """ + BEGIN + EXECUTE IMMEDIATE 'DROP TABLE issues'; + EXCEPTION + WHEN OTHERS THEN + IF SQLCODE != -942 THEN + RAISE; + END IF; + END;"""); } @Test diff --git a/server/sonar-server-common/src/it/java/org/sonar/server/rule/index/RuleIndexerIT.java b/server/sonar-server-common/src/it/java/org/sonar/server/rule/index/RuleIndexerIT.java index 9704c193a77..fd261b95cda 100644 --- a/server/sonar-server-common/src/it/java/org/sonar/server/rule/index/RuleIndexerIT.java +++ b/server/sonar-server-common/src/it/java/org/sonar/server/rule/index/RuleIndexerIT.java @@ -63,11 +63,12 @@ import static org.sonar.server.security.SecurityStandards.SQ_CATEGORY_KEYS_ORDER @RunWith(DataProviderRunner.class) public class RuleIndexerIT { - private static final String VALID_HOTSPOT_RULE_DESCRIPTION = "acme\n" + - "<h2>Ask Yourself Whether</h2>\n" + - "bar\n" + - "<h2>Recommended Secure Coding Practices</h2>\n" + - "foo"; + private static final String VALID_HOTSPOT_RULE_DESCRIPTION = """ + acme + <h2>Ask Yourself Whether</h2> + bar + <h2>Recommended Secure Coding Practices</h2> + foo"""; private static final UuidFactoryFast uuidFactory = UuidFactoryFast.getInstance(); private static final RuleDescriptionSectionDto RULE_DESCRIPTION_SECTION_DTO = createDefaultRuleDescriptionSection(uuidFactory.create(), VALID_HOTSPOT_RULE_DESCRIPTION); @@ -205,7 +206,7 @@ public class RuleIndexerIT { SQCategory sqCategory1 = sqCategories.toArray(new SQCategory[0])[random.nextInt(sqCategories.size())]; sqCategories.remove(sqCategory1); SQCategory sqCategory2 = sqCategories.toArray(new SQCategory[0])[random.nextInt(sqCategories.size())]; - return new Object[][]{ + return new Object[][] { {sqCategory1, sqCategory2} }; } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGeneratorTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGeneratorTest.java index 11603d9cfe7..ad3605cf9e1 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGeneratorTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGeneratorTest.java @@ -41,43 +41,92 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { /* * Bunch of static constant to create rule description. */ - private static final String DESCRIPTION = - "<p>The use of operators pairs ( <code>=+</code>, <code>=-</code> or <code>=!</code> ) where the reversed, single operator was meant (<code>+=</code>,\n" - + "<code>-=</code> or <code>!=</code>) will compile and run, but not produce the expected results.</p>\n" - + "<p>This rule raises an issue when <code>=+</code>, <code>=-</code>, or <code>=!</code> is used without any spacing between the two operators and when\n" - + "there is at least one whitespace character after.</p>\n"; - private static final String NONCOMPLIANTCODE = "<h2>Noncompliant Code Example</h2>\n" + "<pre>Integer target = -5;\n" + "Integer num = 3;\n" + "\n" - + "target =- num; // Noncompliant; target = -3. Is that really what's meant?\n" + "target =+ num; // Noncompliant; target = 3\n" + "</pre>\n"; - - private static final String COMPLIANTCODE = - "<h2>Compliant Solution</h2>\n" + "<pre>Integer target = -5;\n" + "Integer num = 3;\n" + "\n" + "target = -num; // Compliant; intent to assign inverse value of num is clear\n" - + "target += num;\n" + "</pre>\n"; - - private static final String SEE = - "<h2>See</h2>\n" + "<ul>\n" + " <li> <a href=\"https://cwe.mitre.org/data/definitions/352.html\">MITRE, CWE-352</a> - Cross-Site Request Forgery (CSRF) </li>\n" - + " <li> <a href=\"https://www.owasp.org/index.php/Top_10-2017_A6-Security_Misconfiguration\">OWASP Top 10 2017 Category A6</a> - Security\n" + " Misconfiguration </li>\n" - + " <li> <a href=\"https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28CSRF%29\">OWASP: Cross-Site Request Forgery</a> </li>\n" - + " <li> <a href=\"https://www.sans.org/top25-software-errors/#cat1\">SANS Top 25</a> - Insecure Interaction Between Components </li>\n" - + " <li> Derived from FindSecBugs rule <a href=\"https://find-sec-bugs.github.io/bugs.htm#SPRING_CSRF_PROTECTION_DISABLED\">SPRING_CSRF_PROTECTION_DISABLED</a> </li>\n" - + " <li> <a href=\"https://docs.spring.io/spring-security/site/docs/current/reference/html/csrf.html#when-to-use-csrf-protection\">Spring Security\n" - + " Official Documentation: When to use CSRF protection</a> </li>\n" + "</ul>\n"; - - private static final String RECOMMENTEDCODINGPRACTICE = - "<h2>Recommended Secure Coding Practices</h2>\n" + "<ul>\n" + " <li> activate Spring Security's CSRF protection. </li>\n" + "</ul>\n"; - - private static final String ASKATRISK = - "<h2>Ask Yourself Whether</h2>\n" + "<ul>\n" + " <li> Any URLs responding with <code>Access-Control-Allow-Origin: *</code> include sensitive content. </li>\n" - + " <li> Any domains specified in <code>Access-Control-Allow-Origin</code> headers are checked against a whitelist. </li>\n" + "</ul>\n"; - - private static final String SENSITIVECODE = "<h2>Sensitive Code Example</h2>\n" + "<pre>\n" + "// === Java Servlet ===\n" + "@Override\n" - + "protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {\n" - + " resp.setHeader(\"Content-Type\", \"text/plain; charset=utf-8\");\n" + " resp.setHeader(\"Access-Control-Allow-Origin\", \"http://localhost:8080\"); // Questionable\n" - + " resp.setHeader(\"Access-Control-Allow-Credentials\", \"true\"); // Questionable\n" + " resp.setHeader(\"Access-Control-Allow-Methods\", \"GET\"); // Questionable\n" - + " resp.getWriter().write(\"response\");\n" + "}\n" + "</pre>\n" + "<pre>\n" + "// === Spring MVC Controller annotation ===\n" - + "@CrossOrigin(origins = \"http://domain1.com\") // Questionable\n" + "@RequestMapping(\"\")\n" + "public class TestController {\n" - + " public String home(ModelMap model) {\n" + " model.addAttribute(\"message\", \"ok \");\n" + " return \"view\";\n" + " }\n" + "\n" - + " @CrossOrigin(origins = \"http://domain2.com\") // Questionable\n" + " @RequestMapping(value = \"/test1\")\n" + " public ResponseEntity<String> test1() {\n" - + " return ResponseEntity.ok().body(\"ok\");\n" + " }\n" + "}\n" + "</pre>\n"; + private static final String DESCRIPTION = """ + <p>The use of operators pairs ( <code>=+</code>, <code>=-</code> or <code>=!</code> ) where the reversed, single operator was meant (<code>+=</code>, + <code>-=</code> or <code>!=</code>) will compile and run, but not produce the expected results.</p> + <p>This rule raises an issue when <code>=+</code>, <code>=-</code>, or <code>=!</code> is used without any spacing between the two operators and when + there is at least one whitespace character after.</p> + """; + private static final String NONCOMPLIANTCODE = """ + <h2>Noncompliant Code Example</h2> + <pre>Integer target = -5; + Integer num = 3; + + target =- num; // Noncompliant; target = -3. Is that really what's meant? + target =+ num; // Noncompliant; target = 3 + </pre> + """; + + private static final String COMPLIANTCODE = """ + <h2>Compliant Solution</h2> + <pre>Integer target = -5; + Integer num = 3; + + target = -num; // Compliant; intent to assign inverse value of num is clear + target += num; + </pre> + """; + + private static final String SEE = """ + <h2>See</h2> + <ul> + <li> <a href="https://cwe.mitre.org/data/definitions/352.html">MITRE, CWE-352</a> - Cross-Site Request Forgery (CSRF) </li> + <li> <a href="https://www.owasp.org/index.php/Top_10-2017_A6-Security_Misconfiguration">OWASP Top 10 2017 Category A6</a> - Security + Misconfiguration </li> + <li> <a href="https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28CSRF%29">OWASP: Cross-Site Request Forgery</a> </li> + <li> <a href="https://www.sans.org/top25-software-errors/#cat1">SANS Top 25</a> - Insecure Interaction Between Components </li> + <li> Derived from FindSecBugs rule <a href="https://find-sec-bugs.github.io/bugs.htm#SPRING_CSRF_PROTECTION_DISABLED">SPRING_CSRF_PROTECTION_DISABLED</a> </li> + <li> <a href="https://docs.spring.io/spring-security/site/docs/current/reference/html/csrf.html#when-to-use-csrf-protection">Spring Security + Official Documentation: When to use CSRF protection</a> </li> + </ul> + """; + + private static final String RECOMMENTEDCODINGPRACTICE = """ + <h2>Recommended Secure Coding Practices</h2> + <ul> + <li> activate Spring Security's CSRF protection. </li> + </ul> + """; + + private static final String ASKATRISK = """ + <h2>Ask Yourself Whether</h2> + <ul> + <li> Any URLs responding with <code>Access-Control-Allow-Origin: *</code> include sensitive content. </li> + <li> Any domains specified in <code>Access-Control-Allow-Origin</code> headers are checked against a whitelist. </li> + </ul> + """; + + private static final String SENSITIVECODE = """ + <h2>Sensitive Code Example</h2> + <pre> + // === Java Servlet === + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setHeader("Content-Type", "text/plain; charset=utf-8"); + resp.setHeader("Access-Control-Allow-Origin", "http://localhost:8080"); // Questionable + resp.setHeader("Access-Control-Allow-Credentials", "true"); // Questionable + resp.setHeader("Access-Control-Allow-Methods", "GET"); // Questionable + resp.getWriter().write("response"); + } + </pre> + <pre> + // === Spring MVC Controller annotation === + @CrossOrigin(origins = "http://domain1.com") // Questionable + @RequestMapping("") + public class TestController { + public String home(ModelMap model) { + model.addAttribute("message", "ok "); + return "view"; + } + + @CrossOrigin(origins = "http://domain2.com") // Questionable + @RequestMapping(value = "/test1") + public ResponseEntity<String> test1() { + return ResponseEntity.ok().body("ok"); + } + } + </pre> + """; private static final String DEFAULT_SECTION_KEY = "default"; @@ -137,7 +186,6 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { .containsEntry(HOW_TO_FIX_SECTION_KEY, RECOMMENTEDCODINGPRACTICE); } - @Test public void parse_return_null_vulnerable_when_no_ask_yourself_whether_title() { when(rule.htmlDescription()).thenReturn(DESCRIPTION + RECOMMENTEDCODINGPRACTICE); @@ -229,7 +277,7 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { .containsEntry(ROOT_CAUSE_SECTION_KEY, ruleDescription + "<br/>" + "<h2>Exceptions</h2>" + exceptionsContent + "<br/>") - .containsEntry(ASSESS_THE_PROBLEM_SECTION_KEY,"<h2>Ask Yourself Whether</h2>" + .containsEntry(ASSESS_THE_PROBLEM_SECTION_KEY, "<h2>Ask Yourself Whether</h2>" + askContent + "<br/>") .containsEntry(HOW_TO_FIX_SECTION_KEY, "<h2>Recommended Secure Coding Practices</h2>" + recommendedContent + "<br/>"); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java index 3fbfbdb96b5..45f252a176f 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java @@ -69,6 +69,7 @@ public class AppActionIT { projectData = db.components().insertPrivateProject(); mainBranchComponent = projectData.getMainBranchComponent(); } + @Test public void file_info() { ComponentDto directory = db.components().insertComponent(newDirectory(mainBranchComponent, "src")); @@ -134,9 +135,11 @@ public class AppActionIT { .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"measures\": {}\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "measures": {} + } + """); } @Test @@ -152,21 +155,22 @@ public class AppActionIT { userSession.logIn("john").addProjectPermission(USER, projectData.getProjectDto()) .registerBranches(projectData.getMainBranchDto()); - String result = ws.newRequest() .setParam("component", file.getKey()) .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"measures\": {\n" + - " \"lines\": \"200.0\",\n" + - " \"coverage\": \"95.4\",\n" + - " \"duplicationDensity\": \"7.4\",\n" + - " \"issues\": \"231.0\",\n" + - " \"tests\": \"3.0\"\n" + - " }" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "measures": { + "lines": "200.0", + "coverage": "95.4", + "duplicationDensity": "7.4", + "issues": "231.0", + "tests": "3.0" + }\ + } + """); } @Test @@ -200,9 +204,11 @@ public class AppActionIT { .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"canMarkAsFavorite\": true,\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "canMarkAsFavorite": true, + } + """); } @Test @@ -215,9 +221,11 @@ public class AppActionIT { .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"canMarkAsFavorite\": false,\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "canMarkAsFavorite": false, + } + """); } @Test @@ -234,9 +242,11 @@ public class AppActionIT { .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"fav\": true,\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "fav": true, + } + """); } @Test @@ -249,9 +259,11 @@ public class AppActionIT { .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"fav\": false,\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "fav": false, + } + """); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java index a53261fc569..695d72d6680 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java @@ -55,12 +55,13 @@ public class DuplicationsParserIT { ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); ComponentDto file = db.components().insertComponent(newFileDto(project)); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file, null, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + - " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file.getKey(), file.getKey())); + format(""" + <duplications> + <g> + <b s="31" l="5" r="%s"/> + <b s="20" l="5" r="%s"/> + </g> + </duplications>""", file.getKey(), file.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -84,12 +85,13 @@ public class DuplicationsParserIT { ComponentDto file1 = db.components().insertComponent(newFileDto(project)); ComponentDto file2 = db.components().insertComponent(newFileDto(project)); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, null, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + - " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file2.getKey(), file1.getKey())); + format(""" + <duplications> + <g> + <b s="20" l="5" r="%s"/> + <b s="31" l="5" r="%s"/> + </g> + </duplications>""", file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -115,13 +117,14 @@ public class DuplicationsParserIT { ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent(); ComponentDto fileOnProject2 = db.components().insertComponent(newFileDto(project2)); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, null, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"148\" l=\"24\" r=\"%s\"/>\n" + - " <b s=\"137\" l=\"24\" r=\"%s\"/>\n" + - " <b s=\"111\" l=\"24\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file1.getKey(), fileOnProject2.getKey(), file2.getKey())); + format(""" + <duplications> + <g> + <b s="148" l="24" r="%s"/> + <b s="137" l="24" r="%s"/> + <b s="111" l="24" r="%s"/> + </g> + </duplications>""", file1.getKey(), fileOnProject2.getKey(), file2.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -158,16 +161,18 @@ public class DuplicationsParserIT { .setKey("com.sonarsource.orchestrator:sonar-orchestrator:src/main/java/com/sonar/orchestrator/util/CommandExecutor.java") .setLongName("CommandExecutor")); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, null, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"94\" l=\"101\" r=\"%s\"/>\n" + - " <b s=\"83\" l=\"101\" r=\"%s\"/>\n" + - " </g>\n" + - " <g>\n" + - " <b s=\"38\" l=\"40\" r=\"%s\"/>\n" + - " <b s=\"29\" l=\"39\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>\n", file2.getKey(), file1.getKey(), file2.getKey(), file1.getKey())); + format(""" + <duplications> + <g> + <b s="94" l="101" r="%s"/> + <b s="83" l="101" r="%s"/> + </g> + <g> + <b s="38" l="40" r="%s"/> + <b s="29" l="39" r="%s"/> + </g> + </duplications> + """, file2.getKey(), file1.getKey(), file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(2); // Block with smaller line should come first @@ -184,12 +189,13 @@ public class DuplicationsParserIT { ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); ComponentDto file = db.components().insertComponent(newFileDto(project)); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file, null, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + - " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file.getKey(), "not_existing")); + format(""" + <duplications> + <g> + <b s="20" l="5" r="%s"/> + <b s="31" l="5" r="%s"/> + </g> + </duplications>""", file.getKey(), "not_existing")); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -255,12 +261,13 @@ public class DuplicationsParserIT { ComponentDto file1 = db.components().insertComponent(newFileDto(branch, project.uuid())); ComponentDto file2 = db.components().insertComponent(newFileDto(branch, project.uuid())); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, branchName, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + - " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file2.getKey(), file1.getKey())); + format(""" + <duplications> + <g> + <b s="20" l="5" r="%s"/> + <b s="31" l="5" r="%s"/> + </g> + </duplications>""", file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -290,12 +297,13 @@ public class DuplicationsParserIT { ComponentDto file1 = db.components().insertComponent(newFileDto(pullRequest)); ComponentDto file2 = db.components().insertComponent(newFileDto(pullRequest)); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, null, pullRequestKey, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + - " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file2.getKey(), file1.getKey())); + format(""" + <duplications> + <g> + <b s="20" l="5" r="%s"/> + <b s="31" l="5" r="%s"/> + </g> + </duplications>""", file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/GroupsActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/GroupsActionIT.java index d333314cb51..0bdc3d25816 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/GroupsActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/GroupsActionIT.java @@ -22,18 +22,18 @@ package org.sonar.server.permission.ws; import java.util.Set; import org.junit.Before; import org.junit.Test; -import org.sonar.db.component.ComponentQualifiers; -import org.sonar.server.component.ComponentTypes; import org.sonar.api.security.DefaultGroups; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.WebService.Action; import org.sonar.api.web.UserRole; import org.sonar.db.component.ComponentDto; -import org.sonar.server.component.ComponentTypesRule; +import org.sonar.db.component.ComponentQualifiers; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.portfolio.PortfolioDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.user.GroupDto; +import org.sonar.server.component.ComponentTypes; +import org.sonar.server.component.ComponentTypesRule; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -297,25 +297,24 @@ public class GroupsActionIT extends BasePermissionWsIT<GroupsAction> { .execute() .getInput(); - assertJson(result).isSimilarTo( - "{\n" - + " \"paging\": {\n" - + " \"pageIndex\": 1,\n" - + " \"pageSize\": 20,\n" - + " \"total\": 2\n" - + " },\n" - + " \"groups\": [\n" - + " {\n" - + " \"name\": \"local-group\",\n" - + " \"managed\": false\n" - + " },\n" - + " {\n" - + " \"name\": \"managed-group\",\n" - + " \"managed\": true\n" - + " }\n" - + " ]\n" - + "}" - ); + assertJson(result).isSimilarTo(""" + { + "paging": { + "pageIndex": 1, + "pageSize": 20, + "total": 2 + }, + "groups": [ + { + "name": "local-group", + "managed": false + }, + { + "name": "managed-group", + "managed": true + } + ] + }"""); } @Test @@ -375,13 +374,11 @@ public class GroupsActionIT extends BasePermissionWsIT<GroupsAction> { } private void mockGroupsAsManaged(String... groupUuids) { - when(managedInstanceService.getGroupUuidToManaged(any(), any())).thenAnswer(invocation -> - { - Set<?> allGroupUuids = invocation.getArgument(1, Set.class); - return allGroupUuids.stream() - .map(groupUuid -> (String) groupUuid) - .collect(toMap(identity(), userUuid -> Set.of(groupUuids).contains(userUuid))); - } - ); + when(managedInstanceService.getGroupUuidToManaged(any(), any())).thenAnswer(invocation -> { + Set<?> allGroupUuids = invocation.getArgument(1, Set.class); + return allGroupUuids.stream() + .map(groupUuid -> (String) groupUuid) + .collect(toMap(identity(), userUuid -> Set.of(groupUuids).contains(userUuid))); + }); } } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/UsersActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/UsersActionIT.java index d675080919e..08f78b290ab 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/UsersActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/UsersActionIT.java @@ -21,19 +21,19 @@ package org.sonar.server.permission.ws; import java.util.Set; import org.junit.Test; -import org.sonar.db.component.ComponentQualifiers; -import org.sonar.server.component.ComponentTypes; import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.server.ws.WebService.SelectionMode; import org.sonar.api.web.UserRole; import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ComponentQualifiers; import org.sonar.db.component.ProjectData; -import org.sonar.server.component.ComponentTypesRule; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.project.ProjectDto; import org.sonar.db.user.UserDto; import org.sonar.server.common.avatar.AvatarResolverImpl; +import org.sonar.server.component.ComponentTypes; +import org.sonar.server.component.ComponentTypesRule; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -220,36 +220,38 @@ public class UsersActionIT extends BasePermissionWsIT<UsersAction> { } loginAsAdmin(); - assertJson(newRequest().setParam(PAGE, "1").setParam(PAGE_SIZE, "2").execute().getInput()).withStrictArrayOrder().isSimilarTo("{\n" + - " \"paging\": {\n" + - " \"pageIndex\": 1,\n" + - " \"pageSize\": 2,\n" + - " \"total\": 10\n" + - " },\n" + - " \"users\": [\n" + - " {\n" + - " \"name\": \"user-0\"\n" + - " },\n" + - " {\n" + - " \"name\": \"user-1\"\n" + - " }\n" + - " ]\n" + - "}"); - assertJson(newRequest().setParam(PAGE, "3").setParam(PAGE_SIZE, "4").execute().getInput()).withStrictArrayOrder().isSimilarTo("{\n" + - " \"paging\": {\n" + - " \"pageIndex\": 3,\n" + - " \"pageSize\": 4,\n" + - " \"total\": 10\n" + - " },\n" + - " \"users\": [\n" + - " {\n" + - " \"name\": \"user-8\"\n" + - " },\n" + - " {\n" + - " \"name\": \"user-9\"\n" + - " }\n" + - " ]\n" + - "}"); + assertJson(newRequest().setParam(PAGE, "1").setParam(PAGE_SIZE, "2").execute().getInput()).withStrictArrayOrder().isSimilarTo(""" + { + "paging": { + "pageIndex": 1, + "pageSize": 2, + "total": 10 + }, + "users": [ + { + "name": "user-0" + }, + { + "name": "user-1" + } + ] + }"""); + assertJson(newRequest().setParam(PAGE, "3").setParam(PAGE_SIZE, "4").execute().getInput()).withStrictArrayOrder().isSimilarTo(""" + { + "paging": { + "pageIndex": 3, + "pageSize": 4, + "total": 10 + }, + "users": [ + { + "name": "user-8" + }, + { + "name": "user-9" + } + ] + }"""); } @Test @@ -316,8 +318,8 @@ public class UsersActionIT extends BasePermissionWsIT<UsersAction> { .setParam(PARAM_PROJECT_ID, project.uuid()) .setParam(PARAM_PROJECT_KEY, project.getKey()) .execute()) - .isInstanceOf(BadRequestException.class) - .hasMessage("Project id or project key can be provided, not both."); + .isInstanceOf(BadRequestException.class) + .hasMessage("Project id or project key can be provided, not both."); } @Test @@ -359,13 +361,11 @@ public class UsersActionIT extends BasePermissionWsIT<UsersAction> { } private void mockUsersAsManaged(String... userUuids) { - when(managedInstanceService.getUserUuidToManaged(any(), any())).thenAnswer(invocation -> - { - Set<?> allUsersUuids = invocation.getArgument(1, Set.class); - return allUsersUuids.stream() - .map(userUuid -> (String) userUuid) - .collect(toMap(identity(), userUuid -> Set.of(userUuids).contains(userUuid))); - } - ); + when(managedInstanceService.getUserUuidToManaged(any(), any())).thenAnswer(invocation -> { + Set<?> allUsersUuids = invocation.getArgument(1, Set.class); + return allUsersUuids.stream() + .map(userUuid -> (String) userUuid) + .collect(toMap(identity(), userUuid -> Set.of(userUuids).contains(userUuid))); + }); } } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ChangelogActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ChangelogActionIT.java index 184da7022de..efad6972423 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ChangelogActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ChangelogActionIT.java @@ -86,10 +86,10 @@ class ChangelogActionIT { RuleChangeDto ruleChange = insertRuleChange(CLEAR, TESTED, rule.getUuid(), Set.of(new RuleImpactChangeDto(MAINTAINABILITY, SECURITY, HIGH, MEDIUM))); insertChange(profile, ActiveRuleChange.Type.ACTIVATED, user, ImmutableMap.of( - "ruleUuid", rule.getUuid(), - "severity", "MINOR", - "param_foo", "foo_value", - "param_bar", "bar_value"), + "ruleUuid", rule.getUuid(), + "severity", "MINOR", + "param_foo", "foo_value", + "param_bar", "bar_value"), ruleChange); String response = ws.newRequest() @@ -154,10 +154,10 @@ class ChangelogActionIT { RuleChangeDto ruleChange = insertRuleChange(COMPLETE, FOCUSED, rule.getUuid(), Set.of(new RuleImpactChangeDto(MAINTAINABILITY, null, HIGH, null), new RuleImpactChangeDto(null, RELIABILITY, null, LOW))); insertChange(profile, ActiveRuleChange.Type.DEACTIVATED, user, ImmutableMap.of( - "ruleUuid", rule.getUuid(), - "severity", "MINOR", - "param_foo", "foo_value", - "param_bar", "bar_value"), + "ruleUuid", rule.getUuid(), + "severity", "MINOR", + "param_foo", "foo_value", + "param_bar", "bar_value"), ruleChange); String response = ws.newRequest() @@ -343,9 +343,10 @@ class ChangelogActionIT { .setParam(PARAM_QUALITY_PROFILE, qualityProfile.getName()) .setParam(PARAM_SINCE, "2011-04-25T01:15:43+0100") .execute() - .getInput()).isSimilarTo("{\n" + - " \"events\": []\n" + - "}"); + .getInput()).isSimilarTo(""" + { + "events": [] + }"""); } @Test @@ -452,7 +453,7 @@ class ChangelogActionIT { system2.setNow(DateUtils.parseDateTime(DATE).getTime()); RuleDto rule = db.rules().insert(); UserDto user = db.users().insertUser(); - //ACTIVATED and DEACTIVATED rules must always appear + // ACTIVATED and DEACTIVATED rules must always appear insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user, Map.of("ruleUuid", rule.getUuid())); insertChange(qualityProfile, ActiveRuleChange.Type.DEACTIVATED, user, Map.of("ruleUuid", rule.getUuid())); // Changes with data must appear in STANDARD mode @@ -547,7 +548,7 @@ class ChangelogActionIT { system2.setNow(DateUtils.parseDateTime(DATE).getTime()); RuleDto rule = db.rules().insert(); UserDto user = db.users().insertUser(); - //ACTIVATED and DEACTIVATED rules must always appear + // ACTIVATED and DEACTIVATED rules must always appear insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user, Map.of("ruleUuid", rule.getUuid())); insertChange(qualityProfile, ActiveRuleChange.Type.DEACTIVATED, user, Map.of("ruleUuid", rule.getUuid())); // Changes without rule_change must not appear in MQR mode @@ -670,8 +671,7 @@ class ChangelogActionIT { """.formatted(DATE, user.getLogin(), user.getName(), rule.getKey(), rule.getName(), DATE, user.getLogin(), user.getName(), rule.getKey(), rule.getName(), DATE, user.getLogin(), user.getName(), rule.getKey(), rule.getName(), - DATE, user.getLogin(), user.getName(), rule.getKey(), rule.getName() - )); + DATE, user.getLogin(), user.getName(), rule.getKey(), rule.getName())); } @Test @@ -734,7 +734,7 @@ class ChangelogActionIT { } private void insertChange(QProfileDto profile, ActiveRuleChange.Type type, @Nullable UserDto user, @Nullable Map<String, Object> data, - @Nullable RuleChangeDto ruleChange) { + @Nullable RuleChangeDto ruleChange) { insertChange(c -> c.setRulesProfileUuid(profile.getRulesProfileUuid()) .setUserUuid(user == null ? null : user.getUuid()) .setSqVersion("7.6") diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/CreateActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/CreateActionIT.java index 897136c0b45..981f07e5e7c 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/CreateActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/CreateActionIT.java @@ -224,16 +224,18 @@ public class CreateActionIT { .execute(); assertThat(response.getStatus()).isEqualTo(409); - assertJson(response.getInput()).isSimilarTo("{\n" + - " \"rule\": {\n" + - " \"key\": \"java:MY_CUSTOM\",\n" + - " \"repo\": \"java\",\n" + - " \"name\": \"My custom rule\",\n" + - " \"severity\": \"MAJOR\",\n" + - " \"status\": \"REMOVED\",\n" + - " \"isTemplate\": false\n" + - " }\n" + - "}\n"); + assertJson(response.getInput()).isSimilarTo(""" + { + "rule": { + "key": "java:MY_CUSTOM", + "repo": "java", + "name": "My custom rule", + "severity": "MAJOR", + "status": "REMOVED", + "isTemplate": false + } + } + """); } @Test @@ -308,11 +310,13 @@ public class CreateActionIT { .setParam("type", BUG.name()) .execute().getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"rule\": {\n" + - " \"severity\": \"MAJOR\"" + - " }\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "rule": { + "severity": "MAJOR"\ + } + } + """); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IndexActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IndexActionIT.java index ba218d3a3ce..ca624e8ce9f 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IndexActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IndexActionIT.java @@ -63,12 +63,13 @@ public class IndexActionIT { .setParam("resource", file.getKey()) .execute(); - assertJson(request.getInput()).isSimilarTo("[\n" + - " {\n" + - " \"1\": \"public class HelloWorld {\",\n" + - " \"2\": \"}\"\n" + - " }\n" + - "]"); + assertJson(request.getInput()).isSimilarTo(""" + [ + { + "1": "public class HelloWorld {", + "2": "}" + } + ]"""); } @Test @@ -84,12 +85,13 @@ public class IndexActionIT { .setParam("to", "5") .execute(); - assertJson(request.getInput()).isSimilarTo("[\n" + - " {\n" + - " \"3\": \"public class HelloWorld {\",\n" + - " \"4\": \"}\"\n" + - " }\n" + - "]"); + assertJson(request.getInput()).isSimilarTo(""" + [ + { + "3": "public class HelloWorld {", + "4": "}" + } + ]"""); } @Test @@ -101,7 +103,7 @@ public class IndexActionIT { assertThatThrownBy(() -> tester.newRequest() .setParam("resource", file.getKey()) .execute()) - .isInstanceOf(ForbiddenException.class); + .isInstanceOf(ForbiddenException.class); } @Test @@ -109,7 +111,7 @@ public class IndexActionIT { assertThatThrownBy(() -> tester.newRequest() .setParam("resource", "unknown") .execute()) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } private static DbFileSources.Data newData(String... lines) { diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java index 78b52883d9f..cc36de7dbde 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java @@ -28,10 +28,6 @@ import org.junit.Rule; import org.junit.Test; import org.sonar.api.CoreProperties; import org.sonar.api.config.Configuration; -import org.sonar.db.component.ComponentQualifiers; -import org.sonar.server.component.ComponentType; -import org.sonar.server.component.ComponentTypes; -import org.sonar.db.component.ComponentScopes; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; @@ -39,7 +35,6 @@ import org.sonar.api.web.UserRole; import org.sonar.api.web.page.Page; import org.sonar.api.web.page.Page.Qualifier; import org.sonar.api.web.page.PageDefinition; -import org.sonar.server.component.DefaultComponentTypes; import org.sonar.core.extension.CoreExtensionRepository; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginRepository; @@ -49,6 +44,8 @@ import org.sonar.db.component.BranchDto; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ComponentQualifiers; +import org.sonar.db.component.ComponentScopes; import org.sonar.db.component.ProjectData; import org.sonar.db.component.SnapshotDto; import org.sonar.db.metric.MetricDto; @@ -60,6 +57,9 @@ import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.user.UserDto; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.ComponentType; +import org.sonar.server.component.ComponentTypes; +import org.sonar.server.component.DefaultComponentTypes; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -187,14 +187,16 @@ public class ComponentActionIT { .execute() .getInput(); - assertJson(json).isSimilarTo("{\n" + - " \"key\": \"polop\",\n" + - " \"isFavorite\": true,\n" + - " \"id\": \"xyz\",\n" + - " \"branch\": \"feature1\"," + - " \"name\": \"Polop\",\n" + - " \"description\": \"test project\"\n" + - "}\n"); + assertJson(json).isSimilarTo(""" + { + "key": "polop", + "isFavorite": true, + "id": "xyz", + "branch": "feature1",\ + "name": "Polop", + "description": "test project" + } + """); } @Test @@ -218,11 +220,11 @@ public class ComponentActionIT { .getInput(); assertJson(json).isSimilarTo("{" + - " \"key\": \"" + subportfolio.getKey() + "\"," + - " \"isFavorite\": true," + - " \"id\": \"" + subportfolio.uuid() + "\"," + - " \"name\": \"" + subportfolio.name() + "\"" + - "}"); + " \"key\": \"" + subportfolio.getKey() + "\"," + + " \"isFavorite\": true," + + " \"id\": \"" + subportfolio.uuid() + "\"," + + " \"name\": \"" + subportfolio.name() + "\"" + + "}"); } @Test @@ -245,11 +247,11 @@ public class ComponentActionIT { .getInput(); assertJson(json).isSimilarTo("{" + - " \"key\": \"" + portfolio.getKey() + "\"," + - " \"isFavorite\": true," + - " \"id\": \"" + portfolio.uuid() + "\"," + - " \"name\": \"" + portfolio.name() + "\"" + - "}"); + " \"key\": \"" + portfolio.getKey() + "\"," + + " \"isFavorite\": true," + + " \"id\": \"" + portfolio.uuid() + "\"," + + " \"name\": \"" + portfolio.name() + "\"" + + "}"); } @Test @@ -280,14 +282,14 @@ public class ComponentActionIT { // access to all projects (project11, project12) String json = execute(application1.projectKey()); assertJson(json).isSimilarTo("{" + - "\"canBrowseAllChildProjects\":true" + - "}"); + "\"canBrowseAllChildProjects\":true" + + "}"); // access to some projects (project11) json = execute(application2.projectKey()); assertJson(json).isSimilarTo("{" + - "\"canBrowseAllChildProjects\":false" + - "}"); + "\"canBrowseAllChildProjects\":false" + + "}"); } @Test @@ -341,27 +343,27 @@ public class ComponentActionIT { .getInput(); assertJson(json).isSimilarTo("{\n" + - " \"key\": \"" + fileDto.getKey() + "\",\n" + - " \"branch\": \"feature1\",\n" + - " \"name\": \"Main.xoo\",\n" + - " \"breadcrumbs\": [\n" + - " {\n" + - " \"key\": \"sample\",\n" + - " \"name\": \"Sample\",\n" + - " \"qualifier\": \"TRK\"\n" + - " },\n" + - " {\n" + - " \"key\": \"sample:src\",\n" + - " \"name\": \"src\",\n" + - " \"qualifier\": \"DIR\"\n" + - " },\n" + - " {\n" + - " \"key\": \"" + fileDto.getKey() + "\",\n" + - " \"name\": \"Main.xoo\",\n" + - " \"qualifier\": \"FIL\"\n" + - " }\n" + - " ]\n" + - "}\n"); + " \"key\": \"" + fileDto.getKey() + "\",\n" + + " \"branch\": \"feature1\",\n" + + " \"name\": \"Main.xoo\",\n" + + " \"breadcrumbs\": [\n" + + " {\n" + + " \"key\": \"sample\",\n" + + " \"name\": \"Sample\",\n" + + " \"qualifier\": \"TRK\"\n" + + " },\n" + + " {\n" + + " \"key\": \"sample:src\",\n" + + " \"name\": \"src\",\n" + + " \"qualifier\": \"DIR\"\n" + + " },\n" + + " {\n" + + " \"key\": \"" + fileDto.getKey() + "\",\n" + + " \"name\": \"Main.xoo\",\n" + + " \"qualifier\": \"FIL\"\n" + + " }\n" + + " ]\n" + + "}\n"); } @Test @@ -566,21 +568,22 @@ public class ComponentActionIT { String json = execute(project.projectKey()); - assertJson(json).isSimilarTo("{\n" + - " \"configuration\": {\n" + - " \"showSettings\": true,\n" + - " \"showQualityProfiles\": true,\n" + - " \"showQualityGates\": true,\n" + - " \"showLinks\": true,\n" + - " \"showPermissions\": true,\n" + - " \"showHistory\": true,\n" + - " \"showUpdateKey\": true,\n" + - " \"showBackgroundTasks\": true,\n" + - " \"canApplyPermissionTemplate\": false,\n" + - " \"canBrowseProject\": true,\n" + - " \"canUpdateProjectVisibilityToPrivate\": true\n" + - " }\n" + - "}"); + assertJson(json).isSimilarTo(""" + { + "configuration": { + "showSettings": true, + "showQualityProfiles": true, + "showQualityGates": true, + "showLinks": true, + "showPermissions": true, + "showHistory": true, + "showUpdateKey": true, + "showBackgroundTasks": true, + "canApplyPermissionTemplate": false, + "canBrowseProject": true, + "canUpdateProjectVisibilityToPrivate": true + } + }"""); } @Test @@ -595,21 +598,22 @@ public class ComponentActionIT { String json = execute(project.projectKey()); - assertJson(json).isSimilarTo("{\n" + - " \"configuration\": {\n" + - " \"showSettings\": true,\n" + - " \"showQualityProfiles\": true,\n" + - " \"showQualityGates\": true,\n" + - " \"showLinks\": true,\n" + - " \"showPermissions\": false,\n" + - " \"showHistory\": true,\n" + - " \"showUpdateKey\": true,\n" + - " \"showBackgroundTasks\": true,\n" + - " \"canApplyPermissionTemplate\": false,\n" + - " \"canBrowseProject\": true,\n" + - " \"canUpdateProjectVisibilityToPrivate\": true\n" + - " }\n" + - "}"); + assertJson(json).isSimilarTo(""" + { + "configuration": { + "showSettings": true, + "showQualityProfiles": true, + "showQualityGates": true, + "showLinks": true, + "showPermissions": false, + "showHistory": true, + "showUpdateKey": true, + "showBackgroundTasks": true, + "canApplyPermissionTemplate": false, + "canBrowseProject": true, + "canUpdateProjectVisibilityToPrivate": true + } + }"""); } @Test @@ -818,7 +822,7 @@ public class ComponentActionIT { when(pluginRepository.getPluginInfo(any())).thenReturn(new PluginInfo("unused").setVersion(Version.create("1.0"))); CoreExtensionRepository coreExtensionRepository = mock(CoreExtensionRepository.class); when(coreExtensionRepository.isInstalled(any())).thenReturn(false); - PageRepository pageRepository = new PageRepository(pluginRepository, coreExtensionRepository, new PageDefinition[]{context -> { + PageRepository pageRepository = new PageRepository(pluginRepository, coreExtensionRepository, new PageDefinition[] {context -> { for (Page page : pages) { context.addPage(page); } @@ -866,7 +870,7 @@ public class ComponentActionIT { .setAdmin(true) .build(); - return new Page[]{page1, page2, adminPage}; + return new Page[] {page1, page2, adminPage}; } private void verifySuccess(String componentKey) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java index fdf6475f025..95a0659a877 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java @@ -97,20 +97,21 @@ public class QualityGateDetailsFormatterTest { @Test public void fail_when_measure_level_is_unknown() { - String measureData = "{\n" + - " \"level\": \"UNKNOWN\",\n" + - " \"conditions\": [\n" + - " {\n" + - " \"metric\": \"new_coverage\",\n" + - " \"op\": \"LT\",\n" + - " \"period\": 1,\n" + - " \"warning\": \"80\",\n" + - " \"error\": \"85\",\n" + - " \"actual\": \"82.2985024398452\",\n" + - " \"level\": \"ERROR\"\n" + - " }\n" + - " ]\n" + - "}"; + String measureData = """ + { + "level": "UNKNOWN", + "conditions": [ + { + "metric": "new_coverage", + "op": "LT", + "period": 1, + "warning": "80", + "error": "85", + "actual": "82.2985024398452", + "level": "ERROR" + } + ] + }"""; underTest = newQualityGateDetailsFormatter(measureData, new SnapshotDto()); assertThatThrownBy(() -> underTest.format()) @@ -120,20 +121,21 @@ public class QualityGateDetailsFormatterTest { @Test public void fail_when_measure_op_is_unknown() { - String measureData = "{\n" + - " \"level\": \"ERROR\",\n" + - " \"conditions\": [\n" + - " {\n" + - " \"metric\": \"new_coverage\",\n" + - " \"op\": \"UNKNOWN\",\n" + - " \"period\": 1,\n" + - " \"warning\": \"80\",\n" + - " \"error\": \"85\",\n" + - " \"actual\": \"82.2985024398452\",\n" + - " \"level\": \"ERROR\"\n" + - " }\n" + - " ]\n" + - "}"; + String measureData = """ + { + "level": "ERROR", + "conditions": [ + { + "metric": "new_coverage", + "op": "UNKNOWN", + "period": 1, + "warning": "80", + "error": "85", + "actual": "82.2985024398452", + "level": "ERROR" + } + ] + }"""; underTest = newQualityGateDetailsFormatter(measureData, new SnapshotDto()); assertThatThrownBy(() -> underTest.format()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQPChangeNotificationTemplateTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQPChangeNotificationTemplateTest.java index 825714b097c..cbce966e1f4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQPChangeNotificationTemplateTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQPChangeNotificationTemplateTest.java @@ -121,21 +121,21 @@ public class BuiltInQPChangeNotificationTemplateTest { String languageKey = newLanguageKey(); String languageName = newLanguageName(); BuiltInQPChangeNotificationBuilder notification = new BuiltInQPChangeNotificationBuilder() - .addProfile(Profile.newBuilder() - .setProfileName(profileName) - .setLanguageKey(languageKey) - .setLanguageName(languageName) - .setNewRules(1) - .setUpdatedRules(1) - .setRemovedRules(1) - .build()); + .addProfile(Profile.newBuilder() + .setProfileName(profileName) + .setLanguageKey(languageKey) + .setLanguageName(languageName) + .setNewRules(1) + .setUpdatedRules(1) + .setRemovedRules(1) + .build()); EmailMessage emailMessage = underTest.format(notification.build()); assertThat(emailMessage.getMessage()) - .contains("\n 1 new rule\n") - .contains("\n 1 rule has been updated\n") - .contains("\n 1 rule removed\n"); + .contains("\n 1 new rule\n") + .contains("\n 1 rule has been updated\n") + .contains("\n 1 rule removed\n"); } @Test @@ -155,11 +155,12 @@ public class BuiltInQPChangeNotificationTemplateTest { EmailMessage emailMessage = underTest.format(notification.build()); - assertMessage(emailMessage, - "\n" + - " 2 new rules\n" + - " 3 rules have been updated\n" + - " 4 rules removed\n"); + assertMessage(emailMessage, """ + + 2 new rules + 3 rules have been updated + 4 rules removed + """); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlTextDecoratorTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlTextDecoratorTest.java index 1f8372d7f17..8f9ef7beb96 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlTextDecoratorTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlTextDecoratorTest.java @@ -63,8 +63,7 @@ public class HtmlTextDecoratorTest { "<span class=\"cppd\">" + firstCommentLine + "</span>", "<span class=\"cppd\">" + secondCommentLine + "</span>", "<span class=\"cppd\">" + thirdCommentLine + "</span>", - "" - ); + ""); } @Test @@ -87,14 +86,13 @@ public class HtmlTextDecoratorTest { @Test public void should_allow_multiple_levels_highlighting() { - String javaDocSample = - "/**" + LF_END_OF_LINE + - " * Creates a FormulaDecorator" + LF_END_OF_LINE + - " *" + LF_END_OF_LINE + - " * @param metric the metric should have an associated formula" + LF_END_OF_LINE + - " * " + LF_END_OF_LINE + - " * @throws IllegalArgumentException if no formula is associated to the metric" + LF_END_OF_LINE + - " */" + LF_END_OF_LINE; + String javaDocSample = "/**" + LF_END_OF_LINE + + " * Creates a FormulaDecorator" + LF_END_OF_LINE + + " *" + LF_END_OF_LINE + + " * @param metric the metric should have an associated formula" + LF_END_OF_LINE + + " * " + LF_END_OF_LINE + + " * @throws IllegalArgumentException if no formula is associated to the metric" + LF_END_OF_LINE + + " */" + LF_END_OF_LINE; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,184,cppd;47,53,k;"); @@ -110,21 +108,19 @@ public class HtmlTextDecoratorTest { "<span class=\"cppd\"> * </span>", "<span class=\"cppd\"> * @throws IllegalArgumentException if no formula is associated to the metric</span>", "<span class=\"cppd\"> */</span>", - "" - ); + ""); } @Test public void should_support_crlf_line_breaks() { - String crlfCodeSample = - "/**" + CR_END_OF_LINE + LF_END_OF_LINE + - "* @return metric generated by the decorator" + CR_END_OF_LINE + LF_END_OF_LINE + - "*/" + CR_END_OF_LINE + LF_END_OF_LINE + - "@DependedUpon" + CR_END_OF_LINE + LF_END_OF_LINE + - "public Metric generatesMetric() {" + CR_END_OF_LINE + LF_END_OF_LINE + - " return metric;" + CR_END_OF_LINE + LF_END_OF_LINE + - "}" + CR_END_OF_LINE + LF_END_OF_LINE; + String crlfCodeSample = "/**" + CR_END_OF_LINE + LF_END_OF_LINE + + "* @return metric generated by the decorator" + CR_END_OF_LINE + LF_END_OF_LINE + + "*/" + CR_END_OF_LINE + LF_END_OF_LINE + + "@DependedUpon" + CR_END_OF_LINE + LF_END_OF_LINE + + "public Metric generatesMetric() {" + CR_END_OF_LINE + LF_END_OF_LINE + + " return metric;" + CR_END_OF_LINE + LF_END_OF_LINE + + "}" + CR_END_OF_LINE + LF_END_OF_LINE; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,52,cppd;54,67,a;69,75,k;106,112,k;"); @@ -140,20 +136,18 @@ public class HtmlTextDecoratorTest { "<span class=\"k\">public</span> Metric generatesMetric() {", " <span class=\"k\">return</span> metric;", "}", - "" - ); + ""); } @Test public void should_close_tags_at_end_of_file() { - String classDeclarationSample = - "/*" + LF_END_OF_LINE + - " * Header" + LF_END_OF_LINE + - " */" + LF_END_OF_LINE + - LF_END_OF_LINE + - "public class HelloWorld {" + LF_END_OF_LINE + - "}"; + String classDeclarationSample = "/*" + LF_END_OF_LINE + + " * Header" + LF_END_OF_LINE + + " */" + LF_END_OF_LINE + + LF_END_OF_LINE + + "public class HelloWorld {" + LF_END_OF_LINE + + "}"; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,16,cppd;18,25,k;25,31,k;"); @@ -167,25 +161,25 @@ public class HtmlTextDecoratorTest { "<span class=\"cppd\"> */</span>", "", "<span class=\"k\">public </span><span class=\"k\">class </span>HelloWorld {", - "}" - ); + "}"); } @Test public void should_escape_markup_chars() { - String javadocWithHtml = - "/**\n" + - " * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.\n" + - " * \n" + - " * This framework can used for instance in order to :\n" + - " * <ul>\n" + - " * <li>Create a lexer in charge to generate a list of tokens from a character stream</li>\n" + - " * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li>\n" + - " * <li>Create a javadoc generator</li>\n" + - " * <li>...</li>\n" + - " * </ul>\n" + - " */\n"; + String javadocWithHtml = """ + /** + * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT. + *\s + * This framework can used for instance in order to : + * <ul> + * <li>Create a lexer in charge to generate a list of tokens from a character stream</li> + * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li> + * <li>Create a javadoc generator</li> + * <li>...</li> + * </ul> + */ + """; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,453,cppd;"); @@ -211,15 +205,16 @@ public class HtmlTextDecoratorTest { @Test public void should_escape_ampersand_char() { - String javadocWithAmpersandChar = - "/**\n" + - " * Definition of a dashboard.\n" + - " * <p/>\n" + - " * Its name and description can be retrieved using the i18n mechanism, using the keys \"dashboard.<id>.name\" and\n" + - " * \"dashboard.<id>.description\".\n" + - " *\n" + - " * @since 2.13\n" + - " */\n"; + String javadocWithAmpersandChar = """ + /** + * Definition of a dashboard. + * <p/> + * Its name and description can be retrieved using the i18n mechanism, using the keys "dashboard.<id>.name" and + * "dashboard.<id>.description". + * + * @since 2.13 + */ + """; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,220,cppd;"); @@ -242,14 +237,13 @@ public class HtmlTextDecoratorTest { @Test public void should_support_cr_line_breaks() { - String crCodeSample = - "/**" + CR_END_OF_LINE + - "* @return metric generated by the decorator" + CR_END_OF_LINE + - "*/" + CR_END_OF_LINE + - "@DependedUpon" + CR_END_OF_LINE + - "public Metric generatesMetric() {" + CR_END_OF_LINE + - " return metric;" + CR_END_OF_LINE + - "}" + CR_END_OF_LINE; + String crCodeSample = "/**" + CR_END_OF_LINE + + "* @return metric generated by the decorator" + CR_END_OF_LINE + + "*/" + CR_END_OF_LINE + + "@DependedUpon" + CR_END_OF_LINE + + "public Metric generatesMetric() {" + CR_END_OF_LINE + + " return metric;" + CR_END_OF_LINE + + "}" + CR_END_OF_LINE; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,50,cppd;51,64,a;65,71,k;101,107,k;"); @@ -265,21 +259,19 @@ public class HtmlTextDecoratorTest { "<span class=\"k\">public</span> Metric generatesMetric() {", " <span class=\"k\">return</span> metric;", "}", - "" - ); + ""); } @Test public void should_support_multiple_empty_lines_at_end_of_file() { - String classDeclarationSample = - "/*" + LF_END_OF_LINE + - " * Header" + LF_END_OF_LINE + - " */" + LF_END_OF_LINE + - LF_END_OF_LINE + - "public class HelloWorld {" + LF_END_OF_LINE + - "}" + LF_END_OF_LINE + LF_END_OF_LINE + LF_END_OF_LINE; + String classDeclarationSample = "/*" + LF_END_OF_LINE + + " * Header" + LF_END_OF_LINE + + " */" + LF_END_OF_LINE + + LF_END_OF_LINE + + "public class HelloWorld {" + LF_END_OF_LINE + + "}" + LF_END_OF_LINE + LF_END_OF_LINE + LF_END_OF_LINE; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,16,cppd;18,25,k;25,31,k;"); @@ -296,25 +288,25 @@ public class HtmlTextDecoratorTest { "}", "", "", - "" - ); + ""); } @Test public void returned_code_begin_from_given_param() { - String javadocWithHtml = - "/**\n" + - " * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.\n" + - " * \n" + - " * This framework can used for instance in order to :\n" + - " * <ul>\n" + - " * <li>Create a lexer in charge to generate a list of tokens from a character stream</li>\n" + - " * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li>\n" + - " * <li>Create a javadoc generator</li>\n" + - " * <li>...</li>\n" + - " * </ul>\n" + - " */\n"; + String javadocWithHtml = """ + /** + * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT. + *\s + * This framework can used for instance in order to : + * <ul> + * <li>Create a lexer in charge to generate a list of tokens from a character stream</li> + * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li> + * <li>Create a javadoc generator</li> + * <li>...</li> + * </ul> + */ + """; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,453,cppd;"); @@ -339,18 +331,19 @@ public class HtmlTextDecoratorTest { @Test public void returned_code_end_to_given_param() { - String javadocWithHtml = - "/**\n" + - " * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.\n" + - " * \n" + - " * This framework can used for instance in order to :\n" + - " * <ul>\n" + - " * <li>Create a lexer in charge to generate a list of tokens from a character stream</li>\n" + - " * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li>\n" + - " * <li>Create a javadoc generator</li>\n" + - " * <li>...</li>\n" + - " * </ul>\n" + - " */\n"; + String javadocWithHtml = """ + /** + * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT. + *\s + * This framework can used for instance in order to : + * <ul> + * <li>Create a lexer in charge to generate a list of tokens from a character stream</li> + * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li> + * <li>Create a javadoc generator</li> + * <li>...</li> + * </ul> + */ + """; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,453,cppd;"); @@ -370,18 +363,19 @@ public class HtmlTextDecoratorTest { @Test public void returned_code_is_between_from_and_to_params() { - String javadocWithHtml = - "/**\n" + - " * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.\n" + - " * \n" + - " * This framework can used for instance in order to :\n" + - " * <ul>\n" + - " * <li>Create a lexer in charge to generate a list of tokens from a character stream</li>\n" + - " * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li>\n" + - " * <li>Create a javadoc generator</li>\n" + - " * <li>...</li>\n" + - " * </ul>\n" + - " */\n"; + String javadocWithHtml = """ + /** + * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT. + *\s + * This framework can used for instance in order to : + * <ul> + * <li>Create a lexer in charge to generate a list of tokens from a character stream</li> + * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li> + * <li>Create a javadoc generator</li> + * <li>...</li> + * </ul> + */ + """; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,453,cppd;"); @@ -396,7 +390,6 @@ public class HtmlTextDecoratorTest { "<span class=\"cppd\"> * <ul></span>", "<span class=\"cppd\"> * <li>Create a lexer in charge to generate a list of tokens from a character stream</li></span>", "<span class=\"cppd\"> * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li></span>", - "<span class=\"cppd\"> * <li>Create a javadoc generator</li></span>" - ); + "<span class=\"cppd\"> * <li>Create a javadoc generator</li></span>"); } } diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/CspFilter.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/CspFilter.java index c1095228fbf..a8a3d2c7454 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/CspFilter.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/CspFilter.java @@ -74,11 +74,13 @@ public class CspFilter implements Filter { private static String getAssetsPathScriptCSPHash(String contextPath) { final String WEB_CONTEXT_PLACEHOLDER = "WEB_CONTEXT"; - final String ASSETS_PATH_SCRIPT = "\n" + - " window.__assetsPath = function (filename) {\n" + - " return 'WEB_CONTEXT/' + filename;\n" + - " };\n" + - " "; + final String ASSETS_PATH_SCRIPT = """ + + window.__assetsPath = function (filename) { + return 'WEB_CONTEXT/' + filename; + }; + \ + """; String assetsPathScriptWithContextPath = ASSETS_PATH_SCRIPT.replace(WEB_CONTEXT_PLACEHOLDER, contextPath); return generateCSPHash(assetsPathScriptWithContextPath); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java index ee217c30bb3..b551fc1ba38 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java @@ -161,9 +161,10 @@ public class DefaultCpdTokensTest { tokens.addToken(inputFile.newRange(1, 2, 1, 5), "foo"); fail("Expected exception"); } catch (Exception e) { - assertThat(e).hasMessage("Tokens of file src/Foo.java should be provided in order.\n" + - "Previous token: Range[from [line=1, lineOffset=6] to [line=1, lineOffset=10]]\n" + - "Last token: Range[from [line=1, lineOffset=2] to [line=1, lineOffset=5]]"); + assertThat(e).hasMessage(""" + Tokens of file src/Foo.java should be provided in order. + Previous token: Range[from [line=1, lineOffset=6] to [line=1, lineOffset=10]] + Last token: Range[from [line=1, lineOffset=2] to [line=1, lineOffset=5]]"""); } } diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/cpd/CpdMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/cpd/CpdMediumIT.java index 7637b987ae2..27df471d1f0 100644 --- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/cpd/CpdMediumIT.java +++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/cpd/CpdMediumIT.java @@ -95,11 +95,24 @@ public class CpdMediumIT { module1Dir.mkdir(); module2Dir.mkdir(); - String duplicatedStuff = "Sample xoo\ncontent\n" - + "foo\nbar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti\n" - + "bar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti"; + String duplicatedStuff = """ + Sample xoo + content + foo + bar + toto + titi + foo + bar + toto + titi + bar + toto + titi + foo + bar + toto + titi"""; // create duplicated file in both modules File xooFile1 = new File(module1Dir, "sample1.xoo"); @@ -142,11 +155,24 @@ public class CpdMediumIT { File srcDir = new File(baseDir, "src"); srcDir.mkdir(); - String duplicatedStuff = "Sample xoo\ncontent\n" - + "foo\nbar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti\n" - + "bar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti"; + String duplicatedStuff = """ + Sample xoo + content + foo + bar + toto + titi + foo + bar + toto + titi + bar + toto + titi + foo + bar + toto + titi"""; File xooFile1 = new File(srcDir, "sample1.xoo"); FileUtils.write(xooFile1, duplicatedStuff, StandardCharsets.UTF_8); @@ -194,11 +220,24 @@ public class CpdMediumIT { File srcDir = new File(baseDir, "src"); srcDir.mkdir(); - String file1 = "Sample xoo\ncontent\n" - + "foo\nbar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti\n" - + "bar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti"; + String file1 = """ + Sample xoo + content + foo + bar + toto + titi + foo + bar + toto + titi + bar + toto + titi + foo + bar + toto + titi"""; String file2 = "string\n"; @@ -228,11 +267,24 @@ public class CpdMediumIT { File srcDir = new File(baseDir, "src"); srcDir.mkdir(); - String duplicatedStuff = "Sample xoo\ncontent\n" - + "foo\nbar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti\n" - + "bar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti"; + String duplicatedStuff = """ + Sample xoo + content + foo + bar + toto + titi + foo + bar + toto + titi + bar + toto + titi + foo + bar + toto + titi"""; File xooFile1 = new File(srcDir, "sample1.xoo"); FileUtils.write(xooFile1, duplicatedStuff); @@ -263,11 +315,24 @@ public class CpdMediumIT { @Test public void cross_module_duplication() throws IOException { - String duplicatedStuff = "Sample xoo\ncontent\n" - + "foo\nbar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti\n" - + "bar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti"; + String duplicatedStuff = """ + Sample xoo + content + foo + bar + toto + titi + foo + bar + toto + titi + bar + toto + titi + foo + bar + toto + titi"""; File baseDir = temp.getRoot(); File baseDirModuleA = new File(baseDir, "moduleA"); @@ -306,11 +371,24 @@ public class CpdMediumIT { @Test public void warn_user_for_outdated_inherited_scanner_side_exclusions_for_multi_module_project() throws IOException { - String duplicatedStuff = "Sample xoo\ncontent\n" - + "foo\nbar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti\n" - + "bar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti"; + String duplicatedStuff = """ + Sample xoo + content + foo + bar + toto + titi + foo + bar + toto + titi + bar + toto + titi + foo + bar + toto + titi"""; File baseDir = temp.getRoot(); File baseDirModuleA = new File(baseDir, "moduleA"); @@ -353,11 +431,24 @@ public class CpdMediumIT { @Test public void module_level_exclusions_override_parent_for_multi_module_project() throws IOException { - String duplicatedStuff = "Sample xoo\ncontent\n" - + "foo\nbar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti\n" - + "bar\ntoto\ntiti\n" - + "foo\nbar\ntoto\ntiti"; + String duplicatedStuff = """ + Sample xoo + content + foo + bar + toto + titi + foo + bar + toto + titi + bar + toto + titi + foo + bar + toto + titi"""; File baseDir = temp.getRoot(); File baseDirModuleA = new File(baseDir, "moduleA"); diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/scm/ScmMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/scm/ScmMediumIT.java index 19bfaf52244..59ee1ee8f81 100644 --- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/scm/ScmMediumIT.java +++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/scm/ScmMediumIT.java @@ -191,9 +191,11 @@ public class ScmMediumIT { File xooScmFile = new File(baseDir, CHANGED_CONTENT_SCM_ON_SERVER_XOO + ".scm"); FileUtils.write(xooScmFile, // revision,author,dateTime - "1,foo,2013-01-04\n" + - "1,bar,2013-01-04\n" + - "2,biz,2014-01-04\n", + """ + 1,foo,2013-01-04 + 1,bar,2013-01-04 + 2,biz,2014-01-04 + """, StandardCharsets.UTF_8); File sameContentScmOnServer = new File(baseDir, SAME_CONTENT_SCM_ON_SERVER_XOO); @@ -209,8 +211,10 @@ public class ScmMediumIT { xooScmFile = new File(baseDir, SAME_CONTENT_NO_SCM_ON_SERVER_XOO + ".scm"); FileUtils.write(xooScmFile, // revision,author,dateTime - "1,foo,2013-01-04\n" + - "1,bar,2013-01-04\n", + """ + 1,foo,2013-01-04 + 1,bar,2013-01-04 + """, StandardCharsets.UTF_8); tester.newAnalysis() @@ -252,8 +256,10 @@ public class ScmMediumIT { File xooScmFile = new File(baseDir, SAME_CONTENT_SCM_ON_SERVER_XOO + ".scm"); FileUtils.write(xooScmFile, // revision,author,dateTime - "1,foo,2013-01-04\n" + - "1,bar,2013-01-04\n", + """ + 1,foo,2013-01-04 + 1,bar,2013-01-04 + """, StandardCharsets.UTF_8); AnalysisBuilder analysisBuilder = tester.newAnalysis() diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java index 9d05effedbf..40910a0f364 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java @@ -39,11 +39,11 @@ import org.sonar.api.platform.Server; import org.sonar.api.testfixtures.log.LogTester; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; -import org.sonar.scanner.http.DefaultScannerWsClient; import org.sonar.scanner.bootstrap.GlobalAnalysisMode; import org.sonar.scanner.ci.CiConfiguration; import org.sonar.scanner.ci.DevOpsPlatformInfo; import org.sonar.scanner.fs.InputModuleHierarchy; +import org.sonar.scanner.http.DefaultScannerWsClient; import org.sonar.scanner.protocol.output.FileStructure; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.scan.ScanProperties; @@ -146,13 +146,14 @@ public class ReportPublisherTest { public void dump_information_about_report_uploading() throws IOException { underTest.prepareAndDumpMetadata("TASK-123"); - assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( - "projectKey=org.sonarsource.sonarqube:sonarqube\n" + - "serverUrl=https://localhost\n" + - "serverVersion=6.4\n" + - "dashboardUrl=https://localhost/dashboard?id=org.sonarsource.sonarqube%3Asonarqube\n" + - "ceTaskId=TASK-123\n" + - "ceTaskUrl=https://localhost/api/ce/task?id=TASK-123\n"); + assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo(""" + projectKey=org.sonarsource.sonarqube:sonarqube + serverUrl=https://localhost + serverVersion=6.4 + dashboardUrl=https://localhost/dashboard?id=org.sonarsource.sonarqube%3Asonarqube + ceTaskId=TASK-123 + ceTaskUrl=https://localhost/api/ce/task?id=TASK-123 + """); } @Test @@ -185,13 +186,14 @@ public class ReportPublisherTest { underTest.prepareAndDumpMetadata("TASK-123"); - assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( - "projectKey=org.sonarsource.sonarqube:sonarqube\n" + - "serverUrl=https://publicserver/sonarqube\n" + - "serverVersion=6.4\n" + - "dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube\n" + - "ceTaskId=TASK-123\n" + - "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"); + assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo(""" + projectKey=org.sonarsource.sonarqube:sonarqube + serverUrl=https://publicserver/sonarqube + serverVersion=6.4 + dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube + ceTaskId=TASK-123 + ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123 + """); } @Test @@ -204,13 +206,14 @@ public class ReportPublisherTest { underTest.prepareAndDumpMetadata("TASK-123"); - assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( - "projectKey=org.sonarsource.sonarqube:sonarqube\n" + - "serverUrl=https://publicserver/sonarqube\n" + - "serverVersion=6.4\n" + - "dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&branch=branch-6.7\n" + - "ceTaskId=TASK-123\n" + - "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"); + assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo(""" + projectKey=org.sonarsource.sonarqube:sonarqube + serverUrl=https://publicserver/sonarqube + serverVersion=6.4 + dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&branch=branch-6.7 + ceTaskId=TASK-123 + ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123 + """); } @Test @@ -225,13 +228,14 @@ public class ReportPublisherTest { underTest.prepareAndDumpMetadata("TASK-123"); - assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( - "projectKey=org.sonarsource.sonarqube:sonarqube\n" + - "serverUrl=https://publicserver/sonarqube\n" + - "serverVersion=6.4\n" + - "dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&pullRequest=105\n" + - "ceTaskId=TASK-123\n" + - "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"); + assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo(""" + projectKey=org.sonarsource.sonarqube:sonarqube + serverUrl=https://publicserver/sonarqube + serverVersion=6.4 + dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&pullRequest=105 + ceTaskId=TASK-123 + ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123 + """); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java index 078d91fb6d6..346f35af705 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java @@ -31,12 +31,14 @@ public class ChangedLinesComputerTest { @Test public void do_not_count_deleted_line() throws IOException { - String example = "diff --git a/file-b1.xoo b/file-b1.xoo\n" - + "index 0000000..c2a9048\n" - + "--- a/foo\n" - + "+++ b/bar\n" - + "@@ -1 +0,0 @@\n" - + "-deleted line\n"; + String example = """ + diff --git a/file-b1.xoo b/file-b1.xoo + index 0000000..c2a9048 + --- a/foo + +++ b/bar + @@ -1 +0,0 @@ + -deleted line + """; printDiff(example); assertThat(underTest.changedLines()).isEmpty(); @@ -44,12 +46,14 @@ public class ChangedLinesComputerTest { @Test public void count_single_added_line() throws IOException { - String example = "diff --git a/file-b1.xoo b/file-b1.xoo\n" - + "index 0000000..c2a9048\n" - + "--- a/foo\n" - + "+++ b/bar\n" - + "@@ -0,0 +1 @@\n" - + "+added line\n"; + String example = """ + diff --git a/file-b1.xoo b/file-b1.xoo + index 0000000..c2a9048 + --- a/foo + +++ b/bar + @@ -0,0 +1 @@ + +added line + """; printDiff(example); assertThat(underTest.changedLines()).containsExactly(1); @@ -57,14 +61,16 @@ public class ChangedLinesComputerTest { @Test public void count_multiple_added_lines() throws IOException { - String example = "diff --git a/file-b1.xoo b/file-b1.xoo\n" - + "index 0000000..c2a9048\n" - + "--- a/foo\n" - + "+++ b/bar\n" - + "@@ -1 +1,3 @@\n" - + " unchanged line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + diff --git a/file-b1.xoo b/file-b1.xoo + index 0000000..c2a9048 + --- a/foo + +++ b/bar + @@ -1 +1,3 @@ + unchanged line + +added line 1 + +added line 2 + """; printDiff(example); assertThat(underTest.changedLines()).containsExactly(2, 3); @@ -72,72 +78,78 @@ public class ChangedLinesComputerTest { @Test public void compute_from_multiple_hunks() throws IOException { - String example = "diff --git a/lao b/lao\n" - + "index 635ef2c..5af88a8 100644\n" - + "--- a/lao\n" - + "+++ b/lao\n" - + "@@ -1,7 +1,6 @@\n" - + "-The Way that can be told of is not the eternal Way;\n" - + "-The name that can be named is not the eternal name.\n" - + " The Nameless is the origin of Heaven and Earth;\n" - + "-The Named is the mother of all things.\n" - + "+The named is the mother of all things.\n" - + "+\n" - + " Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + " And let there always be being,\n" - + "@@ -9,3 +8,6 @@ And let there always be being,\n" - + " The two are the same,\n" - + " But after they are produced,\n" - + " they have different names.\n" - + "+They both may be called deep and profound.\n" - + "+Deeper and more profound,\n" - + "+The door of all subtleties!\n"; + String example = """ + diff --git a/lao b/lao + index 635ef2c..5af88a8 100644 + --- a/lao + +++ b/lao + @@ -1,7 +1,6 @@ + -The Way that can be told of is not the eternal Way; + -The name that can be named is not the eternal name. + The Nameless is the origin of Heaven and Earth; + -The Named is the mother of all things. + +The named is the mother of all things. + + + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + @@ -9,3 +8,6 @@ And let there always be being, + The two are the same, + But after they are produced, + they have different names. + +They both may be called deep and profound. + +Deeper and more profound, + +The door of all subtleties! + """; printDiff(example); assertThat(underTest.changedLines()).containsExactly(2, 3, 11, 12, 13); } @Test public void compute_from_multiple_hunks_with_extra_header_lines() throws IOException { - String example = "diff --git a/lao b/lao\n" - + "new file mode 100644\n" - + "whatever " - + "other " - + "surprise header lines git might throw at us...\n" - + "index 635ef2c..5af88a8 100644\n" - + "--- a/lao\n" - + "+++ b/lao\n" - + "@@ -1,7 +1,6 @@\n" - + "-The Way that can be told of is not the eternal Way;\n" - + "-The name that can be named is not the eternal name.\n" - + " The Nameless is the origin of Heaven and Earth;\n" - + "-The Named is the mother of all things.\n" - + "+The named is the mother of all things.\n" - + "+\n" - + " Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + " And let there always be being,\n" - + "@@ -9,3 +8,6 @@ And let there always be being,\n" - + " The two are the same,\n" - + " But after they are produced,\n" - + " they have different names.\n" - + "+They both may be called deep and profound.\n" - + "+Deeper and more profound,\n" - + "+The door of all subtleties!\n"; + String example = """ + diff --git a/lao b/lao + new file mode 100644 + whatever \ + other \ + surprise header lines git might throw at us... + index 635ef2c..5af88a8 100644 + --- a/lao + +++ b/lao + @@ -1,7 +1,6 @@ + -The Way that can be told of is not the eternal Way; + -The name that can be named is not the eternal name. + The Nameless is the origin of Heaven and Earth; + -The Named is the mother of all things. + +The named is the mother of all things. + + + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + @@ -9,3 +8,6 @@ And let there always be being, + The two are the same, + But after they are produced, + they have different names. + +They both may be called deep and profound. + +Deeper and more profound, + +The door of all subtleties! + """; printDiff(example); assertThat(underTest.changedLines()).containsExactly(2, 3, 11, 12, 13); } @Test public void throw_exception_invalid_start_line_format() throws IOException { - String example = "diff --git a/file-b1.xoo b/file-b1.xoo\n" - + "index 0000000..c2a9048\n" - + "--- a/foo\n" - + "+++ b/bar\n" - + "@@ -1 +x1,3 @@\n" - + " unchanged line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + diff --git a/file-b1.xoo b/file-b1.xoo + index 0000000..c2a9048 + --- a/foo + +++ b/bar + @@ -1 +x1,3 @@ + unchanged line + +added line 1 + +added line 2 + """; assertThatThrownBy(() -> printDiff(example)) .isInstanceOf(IllegalStateException.class); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java index f430cc9e50f..884253a7e4f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java @@ -85,31 +85,34 @@ public class GitScmProviderTest { // Sample content for unified diffs // http://www.gnu.org/software/diffutils/manual/html_node/Example-Unified.html#Example-Unified - private static final String CONTENT_LAO = "The Way that can be told of is not the eternal Way;\n" - + "The name that can be named is not the eternal name.\n" - + "The Nameless is the origin of Heaven and Earth;\n" - + "The Named is the mother of all things.\n" - + "Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + "And let there always be being,\n" - + " so we may see their outcome.\n" - + "The two are the same,\n" - + "But after they are produced,\n" - + " they have different names.\n"; - - private static final String CONTENT_TZU = "The Nameless is the origin of Heaven and Earth;\n" - + "The named is the mother of all things.\n" - + "\n" - + "Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + "And let there always be being,\n" - + " so we may see their outcome.\n" - + "The two are the same,\n" - + "But after they are produced,\n" - + " they have different names.\n" - + "They both may be called deep and profound.\n" - + "Deeper and more profound,\n" - + "The door of all subtleties!"; + private static final String CONTENT_LAO = """ + The Way that can be told of is not the eternal Way; + The name that can be named is not the eternal name. + The Nameless is the origin of Heaven and Earth; + The Named is the mother of all things. + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + so we may see their outcome. + The two are the same, + But after they are produced, + they have different names. + """; + + private static final String CONTENT_TZU = """ + The Nameless is the origin of Heaven and Earth; + The named is the mother of all things. + + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + so we may see their outcome. + The two are the same, + But after they are produced, + they have different names. + They both may be called deep and profound. + Deeper and more profound, + The door of all subtleties!"""; private static final String BRANCH_NAME = "branch"; private static final String TEST_DOC_LINK = "documentation link"; @@ -147,7 +150,8 @@ public class GitScmProviderTest { public void returnImplem() { JGitBlameCommand jblameCommand = new JGitBlameCommand(); NativeGitBlameCommand nativeBlameCommand = new NativeGitBlameCommand(System2.INSTANCE, new ProcessWrapperFactory()); - CompositeBlameCommand compositeBlameCommand = new CompositeBlameCommand(analysisWarnings, new PathResolver(), jblameCommand, nativeBlameCommand, new DefaultBlameStrategy(mock(Configuration.class))); + CompositeBlameCommand compositeBlameCommand = new CompositeBlameCommand(analysisWarnings, new PathResolver(), jblameCommand, nativeBlameCommand, + new DefaultBlameStrategy(mock(Configuration.class))); GitScmProvider gitScmProvider = new GitScmProvider(compositeBlameCommand, analysisWarnings, gitIgnoreCommand, system2, documentationLinkGenerator); assertThat(gitScmProvider.blameCommand()).isEqualTo(compositeBlameCommand); @@ -238,8 +242,7 @@ public class GitScmProviderTest { .extracting(ChangedFile::getAbsolutFilePath, ChangedFile::getOldRelativeFilePathReference) .containsExactlyInAnyOrder( tuple(newFileM1AbsolutPath, fileM1), - tuple(newFileM2AbsolutPath, fileM2) - ); + tuple(newFileM2AbsolutPath, fileM2)); } @Test @@ -454,8 +457,7 @@ public class GitScmProviderTest { Map<Path, ChangedFile> changedFiles = Map.of( newFileM1AbsolutPath, ChangedFile.of(newFileM1AbsolutPath, fileM1), - newFileM2AbsolutPath, ChangedFile.of(newFileM2AbsolutPath, fileM2) - ); + newFileM2AbsolutPath, ChangedFile.of(newFileM2AbsolutPath, fileM2)); Map<Path, Set<Integer>> changedLines = newScmProvider().branchChangedLinesWithFileMovementDetection("master", worktree.resolve("project1"), changedFiles); @@ -463,8 +465,7 @@ public class GitScmProviderTest { assertThat(changedLines) .containsOnly( entry(newFileM1AbsolutPath, Set.of(2)), - entry(newFileM2AbsolutPath, Set.of(1)) - ); + entry(newFileM2AbsolutPath, Set.of(1))); } @Test @@ -725,8 +726,7 @@ public class GitScmProviderTest { assertThat(provider.branchChangedLines("master", worktree, changedFiles)) .containsOnly( entry(worktree.resolve(f1), Collections.singleton(1)), - entry(worktree.resolve(f2), Collections.singleton(2)) - ); + entry(worktree.resolve(f2), Collections.singleton(2))); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/ChangedLinesComputerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/ChangedLinesComputerTest.java index bf038962535..f55ba21efc7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/ChangedLinesComputerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/ChangedLinesComputerTest.java @@ -45,12 +45,14 @@ public class ChangedLinesComputerTest { @Test public void do_not_count_deleted_line() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -1 +0,0 @@\n" - + "-deleted line\n"; + String example = """ + Index: sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -1 +0,0 @@ + -deleted line + """; printDiff(example); assertThat(underTest.changedLines()).isEmpty(); @@ -58,12 +60,14 @@ public class ChangedLinesComputerTest { @Test public void count_single_added_line() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -0,0 +1 @@\n" - + "+added line\n"; + String example = """ + Index: sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -0,0 +1 @@ + +added line + """; printDiff(example); assertThat(underTest.changedLines()).isEqualTo(Collections.singletonMap(rootBaseDir.resolve("sample1"), singleton(1))); @@ -71,14 +75,16 @@ public class ChangedLinesComputerTest { @Test public void count_multiple_added_lines() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -1 +1,3 @@\n" - + " same line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + Index: sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -1 +1,3 @@ + same line + +added line 1 + +added line 2 + """; printDiff(example); assertThat(underTest.changedLines()).isEqualTo(Collections.singletonMap(rootBaseDir.resolve("sample1"), new HashSet<>(Arrays.asList(2, 3)))); @@ -86,14 +92,16 @@ public class ChangedLinesComputerTest { @Test public void handle_index_using_absolute_paths() throws IOException { - String example = "Index: /foo/sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -1 +1,3 @@\n" - + " same line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + Index: /foo/sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -1 +1,3 @@ + same line + +added line 1 + +added line 2 + """; printDiff(example); assertThat(underTest.changedLines()).isEqualTo(Collections.singletonMap(rootBaseDir.resolve("sample1"), new HashSet<>(Arrays.asList(2, 3)))); @@ -101,41 +109,45 @@ public class ChangedLinesComputerTest { @Test public void compute_from_multiple_hunks() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- lao\t2002-02-21 23:30:39.942229878 -0800\n" - + "+++ tzu\t2002-02-21 23:30:50.442260588 -0800\n" - + "@@ -1,7 +1,6 @@\n" - + "-The Way that can be told of is not the eternal Way;\n" - + "-The name that can be named is not the eternal name.\n" - + " The Nameless is the origin of Heaven and Earth;\n" - + "-The Named is the mother of all things.\n" - + "+The named is the mother of all things.\n" - + "+\n" - + " Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + " And let there always be being,\n" - + "@@ -9,3 +8,6 @@\n" - + " The two are the same,\n" - + " But after they are produced,\n" - + " they have different names.\n" - + "+They both may be called deep and profound.\n" - + "+Deeper and more profound,\n" - + "+The door of all subtleties!\n"; + String example = """ + Index: sample1 + =================================================================== + --- lao\t2002-02-21 23:30:39.942229878 -0800 + +++ tzu\t2002-02-21 23:30:50.442260588 -0800 + @@ -1,7 +1,6 @@ + -The Way that can be told of is not the eternal Way; + -The name that can be named is not the eternal name. + The Nameless is the origin of Heaven and Earth; + -The Named is the mother of all things. + +The named is the mother of all things. + + + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + @@ -9,3 +8,6 @@ + The two are the same, + But after they are produced, + they have different names. + +They both may be called deep and profound. + +Deeper and more profound, + +The door of all subtleties! + """; printDiff(example); assertThat(underTest.changedLines()).isEqualTo(Collections.singletonMap(rootBaseDir.resolve("sample1"), new HashSet<>(Arrays.asList(2, 3, 11, 12, 13)))); } @Test(expected = IllegalStateException.class) public void crash_on_invalid_start_line_format() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -1 +x1,3 @@\n" - + " same line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + Index: sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -1 +x1,3 @@ + same line + +added line 1 + +added line 2 + """; printDiff(example); underTest.changedLines(); @@ -143,40 +155,42 @@ public class ChangedLinesComputerTest { @Test public void parse_diff_with_multiple_files() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -1 +0,0 @@\n" - + "-deleted line\n" - + "Index: sample2\n" - + "===================================================================\n" - + "--- a/sample2\n" - + "+++ b/sample2\n" - + "@@ -0,0 +1 @@\n" - + "+added line\n" - + "Index: sample3\n" - + "===================================================================\n" - + "--- a/sample3\n" - + "+++ b/sample3\n" - + "@@ -0,0 +1,2 @@\n" - + "+added line 1\n" - + "+added line 2\n" - + "Index: sample3-not-included\n" - + "===================================================================\n" - + "--- a/sample3-not-included\n" - + "+++ b/sample3-not-included\n" - + "@@ -0,0 +1,2 @@\n" - + "+added line 1\n" - + "+added line 2\n" - + "Index: sample4\n" - + "===================================================================\n" - + "--- a/sample4\n" - + "+++ b/sample4\n" - + "@@ -1 +1,3 @@\n" - + " same line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + Index: sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -1 +0,0 @@ + -deleted line + Index: sample2 + =================================================================== + --- a/sample2 + +++ b/sample2 + @@ -0,0 +1 @@ + +added line + Index: sample3 + =================================================================== + --- a/sample3 + +++ b/sample3 + @@ -0,0 +1,2 @@ + +added line 1 + +added line 2 + Index: sample3-not-included + =================================================================== + --- a/sample3-not-included + +++ b/sample3-not-included + @@ -0,0 +1,2 @@ + +added line 1 + +added line 2 + Index: sample4 + =================================================================== + --- a/sample4 + +++ b/sample4 + @@ -1 +1,3 @@ + same line + +added line 1 + +added line 2 + """; printDiff(example); Map<Path, Set<Integer>> expected = new HashMap<>(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java index f753e31bd8f..89dc17cf905 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java @@ -51,31 +51,34 @@ public class SvnScmProviderTest { // Sample content for unified diffs // http://www.gnu.org/software/diffutils/manual/html_node/Example-Unified.html#Example-Unified - private static final String CONTENT_LAO = "The Way that can be told of is not the eternal Way;\n" - + "The name that can be named is not the eternal name.\n" - + "The Nameless is the origin of Heaven and Earth;\n" - + "The Named is the mother of all things.\n" - + "Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + "And let there always be being,\n" - + " so we may see their outcome.\n" - + "The two are the same,\n" - + "But after they are produced,\n" - + " they have different names.\n"; - - private static final String CONTENT_TZU = "The Nameless is the origin of Heaven and Earth;\n" - + "The named is the mother of all things.\n" - + "\n" - + "Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + "And let there always be being,\n" - + " so we may see their outcome.\n" - + "The two are the same,\n" - + "But after they are produced,\n" - + " they have different names.\n" - + "They both may be called deep and profound.\n" - + "Deeper and more profound,\n" - + "The door of all subtleties!"; + private static final String CONTENT_LAO = """ + The Way that can be told of is not the eternal Way; + The name that can be named is not the eternal name. + The Nameless is the origin of Heaven and Earth; + The Named is the mother of all things. + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + so we may see their outcome. + The two are the same, + But after they are produced, + they have different names. + """; + + private static final String CONTENT_TZU = """ + The Nameless is the origin of Heaven and Earth; + The named is the mother of all things. + + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + so we may see their outcome. + The two are the same, + But after they are produced, + they have different names. + They both may be called deep and profound. + Deeper and more profound, + The door of all subtleties!"""; @Rule public TemporaryFolder temp = new TemporaryFolder(); |