53
53
54
54
import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
55
55
import static com .github .tomakehurst .wiremock .client .WireMock .get ;
56
- import static com .github .tomakehurst .wiremock .client .WireMock .urlEqualTo ;
57
- import static com .github .tomakehurst .wiremock .client .WireMock .urlPathMatching ;
58
56
import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
59
57
import static org .assertj .core .api .Assertions .assertThat ;
60
58
import static org .assertj .core .api .Assertions .tuple ;
@@ -339,9 +337,6 @@ void test_uses_binding_clues_from_shared_configuration_when_updating_fs(SonarLin
339
337
void should_suggest_binding_by_remote_url_when_no_other_suggestions_found (SonarLintTestHarness harness , @ TempDir Path tmp ) throws IOException , GitAPIException {
340
338
var gitRepo = tmp .resolve ("git-repo" );
341
339
Files .createDirectory (gitRepo );
342
- String encodedUrl = UrlUtils .urlEncode (REMOTE_URL );
343
- String expectedPath = "/dop-translation/project-bindings?url=" + encodedUrl ;
344
- String expectedSearchProjectsPath = "/api/components/search_projects?projectIds=" + PROJECT_ID + "&organization=orgKey" ;
345
340
346
341
try (var git = GitUtils .createRepository (gitRepo )) {
347
342
git .remoteAdd ()
@@ -359,6 +354,9 @@ void should_suggest_binding_by_remote_url_when_no_other_suggestions_found(SonarL
359
354
var scServer = harness .newFakeSonarCloudServer ()
360
355
.withOrganization ("orgKey" , organization ->
361
356
organization .withProject (SLCORE_PROJECT_KEY , project -> project .withBranch ("main" )))
357
+ .withDopTranslation (dop -> dop
358
+ .withProjectBinding (REMOTE_URL , PROJECT_ID , SLCORE_PROJECT_KEY )
359
+ .withSearchProjectsResponse ("orgKey" , PROJECT_ID , 200 , "{\" components\" :[{\" key\" :\" " + SLCORE_PROJECT_KEY + "\" ,\" name\" :\" " + SLCORE_PROJECT_NAME + "\" }]}\n " ))
362
360
.start ();
363
361
364
362
var backend = harness .newBackend ()
@@ -369,30 +367,6 @@ void should_suggest_binding_by_remote_url_when_no_other_suggestions_found(SonarL
369
367
.withTelemetryEnabled ()
370
368
.start (fakeClient );
371
369
372
- scServer .getMockServer ().stubFor (get (urlEqualTo (expectedPath ))
373
- .willReturn (aResponse ()
374
- .withStatus (200 )
375
- .withHeader ("Content-Type" , "application/json" )
376
- .withBody ("{\" bindings\" :[{\" projectId\" :\" " + PROJECT_ID + "\" }]}" )));
377
-
378
- scServer .getMockServer ().stubFor (get (urlEqualTo (expectedSearchProjectsPath ))
379
- .willReturn (aResponse ()
380
- .withStatus (200 )
381
- .withHeader ("Content-Type" , "application/json" )
382
- .withBody ("{\" components\" :[{\" key\" :\" " + SLCORE_PROJECT_KEY + "\" ,\" name\" :\" " + SLCORE_PROJECT_NAME + "\" }]}\n " )));
383
-
384
- scServer .getMockServer ().stubFor (get (urlPathMatching ("/api/components/search\\ .protobuf" ))
385
- .willReturn (aResponse ()
386
- .withStatus (200 )
387
- .withHeader ("Content-Type" , "application/x-protobuf" )
388
- .withResponseBody (protobufBody (Components .SearchWsResponse .newBuilder ()
389
- .addComponents (Components .Component .newBuilder ()
390
- .setKey ("my-project-key" )
391
- .setName ("My Project" )
392
- .build ())
393
- .setPaging (Common .Paging .newBuilder ().setTotal (1 ).build ())
394
- .build ()))));
395
-
396
370
ArgumentCaptor <Map <String , List <BindingSuggestionDto >>> suggestionCaptor = ArgumentCaptor .forClass (Map .class );
397
371
verify (fakeClient , timeout (5000 )).suggestBinding (suggestionCaptor .capture ());
398
372
@@ -409,8 +383,6 @@ void should_suggest_binding_by_remote_url_when_no_other_suggestions_found_for_so
409
383
GitAPIException {
410
384
var gitRepo = tmp .resolve ("git-repo" );
411
385
Files .createDirectory (gitRepo );
412
- String encodedUrl = UrlUtils .urlEncode (REMOTE_URL );
413
- String expectedPath = "/api/v2/dop-translation/project-bindings?repositoryUrl=" + encodedUrl ;
414
386
415
387
try (var git = GitUtils .createRepository (gitRepo )) {
416
388
git .remoteAdd ()
@@ -426,7 +398,9 @@ void should_suggest_binding_by_remote_url_when_no_other_suggestions_found_for_so
426
398
.build ();
427
399
428
400
var sqServer = harness .newFakeSonarQubeServer ()
429
- .withProject (SLCORE_PROJECT_KEY , project -> project .withBranch ("main" ))
401
+ .withProject (SLCORE_PROJECT_KEY , project -> project .withBranch ("main" ).withProjectName (SLCORE_PROJECT_NAME ))
402
+ .withDopTranslation (dop -> dop
403
+ .withProjectBinding (REMOTE_URL , PROJECT_ID , SLCORE_PROJECT_KEY ))
430
404
.start ();
431
405
432
406
var backend = harness .newBackend ()
@@ -435,25 +409,6 @@ void should_suggest_binding_by_remote_url_when_no_other_suggestions_found_for_so
435
409
.withTelemetryEnabled ()
436
410
.start (fakeClient );
437
411
438
- sqServer .getMockServer ().stubFor (get (urlEqualTo (expectedPath ))
439
- .willReturn (aResponse ()
440
- .withStatus (200 )
441
- .withHeader ("Content-Type" , "application/json" )
442
- .withBody ("{\" projectBindings\" :[{\" projectId\" :\" " + PROJECT_ID + "\" ,\" projectKey\" :\" " + SLCORE_PROJECT_KEY + "\" }]}" )));
443
-
444
- String expectedProjectPath = "/api/components/show.protobuf?component=" + UrlUtils .urlEncode (SLCORE_PROJECT_KEY );
445
- sqServer .getMockServer ().stubFor (get (urlEqualTo (expectedProjectPath ))
446
- .willReturn (aResponse ()
447
- .withStatus (200 )
448
- .withHeader ("Content-Type" , "application/x-protobuf" )
449
- .withResponseBody (protobufBody (Components .ShowWsResponse .newBuilder ()
450
- .setComponent (Components .Component .newBuilder ()
451
- .setKey (SLCORE_PROJECT_KEY )
452
- .setName (SLCORE_PROJECT_NAME )
453
- .setIsAiCodeFixEnabled (false )
454
- .build ())
455
- .build ()))));
456
-
457
412
ArgumentCaptor <Map <String , List <BindingSuggestionDto >>> suggestionCaptor = ArgumentCaptor .forClass (Map .class );
458
413
verify (fakeClient , timeout (5000 )).suggestBinding (suggestionCaptor .capture ());
459
414
@@ -486,6 +441,7 @@ void should_return_empty_when_sqc_project_bindings_is_null(SonarLintTestHarness
486
441
var scServer = harness .newFakeSonarCloudServer ()
487
442
.withOrganization ("orgKey" , organization ->
488
443
organization .withProject (SLCORE_PROJECT_KEY , project -> project .withBranch ("main" )))
444
+ .withCustomEndpointResponse (expectedPath , 500 , "text/plain" , "Internal Server Error" )
489
445
.start ();
490
446
491
447
var backend = harness .newBackend ()
@@ -495,11 +451,6 @@ void should_return_empty_when_sqc_project_bindings_is_null(SonarLintTestHarness
495
451
.withUnboundConfigScope (CONFIG_SCOPE_ID , "unmatched-project-name" )
496
452
.start (fakeClient );
497
453
498
- scServer .getMockServer ().stubFor (get (urlEqualTo (expectedPath ))
499
- .willReturn (aResponse ()
500
- .withStatus (500 )
501
- .withBody ("Internal Server Error" )));
502
-
503
454
ArgumentCaptor <Map <String , List <BindingSuggestionDto >>> suggestionCaptor = ArgumentCaptor .forClass (Map .class );
504
455
verify (fakeClient , timeout (5000 )).suggestBinding (suggestionCaptor .capture ());
505
456
@@ -528,18 +479,14 @@ void should_return_empty_when_sqs_project_bindings_is_null(SonarLintTestHarness
528
479
529
480
var sqServer = harness .newFakeSonarQubeServer ()
530
481
.withProject (SLCORE_PROJECT_KEY , project -> project .withBranch ("main" ))
482
+ .withCustomEndpointResponse (expectedPath , 500 , "text/plain" , "Internal Server Error" )
531
483
.start ();
532
484
533
485
var backend = harness .newBackend ()
534
486
.withSonarQubeConnection (MYSONAR , sqServer .baseUrl ())
535
487
.withUnboundConfigScope (CONFIG_SCOPE_ID , "unmatched-project-name" )
536
488
.start (fakeClient );
537
489
538
- sqServer .getMockServer ().stubFor (get (urlEqualTo (expectedPath ))
539
- .willReturn (aResponse ()
540
- .withStatus (500 )
541
- .withBody ("Internal Server Error" )));
542
-
543
490
ArgumentCaptor <Map <String , List <BindingSuggestionDto >>> suggestionCaptor = ArgumentCaptor .forClass (Map .class );
544
491
verify (fakeClient , timeout (5000 )).suggestBinding (suggestionCaptor .capture ());
545
492
@@ -552,9 +499,6 @@ void should_return_empty_when_sqs_project_bindings_is_null(SonarLintTestHarness
552
499
void should_return_empty_when_sqc_search_response_is_null (SonarLintTestHarness harness , @ TempDir Path tmp ) throws IOException , GitAPIException , URISyntaxException {
553
500
var gitRepo = tmp .resolve ("git-repo" );
554
501
Files .createDirectory (gitRepo );
555
- String encodedUrl = UrlUtils .urlEncode (REMOTE_URL );
556
- String expectedPath = "/dop-translation/project-bindings?url=" + encodedUrl ;
557
- String expectedSearchProjectsPath = "/api/components/search_projects?projectIds=" + PROJECT_ID + "&organization=orgKey" ;
558
502
559
503
try (var git = GitUtils .createRepository (gitRepo )) {
560
504
git .remoteAdd ()
@@ -570,6 +514,9 @@ void should_return_empty_when_sqc_search_response_is_null(SonarLintTestHarness h
570
514
var scServer = harness .newFakeSonarCloudServer ()
571
515
.withOrganization ("orgKey" , organization ->
572
516
organization .withProject (SLCORE_PROJECT_KEY , project -> project .withBranch ("main" )))
517
+ .withDopTranslation (dop -> dop
518
+ .withProjectBinding (REMOTE_URL , PROJECT_ID , SLCORE_PROJECT_KEY )
519
+ .withSearchProjectsResponse ("orgKey" , PROJECT_ID , 500 , "Internal Server Error" ))
573
520
.start ();
574
521
575
522
var backend = harness .newBackend ()
@@ -579,17 +526,6 @@ void should_return_empty_when_sqc_search_response_is_null(SonarLintTestHarness h
579
526
.withUnboundConfigScope (CONFIG_SCOPE_ID , "unmatched-project-name" )
580
527
.start (fakeClient );
581
528
582
- scServer .getMockServer ().stubFor (get (urlEqualTo (expectedPath ))
583
- .willReturn (aResponse ()
584
- .withStatus (200 )
585
- .withHeader ("Content-Type" , "application/json" )
586
- .withBody ("{\" bindings\" :[{\" projectId\" :\" " + PROJECT_ID + "\" }]}" )));
587
-
588
- scServer .getMockServer ().stubFor (get (urlEqualTo (expectedSearchProjectsPath ))
589
- .willReturn (aResponse ()
590
- .withStatus (500 )
591
- .withBody ("Internal Server Error" )));
592
-
593
529
ArgumentCaptor <Map <String , List <BindingSuggestionDto >>> suggestionCaptor = ArgumentCaptor .forClass (Map .class );
594
530
verify (fakeClient , timeout (5000 )).suggestBinding (suggestionCaptor .capture ());
595
531
@@ -602,9 +538,6 @@ void should_return_empty_when_sqc_search_response_is_null(SonarLintTestHarness h
602
538
void should_return_empty_when_sqs_server_project_is_not_present (SonarLintTestHarness harness , @ TempDir Path tmp ) throws IOException , GitAPIException , URISyntaxException {
603
539
var gitRepo = tmp .resolve ("git-repo" );
604
540
Files .createDirectory (gitRepo );
605
- String encodedUrl = UrlUtils .urlEncode (REMOTE_URL );
606
- String expectedPath = "/api/v2/dop-translation/project-bindings?repositoryUrl=" + encodedUrl ;
607
- String expectedProjectPath = "/api/components/show.protobuf?component=" + UrlUtils .urlEncode (SLCORE_PROJECT_KEY );
608
541
609
542
try (var git = GitUtils .createRepository (gitRepo )) {
610
543
git .remoteAdd ()
@@ -619,24 +552,16 @@ void should_return_empty_when_sqs_server_project_is_not_present(SonarLintTestHar
619
552
620
553
var sqServer = harness .newFakeSonarQubeServer ()
621
554
.withProject (SLCORE_PROJECT_KEY , project -> project .withBranch ("main" ))
555
+ .withDopTranslation (dop -> dop
556
+ .withProjectBinding (REMOTE_URL , PROJECT_ID , SLCORE_PROJECT_KEY )
557
+ .withComponentShowStatus (SLCORE_PROJECT_KEY , 404 , "Project not found" ))
622
558
.start ();
623
559
624
560
var backend = harness .newBackend ()
625
561
.withSonarQubeConnection (MYSONAR , sqServer .baseUrl ())
626
562
.withUnboundConfigScope (CONFIG_SCOPE_ID , "unmatched-project-name" )
627
563
.start (fakeClient );
628
564
629
- sqServer .getMockServer ().stubFor (get (urlEqualTo (expectedPath ))
630
- .willReturn (aResponse ()
631
- .withStatus (200 )
632
- .withHeader ("Content-Type" , "application/json" )
633
- .withBody ("{\" projectBindings\" :[{\" projectId\" :\" " + PROJECT_ID + "\" ,\" projectKey\" :\" " + SLCORE_PROJECT_KEY + "\" }]}" )));
634
-
635
- sqServer .getMockServer ().stubFor (get (urlEqualTo (expectedProjectPath ))
636
- .willReturn (aResponse ()
637
- .withStatus (404 )
638
- .withBody ("Project not found" )));
639
-
640
565
ArgumentCaptor <Map <String , List <BindingSuggestionDto >>> suggestionCaptor = ArgumentCaptor .forClass (Map .class );
641
566
verify (fakeClient , timeout (5000 )).suggestBinding (suggestionCaptor .capture ());
642
567
0 commit comments