diff options
author | Jeremy Davis <jeremy.davis@sonarsource.com> | 2023-04-04 10:20:33 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-04-11 20:03:15 +0000 |
commit | ba00face3dc7fbab07c4526b8035a6f42ce2dc2d (patch) | |
tree | 7540208b6b81f7f58501712d760298a05a6b931a /server/sonar-alm-client/src | |
parent | 5e6f30d7c4989a683ba0e45fa39ed7dfa3b0252f (diff) | |
download | sonarqube-ba00face3dc7fbab07c4526b8035a6f42ce2dc2d.tar.gz sonarqube-ba00face3dc7fbab07c4526b8035a6f42ce2dc2d.zip |
SONAR-19015 Use new log test fixtures in the sonar-plugin-api
Diffstat (limited to 'server/sonar-alm-client/src')
6 files changed, 44 insertions, 42 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 059fc103ade..fdf44a85971 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 @@ -29,10 +29,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.slf4j.event.Level; import org.sonar.alm.client.ConstantTimeoutConfiguration; import org.sonar.alm.client.TimeoutConfiguration; -import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggerLevel; +import org.sonar.api.testfixtures.log.LogTester; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -49,6 +49,7 @@ public class AzureDevOpsHttpClientTest { @Before public void prepare() throws IOException { + logTester.setLevel(Level.DEBUG); server.start(); TimeoutConfiguration timeoutConfiguration = new ConstantTimeoutConfiguration(10_000); @@ -82,7 +83,7 @@ public class AzureDevOpsHttpClientTest { assertThat(request.getMethod()).isEqualTo("GET"); assertThat(logTester.logs()).hasSize(1); - assertThat(logTester.logs(LoggerLevel.DEBUG)) + assertThat(logTester.logs(Level.DEBUG)) .contains("check pat : [" + server.url("").toString() + "_apis/projects?api-version=3.0]"); } @@ -135,8 +136,8 @@ public class AzureDevOpsHttpClientTest { assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "_apis/projects?api-version=3.0"); assertThat(request.getMethod()).isEqualTo("GET"); - assertThat(logTester.logs(LoggerLevel.DEBUG)).hasSize(1); - assertThat(logTester.logs(LoggerLevel.DEBUG)) + assertThat(logTester.logs(Level.DEBUG)).hasSize(1); + assertThat(logTester.logs(Level.DEBUG)) .contains("get projects : [" + server.url("") + "_apis/projects?api-version=3.0]"); assertThat(projects.getValues()).hasSize(2); assertThat(projects.getValues()) @@ -152,8 +153,8 @@ public class AzureDevOpsHttpClientTest { .isInstanceOf(IllegalArgumentException.class) .hasMessage(UNABLE_TO_CONTACT_AZURE); - assertThat(logTester.logs(LoggerLevel.ERROR)).hasSize(1); - assertThat(logTester.logs(LoggerLevel.ERROR).iterator().next()) + assertThat(logTester.logs(Level.ERROR)).hasSize(1); + assertThat(logTester.logs(Level.ERROR).iterator().next()) .contains("Response from Azure for request [" + server.url("") + "_apis/projects?api-version=3.0] could not be parsed:"); } @@ -165,8 +166,8 @@ public class AzureDevOpsHttpClientTest { .isInstanceOf(IllegalArgumentException.class) .hasMessage("Invalid personal access token"); - assertThat(logTester.logs(LoggerLevel.ERROR)).hasSize(1); - assertThat(logTester.logs(LoggerLevel.ERROR).iterator().next()) + assertThat(logTester.logs(Level.ERROR)).hasSize(1); + assertThat(logTester.logs(Level.ERROR).iterator().next()) .contains("Unable to contact Azure DevOps server for request [" + server.url("") + "_apis/projects?api-version=3.0]: Invalid personal access token"); } @@ -178,8 +179,8 @@ public class AzureDevOpsHttpClientTest { .isInstanceOf(IllegalArgumentException.class) .hasMessage("Invalid Azure URL"); - assertThat(logTester.logs(LoggerLevel.ERROR)).hasSize(1); - assertThat(logTester.logs(LoggerLevel.ERROR).iterator().next()) + assertThat(logTester.logs(Level.ERROR)).hasSize(1); + assertThat(logTester.logs(Level.ERROR).iterator().next()) .contains("Unable to contact Azure DevOps server for request [" + server.url("") + "_apis/projects?api-version=3.0]: URL Not Found"); } @@ -191,8 +192,8 @@ public class AzureDevOpsHttpClientTest { .isInstanceOf(IllegalArgumentException.class) .hasMessage("Unable to contact Azure DevOps server"); - assertThat(logTester.logs(LoggerLevel.ERROR)).hasSize(1); - assertThat(logTester.logs(LoggerLevel.ERROR).iterator().next()) + assertThat(logTester.logs(Level.ERROR)).hasSize(1); + assertThat(logTester.logs(Level.ERROR).iterator().next()) .contains("Azure API call to [" + server.url("") + "_apis/projects?api-version=3.0] failed with 500 http code. Azure response content :"); } @@ -226,8 +227,8 @@ public class AzureDevOpsHttpClientTest { assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "projectName/_apis/git/repositories?api-version=3.0"); assertThat(request.getMethod()).isEqualTo("GET"); - assertThat(logTester.logs(LoggerLevel.DEBUG)).hasSize(1); - assertThat(logTester.logs(LoggerLevel.DEBUG)) + assertThat(logTester.logs(Level.DEBUG)).hasSize(1); + assertThat(logTester.logs(Level.DEBUG)) .contains("get repos : [" + server.url("").toString() + "projectName/_apis/git/repositories?api-version=3.0]"); assertThat(repos.getValues()).hasSize(1); assertThat(repos.getValues()) @@ -279,8 +280,8 @@ public class AzureDevOpsHttpClientTest { assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "Project-Name/_apis/git/repositories/Repo-Name-1?api-version=3.0"); assertThat(request.getMethod()).isEqualTo("GET"); - assertThat(logTester.logs(LoggerLevel.DEBUG)).hasSize(1); - assertThat(logTester.logs(LoggerLevel.DEBUG)) + assertThat(logTester.logs(Level.DEBUG)).hasSize(1); + assertThat(logTester.logs(Level.DEBUG)) .contains("get repo : [" + server.url("").toString() + "Project-Name/_apis/git/repositories/Repo-Name-1?api-version=3.0]"); assertThat(repo.getId()).isEqualTo("Repo-Id-1"); assertThat(repo.getName()).isEqualTo("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 ecd6d763105..b164a94d957 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 @@ -36,8 +36,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggerLevel; +import org.slf4j.event.Level; +import org.sonar.api.testfixtures.log.LogTester; import org.sonarqube.ws.client.OkHttpClientBuilder; import static org.assertj.core.api.Assertions.assertThat; @@ -182,7 +182,7 @@ public class BitbucketCloudRestClientTest { assertThatIllegalArgumentException() .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage(UNABLE_TO_CONTACT_BBC_SERVERS); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL, "401", "Unauthorized")); + assertThat(logTester.logs(Level.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL, "401", "Unauthorized")); } @Test @@ -218,7 +218,7 @@ public class BitbucketCloudRestClientTest { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage(ERROR_BBC_SERVERS + ": " + MISSING_PULL_REQUEST_READ_PERMISSION); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(MISSING_PULL_REQUEST_READ_PERMISSION + String.format(SCOPE, "")); + assertThat(logTester.logs(Level.INFO)).containsExactly(MISSING_PULL_REQUEST_READ_PERMISSION + String.format(SCOPE, "")); } @Test @@ -233,7 +233,7 @@ public class BitbucketCloudRestClientTest { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage("Error returned by Bitbucket Cloud: No workspace with identifier 'workspace'."); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL + "2.0/repositories/workspace", "404", response)); + assertThat(logTester.logs(Level.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL + "2.0/repositories/workspace", "404", response)); } @Test @@ -246,7 +246,7 @@ public class BitbucketCloudRestClientTest { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage(UNABLE_TO_CONTACT_BBC_SERVERS + ": " + OAUTH_CONSUMER_NOT_PRIVATE); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL, "400", "invalid_grant")); + assertThat(logTester.logs(Level.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL, "400", "invalid_grant")); } @Test @@ -258,7 +258,7 @@ public class BitbucketCloudRestClientTest { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage(UNABLE_TO_CONTACT_BBC_SERVERS + ": " + UNAUTHORIZED_CLIENT); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL, "400", "unauthorized_client")); + assertThat(logTester.logs(Level.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL, "400", "unauthorized_client")); } @Test @@ -274,7 +274,7 @@ public class BitbucketCloudRestClientTest { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage("Error returned by Bitbucket Cloud: Your credentials lack one or more required privilege scopes."); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL + "2.0/repositories/workspace", "400", error)); + assertThat(logTester.logs(Level.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL + "2.0/repositories/workspace", "400", error)); } @Test @@ -303,7 +303,7 @@ public class BitbucketCloudRestClientTest { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> underTest.validateAppPassword("wrong:wrong", "workspace")) .withMessage("Error returned by Bitbucket Cloud: Invalid credentials."); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL + "2.0/repositories/workspace", "401", response)); + assertThat(logTester.logs(Level.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL + "2.0/repositories/workspace", "401", response)); } @Test @@ -326,7 +326,7 @@ public class BitbucketCloudRestClientTest { assertThatIllegalArgumentException() .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage(UNABLE_TO_CONTACT_BBC_SERVERS); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, url, "500", message)); + assertThat(logTester.logs(Level.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, url, "500", message)); } @Test @@ -339,7 +339,7 @@ public class BitbucketCloudRestClientTest { assertThatIllegalArgumentException() .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage(UNABLE_TO_CONTACT_BBC_SERVERS); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL, "500", body)); + assertThat(logTester.logs(Level.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL, "500", body)); } @Test @@ -352,7 +352,7 @@ public class BitbucketCloudRestClientTest { assertThatIllegalArgumentException() .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage(UNABLE_TO_CONTACT_BBC_SERVERS); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL, "500", body)); + assertThat(logTester.logs(Level.INFO)).containsExactly(String.format(BBC_FAIL_WITH_RESPONSE, serverURL, "500", body)); } @Test @@ -368,6 +368,6 @@ public class BitbucketCloudRestClientTest { assertThatIllegalArgumentException() .isThrownBy(() -> underTest.validate("clientId", "clientSecret", "workspace")) .withMessage(UNABLE_TO_CONTACT_BBC_SERVERS); - assertThat(logTester.logs(LoggerLevel.INFO)).containsExactly(String.format(BBC_FAIL_WITH_ERROR, serverURL, "SSL verification failed")); + assertThat(logTester.logs(Level.INFO)).containsExactly(String.format(BBC_FAIL_WITH_ERROR, serverURL, "SSL verification failed")); } } diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java index c1e7cee87ce..5de1f69d9f7 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java @@ -36,7 +36,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.sonar.alm.client.ConstantTimeoutConfiguration; -import org.sonar.api.utils.log.LogTester; +import org.sonar.api.testfixtures.log.LogTester; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; 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 ed823e73d4b..fbe8aa95ca0 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 @@ -34,7 +34,7 @@ import org.sonar.alm.client.github.security.AccessToken; import org.sonar.alm.client.github.security.AppToken; import org.sonar.alm.client.github.security.GithubAppSecurity; import org.sonar.alm.client.github.security.UserAccessToken; -import org.sonar.api.utils.log.LogTester; +import org.sonar.api.testfixtures.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import static java.net.HttpURLConnection.HTTP_FORBIDDEN; diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java index 8487382837d..1e90d5b127b 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java @@ -33,12 +33,13 @@ import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.slf4j.event.Level; import org.sonar.alm.client.ConstantTimeoutConfiguration; import org.sonar.alm.client.github.GithubApplicationHttpClient.GetResponse; import org.sonar.alm.client.github.GithubApplicationHttpClient.Response; import org.sonar.alm.client.github.security.AccessToken; import org.sonar.alm.client.github.security.UserAccessToken; -import org.sonar.api.utils.log.LogTester; +import org.sonar.api.testfixtures.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import static java.lang.String.format; @@ -110,7 +111,7 @@ public class GithubApplicationHttpClientImplTest { GetResponse response = underTest.get(appUrl, accessToken, randomEndPoint); - assertThat(logTester.logs(LoggerLevel.WARN)).isNotEmpty(); + assertThat(logTester.logs(Level.WARN)).isNotEmpty(); assertThat(response.getContent()).isEmpty(); } diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabHttpClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabHttpClientTest.java index 6fb184e6e52..48c0b2d0067 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabHttpClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabHttpClientTest.java @@ -29,10 +29,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.slf4j.event.Level; import org.sonar.alm.client.ConstantTimeoutConfiguration; import org.sonar.alm.client.TimeoutConfiguration; -import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggerLevel; +import org.sonar.api.testfixtures.log.LogTester; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -457,7 +457,7 @@ public class GitlabHttpClientTest { assertThatThrownBy(() -> underTest.checkReadPermission(gitlabUrl, "token")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Could not validate GitLab read permission. Got an unexpected answer."); - assertThat(logTester.logs(LoggerLevel.INFO).get(0)) + assertThat(logTester.logs(Level.INFO).get(0)) .contains("Gitlab API call to [" + server.url("/projects") + "] " + "failed with error message : [Failed to connect to " + server.getHostName()); } @@ -469,7 +469,7 @@ public class GitlabHttpClientTest { assertThatThrownBy(() -> underTest.checkToken(gitlabUrl, "token")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Could not validate GitLab token. Got an unexpected answer."); - assertThat(logTester.logs(LoggerLevel.INFO).get(0)) + assertThat(logTester.logs(Level.INFO).get(0)) .contains("Gitlab API call to [" + server.url("user") + "] " + "failed with error message : [Failed to connect to " + server.getHostName()); } @@ -481,7 +481,7 @@ public class GitlabHttpClientTest { assertThatThrownBy(() -> underTest.checkWritePermission(gitlabUrl, "token")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Could not validate GitLab write permission. Got an unexpected answer."); - assertThat(logTester.logs(LoggerLevel.INFO).get(0)) + assertThat(logTester.logs(Level.INFO).get(0)) .contains("Gitlab API call to [" + server.url("/markdown") + "] " + "failed with error message : [Failed to connect to " + server.getHostName()); } @@ -493,7 +493,7 @@ public class GitlabHttpClientTest { assertThatThrownBy(() -> underTest.getProject(gitlabUrl, "token", 0L)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Failed to connect to"); - assertThat(logTester.logs(LoggerLevel.INFO).get(0)) + assertThat(logTester.logs(Level.INFO).get(0)) .contains("Gitlab API call to [" + server.url("/projects/0") + "] " + "failed with error message : [Failed to connect to " + server.getHostName()); } @@ -505,7 +505,7 @@ public class GitlabHttpClientTest { assertThatThrownBy(() -> underTest.getBranches(gitlabUrl, "token", 0L)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Failed to connect to " + server.getHostName()); - assertThat(logTester.logs(LoggerLevel.INFO).get(0)) + assertThat(logTester.logs(Level.INFO).get(0)) .contains("Gitlab API call to [" + server.url("/projects/0/repository/branches") + "] " + "failed with error message : [Failed to connect to " + server.getHostName()); } @@ -517,7 +517,7 @@ public class GitlabHttpClientTest { assertThatThrownBy(() -> underTest.searchProjects(gitlabUrl, "token", null, 1, 1)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Failed to connect to"); - assertThat(logTester.logs(LoggerLevel.INFO).get(0)) + assertThat(logTester.logs(Level.INFO).get(0)) .contains( "Gitlab API call to [" + server.url("/projects?archived=false&simple=true&membership=true&order_by=name&sort=asc&search=&page=1&per_page=1") + "] " + |