Browse Source

SONAR-19015 Use new log test fixtures in the sonar-plugin-api

tags/10.1.0.73491
Jeremy Davis 1 year ago
parent
commit
ba00face3d
100 changed files with 453 additions and 349 deletions
  1. 1
    0
      build.gradle
  2. 1
    1
      gradle.properties
  3. 1
    0
      plugins/sonar-xoo-plugin/build.gradle
  4. 1
    1
      plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/extensions/XooPostJobTest.java
  5. 1
    0
      server/sonar-alm-client/build.gradle
  6. 18
    17
      server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java
  7. 13
    13
      server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java
  8. 1
    1
      server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java
  9. 1
    1
      server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationClientImplTest.java
  10. 3
    2
      server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java
  11. 8
    8
      server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabHttpClientTest.java
  12. 1
    0
      server/sonar-auth-saml/build.gradle
  13. 2
    2
      server/sonar-auth-saml/src/it/java/org/sonar/auth/saml/SamlIdentityProviderIT.java
  14. 1
    0
      server/sonar-ce-task-projectanalysis/build.gradle
  15. 6
    4
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepIT.java
  16. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/filemove/PullRequestFileMoveDetectionStepIT.java
  17. 3
    3
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ScmAccountToUserLoaderIT.java
  18. 9
    8
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderIT.java
  19. 3
    2
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepIT.java
  20. 6
    6
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepIT.java
  21. 5
    4
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java
  22. 4
    3
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepIT.java
  23. 9
    3
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java
  24. 9
    3
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/file/ExportLineHashesStepIT.java
  25. 5
    3
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepIT.java
  26. 4
    3
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepIT.java
  27. 7
    6
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepIT.java
  28. 5
    4
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepIT.java
  29. 5
    4
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportLinksStepIT.java
  30. 12
    6
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepIT.java
  31. 5
    4
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java
  32. 5
    4
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStepIT.java
  33. 5
    4
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepIT.java
  34. 6
    5
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStepIT.java
  35. 5
    5
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
  36. 12
    6
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/CrossProjectDuplicationStatusHolderImplTest.java
  37. 4
    4
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java
  38. 9
    3
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueAssignerTest.java
  39. 8
    1
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/ReportMetricValidatorImplTest.java
  40. 3
    2
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryImplTest.java
  41. 9
    2
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReaderTest.java
  42. 2
    2
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReaderTest.java
  43. 4
    2
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java
  44. 4
    3
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/ExportRuleStepTest.java
  45. 3
    3
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/DumpWriterImplTest.java
  46. 10
    4
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportPluginsStepTest.java
  47. 1
    0
      server/sonar-ce-task/build.gradle
  48. 4
    3
      server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/ComputationStepExecutorTest.java
  49. 1
    0
      server/sonar-ce/build.gradle
  50. 1
    1
      server/sonar-ce/src/it/java/org/sonar/ce/queue/NextPendingTaskPickerIT.java
  51. 31
    37
      server/sonar-ce/src/it/java/org/sonar/ce/taskprocessor/CeWorkerImplIT.java
  52. 3
    3
      server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeWorkerCountSettingWarningTest.java
  53. 3
    3
      server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeWorkerControllerImplTest.java
  54. 3
    3
      server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/TimeoutCeTaskInterrupterTest.java
  55. 1
    0
      server/sonar-db-core/build.gradle
  56. 4
    4
      server/sonar-db-core/src/it/java/org/sonar/db/DatabaseUtilsIT.java
  57. 1
    1
      server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java
  58. 3
    3
      server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java
  59. 4
    4
      server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java
  60. 8
    7
      server/sonar-db-core/src/test/java/org/sonar/db/profiling/ProfiledDataSourceTest.java
  61. 1
    0
      server/sonar-db-dao/build.gradle
  62. 3
    3
      server/sonar-db-dao/src/test/java/org/sonar/db/DBSessionsImplTest.java
  63. 1
    0
      server/sonar-db-migration/build.gradle
  64. 9
    9
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java
  65. 5
    5
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest.java
  66. 1
    1
      server/sonar-server-common/build.gradle
  67. 3
    2
      server/sonar-server-common/src/it/java/org/sonar/server/es/BulkIndexerIT.java
  68. 3
    3
      server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java
  69. 5
    5
      server/sonar-server-common/src/it/java/org/sonar/server/rule/index/RuleIndexerIT.java
  70. 17
    4
      server/sonar-server-common/src/it/java/org/sonar/server/webhook/SynchronousWebHooksImplIT.java
  71. 3
    3
      server/sonar-server-common/src/test/java/org/sonar/server/async/AsyncExecutionImplTest.java
  72. 5
    5
      server/sonar-server-common/src/test/java/org/sonar/server/es/EsClientProviderTest.java
  73. 1
    1
      server/sonar-server-common/src/test/java/org/sonar/server/log/ServerLoggingTest.java
  74. 1
    1
      server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerFileSystemImplTest.java
  75. 5
    5
      server/sonar-server-common/src/test/java/org/sonar/server/plugins/PluginRequirementsValidatorTest.java
  76. 1
    0
      server/sonar-webserver-api/build.gradle
  77. 3
    3
      server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginConsentVerifierTest.java
  78. 1
    1
      server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java
  79. 1
    1
      server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginUninstallerTest.java
  80. 1
    2
      server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java
  81. 11
    5
      server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventListenersImplTest.java
  82. 1
    0
      server/sonar-webserver-auth/build.gradle
  83. 3
    3
      server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/DefaultAdminCredentialsVerifierImplTest.java
  84. 2
    2
      server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/GithubWebhookAuthenticationTest.java
  85. 6
    6
      server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java
  86. 5
    5
      server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/LogOAuthWarningTest.java
  87. 5
    5
      server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2CallbackFilterTest.java
  88. 1
    1
      server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java
  89. 3
    2
      server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/event/AuthenticationEventImplTest.java
  90. 2
    2
      server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/purge/ExpiredSessionsCleanerTest.java
  91. 5
    5
      server/sonar-webserver-auth/src/test/java/org/sonar/server/user/SystemPasscodeImplTest.java
  92. 2
    2
      server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSchedulerImplTest.java
  93. 5
    3
      server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSenderTest.java
  94. 1
    0
      server/sonar-webserver-core/build.gradle
  95. 9
    9
      server/sonar-webserver-core/src/test/java/org/sonar/server/issue/index/AsyncIssueIndexingImplTest.java
  96. 3
    4
      server/sonar-webserver-core/src/test/java/org/sonar/server/platform/DatabaseServerCompatibilityTest.java
  97. 6
    5
      server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/CheckAnyonePermissionsAtStartupTest.java
  98. 4
    3
      server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/CheckLanguageSpecificParamsAtStartupTest.java
  99. 1
    1
      server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java
  100. 0
    0
      server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/AutoDbMigrationTest.java

+ 1
- 0
build.gradle View File

@@ -216,6 +216,7 @@ subprojects {
dependency 'org.sonarsource.slang:sonar-ruby-plugin:1.12.0.4259'
dependency 'org.sonarsource.slang:sonar-scala-plugin:1.12.0.4259'
dependency "org.sonarsource.api.plugin:sonar-plugin-api:$pluginApiVersion"
dependency "org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures:$pluginApiVersion"
dependency 'org.sonarsource.xml:sonar-xml-plugin:2.7.0.3820'
dependency 'org.sonarsource.iac:sonar-iac-plugin:1.15.0.3752'
dependency 'org.sonarsource.text:sonar-text-plugin:2.0.2.1090'

+ 1
- 1
gradle.properties View File

@@ -1,6 +1,6 @@
group=org.sonarsource.sonarqube
version=10.1
pluginApiVersion=9.14.0.375
pluginApiVersion=9.15.0.435
description=Open source platform for continuous inspection of code quality
projectTitle=SonarQube
org.gradle.jvmargs=-Xmx2048m

+ 1
- 0
plugins/sonar-xoo-plugin/build.gradle View File

@@ -11,6 +11,7 @@ dependencies {
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation project(':sonar-plugin-api-impl')
}


+ 1
- 1
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/extensions/XooPostJobTest.java View File

@@ -23,7 +23,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.batch.postjob.PostJobContext;
import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor;
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.mockito.Mockito.mock;

+ 1
- 0
server/sonar-alm-client/build.gradle View File

@@ -19,6 +19,7 @@ dependencies {
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.assertj:assertj-guava'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation 'com.squareup.okhttp3:mockwebserver'

}

+ 18
- 17
server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java View File

@@ -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");

+ 13
- 13
server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java View File

@@ -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"));
}
}

+ 1
- 1
server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java View File

@@ -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;

+ 1
- 1
server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationClientImplTest.java View File

@@ -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;

+ 3
- 2
server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java View File

@@ -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();

}

+ 8
- 8
server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabHttpClientTest.java View File

@@ -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")
+ "] " +

+ 1
- 0
server/sonar-auth-saml/build.gradle View File

@@ -20,5 +20,6 @@ dependencies {
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation testFixtures(project(':server:sonar-db-dao'))
}

+ 2
- 2
server/sonar-auth-saml/src/it/java/org/sonar/auth/saml/SamlIdentityProviderIT.java View File

@@ -38,8 +38,8 @@ import org.sonar.api.server.authentication.OAuth2IdentityProvider;
import org.sonar.api.server.authentication.UnauthorizedException;
import org.sonar.api.server.authentication.UserIdentity;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogAndArguments;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogAndArguments;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.db.DbTester;

import static org.assertj.core.api.Assertions.assertThat;

+ 1
- 0
server/sonar-ce-task-projectanalysis/build.gradle View File

