|
11 | 11 | import static io.snyk.eclipse.plugin.views.snyktoolview.ISnykToolView.CONGRATS_NO_ISSUES_FOUND; |
12 | 12 | import static io.snyk.eclipse.plugin.views.snyktoolview.ISnykToolView.getPlural; |
13 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 14 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
14 | 15 | import static org.mockito.ArgumentMatchers.any; |
15 | 16 | import static org.mockito.Mockito.mock; |
16 | 17 | import static org.mockito.Mockito.mockStatic; |
|
24 | 25 | import java.io.File; |
25 | 26 | import java.io.IOException; |
26 | 27 | import java.net.URI; |
| 28 | +import java.net.URISyntaxException; |
27 | 29 | import java.nio.file.Path; |
28 | 30 | import java.nio.file.Paths; |
29 | 31 | import java.util.Collection; |
30 | 32 | import java.util.HashSet; |
| 33 | +import java.util.Map; |
31 | 34 | import java.util.Set; |
32 | 35 | import java.util.function.Consumer; |
33 | 36 |
|
@@ -73,6 +76,10 @@ class SnykExtendedLanguageClientTest extends LsBaseTest { |
73 | 76 |
|
74 | 77 | private ISnykToolView toolWindowMock; |
75 | 78 |
|
| 79 | + private URI uri; |
| 80 | + private String paramName; |
| 81 | +// private SnykLogger loggerMock; |
| 82 | + |
76 | 83 | @BeforeEach |
77 | 84 | protected void setUp() { |
78 | 85 | super.setUp(); |
@@ -187,12 +194,11 @@ void testPublishDiagnosticsShouldChangeCache() { |
187 | 194 | var folderPath = "/a/b"; |
188 | 195 | var uri = "file://" + folderPath + "/c/"; |
189 | 196 |
|
190 | | - if(SystemUtils.IS_OS_WINDOWS) { |
| 197 | + if (SystemUtils.IS_OS_WINDOWS) { |
191 | 198 | folderPath = "C://a/b"; |
192 | 199 | uri = "file:///" + folderPath + "/c/"; |
193 | 200 | } |
194 | 201 |
|
195 | | - |
196 | 202 | File pathFromUri = LSPEclipseUtils.fromUri(URI.create(uri)); |
197 | 203 | var filePath = pathFromUri.getAbsolutePath(); |
198 | 204 | var issueCache = new SnykIssueCache(Paths.get(folderPath)); |
@@ -584,4 +590,45 @@ void testGetTotal() throws IOException { |
584 | 590 | private AdditionalData getSecurityIssue() { |
585 | 591 | return Instancio.of(AdditionalData.class).set(Select.field(AdditionalData::isSecurityType), true).create(); |
586 | 592 | } |
| 593 | + |
| 594 | + @Test |
| 595 | + public void getDecodedParam_Returns_Parameter_Value_If_Present_In_Query_String() throws Exception { |
| 596 | + cut = new SnykExtendedLanguageClient(); |
| 597 | + String query = "product=Snyk+Code&issueId=7642f506c568056a7090d3ceb7b3c2e0&action=showInDetailPanel"; |
| 598 | + URI uriWithQuery = new URI("snyk://path/to/resource?" + query); |
| 599 | + |
| 600 | + Map<String, String> paramMapMock = java.util.Collections.singletonMap("issueId", |
| 601 | + "7642f506c568056a7090d3ceb7b3c2e0"); |
| 602 | + |
| 603 | + var result = cut.getDecodedParam(uriWithQuery, "issueId"); |
| 604 | + assertEquals("7642f506c568056a7090d3ceb7b3c2e0", result); |
| 605 | + |
| 606 | + // Test action parameter |
| 607 | + result = cut.getDecodedParam(uriWithQuery, "action"); |
| 608 | + assertEquals("showInDetailPanel", result); |
| 609 | + |
| 610 | + // Test product parameter |
| 611 | + result = cut.getDecodedParam(uriWithQuery, "product"); |
| 612 | + assertEquals("Snyk Code", result); |
| 613 | + } |
| 614 | + |
| 615 | + @Test |
| 616 | + public void parseQueryString_Returns_Parameters_In_Query_String() throws Exception { |
| 617 | + cut = new SnykExtendedLanguageClient(); |
| 618 | + String query = "product=Snyk+Code&issueId=7642f506c568056a7090d3ceb7b3c2e0&action=showInDetailPanel"; |
| 619 | + URI uriWithQuery = new URI("snyk://path/to/resource?" + query); |
| 620 | + |
| 621 | + var result = cut.parseQueryString(uriWithQuery.getQuery()); |
| 622 | + assertEquals(3, result.size()); |
| 623 | + } |
| 624 | + |
| 625 | + @Test |
| 626 | + public void parseQueryString_Returns_Empty_Map_If_Query_String_Is_Empty() throws URISyntaxException { |
| 627 | + cut = new SnykExtendedLanguageClient(); |
| 628 | + URI uriWithoutQuery = new URI("snyk://path/to/resource"); |
| 629 | + |
| 630 | + var result = cut.parseQueryString(null); |
| 631 | + assertTrue(result.isEmpty()); |
| 632 | + } |
| 633 | + |
587 | 634 | } |
0 commit comments