3535import java .util .Map ;
3636import java .util .Random ;
3737import java .util .Set ;
38- import java .util .UUID ;
3938import java .util .concurrent .ConcurrentHashMap ;
4039import java .util .concurrent .ExecutionException ;
4140import java .util .concurrent .TimeUnit ;
7170import org .sonarqube .ws .client .sources .RawRequest ;
7271import org .sonarsource .sonarlint .core .rpc .client .ClientJsonRpcLauncher ;
7372import org .sonarsource .sonarlint .core .rpc .client .ConnectionNotFoundException ;
74- import org .sonarsource .sonarlint .core .rpc .client .SonarLintRpcClientDelegate ;
7573import org .sonarsource .sonarlint .core .rpc .impl .BackendJsonRpcLauncher ;
7674import org .sonarsource .sonarlint .core .rpc .protocol .SonarLintRpcServer ;
77- import org .sonarsource .sonarlint .core .rpc .protocol .backend .analysis .AnalyzeFilesAndTrackParams ;
7875import org .sonarsource .sonarlint .core .rpc .protocol .backend .analysis .ShouldUseEnterpriseCSharpAnalyzerParams ;
7976import org .sonarsource .sonarlint .core .rpc .protocol .backend .branch .GetMatchedSonarProjectBranchParams ;
8077import org .sonarsource .sonarlint .core .rpc .protocol .backend .config .binding .BindingConfigurationDto ;
8986import org .sonarsource .sonarlint .core .rpc .protocol .backend .connection .projects .GetAllProjectsParams ;
9087import org .sonarsource .sonarlint .core .rpc .protocol .backend .connection .projects .SonarProjectDto ;
9188import org .sonarsource .sonarlint .core .rpc .protocol .backend .connection .validate .ValidateConnectionParams ;
92- import org .sonarsource .sonarlint .core .rpc .protocol .backend .file .DidUpdateFileSystemParams ;
9389import org .sonarsource .sonarlint .core .rpc .protocol .backend .hotspot .HotspotStatus ;
9490import org .sonarsource .sonarlint .core .rpc .protocol .backend .initialize .BackendCapability ;
9591import org .sonarsource .sonarlint .core .rpc .protocol .backend .initialize .HttpConfigurationDto ;
9995import org .sonarsource .sonarlint .core .rpc .protocol .backend .rules .GetEffectiveRuleDetailsParams ;
10096import org .sonarsource .sonarlint .core .rpc .protocol .backend .tracking .ListAllParams ;
10197import org .sonarsource .sonarlint .core .rpc .protocol .client .hotspot .RaisedHotspotDto ;
102- import org .sonarsource .sonarlint .core .rpc .protocol .client .issue .RaisedIssueDto ;
10398import org .sonarsource .sonarlint .core .rpc .protocol .client .log .LogParams ;
10499import org .sonarsource .sonarlint .core .rpc .protocol .common .CleanCodeAttribute ;
105- import org .sonarsource .sonarlint .core .rpc .protocol .common .ClientFileDto ;
106100import org .sonarsource .sonarlint .core .rpc .protocol .common .Either ;
107101import org .sonarsource .sonarlint .core .rpc .protocol .common .ImpactSeverity ;
108102import org .sonarsource .sonarlint .core .rpc .protocol .common .RuleType ;
111105import org .sonarsource .sonarlint .core .rpc .protocol .common .TokenDto ;
112106import org .sonarsource .sonarlint .core .rpc .protocol .common .UsernamePasswordDto ;
113107
108+ import static its .utils .AnalysisUtils .analyzeAndAwaitHotspots ;
109+ import static its .utils .AnalysisUtils .analyzeAndAwaitIssues ;
114110import static java .util .Collections .emptyList ;
115111import static java .util .Collections .emptyMap ;
116112import static java .util .Collections .emptySet ;
@@ -156,7 +152,7 @@ class SonarCloudTests extends AbstractConnectedTests {
156152 private static int randomPositiveInt ;
157153
158154 private static SonarLintRpcServer backend ;
159- private static SonarLintRpcClientDelegate client ;
155+ private static MockSonarLintRpcClientDelegate client ;
160156 private static final Set <String > openedConfigurationScopeIds = new HashSet <>();
161157 private static final Map <String , Boolean > analysisReadinessByConfigScopeId = new ConcurrentHashMap <>();
162158
@@ -205,7 +201,7 @@ static void cleanup() throws Exception {
205201 try (var response = adminWsClient .wsConnector ().call (request )) {
206202 assertIsOk (response );
207203 }
208- (( MockSonarLintRpcClientDelegate ) client ) .clear ();
204+ client .clear ();
209205 backend .shutdown ().get ();
210206 }
211207
@@ -332,7 +328,7 @@ void analysisJavascript() {
332328
333329 openBoundConfigurationScope (configScopeId , projectKeyJs );
334330 waitForAnalysisToBeReady (configScopeId );
335- var issues = analyzeAndGetIssues ( projectKeyJs , "src/Person.js" , configScopeId );
331+ var issues = analyzeAndAwaitIssues ( backend , client , configScopeId , Path . of ( "projects" , projectKeyJs ) , "src/Person.js" );
336332 assertThat (issues ).hasSize (1 );
337333 }
338334
@@ -347,7 +343,7 @@ void analysisPHP() {
347343 openBoundConfigurationScope (configScopeId , projectKeyPhp );
348344 waitForAnalysisToBeReady (configScopeId );
349345
350- var issues = analyzeAndGetIssues ( projectKeyPhp , "src/Math.php" , configScopeId );
346+ var issues = analyzeAndAwaitIssues ( backend , client , configScopeId , Path . of ( "projects" , projectKeyPhp ) , "src/Math.php" );
351347 assertThat (issues ).hasSize (1 );
352348 }
353349
@@ -362,7 +358,7 @@ void analysisPython() {
362358 openBoundConfigurationScope (configScopeId , projectKeyPython );
363359 waitForAnalysisToBeReady (configScopeId );
364360
365- var issues = analyzeAndGetIssues ( projectKeyPython , "src/hello.py" , configScopeId );
361+ var issues = analyzeAndAwaitIssues ( backend , client , configScopeId , Path . of ( "projects" , projectKeyPython ) , "src/hello.py" );
366362 assertThat (issues ).hasSize (1 );
367363 }
368364
@@ -377,7 +373,7 @@ void analysisWeb() {
377373 openBoundConfigurationScope (configScopeId , projectKey );
378374 waitForAnalysisToBeReady (configScopeId );
379375
380- var issues = analyzeAndGetIssues ( projectKey , "src/file.html" , configScopeId );
376+ var issues = analyzeAndAwaitIssues ( backend , client , configScopeId , Path . of ( "projects" , projectKey ) , "src/file.html" );
381377
382378 assertThat (issues ).hasSize (1 );
383379 }
@@ -387,7 +383,7 @@ void analysisWeb() {
387383 void analysisUseConfiguration () {
388384 var configScopeId = "analysisUseConfiguration" ;
389385 openUnboundConfigurationScope (configScopeId );
390- var issues = analyzeAndGetIssues ( PROJECT_KEY_JAVA , "src/main/java/foo/Foo.java" , configScopeId ,
386+ var issues = analyzeAndAwaitIssues ( backend , client , configScopeId , Path . of ( "projects" , PROJECT_KEY_JAVA ) , "src/main/java/foo/Foo.java" ,
391387 "sonar.java.binaries" , new File ("projects/sample-java/target/classes" ).getAbsolutePath ());
392388 assertThat (issues ).hasSize (2 );
393389
@@ -398,7 +394,7 @@ void analysisUseConfiguration() {
398394 backend .getConfigurationService ().didUpdateBinding (new DidUpdateBindingParams (configScopeId , new BindingConfigurationDto (CONNECTION_ID , projectKey (PROJECT_KEY_JAVA ), true )));
399395 waitForAnalysisToBeReady (configScopeId );
400396
401- issues = analyzeAndGetIssues ( PROJECT_KEY_JAVA , "src/main/java/foo/Foo.java" , configScopeId ,
397+ issues = analyzeAndAwaitIssues ( backend , client , configScopeId , Path . of ( "projects" , PROJECT_KEY_JAVA ) , "src/main/java/foo/Foo.java" ,
402398 "sonar.java.binaries" , new File ("projects/sample-java/target/classes" ).getAbsolutePath ());
403399 assertThat (issues ).isEmpty ();
404400 } finally {
@@ -436,7 +432,7 @@ void analysisRuby() {
436432 openBoundConfigurationScope (configScopeId , projectKeyRuby );
437433 waitForAnalysisToBeReady (configScopeId );
438434
439- var issues = analyzeAndGetIssues ( projectKeyRuby , "src/hello.rb" , configScopeId );
435+ var issues = analyzeAndAwaitIssues ( backend , client , configScopeId , Path . of ( "projects" , projectKeyRuby ) , "src/hello.rb" );
440436 assertThat (issues ).hasSize (1 );
441437 }
442438
@@ -451,7 +447,7 @@ void analysisKotlin() {
451447 openBoundConfigurationScope (configScopeId , projectKeyKotlin );
452448 waitForAnalysisToBeReady (configScopeId );
453449
454- var issues = analyzeAndGetIssues ( projectKeyKotlin , "src/hello.kt" , configScopeId );
450+ var issues = analyzeAndAwaitIssues ( backend , client , configScopeId , Path . of ( "projects" , projectKeyKotlin ) , "src/hello.kt" );
455451 assertThat (issues ).hasSize (1 );
456452 }
457453
@@ -466,7 +462,7 @@ void analysisScala() {
466462 openBoundConfigurationScope (configScopeId , projectKeyScala );
467463 waitForAnalysisToBeReady (configScopeId );
468464
469- var issues = analyzeAndGetIssues ( projectKeyScala , "src/Hello.scala" , configScopeId );
465+ var issues = analyzeAndAwaitIssues ( backend , client , configScopeId , Path . of ( "projects" , projectKeyScala ) , "src/Hello.scala" );
470466 assertThat (issues ).hasSize (1 );
471467 }
472468
@@ -481,7 +477,7 @@ void analysisXml() {
481477 openBoundConfigurationScope (configScopeId , projectKeyXml );
482478 waitForAnalysisToBeReady (configScopeId );
483479
484- var issues = analyzeAndGetIssues ( projectKeyXml , "src/foo.xml" , configScopeId );
480+ var issues = analyzeAndAwaitIssues ( backend , client , configScopeId , Path . of ( "projects" , projectKeyXml ) , "src/foo.xml" );
485481 assertThat (issues ).hasSize (1 );
486482 }
487483
@@ -525,7 +521,7 @@ void reportHotspots() {
525521 openBoundConfigurationScope (configScopeId , PROJECT_KEY_JAVA_HOTSPOT );
526522 waitForAnalysisToBeReady (configScopeId );
527523
528- var issues = analyzeAndGetHotspots ( PROJECT_KEY_JAVA_HOTSPOT , "src/main/java/foo/Foo.java" , configScopeId );
524+ var issues = analyzeAndAwaitHotspots ( backend , client , configScopeId , Path . of ( "projects" , PROJECT_KEY_JAVA_HOTSPOT ) , "src/main/java/foo/Foo.java" );
529525 assertThat (issues )
530526 .extracting (RaisedHotspotDto ::getRuleKey , h -> h .getSeverityMode ().getLeft ().getType ())
531527 .containsExactly (tuple ("java:S4792" , RuleType .SECURITY_HOTSPOT ));
@@ -547,7 +543,7 @@ void shouldMatchServerSecurityHotspots() {
547543 openBoundConfigurationScope (configScopeId , PROJECT_KEY_JAVA_HOTSPOT );
548544 waitForAnalysisToBeReady (configScopeId );
549545
550- var raisedHotspots = analyzeAndGetHotspots ( PROJECT_KEY_JAVA_HOTSPOT , "src/main/java/foo/Foo.java" , configScopeId );
546+ var raisedHotspots = analyzeAndAwaitHotspots ( backend , client , configScopeId , Path . of ( "projects" , PROJECT_KEY_JAVA_HOTSPOT ) , "src/main/java/foo/Foo.java" );
551547
552548 assertThat (raisedHotspots ).hasSize (1 );
553549 assertThat (raisedHotspots .get (0 ).getStatus ()).isEqualTo (HotspotStatus .TO_REVIEW );
@@ -692,7 +688,7 @@ private static void assertIsOk(WsResponse response) {
692688 .isBetween (200 , 399 );
693689 }
694690
695- private static SonarLintRpcClientDelegate newDummySonarLintClient () {
691+ private static MockSonarLintRpcClientDelegate newDummySonarLintClient () {
696692 return new MockSonarLintRpcClientDelegate () {
697693
698694 @ Override
@@ -716,36 +712,4 @@ public void log(LogParams params) {
716712 };
717713 }
718714
719- private static List <RaisedIssueDto > analyzeAndGetIssues (String projectKey , String fileName , String configScopeId , String ... properties ) {
720- final var baseDir = Paths .get ("projects/" + projectKey ).toAbsolutePath ();
721- final var filePath = baseDir .resolve (fileName );
722- backend .getFileService ().didUpdateFileSystem (new DidUpdateFileSystemParams (
723- List .of (new ClientFileDto (filePath .toUri (), Path .of (fileName ), configScopeId , false , null , filePath , null , null , true )),
724- List .of (),
725- List .of ()));
726-
727- var analyzeResponse = backend .getAnalysisService ().analyzeFilesAndTrack (
728- new AnalyzeFilesAndTrackParams (configScopeId , UUID .randomUUID (), List .of (filePath .toUri ()), toMap (properties ), true , System .currentTimeMillis ())).join ();
729-
730- assertThat (analyzeResponse .getFailedAnalysisFiles ()).isEmpty ();
731- var raisedIssues = ((MockSonarLintRpcClientDelegate ) client ).getRaisedIssues (configScopeId );
732- ((MockSonarLintRpcClientDelegate ) client ).getRaisedIssues ().clear ();
733- return raisedIssues != null ? raisedIssues .values ().stream ().flatMap (List ::stream ).toList () : List .of ();
734- }
735-
736- private static List <RaisedHotspotDto > analyzeAndGetHotspots (String projectKey , String fileName , String configScopeId , String ... properties ) {
737- final var baseDir = Paths .get ("projects/" + projectKey ).toAbsolutePath ();
738- final var filePath = baseDir .resolve (fileName );
739- backend .getFileService ().didUpdateFileSystem (new DidUpdateFileSystemParams (List .of (),
740- List .of (new ClientFileDto (filePath .toUri (), Path .of (fileName ), configScopeId , false , null , filePath , null , null , true )), List .of ()));
741-
742- var analyzeResponse = backend .getAnalysisService ().analyzeFilesAndTrack (
743- new AnalyzeFilesAndTrackParams (configScopeId , UUID .randomUUID (), List .of (filePath .toUri ()), toMap (properties ), true , System .currentTimeMillis ())).join ();
744-
745- assertThat (analyzeResponse .getFailedAnalysisFiles ()).isEmpty ();
746- var raisedHotspots = ((MockSonarLintRpcClientDelegate ) client ).getRaisedHotspots (configScopeId );
747- ((MockSonarLintRpcClientDelegate ) client ).getRaisedIssues ().clear ();
748- return raisedHotspots != null ? raisedHotspots .values ().stream ().flatMap (List ::stream ).toList () : List .of ();
749- }
750-
751715}
0 commit comments