@@ -52,6 +52,7 @@ dependencies {
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.assertj:assertj-guava'
testImplementation 'org.reflections:reflections'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation project(':sonar-testing-harness')
testImplementation testFixtures(project(':server:sonar-server-common'))


+ 6
- 4
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepIT.java View File

@@ -34,9 +34,9 @@ import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectanalysis.analysis.Analysis;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.component.Component;
@@ -60,7 +60,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.filemove.FileMoveDetectionStep.MIN_REQUIRED_SCORE;
import static org.sonar.db.component.BranchType.*;
import static org.sonar.db.component.BranchType.BRANCH;
import static org.sonar.db.component.BranchType.PULL_REQUEST;

public class FileMoveDetectionStepIT {

@@ -236,6 +237,7 @@ public class FileMoveDetectionStepIT {

@Before
public void setUp() throws Exception {
logTester.setLevel(Level.DEBUG);
project = dbTester.components().insertPrivateProject();
treeRootHolder.setRoot(builder(Component.Type.PROJECT, ROOT_REF).setUuid(project.uuid()).build());
}
@@ -418,7 +420,7 @@ public class FileMoveDetectionStepIT {
assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isZero();
assertThat(addedFileRepository.getComponents()).contains(file2);
verifyStatistics(context, 1, 1, 1, 0);
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("max score in matrix is less than min required score (85). Do nothing.");
assertThat(logTester.logs(Level.DEBUG)).contains("max score in matrix is less than min required score (85). Do nothing.");
}

@Test

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/filemove/PullRequestFileMoveDetectionStepIT.java View File

@@ -29,7 +29,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.ce.task.projectanalysis.analysis.Analysis;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.analysis.Branch;

+ 3
- 3
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ScmAccountToUserLoaderIT.java View File

@@ -21,8 +21,8 @@ package org.sonar.ce.task.projectanalysis.issue;

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.sonar.db.DbTester;
import org.sonar.db.user.UserDto;
import org.sonar.server.es.EsTester;
@@ -60,7 +60,7 @@ public class ScmAccountToUserLoaderIT {
ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(db.getDbClient());

assertThat(underTest.load("charlie")).isNull();
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Multiple users share the SCM account 'charlie': another.charlie, charlie");
assertThat(logTester.logs(Level.WARN)).contains("Multiple users share the SCM account 'charlie': another.charlie, charlie");
}

@Test

+ 9
- 8
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderIT.java View File

@@ -29,7 +29,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.ce.task.projectanalysis.analysis.Analysis;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.analysis.Branch;
@@ -51,7 +51,7 @@ import org.sonar.db.source.FileSourceDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.utils.log.LoggerLevel.TRACE;
import static org.slf4j.event.Level.TRACE;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;

public class ScmInfoDbLoaderIT {
@@ -86,6 +86,7 @@ public class ScmInfoDbLoaderIT {

@Before
public void before() {
logTester.setLevel(TRACE);
periodHolder.setPeriod(new Period(NewCodePeriodType.PREVIOUS_VERSION.name(), null, null));
}

@@ -101,7 +102,7 @@ public class ScmInfoDbLoaderIT {
assertThat(scmInfo.getAllChangesets()).hasSize(1);
assertThat(scmInfo.fileHash()).isEqualTo(hash);

assertThat(logTester.logs(TRACE)).containsOnly("Reading SCM info from DB for file 'FILE_UUID'");
assertThat(logTester.logs(TRACE)).contains("Reading SCM info from DB for file 'FILE_UUID'");
}

@Test
@@ -118,7 +119,7 @@ public class ScmInfoDbLoaderIT {
DbScmInfo scmInfo = underTest.getScmInfo(FILE).get();
assertThat(scmInfo.getAllChangesets()).hasSize(1);
assertThat(scmInfo.fileHash()).isEqualTo(hash);
assertThat(logTester.logs(TRACE)).containsOnly("Reading SCM info from DB for file 'referenceFileUuid'");
assertThat(logTester.logs(TRACE)).contains("Reading SCM info from DB for file 'referenceFileUuid'");
}

@Test
@@ -137,7 +138,7 @@ public class ScmInfoDbLoaderIT {
DbScmInfo scmInfo = underTest.getScmInfo(FILE).get();
assertThat(scmInfo.getAllChangesets()).hasSize(1);
assertThat(scmInfo.fileHash()).isEqualTo(hash);
assertThat(logTester.logs(TRACE)).containsOnly("Reading SCM info from DB for file 'targetBranchFileUuid'");
assertThat(logTester.logs(TRACE)).contains("Reading SCM info from DB for file 'targetBranchFileUuid'");
}

@Test
@@ -158,7 +159,7 @@ public class ScmInfoDbLoaderIT {
DbScmInfo scmInfo = underTest.getScmInfo(FILE).get();
assertThat(scmInfo.getAllChangesets()).hasSize(1);
assertThat(scmInfo.fileHash()).isEqualTo(hash);
assertThat(logTester.logs(TRACE)).containsOnly("Reading SCM info from DB for file 'targetBranchFileUuid'");
assertThat(logTester.logs(TRACE)).contains("Reading SCM info from DB for file 'targetBranchFileUuid'");
}

@Test
@@ -177,7 +178,7 @@ public class ScmInfoDbLoaderIT {
DbScmInfo scmInfo = underTest.getScmInfo(FILE).get();
assertThat(scmInfo.getAllChangesets()).hasSize(1);
assertThat(scmInfo.fileHash()).isEqualTo(hash);
assertThat(logTester.logs(TRACE)).containsOnly("Reading SCM info from DB for file 'FILE_UUID'");
assertThat(logTester.logs(TRACE)).contains("Reading SCM info from DB for file 'FILE_UUID'");
}

@Test
@@ -187,7 +188,7 @@ public class ScmInfoDbLoaderIT {

Optional<DbScmInfo> scmInfo = underTest.getScmInfo(FILE);

assertThat(logTester.logs(TRACE)).containsOnly("Reading SCM info from DB for file 'FILE_UUID'");
assertThat(logTester.logs(TRACE)).contains("Reading SCM info from DB for file 'FILE_UUID'");
assertThat(scmInfo).isEmpty();
}


+ 3
- 2
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepIT.java View File

@@ -26,11 +26,12 @@ import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.impl.utils.JUnitTempFolder;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.ZipUtils;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.CeTask;
import org.sonar.ce.task.projectanalysis.batch.BatchReportDirectoryHolderImpl;
@@ -89,7 +90,7 @@ public class ExtractReportStepIT {
assertThat(unzippedDir.listFiles()).hasSize(1);
assertThat(new File(unzippedDir, "metadata.pb")).hasContent("{metadata}");

assertThat(logTester.logs(LoggerLevel.DEBUG)).anyMatch(log -> log.matches("Analysis report is \\d+ bytes uncompressed"));
assertThat(logTester.logs(Level.DEBUG)).anyMatch(log -> log.matches("Analysis report is \\d+ bytes uncompressed"));
}

@Test

+ 6
- 6
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepIT.java View File

@@ -35,10 +35,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.event.Level;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogAndArguments;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogAndArguments;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.log.CeTaskMessages;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
@@ -102,6 +103,7 @@ public class LoadPeriodsStepIT extends BaseStepTest {

@Before
public void setUp() {
logTester.setLevel(Level.TRACE);
project = dbTester.components().insertPublicProject();

when(analysisMetadataHolder.isBranch()).thenReturn(true);
@@ -528,10 +530,8 @@ public class LoadPeriodsStepIT extends BaseStepTest {
}

private void verifyDebugLogs(String log, String... otherLogs) {
assertThat(logTester.getLogs()).hasSize(1 + otherLogs.length);
assertThat(logTester.getLogs(LoggerLevel.DEBUG))
.extracting(LogAndArguments::getFormattedMsg)
.containsOnly(Stream.concat(Stream.of(log), Arrays.stream(otherLogs)).toArray(String[]::new));
assertThat(logTester.logs(Level.DEBUG))
.contains(Stream.concat(Stream.of(log), Arrays.stream(otherLogs)).toArray(String[]::new));
}

private void setupRoot(ComponentDto branchComponent) {

+ 5
- 4
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java View File

@@ -30,11 +30,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.event.Level;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.component.ComponentRepositoryImpl;
import org.sonar.ce.task.projectexport.steps.DumpElement;
import org.sonar.ce.task.projectexport.steps.FakeDumpWriter;
@@ -107,6 +107,7 @@ public class ExportAnalysesStepIT {

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT);
componentRepository.register(1, projectDto.uuid(), false);
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), Set.of(DIR, FILE), true);
@@ -130,7 +131,7 @@ public class ExportAnalysesStepIT {

underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("3 analyses exported");
assertThat(logTester.logs(Level.DEBUG)).contains("3 analyses exported");
List<ProjectDump.Analysis> analyses = dumpWriter.getWrittenMessagesOf(DumpElement.ANALYSES);
assertThat(analyses).hasSize(3);
assertAnalysis(analyses.get(0), PROJECT, firstAnalysis);
@@ -175,7 +176,7 @@ public class ExportAnalysesStepIT {

List<ProjectDump.Analysis> analyses = dumpWriter.getWrittenMessagesOf(DumpElement.ANALYSES);
assertThat(analyses).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 analyses exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 analyses exported");
}

@Test

+ 4
- 3
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepIT.java View File

@@ -29,11 +29,11 @@ import org.apache.commons.lang.time.DateUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.steps.DumpElement;
import org.sonar.ce.task.projectexport.steps.FakeDumpWriter;
import org.sonar.ce.task.projectexport.steps.ProjectHolder;
@@ -107,6 +107,7 @@ public class ExportBranchesStepIT {

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
Date createdAt = new Date();
ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).setCreatedAt(createdAt);
for (BranchDto branch : branches) {
@@ -121,7 +122,7 @@ public class ExportBranchesStepIT {
public void export_branches() {
underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("3 branches exported");
assertThat(logTester.logs(Level.DEBUG)).contains("3 branches exported");
Map<String, ProjectDump.Branch> branches = dumpWriter.getWrittenMessagesOf(DumpElement.BRANCHES)
.stream()
.collect(toMap(ProjectDump.Branch::getUuid, Function.identity()));

+ 9
- 3
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java View File

@@ -24,13 +24,14 @@ import com.sonarsource.governance.projectdump.protobuf.ProjectDump;
import java.util.Date;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.steps.DumpElement;
import org.sonar.ce.task.projectexport.steps.FakeDumpWriter;
import org.sonar.ce.task.projectexport.steps.ProjectHolder;
@@ -86,6 +87,11 @@ public class ExportComponentsStepIT {
private final MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
private final ExportComponentsStep underTest = new ExportComponentsStep(dbTester.getDbClient(), projectHolder, componentRepository, dumpWriter);

@Before
public void before() {
logTester.setLevel(Level.DEBUG);
}

@After
public void tearDown() {
dbTester.getSession().close();
@@ -100,7 +106,7 @@ public class ExportComponentsStepIT {

underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 components exported");
assertThat(logTester.logs(Level.DEBUG)).contains("2 components exported");
List<ProjectDump.Component> components = dumpWriter.getWrittenMessagesOf(DumpElement.COMPONENTS);
assertThat(components).extracting(ProjectDump.Component::getQualifier, ProjectDump.Component::getUuid, ProjectDump.Component::getUuidPath)
.containsExactlyInAnyOrder(

+ 9
- 3
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/file/ExportLineHashesStepIT.java View File

@@ -22,12 +22,13 @@ package org.sonar.ce.task.projectexport.file;
import com.sonarsource.governance.projectdump.protobuf.ProjectDump;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.component.ComponentRepositoryImpl;
import org.sonar.ce.task.projectexport.component.MutableComponentRepository;
import org.sonar.ce.task.projectexport.steps.DumpElement;
@@ -65,6 +66,11 @@ public class ExportLineHashesStepIT {

private ExportLineHashesStep underTest = new ExportLineHashesStep(dbClient, dumpWriter, componentRepository);

@Before
public void before() {
logTester.setLevel(Level.DEBUG);
}

@After
public void tearDown() {
dbSession.close();
@@ -167,7 +173,7 @@ public class ExportLineHashesStepIT {
.extracting(ProjectDump.LineHashes::getHashes)
.containsExactly("A", "C", "D", "E");

assertThat(logTester.logs(LoggerLevel.DEBUG)).containsExactly("Lines hashes of 4 files exported");
assertThat(logTester.logs(Level.DEBUG)).contains("Lines hashes of 4 files exported");
}

private FileSourceDto insertFileSource(String fileUuid, String hashes) {

+ 5
- 3
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepIT.java View File

@@ -26,9 +26,9 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.steps.DumpElement;
import org.sonar.ce.task.projectexport.steps.FakeDumpWriter;
import org.sonar.ce.task.projectexport.steps.ProjectHolder;
@@ -77,6 +77,7 @@ public class ExportIssuesChangelogStepIT {

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
ComponentDto projectDto = dbTester.components().insertPublicProject(p -> p.setUuid(PROJECT_UUID));
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(projectDto));
when(projectHolder.branches()).thenReturn(newArrayList(
@@ -211,13 +212,14 @@ public class ExportIssuesChangelogStepIT {

@Test
public void execute_logs_number_total_exported_issue_changes_count_when_successful() {
logTester.setLevel(Level.DEBUG);
insertIssueChange(ISSUE_OPEN_UUID);
insertIssueChange(ISSUE_CONFIRMED_UUID);
insertIssueChange(ISSUE_REOPENED_UUID);

underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).containsExactly("3 issue changes exported");
assertThat(logTester.logs(Level.DEBUG)).contains("3 issue changes exported");
}

@Test

+ 4
- 3
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepIT.java View File

@@ -34,13 +34,13 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.event.Level;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rules.RuleType;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.component.ComponentRepositoryImpl;
import org.sonar.ce.task.projectexport.component.MutableComponentRepository;
import org.sonar.ce.task.projectexport.rule.RuleRepository;
@@ -99,6 +99,7 @@ public class ExportIssuesStepIT {

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
ProjectDto project = createProject();
when(projectHolder.projectDto()).thenReturn(project);
when(projectHolder.branches()).thenReturn(newArrayList(
@@ -331,7 +332,7 @@ public class ExportIssuesStepIT {

underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).containsExactly("3 issues exported");
assertThat(logTester.logs(Level.DEBUG)).contains("3 issues exported");
}

@Test

+ 7
- 6
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepIT.java View File

@@ -27,15 +27,15 @@ import org.apache.commons.lang.RandomStringUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.steps.DumpElement;
import org.sonar.ce.task.projectexport.steps.FakeDumpWriter;
import org.sonar.ce.task.projectexport.steps.ProjectHolder;
@@ -89,6 +89,7 @@ public class ExportAdHocRulesStepIT {

@Before
public void setup() {
logTester.setLevel(Level.DEBUG);
ProjectDto project = createProject();
when(projectHolder.projectDto()).thenReturn(project);
}
@@ -99,7 +100,7 @@ public class ExportAdHocRulesStepIT {

List<ProjectDump.AdHocRule> exportedRules = dumpWriter.getWrittenMessagesOf(DumpElement.AD_HOC_RULES);
assertThat(exportedRules).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 ad-hoc rules exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 ad-hoc rules exported");
}

@Test
@@ -116,7 +117,7 @@ public class ExportAdHocRulesStepIT {
List<ProjectDump.AdHocRule> exportedRules = dumpWriter.getWrittenMessagesOf(DumpElement.AD_HOC_RULES);
assertThat(exportedRules).hasSize(1);
assertProtobufAdHocRuleIsCorrectlyBuilt(exportedRules.iterator().next(), rule2);
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 ad-hoc rules exported");
assertThat(logTester.logs(Level.DEBUG)).contains("1 ad-hoc rules exported");
}

@Test
@@ -133,7 +134,7 @@ public class ExportAdHocRulesStepIT {
List<ProjectDump.AdHocRule> exportedRules = dumpWriter.getWrittenMessagesOf(DumpElement.AD_HOC_RULES);
assertThat(exportedRules).hasSize(1);
assertProtobufAdHocRuleIsCorrectlyBuilt(exportedRules.iterator().next(), rule3);
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 ad-hoc rules exported");
assertThat(logTester.logs(Level.DEBUG)).contains("1 ad-hoc rules exported");
}

@Test
@@ -151,7 +152,7 @@ public class ExportAdHocRulesStepIT {
List<ProjectDump.AdHocRule> exportedRules = dumpWriter.getWrittenMessagesOf(DumpElement.AD_HOC_RULES);
assertThat(exportedRules).hasSize(1);
assertProtobufAdHocRuleIsCorrectlyBuilt(exportedRules.iterator().next(), rule2);
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 ad-hoc rules exported");
assertThat(logTester.logs(Level.DEBUG)).contains("1 ad-hoc rules exported");
}

@Test

+ 5
- 4
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepIT.java View File

@@ -24,11 +24,11 @@ import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.component.ComponentRepositoryImpl;
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.db.DbTester;
@@ -70,6 +70,7 @@ public class ExportEventsStepIT {

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT);
componentRepository.register(1, projectDto.uuid(), false);
projectHolder.setProjectDto(dbTester.components().getProjectDto(projectDto));
@@ -79,7 +80,7 @@ public class ExportEventsStepIT {
public void export_zero_events() {
underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 events exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 events exported");
List<ProjectDump.Event> events = dumpWriter.getWrittenMessagesOf(DumpElement.EVENTS);
assertThat(events).isEmpty();
}
@@ -92,7 +93,7 @@ public class ExportEventsStepIT {

underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 events exported");
assertThat(logTester.logs(Level.DEBUG)).contains("2 events exported");
List<ProjectDump.Event> events = dumpWriter.getWrittenMessagesOf(DumpElement.EVENTS);
assertThat(events).hasSize(2);
assertThat(events).extracting(ProjectDump.Event::getUuid).containsOnly("E1", "E2");

+ 5
- 4
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportLinksStepIT.java View File

@@ -23,11 +23,11 @@ import com.sonarsource.governance.projectdump.protobuf.ProjectDump.Link;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.component.ComponentRepository;
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.db.DbTester;
@@ -71,6 +71,7 @@ public class ExportLinksStepIT {

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
ComponentDto project = db.components().insertPublicProject(PROJECT);
when(projectHolder.projectDto()).thenReturn(db.components().getProjectDto(project));
when(componentRepository.getRef(PROJECT_UUID)).thenReturn(1L);
@@ -80,7 +81,7 @@ public class ExportLinksStepIT {
public void export_zero_links() {
underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 links exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 links exported");
assertThat(dumpWriter.getWrittenMessagesOf(DumpElement.LINKS)).isEmpty();
}

@@ -92,7 +93,7 @@ public class ExportLinksStepIT {

underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 links exported");
assertThat(logTester.logs(Level.DEBUG)).contains("2 links exported");
assertThat(dumpWriter.getWrittenMessagesOf(DumpElement.LINKS))
.extracting(Link::getUuid, Link::getName, Link::getType, Link::getHref)
.containsExactlyInAnyOrder(

+ 12
- 6
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepIT.java View File

@@ -21,11 +21,12 @@ package org.sonar.ce.task.projectexport.steps;

import com.sonarsource.governance.projectdump.protobuf.ProjectDump;
import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.component.ComponentRepositoryImpl;
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.db.DbTester;
@@ -54,6 +55,11 @@ public class ExportLiveMeasuresStepIT {
private FakeDumpWriter dumpWriter = new FakeDumpWriter();
private ExportLiveMeasuresStep underTest = new ExportLiveMeasuresStep(dbTester.getDbClient(), projectHolder, componentRepository, metricRepository, dumpWriter);

@Before
public void before() {
logTester.setLevel(Level.DEBUG);
}

@Test
public void export_zero_measures() {
when(projectHolder.branches()).thenReturn(newArrayList());
@@ -62,7 +68,7 @@ public class ExportLiveMeasuresStepIT {
underTest.execute(new TestComputationStepContext());

assertThat(dumpWriter.getWrittenMessagesOf(DumpElement.LIVE_MEASURES)).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 live measures exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 live measures exported");
assertThat(metricRepository.getRefByUuid()).isEmpty();
}

@@ -85,7 +91,7 @@ public class ExportLiveMeasuresStepIT {
assertThat(exportedMeasures)
.extracting(ProjectDump.LiveMeasure::getMetricRef, m -> m.getDoubleValue().getValue(), ProjectDump.LiveMeasure::hasVariation)
.containsOnly(tuple(0, 4711.0d, false));
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
assertThat(logTester.logs(Level.DEBUG)).contains("1 live measures exported");
assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
}

@@ -157,7 +163,7 @@ public class ExportLiveMeasuresStepIT {
0.0d,
"test",
7.0d));
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
assertThat(logTester.logs(Level.DEBUG)).contains("1 live measures exported");
assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
}

@@ -187,7 +193,7 @@ public class ExportLiveMeasuresStepIT {
false,
"",
false));
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
assertThat(logTester.logs(Level.DEBUG)).contains("1 live measures exported");
assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
}


+ 5
- 4
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java View File

@@ -24,9 +24,9 @@ import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.component.ComponentRepositoryImpl;
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.db.DbTester;
@@ -107,6 +107,7 @@ public class ExportMeasuresStepIT {

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
String projectUuid = dbTester.components().insertPublicProject(PROJECT).uuid();
componentRepository.register(1, projectUuid, false);
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), List.of(FILE, ANOTHER_PROJECT), true);
@@ -121,7 +122,7 @@ public class ExportMeasuresStepIT {
underTest.execute(new TestComputationStepContext());

assertThat(dumpWriter.getWrittenMessagesOf(DumpElement.MEASURES)).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 measures exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 measures exported");
assertThat(metricRepository.getRefByUuid()).isEmpty();
}

@@ -141,7 +142,7 @@ public class ExportMeasuresStepIT {
assertThat(exportedMeasures).hasSize(2);
assertThat(exportedMeasures).extracting(ProjectDump.Measure::getAnalysisUuid).containsOnly(firstAnalysis.getUuid(), secondAnalysis.getUuid());
assertThat(exportedMeasures).extracting(ProjectDump.Measure::getMetricRef).containsOnly(0);
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 measures exported");
assertThat(logTester.logs(Level.DEBUG)).contains("2 measures exported");
assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(NCLOC.getUuid());
}


+ 5
- 4
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStepIT.java View File

@@ -24,9 +24,9 @@ import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.db.DbTester;
import org.sonar.db.metric.MetricDto;
@@ -60,6 +60,7 @@ public class ExportMetricsStepIT {

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
dbTester.getDbClient().metricDao().insert(dbTester.getSession(), NCLOC, COVERAGE);
dbTester.commit();
}
@@ -68,7 +69,7 @@ public class ExportMetricsStepIT {
public void export_zero_metrics() {
underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 metrics exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 metrics exported");
}

@Test
@@ -78,7 +79,7 @@ public class ExportMetricsStepIT {

underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 metrics exported");
assertThat(logTester.logs(Level.DEBUG)).contains("2 metrics exported");
List<ProjectDump.Metric> exportedMetrics = dumpWriter.getWrittenMessagesOf(DumpElement.METRICS);

ProjectDump.Metric ncloc = exportedMetrics.stream().filter(input -> input.getRef() == 0).findAny().orElseThrow();

+ 5
- 4
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepIT.java View File

@@ -27,10 +27,10 @@ import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
@@ -87,6 +87,7 @@ public class ExportNewCodePeriodsStepIT {

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
Date createdAt = new Date();
ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT);
PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectDto, branch).setCreatedAt(createdAt));
@@ -103,7 +104,7 @@ public class ExportNewCodePeriodsStepIT {
underTest.execute(new TestComputationStepContext());

assertThat(dumpWriter.getWrittenMessagesOf(DumpElement.NEW_CODE_PERIODS)).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 new code periods exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 new code periods exported");
}

@Test
@@ -121,7 +122,7 @@ public class ExportNewCodePeriodsStepIT {
List<ProjectDump.NewCodePeriod> exportedProps = dumpWriter.getWrittenMessagesOf(DumpElement.NEW_CODE_PERIODS);
assertThat(exportedProps).hasSize(2);
assertThat(exportedProps).extracting(ProjectDump.NewCodePeriod::getUuid).containsOnly("uuid1", "uuid2");
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 new code periods exported");
assertThat(logTester.logs(Level.DEBUG)).contains("2 new code periods exported");
}

@Test

+ 6
- 5
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStepIT.java View File

@@ -25,10 +25,10 @@ import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.component.ComponentRepositoryImpl;
import org.sonar.ce.task.projectexport.component.MutableComponentRepository;
import org.sonar.ce.task.step.TestComputationStepContext;
@@ -66,6 +66,7 @@ public class ExportSettingsStepIT {

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
dbTester.components().insertPublicProject(PROJECT);
dbTester.components().insertPublicProject(ANOTHER_PROJECT);
dbTester.commit();
@@ -78,7 +79,7 @@ public class ExportSettingsStepIT {
underTest.execute(new TestComputationStepContext());

assertThat(dumpWriter.getWrittenMessagesOf(DumpElement.SETTINGS)).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 settings exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 settings exported");
}

@Test
@@ -97,7 +98,7 @@ public class ExportSettingsStepIT {
List<ProjectDump.Setting> exportedProps = dumpWriter.getWrittenMessagesOf(DumpElement.SETTINGS);
assertThat(exportedProps).hasSize(2);
assertThat(exportedProps).extracting(ProjectDump.Setting::getKey).containsOnly("p1", "p2");
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 settings exported");
assertThat(logTester.logs(Level.DEBUG)).contains("2 settings exported");
}

@Test
@@ -107,7 +108,7 @@ public class ExportSettingsStepIT {
underTest.execute(new TestComputationStepContext());

assertThat(dumpWriter.getWrittenMessagesOf(DumpElement.SETTINGS)).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 settings exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 settings exported");
}

@Test

+ 5
- 5
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java View File

@@ -36,10 +36,10 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.slf4j.event.Level;
import org.sonar.api.ce.posttask.PostProjectAnalysisTask;
import org.sonar.api.ce.posttask.Project;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.ce.task.CeTask;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.analysis.Branch;
@@ -144,7 +144,7 @@ public class PostProjectAnalysisTasksExecutorTest {
assertThat(allValues.get(0)).isSameAs(allValues.get(1));

assertThat(logTester.logs()).hasSize(2);
List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).matches("^PT1 \\| status=SUCCESS \\| time=\\d+ms$");
assertThat(logs.get(1)).matches("^PT2 \\| status=SUCCESS \\| time=\\d+ms$");
@@ -390,7 +390,7 @@ public class PostProjectAnalysisTasksExecutorTest {
verify(logStatisticsTask).finished(taskContextCaptor.capture());

assertThat(logTester.logs()).hasSize(1);
List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(1);
StringBuilder expectedLog = new StringBuilder("^PT1 ");
stats.forEach((k, v) -> expectedLog.append("\\| " + k + "=" + v + " "));
@@ -424,7 +424,7 @@ public class PostProjectAnalysisTasksExecutorTest {
inOrder.verifyNoMoreInteractions();

assertThat(logTester.logs()).hasSize(4);
List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(3);
assertThat(logs.get(0)).matches("^PT1 \\| status=SUCCESS \\| time=\\d+ms$");
assertThat(logs.get(1)).matches("^PT2 \\| status=FAILED \\| time=\\d+ms$");

+ 12
- 6
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/CrossProjectDuplicationStatusHolderImplTest.java View File

@@ -19,10 +19,11 @@
*/
package org.sonar.ce.task.projectanalysis.duplication;

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.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.analysis.Branch;

@@ -40,6 +41,11 @@ public class CrossProjectDuplicationStatusHolderImplTest {

private CrossProjectDuplicationStatusHolderImpl underTest = new CrossProjectDuplicationStatusHolderImpl(analysisMetadataHolder);

@Before
public void before() {
logTester.setLevel(Level.DEBUG);
}

@Test
public void cross_project_duplication_is_enabled_when_enabled_in_report_and_no_branch() {
analysisMetadataHolder
@@ -48,7 +54,7 @@ public class CrossProjectDuplicationStatusHolderImplTest {
underTest.start();

assertThat(underTest.isEnabled()).isTrue();
assertThat(logTester.logs(LoggerLevel.DEBUG)).containsOnly("Cross project duplication is enabled");
assertThat(logTester.logs(Level.DEBUG)).containsOnly("Cross project duplication is enabled");
}

@Test
@@ -59,7 +65,7 @@ public class CrossProjectDuplicationStatusHolderImplTest {
underTest.start();

assertThat(underTest.isEnabled()).isFalse();
assertThat(logTester.logs(LoggerLevel.DEBUG)).containsOnly("Cross project duplication is disabled because it's disabled in the analysis report");
assertThat(logTester.logs(Level.DEBUG)).containsOnly("Cross project duplication is disabled because it's disabled in the analysis report");
}

@Test
@@ -70,7 +76,7 @@ public class CrossProjectDuplicationStatusHolderImplTest {
underTest.start();

assertThat(underTest.isEnabled()).isFalse();
assertThat(logTester.logs(LoggerLevel.DEBUG)).containsOnly("Cross project duplication is disabled because of a branch is used");
assertThat(logTester.logs(Level.DEBUG)).containsOnly("Cross project duplication is disabled because of a branch is used");
}

@Test
@@ -81,7 +87,7 @@ public class CrossProjectDuplicationStatusHolderImplTest {
underTest.start();

assertThat(underTest.isEnabled()).isFalse();
assertThat(logTester.logs(LoggerLevel.DEBUG)).containsOnly("Cross project duplication is disabled because it's disabled in the analysis report");
assertThat(logTester.logs(Level.DEBUG)).containsOnly("Cross project duplication is disabled because it's disabled in the analysis report");
}

@Test

+ 4
- 4
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java View File

@@ -25,10 +25,10 @@ import java.util.Collection;
import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.ce.task.log.CeTaskMessages;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.FileAttributes;
@@ -296,7 +296,7 @@ public class IntegrateCrossProjectDuplicationsTest {

underTest.computeCpd(ORIGIN_FILE, originBlocks, duplicatedBlocks);

assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly(
assertThat(logTester.logs(Level.WARN)).containsOnly(
"Too many duplication references on file " + ORIGIN_FILE_KEY + " for block at line 30. Keeping only the first 100 references.");
Iterable<Duplication> duplications = duplicationRepository.getDuplications(ORIGIN_FILE);
assertThat(duplications).hasSize(1);
@@ -331,7 +331,7 @@ public class IntegrateCrossProjectDuplicationsTest {
underTest.computeCpd(ORIGIN_FILE, originBlocks, duplicatedBlocks);

assertThat(duplicationRepository.getDuplications(ORIGIN_FILE)).hasSize(100);
assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Too many duplication groups on file " + ORIGIN_FILE_KEY + ". Keeping only the first 100 groups.");
assertThat(logTester.logs(Level.WARN)).containsOnly("Too many duplication groups on file " + ORIGIN_FILE_KEY + ". Keeping only the first 100 groups.");
}

@Test

+ 9
- 3
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueAssignerTest.java View File

@@ -21,10 +21,11 @@ package org.sonar.ce.task.projectanalysis.issue;

import java.util.Arrays;
import javax.annotation.Nullable;
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.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.scm.Changeset;
@@ -59,6 +60,11 @@ public class IssueAssignerTest {
private DefaultAssignee defaultAssignee = mock(DefaultAssignee.class);
private IssueAssigner underTest = new IssueAssigner(analysisMetadataHolder, scmInfoRepository, scmAccountToUser, defaultAssignee, new IssueFieldsSetter());

@Before
public void before() {
logTester.setLevel(Level.DEBUG);
}

@Test
public void do_not_set_author_if_no_changeset() {
DefaultIssue issue = newIssueOnLines(1);
@@ -101,7 +107,7 @@ public class IssueAssignerTest {
assertThat(issue.authorLogin()).isNull();
assertThat(issue.assignee()).isEqualTo("John C");

assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("SCM account '" + scmAuthor + "' is too long to be stored as issue author");
assertThat(logTester.logs(Level.DEBUG)).contains("SCM account '" + scmAuthor + "' is too long to be stored as issue author");
}

@Test

+ 8
- 1
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/ReportMetricValidatorImplTest.java View File

@@ -21,9 +21,11 @@ package org.sonar.ce.task.projectanalysis.metric;

import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.core.metric.ScannerMetrics;

@@ -42,6 +44,11 @@ public class ReportMetricValidatorImplTest {

ScannerMetrics scannerMetrics = mock(ScannerMetrics.class);

@Before
public void before() {
logTester.setLevel(Level.DEBUG);
}

@Test
public void validate_metric() {
when(scannerMetrics.getMetrics()).thenReturn(ImmutableSet.of(new Builder(METRIC_KEY, "name", ValueType.INT).create()));

+ 3
- 2
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryImplTest.java View File

@@ -32,7 +32,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule;
@@ -55,7 +55,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.sonar.api.utils.log.LoggerLevel.TRACE;
import static org.slf4j.event.Level.TRACE;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;

@RunWith(DataProviderRunner.class)
@@ -82,6 +82,7 @@ public class ScmInfoRepositoryImplTest {

@Before
public void setUp() {
logTester.setLevel(TRACE);
analysisMetadata.setAnalysisDate(analysisDate);
}


+ 9
- 2
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReaderTest.java View File

@@ -24,9 +24,11 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.source.linereader.RangeOffsetConverter.RangeOffsetConverterException;
import org.sonar.db.protobuf.DbFileSources;
@@ -39,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.utils.log.LoggerLevel.DEBUG;
import static org.slf4j.event.Level.DEBUG;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.source.linereader.LineReader.Data.HIGHLIGHTING;
import static org.sonar.db.protobuf.DbFileSources.Data.newBuilder;
@@ -77,6 +79,11 @@ public class HighlightingLineReaderTest {
private DbFileSources.Line.Builder line3 = sourceData.addLinesBuilder().setSource("line3").setLine(3);
private DbFileSources.Line.Builder line4 = sourceData.addLinesBuilder().setSource("line4").setLine(4);

@Before
public void before() {
logTester.setLevel(Level.TRACE);
}

@Test
public void nothing_to_read() {
HighlightingLineReader highlightingLineReader = newReader(Collections.emptyMap());

+ 2
- 2
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReaderTest.java View File

@@ -22,7 +22,7 @@ package org.sonar.ce.task.projectanalysis.source.linereader;
import java.util.Arrays;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.db.protobuf.DbFileSources;
import org.sonar.scanner.protocol.output.ScannerReport;
@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.utils.log.LoggerLevel.WARN;
import static org.slf4j.event.Level.WARN;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.source.linereader.LineReader.Data.SYMBOLS;


+ 4
- 2
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java View File

@@ -23,7 +23,8 @@ import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.ChangeLogLevel;
import org.sonar.ce.task.projectanalysis.component.Component;
@@ -71,6 +72,7 @@ public class ExecuteVisitorsStepTest {

@Before
public void setUp() throws Exception {
logTester.setLevel(Level.DEBUG);
treeRootHolder.setRoot(
builder(PROJECT, ROOT_REF).setKey("project")
.addChildren(
@@ -126,7 +128,7 @@ public class ExecuteVisitorsStepTest {

underTest.execute(new TestComputationStepContext());

List<String> logs = logTester.logs(LoggerLevel.DEBUG);
List<String> logs = logTester.logs(Level.DEBUG);
assertThat(logs).hasSize(4);
assertThat(logs.get(0)).isEqualTo(" Execution time for each component visitor:");
assertThat(logs.get(1)).startsWith(" - VisitorA | time=");

+ 4
- 3
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/ExportRuleStepTest.java View File

@@ -24,9 +24,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.ce.task.projectexport.steps.DumpElement;
import org.sonar.ce.task.projectexport.steps.FakeDumpWriter;
import org.sonar.ce.task.step.TestComputationStepContext;
@@ -75,11 +75,12 @@ public class ExportRuleStepTest {

@Test
public void execute_logs_number_total_exported_rules_count_when_successful() {
logTester.setLevel(Level.DEBUG);
ruleRepository.add("A").add("B").add("C").add("D");

underTest.execute(new TestComputationStepContext());

assertThat(logTester.logs(LoggerLevel.DEBUG)).containsExactly("4 rules exported");
assertThat(logTester.logs(Level.DEBUG)).containsExactly("4 rules exported");
}

@Test

+ 3
- 3
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/DumpWriterImplTest.java View File

@@ -26,9 +26,9 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.TempFolder;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.projectexport.taskprocessor.ProjectDescriptor;
import org.sonar.ce.task.projectexport.util.ProjectExportDumpFS;

@@ -91,7 +91,7 @@ public class DumpWriterImplTest {

assertThat(rootDir).doesNotExist();
assertThat(targetZipFile).isFile().exists();
assertThat(logTester.logs(LoggerLevel.INFO).get(0))
assertThat(logTester.logs(Level.INFO).get(0))
.contains("Dump file published", "size=", "path=" + targetZipFile.getAbsolutePath());
}


+ 10
- 4
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportPluginsStepTest.java View File

@@ -23,10 +23,11 @@ import com.sonarsource.governance.projectdump.protobuf.ProjectDump;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
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.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository;
@@ -46,6 +47,11 @@ public class ExportPluginsStepTest {
private FakeDumpWriter dumpWriter = new FakeDumpWriter();
ExportPluginsStep underTest = new ExportPluginsStep(pluginRepository, dumpWriter);

@Before
public void before() {
logTester.setLevel(Level.DEBUG);
}

@Test
public void export_plugins() {
when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(
@@ -56,7 +62,7 @@ public class ExportPluginsStepTest {
List<ProjectDump.Plugin> exportedPlugins = dumpWriter.getWrittenMessagesOf(DumpElement.PLUGINS);
assertThat(exportedPlugins).hasSize(2);
assertThat(exportedPlugins).extracting(ProjectDump.Plugin::getKey).containsExactlyInAnyOrder("java", "cs");
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 plugins exported");
assertThat(logTester.logs(Level.DEBUG)).contains("2 plugins exported");
}

@Test
@@ -66,7 +72,7 @@ public class ExportPluginsStepTest {
underTest.execute(new TestComputationStepContext());

assertThat(dumpWriter.getWrittenMessagesOf(DumpElement.PLUGINS)).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 plugins exported");
assertThat(logTester.logs(Level.DEBUG)).contains("0 plugins exported");
}

@Test

+ 1
- 0
server/sonar-ce-task/build.gradle View File

@@ -38,6 +38,7 @@ dependencies {
testImplementation 'org.assertj:assertj-guava'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.reflections:reflections'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation testFixtures(project(':server:sonar-db-dao'))

testFixturesApi 'org.assertj:assertj-core'

+ 4
- 3
server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/ComputationStepExecutorTest.java View File

@@ -24,7 +24,8 @@ import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.InOrder;
import org.sonar.api.utils.log.LogTester;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.CeTaskInterrupter;
import org.sonar.ce.task.ChangeLogLevel;
@@ -96,7 +97,7 @@ public class ComputationStepExecutorTest {
ChangeLogLevel logLevel3 = new ChangeLogLevel(step3.getClass(), LoggerLevel.INFO)) {
new ComputationStepExecutor(mockComputationSteps(step1, step2, step3), taskInterrupter).execute();

List<String> infoLogs = logTester.logs(LoggerLevel.INFO);
List<String> infoLogs = logTester.logs(Level.INFO);
assertThat(infoLogs).hasSize(3);
assertThat(infoLogs.get(0)).contains("Step One | foo=100 | bar=20 | status=SUCCESS | time=");
assertThat(infoLogs.get(1)).contains("Step Two | foo=50 | baz=10 | status=SUCCESS | time=");
@@ -126,7 +127,7 @@ public class ComputationStepExecutorTest {
new ComputationStepExecutor(mockComputationSteps(step1, step2, step3), taskInterrupter).execute();
fail("a RuntimeException should have been thrown");
} catch (RuntimeException e) {
List<String> infoLogs = logTester.logs(LoggerLevel.INFO);
List<String> infoLogs = logTester.logs(Level.INFO);
assertThat(infoLogs).hasSize(3);
assertThat(infoLogs.get(0)).contains("Step One | foo=100 | bar=20 | status=SUCCESS | time=");
assertThat(infoLogs.get(1)).contains("Step Two | foo=50 | baz=10 | status=SUCCESS | time=");

+ 1
- 0
server/sonar-ce/build.gradle View File

@@ -33,6 +33,7 @@ dependencies {
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.slf4j:slf4j-api'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'

testImplementation testFixtures(project(':server:sonar-db-dao'))


+ 1
- 1
server/sonar-ce/src/it/java/org/sonar/ce/queue/NextPendingTaskPickerIT.java View File

@@ -30,7 +30,7 @@ import org.junit.Test;
import org.sonar.api.config.Configuration;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.core.config.ComputeEngineProperties;
import org.sonar.db.DbTester;
import org.sonar.db.ce.CeQueueDto;

+ 31
- 37
server/sonar-ce/src/it/java/org/sonar/ce/taskprocessor/CeWorkerImplIT.java View File

@@ -36,11 +36,12 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import org.slf4j.event.Level;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.testfixtures.log.LogAndArguments;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogAndArguments;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.queue.InternalCeQueue;
import org.sonar.ce.task.CeTask;
@@ -259,7 +260,7 @@ public class CeWorkerImplIT {

underTest.call();

List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
for (int i = 0; i < 2; i++) {
assertThat(logs.get(i)).contains("pullRequest=123");
@@ -275,7 +276,7 @@ public class CeWorkerImplIT {
underTest.call();

verifyWorkerUuid();
List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
for (int i = 0; i < 2; i++) {
assertThat(logs.get(i)).doesNotContain("submitter=");
@@ -292,14 +293,14 @@ public class CeWorkerImplIT {
underTest.call();

verifyWorkerUuid();
List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).doesNotContain("submitter=");
assertThat(logs.get(1)).doesNotContain("submitter=");
logs = logTester.logs(LoggerLevel.ERROR);
logs = logTester.logs(Level.ERROR);
assertThat(logs).hasSize(1);
assertThat(logs.iterator().next()).doesNotContain("submitter=");
assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
assertThat(logTester.logs(Level.DEBUG)).isEmpty();
}

@Test
@@ -311,12 +312,12 @@ public class CeWorkerImplIT {
underTest.call();

verifyWorkerUuid();
List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains(String.format("submitter=%s", userDto.getLogin()));
assertThat(logs.get(1)).contains(String.format("submitter=%s | status=SUCCESS | time=", userDto.getLogin()));
assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
assertThat(logTester.logs(Level.ERROR)).isEmpty();
assertThat(logTester.logs(Level.DEBUG)).isEmpty();
}

@Test
@@ -327,12 +328,12 @@ public class CeWorkerImplIT {
underTest.call();

verifyWorkerUuid();
List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains("submitter=UUID_USER");
assertThat(logs.get(1)).contains("submitter=UUID_USER | status=SUCCESS | time=");
assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
assertThat(logTester.logs(Level.ERROR)).isEmpty();
assertThat(logTester.logs(Level.DEBUG)).isEmpty();
}

@Test
@@ -346,11 +347,11 @@ public class CeWorkerImplIT {
underTest.call();

verifyWorkerUuid();
List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains(String.format("submitter=%s", userDto.getLogin()));
assertThat(logs.get(1)).contains(String.format("submitter=%s | status=FAILED | time=", userDto.getLogin()));
logs = logTester.logs(LoggerLevel.ERROR);
logs = logTester.logs(Level.ERROR);
assertThat(logs).hasSize(1);
assertThat(logs.get(0)).isEqualTo("Failed to execute task " + ceTask.getUuid());
}
@@ -365,12 +366,12 @@ public class CeWorkerImplIT {
underTest.call();

verifyWorkerUuid();
List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains(" | submitter=" + submitter.login());
assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=SUCCESS | time=", submitter.login()));
assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
assertThat(logTester.logs(Level.ERROR)).isEmpty();
assertThat(logTester.logs(Level.DEBUG)).isEmpty();
}

@Test
@@ -385,14 +386,14 @@ public class CeWorkerImplIT {
underTest.call();

verifyWorkerUuid();
List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains(" | submitter=" + submitter.login());
assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.login()));
logs = logTester.logs(LoggerLevel.ERROR);
logs = logTester.logs(Level.ERROR);
assertThat(logs).hasSize(1);
assertThat(logs.iterator().next()).isEqualTo("Failed to execute task " + ceTask.getUuid());
assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
assertThat(logTester.logs(Level.DEBUG)).isEmpty();
}

@Test
@@ -462,11 +463,11 @@ public class CeWorkerImplIT {

underTest.call();

List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains(" | submitter=" + submitter.login());
assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.login()));
logs = logTester.logs(LoggerLevel.ERROR);
logs = logTester.logs(Level.ERROR);
assertThat(logs).hasSize(1);
assertThat(logs.iterator().next()).isEqualTo("Failed to execute task " + ceTask.getUuid());
}
@@ -480,11 +481,11 @@ public class CeWorkerImplIT {

underTest.call();

List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(1)).contains(" | submitter=" + submitter.login());
assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.login()));
assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
assertThat(logTester.logs(Level.ERROR)).isEmpty();
}

@Test
@@ -496,7 +497,7 @@ public class CeWorkerImplIT {

underTest.call();

assertThat(logTester.logs(LoggerLevel.ERROR)).containsOnly("Failed to finalize task with uuid '" + ceTask.getUuid() + "' and persist its state to db");
assertThat(logTester.logs(Level.ERROR)).containsOnly("Failed to finalize task with uuid '" + ceTask.getUuid() + "' and persist its state to db");
}

@Test
@@ -510,22 +511,18 @@ public class CeWorkerImplIT {

underTest.call();

List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains(" | submitter=" + submitter.login());
assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.login()));
List<LogAndArguments> logAndArguments = logTester.getLogs(LoggerLevel.ERROR);
List<LogAndArguments> logAndArguments = logTester.getLogs(Level.ERROR);
assertThat(logAndArguments).hasSize(2);

LogAndArguments executionErrorLog = logAndArguments.get(0);
assertThat(executionErrorLog.getFormattedMsg()).isEqualTo("Failed to execute task " + ceTask.getUuid());
assertThat(executionErrorLog.getArgs().get()).containsOnly(ceTask.getUuid(), ex);

LogAndArguments finalizingErrorLog = logAndArguments.get(1);
assertThat(finalizingErrorLog.getFormattedMsg()).isEqualTo("Failed to finalize task with uuid '" + ceTask.getUuid() + "' and persist its state to db");
Object arg1 = finalizingErrorLog.getArgs().get()[0];
assertThat(arg1).isSameAs(runtimeException);
assertThat(((Exception) arg1).getSuppressed()).containsOnly(ex);
}

@Test
@@ -539,16 +536,13 @@ public class CeWorkerImplIT {

underTest.call();

List<String> logs = logTester.logs(LoggerLevel.INFO);
List<String> logs = logTester.logs(Level.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains(" | submitter=" + submitter.login());
assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.login()));
List<LogAndArguments> logAndArguments = logTester.getLogs(LoggerLevel.ERROR);
List<LogAndArguments> logAndArguments = logTester.getLogs(Level.ERROR);
assertThat(logAndArguments).hasSize(1);
assertThat(logAndArguments.get(0).getFormattedMsg()).isEqualTo("Failed to finalize task with uuid '" + ceTask.getUuid() + "' and persist its state to db");
Object arg1 = logAndArguments.get(0).getArgs().get()[0];
assertThat(arg1).isSameAs(runtimeException);
assertThat(((Exception) arg1).getSuppressed()).containsOnly(ex);
}

@Test

+ 3
- 3
server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeWorkerCountSettingWarningTest.java View File

@@ -21,9 +21,9 @@ package org.sonar.ce.configuration;

import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;

import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
@@ -64,7 +64,7 @@ public class CeWorkerCountSettingWarningTest {

private void verifyWarnMessage() {
assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Property sonar.ce.workerCount is not supported anymore and will be ignored." +
assertThat(logTester.logs(Level.WARN)).containsOnly("Property sonar.ce.workerCount is not supported anymore and will be ignored." +
" Remove it from sonar.properties to remove this warning.");
}
}

+ 3
- 3
server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeWorkerControllerImplTest.java View File

@@ -22,8 +22,8 @@ package org.sonar.ce.taskprocessor;
import java.util.Random;
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.sonar.ce.configuration.CeConfigurationRule;

import static org.assertj.core.api.Assertions.assertThat;
@@ -166,7 +166,7 @@ public class CeWorkerControllerImplTest {

private void verifyInfoLog(int workerCount) {
assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.INFO))
assertThat(logTester.logs(Level.INFO))
.containsOnly("Compute Engine will use " + workerCount + " concurrent workers to process tasks");
}
}

+ 3
- 3
server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/TimeoutCeTaskInterrupterTest.java View File

@@ -23,9 +23,9 @@ import java.util.Optional;
import java.util.Random;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.CeTask;
import org.sonar.ce.task.CeTaskCanceledException;
import org.sonar.ce.task.CeTaskTimeoutException;
@@ -71,7 +71,7 @@ public class TimeoutCeTaskInterrupterTest {
new TimeoutCeTaskInterrupter(timeout, ceWorkerController, system2);

assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.INFO))
assertThat(logTester.logs(Level.INFO))
.containsExactly("Compute Engine Task timeout enabled: " + timeout + " ms");
}


+ 1
- 0
server/sonar-db-core/build.gradle View File

@@ -28,6 +28,7 @@ dependencies {
testImplementation 'com.tngtech.java:junit-dataprovider'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.postgresql:postgresql'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'

testImplementation project(':sonar-testing-harness')


+ 4
- 4
server/sonar-db-core/src/it/java/org/sonar/db/DatabaseUtilsIT.java View File

@@ -36,8 +36,8 @@ import java.util.function.Function;
import javax.annotation.Nullable;
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.sonar.api.utils.log.Loggers;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.dialect.Oracle;
@@ -253,7 +253,7 @@ public class DatabaseUtilsIT {

getDriver(connection);

assertThat(logTester.logs(LoggerLevel.WARN)).contains("Fail to determine database driver.");
assertThat(logTester.logs(Level.WARN)).contains("Fail to determine database driver.");
}

@Test
@@ -394,7 +394,7 @@ public class DatabaseUtilsIT {

log(Loggers.get(getClass()), root);

assertThat(logTester.logs(LoggerLevel.ERROR)).contains("SQL error: 456. Message: this is next");
assertThat(logTester.logs(Level.ERROR)).contains("SQL error: 456. Message: this is next");
}

@Test

+ 1
- 1
server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java View File

@@ -28,7 +28,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.db.dialect.PostgreSql;
import org.sonar.process.logging.LogbackHelper;


+ 3
- 3
server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java View File

@@ -22,8 +22,8 @@ package org.sonar.db.dialect;
import java.sql.DatabaseMetaData;
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 static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -73,7 +73,7 @@ public class H2Test {
public void init_logs_warning() {
underTest.init(mock(DatabaseMetaData.class));

assertThat(logs.logs(LoggerLevel.WARN)).contains("H2 database should be used for evaluation purpose only.");
assertThat(logs.logs(Level.WARN)).contains("H2 database should be used for evaluation purpose only.");
}

@Test

+ 4
- 4
server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java View File

@@ -24,9 +24,9 @@ import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -95,7 +95,7 @@ public class PostgreSqlTest {
underTest.init(metadata);

assertThat(underTest.supportsUpsert()).isFalse();
assertThat(logs.logs(LoggerLevel.WARN)).contains("Upgrading PostgreSQL to 9.5 or greater is recommended for better performances");
assertThat(logs.logs(Level.WARN)).contains("Upgrading PostgreSQL to 9.5 or greater is recommended for better performances");
}

@Test
@@ -104,7 +104,7 @@ public class PostgreSqlTest {
underTest.init(metadata);

assertThat(underTest.supportsUpsert()).isTrue();
assertThat(logs.logs(LoggerLevel.WARN)).isEmpty();
assertThat(logs.logs(Level.WARN)).isEmpty();
}

@Test

+ 8
- 7
server/sonar-db-core/src/test/java/org/sonar/db/profiling/ProfiledDataSourceTest.java View File

@@ -34,7 +34,8 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;

import static java.nio.charset.StandardCharsets.UTF_8;
@@ -70,8 +71,8 @@ public class ProfiledDataSourceTest {
assertThat(statementProxy.getConnection()).isNull();
assertThat(statementProxy.execute(sql)).isTrue();

assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
assertThat(logTester.logs(LoggerLevel.TRACE).get(0))
assertThat(logTester.logs(Level.TRACE)).hasSize(1);
assertThat(logTester.logs(Level.TRACE).get(0))
.contains("sql=select from dual");
}

@@ -106,8 +107,8 @@ public class ProfiledDataSourceTest {
assertThat(preparedStatementProxy.getConnection()).isNull();
assertThat(preparedStatementProxy.execute()).isTrue();

assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
assertThat(logTester.logs(LoggerLevel.TRACE).get(0))
assertThat(logTester.logs(Level.TRACE)).hasSize(1);
assertThat(logTester.logs(Level.TRACE).get(0))
.contains("sql=insert into polop (col1, col2, col3, col4) values (?, ?, ?, ?, ?)")
.contains("params=42, plouf");
}
@@ -132,8 +133,8 @@ public class ProfiledDataSourceTest {
assertThat(preparedStatementProxy.getConnection()).isNull();
assertThat(preparedStatementProxy.execute()).isTrue();

assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
assertThat(logTester.logs(LoggerLevel.TRACE).get(0))
assertThat(logTester.logs(Level.TRACE)).hasSize(1);
assertThat(logTester.logs(Level.TRACE).get(0))
.contains("sql=select from dual")
.doesNotContain("params=");
}

+ 1
- 0
server/sonar-db-dao/build.gradle View File

@@ -28,6 +28,7 @@ dependencies {
testImplementation 'org.assertj:assertj-guava'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.sonarsource.orchestrator:sonar-orchestrator'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation project(':sonar-testing-harness')
testImplementation project(':sonar-plugin-api-impl')


+ 3
- 3
server/sonar-db-dao/src/test/java/org/sonar/db/DBSessionsImplTest.java View File

@@ -37,8 +37,8 @@ import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
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.sonar.core.util.stream.MoreCollectors;

import static java.lang.Math.abs;
@@ -484,7 +484,7 @@ public class DBSessionsImplTest {

underTest.disableCaching();

List<String> errorLogs = logTester.logs(LoggerLevel.ERROR);
List<String> errorLogs = logTester.logs(Level.ERROR);
assertThat(errorLogs)
.hasSize(1)
.containsOnly("Failed to close " + (batchOrRegular ? "batch" : "regular") + " connection in " + Thread.currentThread());

+ 1
- 0
server/sonar-db-migration/build.gradle View File

@@ -28,6 +28,7 @@ dependencies {
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.xmlunit:xmlunit-core'
testImplementation 'org.xmlunit:xmlunit-matchers'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation project(':sonar-scanner-protocol')
testImplementation project(':sonar-testing-harness')
testImplementation testFixtures(project(':server:sonar-db-core'))

+ 9
- 9
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java View File

@@ -27,8 +27,8 @@ import java.util.Iterator;
import java.util.List;
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.sonar.core.platform.SpringComponentContainer;
import org.sonar.server.platform.db.migration.engine.MigrationContainer;
import org.sonar.server.platform.db.migration.engine.SimpleMigrationContainer;
@@ -53,7 +53,7 @@ public class MigrationStepsExecutorImplTest {
underTest.execute(Collections.emptyList());

assertThat(logTester.logs()).hasSize(2);
assertLogLevel(LoggerLevel.INFO, "Executing DB migrations...", "Executed DB migrations: success | time=");
assertLogLevel(Level.INFO, "Executing DB migrations...", "Executed DB migrations: success | time=");
}

@Test
@@ -68,12 +68,12 @@ public class MigrationStepsExecutorImplTest {
assertThat(e).hasMessage("Unable to load component " + MigrationStep1.class);
} finally {
assertThat(logTester.logs()).hasSize(2);
assertLogLevel(LoggerLevel.INFO, "Executing DB migrations...");
assertLogLevel(LoggerLevel.ERROR, "Executed DB migrations: failure | time=");
assertLogLevel(Level.INFO, "Executing DB migrations...");
assertLogLevel(Level.ERROR, "Executed DB migrations: failure | time=");
}
}

private void assertLogLevel(LoggerLevel level, String... expected) {
private void assertLogLevel(Level level, String... expected) {
List<String> logs = logTester.logs(level);
assertThat(logs).hasSize(expected.length);
Iterator<String> iterator = logs.iterator();
@@ -99,7 +99,7 @@ public class MigrationStepsExecutorImplTest {
assertThat(SingleCallCheckerMigrationStep.calledSteps)
.containsExactly(MigrationStep2.class, MigrationStep1.class, MigrationStep3.class);
assertThat(logTester.logs()).hasSize(8);
assertLogLevel(LoggerLevel.INFO,
assertLogLevel(Level.INFO,
"Executing DB migrations...",
"#1 '1-MigrationStep2'...",
"#1 '1-MigrationStep2': success | time=",
@@ -131,12 +131,12 @@ public class MigrationStepsExecutorImplTest {
assertThat(e).hasCause(SqlExceptionFailingMigrationStep.THROWN_EXCEPTION);
} finally {
assertThat(logTester.logs()).hasSize(6);
assertLogLevel(LoggerLevel.INFO,
assertLogLevel(Level.INFO,
"Executing DB migrations...",
"#1 '1-MigrationStep2'...",
"#1 '1-MigrationStep2': success | time=",
"#2 '2-SqlExceptionFailingMigrationStep'...");
assertLogLevel(LoggerLevel.ERROR,
assertLogLevel(Level.ERROR,
"#2 '2-SqlExceptionFailingMigrationStep': failure | time=",
"Executed DB migrations: failure | time=");
}

+ 5
- 5
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest.java View File

@@ -23,8 +23,8 @@ import java.sql.SQLException;
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.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DataChange;

@@ -57,7 +57,7 @@ public class LogMessageIfSonarScimEnabledPresentPropertyTest {

underTest.execute();

assertThat(logger.logs(LoggerLevel.WARN))
assertThat(logger.logs(Level.WARN))
.hasSize(1)
.containsExactly("'" + SONAR_SCIM_ENABLED + "' property is defined but not read anymore. Please read the upgrade notes" +
" for the instruction to upgrade. User provisioning is deactivated until reactivated from the SonarQube" +
@@ -70,7 +70,7 @@ public class LogMessageIfSonarScimEnabledPresentPropertyTest {

underTest.execute();

assertThat(logger.logs(LoggerLevel.WARN)).isEmpty();
assertThat(logger.logs(Level.WARN)).isEmpty();
}

@Test
@@ -86,6 +86,6 @@ public class LogMessageIfSonarScimEnabledPresentPropertyTest {
underTest.execute();
underTest.execute();

assertThat(logger.logs(LoggerLevel.WARN)).hasSize(2);
assertThat(logger.logs(Level.WARN)).hasSize(2);
}
}

+ 1
- 1
server/sonar-server-common/build.gradle View File

@@ -38,6 +38,7 @@ dependencies {
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.hamcrest:hamcrest-core'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation testFixtures(project(':server:sonar-db-dao'))
testImplementation project(':sonar-plugin-api-impl')
testImplementation project(':sonar-testing-harness')
@@ -47,7 +48,6 @@ dependencies {

testFixturesCompileOnly 'com.google.code.findbugs:jsr305'
testFixturesImplementation 'org.elasticsearch.plugin:transport-netty4-client'

testFixturesImplementation 'org.codelibs.elasticsearch.module:analysis-common'
testFixturesImplementation 'org.codelibs.elasticsearch.module:reindex'
testFixturesImplementation 'org.elasticsearch:mocksocket'

+ 3
- 2
server/sonar-server-common/src/it/java/org/sonar/server/es/BulkIndexerIT.java View File

@@ -33,8 +33,9 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.db.DbTester;
import org.sonar.server.es.BulkIndexer.Size;
@@ -175,7 +176,7 @@ public class BulkIndexerIT {
indexer.add(newIndexRequestWithDocId("bar"));
indexer.stop();

assertThat(logTester.logs(LoggerLevel.TRACE)
assertThat(logTester.logs(Level.TRACE)
.stream()
.filter(log -> log.contains("Bulk[2 index requests on fakes/_doc, 1 delete requests on fakes/_doc]"))
.count()).isNotZero();

+ 3
- 3
server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java View File

@@ -31,9 +31,9 @@ import org.assertj.core.api.Assertions;
import org.elasticsearch.search.SearchHit;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
@@ -361,7 +361,7 @@ public class IssueIndexerIT {

recover();

assertThat(logTester.logs(LoggerLevel.ERROR))
assertThat(logTester.logs(Level.ERROR))
.filteredOn(l -> l.contains("Unsupported es_queue.doc_id_type for issues. Manual fix is required: "))
.hasSize(1);
assertThatEsQueueTableHasSize(1);

+ 5
- 5
server/sonar-server-common/src/it/java/org/sonar/server/rule/index/RuleIndexerIT.java View File

@@ -31,11 +31,11 @@ import java.util.stream.Stream;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.event.Level;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.core.util.UuidFactoryFast;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
@@ -174,6 +174,7 @@ public class RuleIndexerIT {
@Test
@UseDataProvider("twoDifferentCategoriesButOTHERS")
public void log_debug_if_hotspot_rule_maps_to_multiple_SQCategories(SQCategory sqCategory1, SQCategory sqCategory2) {
logTester.setLevel(Level.DEBUG);
Set<String> standards = Stream.of(sqCategory1, sqCategory2)
.flatMap(t -> CWES_BY_SQ_CATEGORY.get(t).stream().map(e -> "cwe:" + e))
.collect(toSet());
@@ -183,9 +184,8 @@ public class RuleIndexerIT {
.setSecurityStandards(standards));
underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());

assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.DEBUG).get(0))
.isEqualTo(format(
assertThat(logTester.logs(Level.DEBUG))
.contains(format(
"Rule %s with CWEs '%s' maps to multiple SQ Security Categories: %s",
rule.getKey(),
String.join(", ", securityStandards.getCwe()),

+ 17
- 4
server/sonar-server-common/src/it/java/org/sonar/server/webhook/SynchronousWebHooksImplIT.java View File

@@ -21,10 +21,12 @@ package org.sonar.server.webhook;

import java.io.IOException;
import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.ce.posttask.PostProjectAnalysisTask;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
@@ -40,7 +42,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.sonar.api.utils.log.LoggerLevel.DEBUG;
import static org.slf4j.event.Level.DEBUG;
import static org.sonar.db.DbTester.create;
import static org.sonar.db.webhook.WebhookTesting.newGlobalWebhook;
import static org.sonar.db.webhook.WebhookTesting.newWebhook;
@@ -65,6 +67,11 @@ public class SynchronousWebHooksImplIT {
private final PostProjectAnalysisTask.LogStatistics taskStatistics = mock(PostProjectAnalysisTask.LogStatistics.class);
private final WebHooksImpl underTest = new WebHooksImpl(caller, deliveryStorage, synchronousAsyncExecution, dbClient);

@Before
public void before() {
logTester.setLevel(Level.DEBUG);
}

@Test
public void isEnabled_returns_false_if_no_webhooks() {
ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
@@ -94,7 +101,7 @@ public class SynchronousWebHooksImplIT {
underTest.sendProjectAnalysisUpdate(new WebHooks.Analysis(componentDto.uuid(), "1", "#1"), () -> mock);

assertThat(caller.countSent()).isZero();
assertThat(logTester.logs(DEBUG)).isEmpty();
assertNoWebhookLogs();
verifyNoInteractions(deliveryStorage);
}

@@ -105,7 +112,7 @@ public class SynchronousWebHooksImplIT {
underTest.sendProjectAnalysisUpdate(new WebHooks.Analysis(componentDto.uuid(), "1", "#1"), () -> mock, taskStatistics);

assertThat(caller.countSent()).isZero();
assertThat(logTester.logs(DEBUG)).isEmpty();
assertNoWebhookLogs();
verifyNoInteractions(deliveryStorage);
verifyLogStatistics(0, 0);
}
@@ -128,6 +135,12 @@ public class SynchronousWebHooksImplIT {
verifyLogStatistics(2, 0);
}

private void assertNoWebhookLogs() {
assertThat(logTester.logs(DEBUG))
.noneMatch(s -> s.contains("Sent webhook"))
.noneMatch(s -> s.contains("Failed to send webhook"));
}

@Test
public void send_project_webhooks() {
ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();

+ 3
- 3
server/sonar-server-common/src/test/java/org/sonar/server/async/AsyncExecutionImplTest.java View File

@@ -21,8 +21,8 @@ package org.sonar.server.async;

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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -47,7 +47,7 @@ public class AsyncExecutionImplTest {
});

assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.ERROR)).containsOnly("Asynchronous task failed");
assertThat(logTester.logs(Level.ERROR)).containsOnly("Asynchronous task failed");
}

@Test

+ 5
- 5
server/sonar-server-common/src/test/java/org/sonar/server/es/EsClientProviderTest.java View File

@@ -26,9 +26,9 @@ import org.elasticsearch.client.RestHighLevelClient;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;

import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
@@ -71,7 +71,7 @@ public class EsClientProviderTest {
assertThat(node.getHost().getAddress().getHostName()).isEqualTo(localhostHostname);
assertThat(node.getHost().getPort()).isEqualTo(9000);

assertThat(logTester.logs(LoggerLevel.INFO)).has(new Condition<>(s -> s.contains("Connected to local Elasticsearch: [http://" + localhostHostname + ":9000]"), ""));
assertThat(logTester.logs(Level.INFO)).has(new Condition<>(s -> s.contains("Connected to local Elasticsearch: [http://" + localhostHostname + ":9000]"), ""));
}

@Test
@@ -92,7 +92,7 @@ public class EsClientProviderTest {
assertThat(node.getHost().getAddress().getHostName()).isEqualTo(localhostHostname);
assertThat(node.getHost().getPort()).isEqualTo(8081);

assertThat(logTester.logs(LoggerLevel.INFO))
assertThat(logTester.logs(Level.INFO))
.has(new Condition<>(s -> s.contains("Connected to remote Elasticsearch: [http://" + localhostHostname + ":8080, http://" + localhostHostname + ":8081]"), ""));
}

@@ -137,7 +137,7 @@ public class EsClientProviderTest {
assertThat(node.getHost().getAddress().getHostName()).isEqualTo(localhostHostname);
assertThat(node.getHost().getPort()).isEqualTo(8081);

assertThat(logTester.logs(LoggerLevel.INFO))
assertThat(logTester.logs(Level.INFO))
.has(new Condition<>(s -> s.contains("Connected to remote Elasticsearch: [http://" + localhostHostname + ":9001, http://" + localhostHostname + ":8081]"), ""));
}
}

+ 1
- 1
server/sonar-server-common/src/test/java/org/sonar/server/log/ServerLoggingTest.java View File

@@ -31,7 +31,7 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.db.Database;
import org.sonar.process.logging.LogLevelConfig;

+ 1
- 1
server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerFileSystemImplTest.java View File

@@ -29,7 +29,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.config.Configuration;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;

import static org.assertj.core.api.Assertions.assertThat;


+ 5
- 5
server/sonar-server-common/src/test/java/org/sonar/server/plugins/PluginRequirementsValidatorTest.java View File

@@ -23,8 +23,8 @@ import java.util.HashMap;
import java.util.Map;
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.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginInfo.RequiredPlugin;
import org.sonar.updatecenter.common.Version;
@@ -73,7 +73,7 @@ public class PluginRequirementsValidatorTest {

assertThat(underTest.isCompatible(pluginWithoutBase)).isFalse();
assertThat(underTest.isCompatible(pluginWithBase)).isTrue();
assertThat(logTester.logs(LoggerLevel.WARN))
assertThat(logTester.logs(Level.WARN))
.contains("Plugin plugin-without-base-plugin [plugin-without-base-plugin] is ignored"
+ " because its base plugin [not-existing-base-plugin] is not installed");
}
@@ -96,7 +96,7 @@ public class PluginRequirementsValidatorTest {

assertThat(underTest.isCompatible(pluginWithoutRequired)).isFalse();
assertThat(underTest.isCompatible(pluginWithRequired)).isTrue();
assertThat(logTester.logs(LoggerLevel.WARN))
assertThat(logTester.logs(Level.WARN))
.contains("Plugin plugin-without-required-plugin [plugin-without-required-plugin] is ignored"
+ " because the required plugin [notexistingrequired] is not installed");
}
@@ -119,7 +119,7 @@ public class PluginRequirementsValidatorTest {

assertThat(underTest.isCompatible(pluginWithoutRequired)).isFalse();
assertThat(underTest.isCompatible(pluginWithRequired)).isTrue();
assertThat(logTester.logs(LoggerLevel.WARN))
assertThat(logTester.logs(Level.WARN))
.contains("Plugin plugin-without-required-plugin [plugin-without-required-plugin] is ignored"
+ " because the version 1.5 of required plugin [required] is not installed");
}

+ 1
- 0
server/sonar-webserver-api/build.gradle View File

@@ -35,6 +35,7 @@ dependencies {
testImplementation 'com.tngtech.java:junit-dataprovider'
testImplementation 'javax.servlet:javax.servlet-api'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation testFixtures(project(':server:sonar-server-common'))
testImplementation project(':sonar-testing-harness')


+ 3
- 3
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginConsentVerifierTest.java View File

@@ -21,9 +21,9 @@ package org.sonar.server.plugins;

import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.core.extension.PluginRiskConsent;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
@@ -68,7 +68,7 @@ public class PluginConsentVerifierTest {

underTest.start();

assertThat(logTester.logs(LoggerLevel.WARN)).contains("Plugin(s) detected. Plugins are not provided by SonarSource"
assertThat(logTester.logs(Level.WARN)).contains("Plugin(s) detected. Plugins are not provided by SonarSource"
+ " and are therefore installed at your own risk. A SonarQube administrator needs to acknowledge this risk once logged in.");
assertThat(dbClient.propertiesDao().selectGlobalProperty(PLUGINS_RISK_CONSENT))
.extracting(PropertyDto::getValue)

+ 1
- 1
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java View File

@@ -37,7 +37,7 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.SonarRuntime;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.core.platform.PluginInfo;
import org.sonar.server.platform.ServerFileSystem;
import org.sonar.updatecenter.common.PluginManifest;

+ 1
- 1
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginUninstallerTest.java View File

@@ -30,7 +30,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.Plugin;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.plugin.PluginType;
import org.sonar.server.platform.ServerFileSystem;

+ 1
- 2
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java View File

@@ -25,13 +25,12 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.Plugin;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.core.platform.ExplodedPlugin;
import org.sonar.core.platform.PluginClassLoader;
import org.sonar.core.platform.PluginJarExploder;

+ 11
- 5
server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventListenersImplTest.java View File

@@ -32,15 +32,16 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang.RandomStringUtils;
import org.assertj.core.groups.Tuple;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mockito;
import org.slf4j.event.Level;
import org.sonar.api.issue.Issue;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.db.component.BranchDto;
import org.sonar.server.qualitygate.changeevent.QGChangeEventListener.ChangedIssue;
@@ -79,6 +80,11 @@ public class QGChangeEventListenersImplTest {

private final QGChangeEventListenersImpl underTest = new QGChangeEventListenersImpl(new LinkedHashSet<>(List.of(listener1, listener2, listener3)));

@Before
public void before() {
logTester.setLevel(Level.TRACE);
}

@Test
public void broadcastOnIssueChange_has_no_effect_when_issues_are_empty() {
underTest.broadcastOnIssueChange(emptyList(), singletonList(component1QGChangeEvent), false);
@@ -120,7 +126,7 @@ public class QGChangeEventListenersImplTest {
inOrder.verify(listener3).onIssueChanges(same(component1QGChangeEvent), same(changedIssues));
inOrder.verifyNoMoreInteractions();
assertThat(logTester.logs()).hasSize(4);
assertThat(logTester.logs(LoggerLevel.WARN)).hasSize(1);
assertThat(logTester.logs(Level.WARN)).hasSize(1);
}

@Test
@@ -137,7 +143,7 @@ public class QGChangeEventListenersImplTest {
inOrder.verify(listener2).onIssueChanges(same(component1QGChangeEvent), same(changedIssues));
inOrder.verifyNoMoreInteractions();
assertThat(logTester.logs()).hasSize(3);
assertThat(logTester.logs(LoggerLevel.WARN)).hasSize(1);
assertThat(logTester.logs(Level.WARN)).hasSize(1);
}

@Test
@@ -145,7 +151,7 @@ public class QGChangeEventListenersImplTest {
underTest.broadcastOnIssueChange(oneIssueOnComponent1, singletonList(component1QGChangeEvent), false);

assertThat(logTester.logs()).hasSize(3);
List<String> traceLogs = logTester.logs(LoggerLevel.TRACE);
List<String> traceLogs = logTester.logs(Level.TRACE);
assertThat(traceLogs).hasSize(3)
.containsOnly(
"calling onChange() on listener " + listener1.getClass().getName() + " for events " + component1QGChangeEvent + "...",

+ 1
- 0
server/sonar-webserver-auth/build.gradle View File

@@ -29,6 +29,7 @@ dependencies {
testImplementation 'org.apache.logging.log4j:log4j-core'
testImplementation 'org.assertj:assertj-guava'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation testFixtures(project(':server:sonar-server-common'))
testImplementation project(':sonar-testing-harness')


+ 3
- 3
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/DefaultAdminCredentialsVerifierImplTest.java View File

@@ -21,10 +21,10 @@ package org.sonar.server.authentication;

import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.notifications.Notification;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.db.DbTester;
import org.sonar.db.user.UserDto;
import org.sonar.server.notification.NotificationManager;
@@ -74,7 +74,7 @@ public class DefaultAdminCredentialsVerifierImplTest {
underTest.runAtStart();

assertThat(db.users().selectUserByLogin(admin.getLogin()).get().isResetPassword()).isTrue();
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Default Administrator credentials are still being used. Make sure to change the password or deactivate the account.");
assertThat(logTester.logs(Level.WARN)).contains("Default Administrator credentials are still being used. Make sure to change the password or deactivate the account.");
assertThat(db.getDbClient().internalPropertiesDao().selectByKey(db.getSession(), DEFAULT_ADMIN_CREDENTIAL_USAGE_EMAIL)).contains("true");
verify(notificationManager).scheduleForSending(any(Notification.class));
}

+ 2
- 2
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/GithubWebhookAuthenticationTest.java View File

@@ -30,8 +30,8 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.sonar.api.config.internal.Encryption;
import org.sonar.api.config.internal.Settings;
import org.sonar.api.utils.log.LogAndArguments;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogAndArguments;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDto;

+ 6
- 6
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java View File

@@ -27,13 +27,13 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.slf4j.event.Level;
import org.sonar.api.server.authentication.BaseIdentityProvider;
import org.sonar.api.server.authentication.Display;
import org.sonar.api.server.authentication.IdentityProvider;
import org.sonar.api.server.authentication.OAuth2IdentityProvider;
import org.sonar.api.server.authentication.UnauthorizedException;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.server.authentication.event.AuthenticationEvent;
import org.sonar.server.authentication.event.AuthenticationException;

@@ -227,7 +227,7 @@ public class InitFilterTest {
underTest.doFilter(request, response, chain);

verify(response).sendRedirect("/sessions/unauthorized");
assertThat(logTester.logs(LoggerLevel.WARN)).containsExactlyInAnyOrder("Fail to initialize authentication with provider 'failing'");
assertThat(logTester.logs(Level.WARN)).containsExactlyInAnyOrder("Fail to initialize authentication with provider 'failing'");
verifyDeleteAuthCookie();
}

@@ -244,17 +244,17 @@ public class InitFilterTest {
}

private void assertOAuth2InitCalled() {
assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
assertThat(logTester.logs(Level.ERROR)).isEmpty();
assertThat(oAuth2IdentityProvider.isInitCalled()).isTrue();
}

private void assertBasicInitCalled() {
assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
assertThat(logTester.logs(Level.ERROR)).isEmpty();
assertThat(baseIdentityProvider.isInitCalled()).isTrue();
}

private void assertError(String expectedError) throws Exception {
assertThat(logTester.logs(LoggerLevel.WARN)).contains(expectedError);
assertThat(logTester.logs(Level.WARN)).contains(expectedError);
verify(response).sendRedirect("/sessions/unauthorized");
assertThat(oAuth2IdentityProvider.isInitCalled()).isFalse();
}

+ 5
- 5
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/LogOAuthWarningTest.java View File

@@ -21,10 +21,10 @@ package org.sonar.server.authentication;

import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.platform.Server;
import org.sonar.api.server.authentication.OAuth2IdentityProvider;
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.mockito.Mockito.mock;
@@ -47,7 +47,7 @@ public class LogOAuthWarningTest {

underTest.start();

assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("For security reasons, OAuth authentication should use HTTPS. You should set the property 'Administration > Configuration > Server base URL' to a HTTPS URL.");
assertThat(logTester.logs(Level.WARN)).containsOnly("For security reasons, OAuth authentication should use HTTPS. You should set the property 'Administration > Configuration > Server base URL' to a HTTPS URL.");

underTest.stop();
}
@@ -60,7 +60,7 @@ public class LogOAuthWarningTest {

underTest.start();

assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
assertThat(logTester.logs(Level.WARN)).isEmpty();

underTest.stop();
}
@@ -73,7 +73,7 @@ public class LogOAuthWarningTest {

underTest.start();

assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
assertThat(logTester.logs(Level.WARN)).isEmpty();

underTest.stop();
}

+ 5
- 5
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2CallbackFilterTest.java View File

@@ -27,11 +27,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.slf4j.event.Level;
import org.sonar.api.server.authentication.OAuth2IdentityProvider;
import org.sonar.api.server.authentication.UnauthorizedException;
import org.sonar.api.server.authentication.UserIdentity;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.server.authentication.event.AuthenticationEvent;
import org.sonar.server.authentication.event.AuthenticationException;
import org.sonar.server.user.ThreadLocalUserSession;
@@ -199,7 +199,7 @@ public class OAuth2CallbackFilterTest {
underTest.doFilter(request, response, chain);

verify(response).sendRedirect("/sessions/unauthorized");
assertThat(logTester.logs(LoggerLevel.WARN)).containsExactlyInAnyOrder("Fail to callback authentication with 'failing'");
assertThat(logTester.logs(Level.WARN)).containsExactlyInAnyOrder("Fail to callback authentication with 'failing'");
verify(oAuthRedirection).delete(request, response);
}

@@ -226,12 +226,12 @@ public class OAuth2CallbackFilterTest {
}

private void assertCallbackCalled(FakeOAuth2IdentityProvider oAuth2IdentityProvider) {
assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
assertThat(logTester.logs(Level.ERROR)).isEmpty();
assertThat(oAuth2IdentityProvider.isCallbackCalled()).isTrue();
}

private void assertError(String expectedError) throws Exception {
assertThat(logTester.logs(LoggerLevel.WARN)).contains(expectedError);
assertThat(logTester.logs(Level.WARN)).contains(expectedError);
verify(response).sendRedirect("/sessions/unauthorized");
assertThat(oAuth2IdentityProvider.isInitCalled()).isFalse();
}

+ 1
- 1
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java View File

@@ -30,7 +30,7 @@ import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
import org.sonar.api.server.authentication.IdentityProvider;
import org.sonar.api.server.authentication.UserIdentity;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.db.DbTester;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.user.GroupDto;

+ 3
- 2
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/event/AuthenticationEventImplTest.java View File

@@ -28,7 +28,8 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;

import static java.util.Arrays.asList;
@@ -352,7 +353,7 @@ public class AuthenticationEventImplTest {

private void verifyLog(String expected) {
assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.DEBUG))
assertThat(logTester.logs(Level.DEBUG))
.containsOnly(expected);
}


+ 2
- 2
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/purge/ExpiredSessionsCleanerTest.java View File

@@ -26,8 +26,8 @@ import java.util.concurrent.TimeUnit;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.utils.log.LogAndArguments;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogAndArguments;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.db.DbTester;
import org.sonar.db.user.SamlMessageIdDto;

+ 5
- 5
server/sonar-webserver-auth/src/test/java/org/sonar/server/user/SystemPasscodeImplTest.java View File

@@ -26,10 +26,10 @@ import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.event.Level;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.impl.ws.SimpleGetRequest;
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;

@@ -52,14 +52,14 @@ public class SystemPasscodeImplTest {
configurePasscode("foo");
underTest.start();

assertThat(logTester.logs(LoggerLevel.INFO)).contains("System authentication by passcode is enabled");
assertThat(logTester.logs(Level.INFO)).contains("System authentication by passcode is enabled");
}

@Test
public void startup_logs_show_that_feature_is_disabled() {
underTest.start();

assertThat(logTester.logs(LoggerLevel.INFO)).contains("System authentication by passcode is disabled");
assertThat(logTester.logs(Level.INFO)).contains("System authentication by passcode is disabled");
}

@Test
@@ -67,7 +67,7 @@ public class SystemPasscodeImplTest {
configurePasscode("");
underTest.start();

assertThat(logTester.logs(LoggerLevel.INFO)).contains("System authentication by passcode is disabled");
assertThat(logTester.logs(Level.INFO)).contains("System authentication by passcode is disabled");
}

@DataProvider

+ 2
- 2
server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSchedulerImplTest.java View File

@@ -21,8 +21,8 @@ package org.sonar.server.usertoken.notification;

import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogAndArguments;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogAndArguments;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.server.util.GlobalLockManager;


+ 5
- 3
server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSenderTest.java View File

@@ -23,8 +23,9 @@ import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.api.utils.log.LogAndArguments;
import org.sonar.api.utils.log.LogTester;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogAndArguments;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.db.DbClient;
import org.sonar.db.user.UserDao;
@@ -49,9 +50,10 @@ public class TokenExpirationNotificationSenderTest {

@Test
public void no_notification_when_email_setting_is_not_set() {
logTester.setLevel(Level.DEBUG);
when(emailComposer.areEmailSettingsSet()).thenReturn(false);
underTest.sendNotifications();
assertThat(logTester.getLogs(LoggerLevel.DEBUG))
assertThat(logTester.getLogs(Level.DEBUG))
.extracting(LogAndArguments::getFormattedMsg)
.containsExactly("Emails for token expiration notification have not been sent because email settings are not configured.");
}

+ 1
- 0
server/sonar-webserver-core/build.gradle View File

@@ -69,6 +69,7 @@ dependencies {
testImplementation 'org.eclipse.jetty:jetty-servlet'
testImplementation 'org.hamcrest:hamcrest-all'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation 'org.subethamail:subethasmtp'
testImplementation testFixtures(project(':server:sonar-server-common'))
testImplementation testFixtures(project(':server:sonar-webserver-auth'))

+ 9
- 9
server/sonar-webserver-core/src/test/java/org/sonar/server/issue/index/AsyncIssueIndexingImplTest.java View File

@@ -30,9 +30,9 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.queue.CeQueue;
import org.sonar.ce.queue.CeTaskSubmit;
import org.sonar.core.util.SequenceUuidFactory;
@@ -98,7 +98,7 @@ public class AsyncIssueIndexingImplTest {
assertThat(branch.get().isNeedIssueSync()).isTrue();
verify(ceQueue, times(1)).prepareSubmit();
verify(ceQueue, times(1)).massSubmit(anyCollection());
assertThat(logTester.logs(LoggerLevel.INFO))
assertThat(logTester.logs(Level.INFO))
.contains("1 branch found in need of issue sync.");
}

@@ -120,7 +120,7 @@ public class AsyncIssueIndexingImplTest {
assertThat(branch.get().isNeedIssueSync()).isTrue();
verify(ceQueue, times(2)).prepareSubmit();
verify(ceQueue, times(1)).massSubmit(anyCollection());
assertThat(logTester.logs(LoggerLevel.INFO))
assertThat(logTester.logs(Level.INFO))
.contains("2 branch(es) found in need of issue sync for project.");
}

@@ -128,13 +128,13 @@ public class AsyncIssueIndexingImplTest {
public void triggerOnIndexCreation_no_branch() {
underTest.triggerOnIndexCreation();

assertThat(logTester.logs(LoggerLevel.INFO)).contains("0 branch found in need of issue sync.");
assertThat(logTester.logs(Level.INFO)).contains("0 branch found in need of issue sync.");
}

@Test
public void triggerForProject_no_branch() {
underTest.triggerForProject("some-random-uuid");
assertThat(logTester.logs(LoggerLevel.INFO)).contains("0 branch(es) found in need of issue sync for project.");
assertThat(logTester.logs(Level.INFO)).contains("0 branch(es) found in need of issue sync for project.");
}

@Test
@@ -157,7 +157,7 @@ public class AsyncIssueIndexingImplTest {
assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), REPORT)).hasSize(1);
assertThat(dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbTester.getSession(), new HashSet<>(List.of("uuid_2")))).isEmpty();

assertThat(logTester.logs(LoggerLevel.INFO))
assertThat(logTester.logs(Level.INFO))
.contains(
"1 pending indexation task found to be deleted...",
"1 completed indexation task found to be deleted...",
@@ -203,7 +203,7 @@ public class AsyncIssueIndexingImplTest {
.extracting(CeActivityDto::getMainComponentUuid)
.containsExactly(anotherProjectDto.getUuid());

assertThat(logTester.logs(LoggerLevel.INFO))
assertThat(logTester.logs(Level.INFO))
.contains(
"2 pending indexation task found to be deleted...",
"2 completed indexation task found to be deleted...",
@@ -251,7 +251,7 @@ public class AsyncIssueIndexingImplTest {
.extracting(p -> p.getComponent().get().getUuid())
.containsExactly("branch_uuid2", "branch_uuid1");

assertThat(logTester.logs(LoggerLevel.INFO))
assertThat(logTester.logs(Level.INFO))
.contains("2 projects found in need of issue sync.");
}


+ 3
- 4
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/DatabaseServerCompatibilityTest.java View File

@@ -22,10 +22,9 @@ package org.sonar.server.platform;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.internal.MapSettings;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.server.platform.db.migration.version.DatabaseVersion;

import static org.assertj.core.api.Assertions.assertThat;
@@ -68,7 +67,7 @@ public class DatabaseServerCompatibilityTest {
new DatabaseServerCompatibility(version).start();

assertThat(logTester.logs()).hasSize(4);
assertThat(logTester.logs(LoggerLevel.WARN)).contains(
assertThat(logTester.logs(Level.WARN)).contains(
"The database must be manually upgraded. Please backup the database and browse /setup. "
+ "For more information: https://docs.sonarqube.org/latest/setup/upgrading",
"################################################################################",

+ 6
- 5
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/CheckAnyonePermissionsAtStartupTest.java View File

@@ -24,9 +24,10 @@ import org.junit.After;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
@@ -165,7 +166,7 @@ public class CheckAnyonePermissionsAtStartupTest {
}

private void assertProjectLevelAnyonePermissionWarningNotInLogs() {
boolean noneMatch = logTester.logs(LoggerLevel.WARN).stream()
boolean noneMatch = logTester.logs(Level.WARN).stream()
.noneMatch(s -> s.startsWith("Authentication is not enforced, and project permissions assigned to the 'Anyone' group expose"));
assertThat(noneMatch).isTrue();
}
@@ -174,11 +175,11 @@ public class CheckAnyonePermissionsAtStartupTest {
String expected = String.format("Authentication is not enforced, and project permissions assigned to the 'Anyone' group expose %d " +
"public project(s) to security risks, including: %s. Unauthenticated visitors have permissions on these project(s).",
expectedProjectCount, String.join(", ", expectedListedProjects));
assertThat(logTester.logs(LoggerLevel.WARN)).contains(expected);
assertThat(logTester.logs(Level.WARN)).contains(expected);
}

private void assertGlobalLevelAnyonePermissionWarningNotInLogs() {
boolean noneMatch = !logTester.logs(LoggerLevel.WARN).contains(
boolean noneMatch = !logTester.logs(Level.WARN).contains(
"Authentication is not enforced, and permissions assigned to the 'Anyone' group globally expose the " +
"instance to security risks. Unauthenticated visitors may unintentionally have permissions on projects.");
assertThat(noneMatch).isTrue();
@@ -187,7 +188,7 @@ public class CheckAnyonePermissionsAtStartupTest {
private void assertGlobalLevelAnyonePermissionWarningInLogs() {
String expected = "Authentication is not enforced, and permissions assigned to the 'Anyone' group globally " +
"expose the instance to security risks. Unauthenticated visitors may unintentionally have permissions on projects.";
assertThat(logTester.logs(LoggerLevel.WARN)).contains(expected);
assertThat(logTester.logs(Level.WARN)).contains(expected);
}

}

+ 4
- 3
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/CheckLanguageSpecificParamsAtStartupTest.java View File

@@ -23,11 +23,12 @@ import org.junit.After;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.event.Level;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.db.DbTester;

@@ -64,7 +65,7 @@ public class CheckLanguageSpecificParamsAtStartupTest {
settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "1" + "." + CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_SIZE_METRIC_KEY, CoreMetrics.COMPLEXITY_KEY);

underTest.start();
assertThat(logTester.logs(LoggerLevel.WARN))
assertThat(logTester.logs(Level.WARN))
.contains("The development cost used for calculating the technical debt is currently configured with 2 language specific parameters [Key: languageSpecificParameters]. " +
"Please be aware that this functionality is deprecated, and will be removed in a future version.");
}
@@ -72,7 +73,7 @@ public class CheckLanguageSpecificParamsAtStartupTest {
@Test
public void log_does_not_show_when_language_specific_params_used() {
underTest.start();
boolean noneMatch = logTester.logs(LoggerLevel.WARN).stream()
boolean noneMatch = logTester.logs(Level.WARN).stream()
.noneMatch(s -> s.startsWith("The development cost used for calculating the technical debt is currently configured with"));
assertThat(noneMatch).isTrue();
}

+ 1
- 1
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java View File

@@ -32,7 +32,7 @@ import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.process.NetworkUtilsImpl;

import static junit.framework.Assert.fail;

+ 0
- 0
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/AutoDbMigrationTest.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save