> conflicts) {
- StringBuilder htmlBuilder = new StringBuilder();
-
- htmlBuilder.append("");
-
- if (scanResults != null && scanResults.size() != 0) {
- htmlBuilder.append("Detected licenses: ");
- for (LPVSFile file : scanResults) {
- htmlBuilder
- .append("File: ")
- .append(file.getFilePath())
- .append("
");
- htmlBuilder
- .append("License(s): ")
- .append(file.convertLicensesToString(LPVSVcs.GITHUB))
- .append("
");
- htmlBuilder
- .append("Component: ")
- .append(file.getComponentName())
- .append(" (")
- .append(file.getComponentFilePath())
- .append(")
");
- htmlBuilder
- .append("Matched Lines: ")
- .append(
- LPVSCommentUtil.getMatchedLinesAsLink(
- webhookConfig, file, LPVSVcs.GITHUB))
- .append("
");
- htmlBuilder
- .append("Snippet Match: ")
- .append(file.getSnippetMatch())
- .append("
");
- htmlBuilder.append(" ");
- }
- }
-
- if (conflicts != null && conflicts.size() > 0) {
- htmlBuilder.append("Detected license conflicts: ");
- htmlBuilder.append("");
- for (LPVSLicenseService.Conflict conflict : conflicts) {
- htmlBuilder
- .append("")
- .append(conflict.l1)
- .append(" and ")
- .append(conflict.l2)
- .append(" ");
- }
- htmlBuilder.append(" ");
- if (webhookConfig.getHubLink() != null) {
- htmlBuilder.append("").append(webhookConfig.getHubLink()).append("
");
- }
- }
-
- htmlBuilder.append("");
-
- return htmlBuilder.toString();
- }
-
- /**
- * Saves HTML report to given location.
- *
- * @param htmlContent The string, containing report in HTML format.
- * @param filePath The path to expected html report file.
- */
- public static void saveHTMLToFile(String htmlContent, String filePath) {
- File file = new File(filePath);
- try (BufferedWriter writer =
- new BufferedWriter(new FileWriter(file, StandardCharsets.UTF_8))) {
- writer.write(htmlContent);
- log.info("LPVS report saved to: " + filePath);
- } catch (IOException ex) {
- log.error("error during saving HTML report: " + ex.getMessage());
- }
- }
}
diff --git a/src/main/resources/templates/report_single_scan.html b/src/main/resources/templates/report_single_scan.html
new file mode 100644
index 00000000..64860931
--- /dev/null
+++ b/src/main/resources/templates/report_single_scan.html
@@ -0,0 +1,141 @@
+
+
+
+
+
+
+
+ title
+
+
+
+
+
+
+
Report - L icense P re-V alidation S ervice (LPVS )
+
+
+ Scan date: scanDate
+ Source code location: codeLocation
+ Used scanner: usedScanner
+ Version of LPVS: lpvsVersion
+
+
+Detected Licenses
+
+
Potential license problem(s) detected: licenseDetected
+
+ Prohibited license(s): prohibitedLicenses
+ Restricted license(s): restrictedLicenses
+ Unreviewed license(s): unreviewedLicenses
+
+
+
+ No license problems detected.
+
+
+
+
Detailed description of detected licenses
+
+
+
+Detected License Conflicts
+
+ Potential license conflict(s) detected: licenseConflicts
+
+
+ No license conflicts detected.
+
+
+
Detailed description of detected license conflicts
+
+
+
+
+
+
diff --git a/src/test/java/com/lpvs/entity/report/LPVSReportBuilderTest.java b/src/test/java/com/lpvs/entity/report/LPVSReportBuilderTest.java
new file mode 100644
index 00000000..a53ac20c
--- /dev/null
+++ b/src/test/java/com/lpvs/entity/report/LPVSReportBuilderTest.java
@@ -0,0 +1,304 @@
+/**
+ * Copyright (c) 2024, Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Use of this source code is governed by a MIT license that can be
+ * found in the LICENSE file.
+ */
+package com.lpvs.entity.report;
+
+import com.lpvs.entity.LPVSFile;
+import com.lpvs.entity.LPVSLicense;
+import com.lpvs.service.LPVSLicenseService;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
+import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.thymeleaf.TemplateEngine;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+import static com.lpvs.entity.report.LPVSReportBuilder.saveHTMLToFile;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.*;
+
+@ExtendWith(SpringExtension.class)
+@ImportAutoConfiguration(ThymeleafAutoConfiguration.class)
+@ContextConfiguration(classes = {LPVSReportBuilder.class})
+@Slf4j
+public class LPVSReportBuilderTest {
+
+ @Autowired private TemplateEngine templateEngine;
+
+ LPVSFile fileLicPermitted,
+ fileLicProhibitedRestricted,
+ fileLicUnreviewed_1,
+ fileLicUnreviewed_2,
+ fileLicUnreviewed_3,
+ fileLicIncorrect;
+ LPVSLicense licPermitted,
+ licProhibited,
+ licRestricted,
+ licUnreviewed,
+ licUnreviewed_2,
+ licIncorrect;
+ LPVSLicenseService.Conflict conflict1, conflict2;
+ LPVSReportBuilder reportBuilder;
+
+ @TempDir Path tempDir;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ licPermitted =
+ new LPVSLicense() {
+ {
+ setLicenseName("MIT License");
+ setAccess("PERMITTED");
+ setSpdxId("MIT");
+ }
+ };
+ licProhibited =
+ new LPVSLicense() {
+ {
+ setLicenseName("GNU General Public License v3.0 only");
+ setAccess("PROHIBITED");
+ setSpdxId("GPL-3.0-only");
+ }
+ };
+ licRestricted =
+ new LPVSLicense() {
+ {
+ setLicenseName("GNU Lesser General Public License v2.0 or later");
+ setAccess("RESTRICTED");
+ setSpdxId("LGPL-2.0-or-later");
+ }
+ };
+ licUnreviewed =
+ new LPVSLicense() {
+ {
+ setLicenseName("Apache License 2.0");
+ setAccess("UNREVIEWED");
+ setSpdxId("Apache-2.0");
+ }
+ };
+
+ licUnreviewed_2 =
+ new LPVSLicense() {
+ {
+ setLicenseName("BSD 3-Clause \"New\" or \"Revised\" License");
+ setAccess("UNREVIEWED");
+ setSpdxId("BSD-3-Clause");
+ }
+ };
+
+ licIncorrect =
+ new LPVSLicense() {
+ {
+ setLicenseName("Some incorrect license");
+ setAccess("INCORRECT");
+ setSpdxId("Some-license");
+ }
+ };
+
+ fileLicPermitted = new LPVSFile();
+ fileLicPermitted.setLicenses(
+ new HashSet<>() {
+ {
+ add(licPermitted);
+ }
+ });
+ fileLicPermitted.setFilePath("local_file_path_1");
+ fileLicPermitted.setComponentFilePath("component_file_path_1");
+ fileLicPermitted.setComponentFileUrl("http://component_name_1/file_url");
+ fileLicPermitted.setComponentName("component_name_1");
+ fileLicPermitted.setComponentUrl("http://component_name_1/url");
+ fileLicPermitted.setComponentVersion("v1.0.0");
+ fileLicPermitted.setComponentVendor("component_vendor_1");
+ fileLicPermitted.setSnippetMatch("80%");
+ fileLicPermitted.setMatchedLines("5-17");
+
+ fileLicProhibitedRestricted = new LPVSFile();
+ fileLicProhibitedRestricted.setLicenses(
+ new HashSet<>() {
+ {
+ add(licProhibited);
+ add(licRestricted);
+ }
+ });
+ fileLicProhibitedRestricted.setFilePath("local_file_path_2");
+ fileLicProhibitedRestricted.setComponentFilePath("component_file_path_2");
+ fileLicProhibitedRestricted.setComponentName("component_name_2");
+ fileLicProhibitedRestricted.setComponentUrl("http://component_name_2/url");
+ fileLicProhibitedRestricted.setComponentVersion("v2.0.0");
+ fileLicProhibitedRestricted.setComponentVendor("component_vendor_2");
+ fileLicProhibitedRestricted.setSnippetMatch("100%");
+ fileLicProhibitedRestricted.setMatchedLines("all");
+
+ fileLicUnreviewed_1 = new LPVSFile();
+ fileLicUnreviewed_1.setLicenses(
+ new HashSet<>() {
+ {
+ add(licUnreviewed_2);
+ }
+ });
+ fileLicUnreviewed_1.setFilePath("local_file_path_3");
+ fileLicUnreviewed_1.setComponentFilePath("component_file_path_3");
+ fileLicUnreviewed_1.setComponentFileUrl("http://component_name_3/file_url");
+ fileLicUnreviewed_1.setComponentName("component_name_3");
+ fileLicUnreviewed_1.setComponentUrl("http://component_name_3/url");
+ fileLicUnreviewed_1.setComponentVersion("v3.0.0");
+ fileLicUnreviewed_1.setComponentVendor("component_vendor_3");
+ fileLicUnreviewed_1.setSnippetMatch("20%");
+ fileLicUnreviewed_1.setMatchedLines("1-10");
+
+ fileLicUnreviewed_2 = new LPVSFile();
+ fileLicUnreviewed_2.setLicenses(
+ new HashSet<>() {
+ {
+ add(licUnreviewed);
+ }
+ });
+ fileLicUnreviewed_2.setFilePath("local_file_path_4");
+ fileLicUnreviewed_2.setComponentFilePath("component_file_path_4");
+ fileLicUnreviewed_2.setComponentName("component_name_4");
+ fileLicUnreviewed_2.setComponentUrl("http://component_name_4/url");
+ fileLicUnreviewed_2.setComponentVersion("v4.0.0");
+ fileLicUnreviewed_2.setComponentVendor("component_vendor_4");
+ fileLicUnreviewed_2.setSnippetMatch("50%");
+ fileLicUnreviewed_2.setMatchedLines("5-10");
+
+ fileLicUnreviewed_3 = new LPVSFile();
+ fileLicUnreviewed_3.setLicenses(
+ new HashSet<>() {
+ {
+ add(licUnreviewed);
+ }
+ });
+ fileLicUnreviewed_3.setFilePath("local_file_path_4");
+ fileLicUnreviewed_3.setComponentFilePath("component_file_path_4");
+ fileLicUnreviewed_3.setComponentName("component_name_4");
+ fileLicUnreviewed_3.setComponentUrl("http://component_name_4/url");
+ fileLicUnreviewed_3.setComponentVersion("v4.0.0");
+ fileLicUnreviewed_3.setComponentVendor("component_vendor_4");
+ fileLicUnreviewed_3.setSnippetMatch("40%");
+ fileLicUnreviewed_3.setMatchedLines("1-10");
+
+ fileLicIncorrect = new LPVSFile();
+ fileLicIncorrect.setLicenses(
+ new HashSet<>() {
+ {
+ add(licIncorrect);
+ }
+ });
+ fileLicIncorrect.setFilePath("local_file_path_4");
+ fileLicIncorrect.setComponentFilePath("component_file_path_4");
+ fileLicIncorrect.setComponentName("component_name_4");
+ fileLicIncorrect.setComponentUrl("http://component_name_4/url");
+ fileLicIncorrect.setComponentVersion("v4.0.0");
+ fileLicIncorrect.setComponentVendor("component_vendor_4");
+ fileLicIncorrect.setSnippetMatch("50%");
+ fileLicIncorrect.setMatchedLines("5-10");
+
+ conflict1 = new LPVSLicenseService.Conflict<>("GPL-3.0-only", "Apache-2.0");
+ conflict2 = new LPVSLicenseService.Conflict<>("LGPL-2.0-or-later", "MIT");
+
+ reportBuilder = new LPVSReportBuilder(templateEngine);
+ }
+
+ private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+ @Test
+ public void testGenerateHtmlReportSingleScan_Empty() {
+ String actual =
+ reportBuilder.generateHtmlReportSingleScan(
+ "some/path", new ArrayList<>(), null, null, null);
+ assertThat(actual).contains(sdf.format(new Date())); // check title and scanDate
+ assertThat(actual).contains("No license problems detected");
+ assertThat(actual).contains("No license conflicts detected");
+ }
+
+ @Test
+ public void testGenerateHtmlReportSingleScan_WithLicensesAndConflicts() {
+ List scanResults =
+ List.of(
+ fileLicPermitted,
+ fileLicProhibitedRestricted,
+ fileLicUnreviewed_1,
+ fileLicUnreviewed_2);
+ List> conflicts = List.of(conflict1, conflict2);
+ String actual =
+ reportBuilder.generateHtmlReportSingleScan(
+ "some/path", scanResults, conflicts, null, null);
+ assertThat(actual).contains(sdf.format(new Date()));
+ assertThat(actual).doesNotContain("No license problems detected");
+ assertThat(actual).doesNotContain("No license conflicts detected");
+ }
+
+ @Test
+ public void testGenerateHtmlReportSingleScan_WithLicenses() {
+ List scanResults = List.of(fileLicUnreviewed_1, fileLicUnreviewed_2);
+ String actual =
+ reportBuilder.generateHtmlReportSingleScan(
+ "some/path", scanResults, null, null, null);
+ assertThat(actual).contains(sdf.format(new Date()));
+ assertThat(actual).doesNotContain("No license problems detected");
+ assertThat(actual).contains("No license conflicts detected");
+ }
+
+ @Test
+ public void testGenerateHtmlReportSingleScan_WithPermittedLicenses() {
+ List scanResults = List.of(fileLicPermitted);
+ String actual =
+ reportBuilder.generateHtmlReportSingleScan(
+ "some/path", scanResults, null, null, null);
+ assertThat(actual).contains(sdf.format(new Date()));
+ assertThat(actual).contains("No license problems detected");
+ assertThat(actual).contains("No license conflicts detected");
+ }
+
+ @Test
+ public void testGenerateHtmlReportSingleScan_WithSimilarLicenses() {
+ List scanResults =
+ List.of(fileLicUnreviewed_1, fileLicUnreviewed_2, fileLicUnreviewed_3);
+ String actual =
+ reportBuilder.generateHtmlReportSingleScan(
+ "some/path", scanResults, new ArrayList<>(), null, null);
+ assertThat(actual).contains(sdf.format(new Date()));
+ assertThat(actual).doesNotContain("No license problems detected");
+ assertThat(actual).contains("No license conflicts detected");
+ }
+
+ @Test
+ void testSaveHTMLToFile() throws IOException {
+ String htmlContent = "Test HTML
";
+ String filePath = "test-output.html";
+
+ saveHTMLToFile(htmlContent, filePath);
+
+ Path path = Paths.get(filePath);
+ assertTrue(Files.exists(path));
+ String fileContent = Files.readString(path);
+ assertEquals(htmlContent, fileContent);
+
+ // Clean up: delete the created file
+ Files.deleteIfExists(path);
+ }
+
+ @Test
+ void saveHTMLToFile_CatchBlock_N() {
+ String htmlContent = "";
+ Path invalidPath = tempDir.resolve("invalid/path/with/special/characters");
+ saveHTMLToFile(htmlContent, invalidPath.toString());
+ assertFalse(Files.exists(invalidPath));
+ }
+}
diff --git a/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java b/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java
index 6fd0c860..c9f72e26 100644
--- a/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java
+++ b/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java
@@ -9,6 +9,7 @@
import com.lpvs.entity.LPVSFile;
import com.lpvs.entity.LPVSLicense;
import com.lpvs.entity.LPVSQueue;
+import com.lpvs.entity.report.LPVSReportBuilder;
import com.lpvs.service.LPVSGitHubConnectionService;
import com.lpvs.service.LPVSGitHubService;
import com.lpvs.service.LPVSLicenseService;
@@ -60,6 +61,7 @@ class TestRunScan__Scanoss {
LPVSLicenseService licenseservice_mock = mock(LPVSLicenseService.class);
LPVSGitHubService githubservice_mock = mock(LPVSGitHubService.class);
LPVSScanServiceFactory scanServiceFactory_mock = mock(LPVSScanServiceFactory.class);
+ LPVSReportBuilder reportBuilder_mock = mock(LPVSReportBuilder.class);
GitHub mockGitHub = mock(GitHub.class);
GHCommitPointer mockCommitPointer = mock(GHCommitPointer.class);
GHRepository mockRepository = mock(GHRepository.class);
@@ -82,7 +84,8 @@ void setUp() throws IOException {
github_mock,
licenseservice_mock,
githubservice_mock,
- scanServiceFactory_mock);
+ scanServiceFactory_mock,
+ reportBuilder_mock);
webhookConfig = new LPVSQueue();
webhookConfig.setId(1L);
@@ -149,7 +152,13 @@ void testRunOneScanPullRequestWithNullTrigger()
lpvsDetectService =
spy(
new LPVSDetectService(
- "scanoss", false, null, null, null, scanServiceFactory_mock));
+ "scanoss",
+ false,
+ null,
+ null,
+ null,
+ scanServiceFactory_mock,
+ null));
setPrivateField(lpvsDetectService, "trigger", null);
@@ -166,7 +175,13 @@ void testRunOneScanLocalFileWithNullTrigger()
lpvsDetectService =
spy(
new LPVSDetectService(
- "scanoss", false, null, null, null, scanServiceFactory_mock));
+ "scanoss",
+ false,
+ null,
+ null,
+ null,
+ scanServiceFactory_mock,
+ null));
setPrivateField(lpvsDetectService, "localPath", null);
@@ -183,7 +198,13 @@ void testRunOneScanBothPullRequestAndLocalFile()
lpvsDetectService =
spy(
new LPVSDetectService(
- "scanoss", false, null, null, null, scanServiceFactory_mock));
+ "scanoss",
+ false,
+ null,
+ null,
+ null,
+ scanServiceFactory_mock,
+ null));
setPrivateField(lpvsDetectService, "ctx", mockApplicationContext);
setPrivateField(lpvsDetectService, "trigger", "");
@@ -198,7 +219,13 @@ void testRunOneScanBothPullRequestAndLocalFile2()
lpvsDetectService =
spy(
new LPVSDetectService(
- "scanoss", false, null, null, null, scanServiceFactory_mock));
+ "scanoss",
+ false,
+ null,
+ null,
+ null,
+ scanServiceFactory_mock,
+ null));
setPrivateField(lpvsDetectService, "ctx", mockApplicationContext);
setPrivateField(lpvsDetectService, "trigger", "some-pull-request");
@@ -214,7 +241,13 @@ void testRunOneScan_PullRequest_Default()
lpvsDetectService =
spy(
new LPVSDetectService(
- "scanoss", false, null, null, null, scanServiceFactory_mock));
+ "scanoss",
+ false,
+ null,
+ null,
+ null,
+ scanServiceFactory_mock,
+ null));
setPrivateField(lpvsDetectService, "trigger", "fake-trigger-value");
setPrivateField(lpvsDetectService, "ctx", mockApplicationContext);
@@ -235,7 +268,13 @@ void testRunOneScan_PullRequest_Branch2()
lpvsDetectService =
spy(
new LPVSDetectService(
- "scanoss", false, null, null, null, scanServiceFactory_mock));
+ "scanoss",
+ false,
+ null,
+ null,
+ null,
+ scanServiceFactory_mock,
+ null));
// Mock the necessary GitHub objects for LPVSQueue
when(mockGitHub.getRepository(any())).thenReturn(mockRepository);
@@ -284,7 +323,13 @@ void testRunOneScan_Branch3()
lpvsDetectService =
spy(
new LPVSDetectService(
- "scanoss", false, null, null, null, scanServiceFactory_mock));
+ "scanoss",
+ false,
+ null,
+ null,
+ null,
+ scanServiceFactory_mock,
+ null));
setPrivateField(detectService, "trigger", "github/owner/repo/branch/123");
setPrivateField(detectService, "htmlReport", "build");
@@ -302,6 +347,9 @@ void testRunOneScan_Branch3()
.thenReturn(new URL("https://example.com/repo/files"));
when(githubservice_mock.getInternalQueueByPullRequest(anyString()))
.thenReturn(webhookConfig);
+ when(reportBuilder_mock.generateHtmlReportSingleScan(
+ anyString(), anyList(), anyList(), any(), any()))
+ .thenReturn("");
// Set up expected values
String expectedPullRequestUrl = "https://example.com/pull/1";
@@ -331,7 +379,13 @@ void testRunOneScan_LocalFiles_WithConsoleReport()
lpvsDetectService =
spy(
new LPVSDetectService(
- "scanoss", false, null, null, null, scanServiceFactory_mock));
+ "scanoss",
+ false,
+ null,
+ null,
+ null,
+ scanServiceFactory_mock,
+ null));
File sourceDir = Files.createTempDirectory("source").toFile();
File sourceFile1 = new File(sourceDir, "file1.txt");
@@ -381,7 +435,13 @@ void testRunOneScan_LocalFiles_WithHtmlReport()
lpvsDetectService =
spy(
new LPVSDetectService(
- "scanoss", false, null, null, null, scanServiceFactory_mock));
+ "scanoss",
+ false,
+ null,
+ null,
+ null,
+ scanServiceFactory_mock,
+ null));
File sourceDir = Files.createTempDirectory("source").toFile();
File sourceFile1 = new File(sourceDir, "file1.txt");
@@ -407,6 +467,9 @@ void testRunOneScan_LocalFiles_WithHtmlReport()
.thenReturn(new URL("https://example.com/repo/files"));
when(githubservice_mock.getInternalQueueByPullRequest(anyString()))
.thenReturn(webhookConfig);
+ when(reportBuilder_mock.generateHtmlReportSingleScan(
+ anyString(), anyList(), anyList(), any(), any()))
+ .thenReturn("");
// Set up expected values
String expectedPullRequestUrl = "https://example.com/pull/1";
@@ -437,7 +500,13 @@ void testRunOneScan_LocalFiles_NoFile()
lpvsDetectService =
spy(
new LPVSDetectService(
- "scanoss", false, null, null, null, scanServiceFactory_mock));
+ "scanoss",
+ false,
+ null,
+ null,
+ null,
+ scanServiceFactory_mock,
+ null));
File sourceDir = Files.createTempDirectory("source").toFile();
File sourceFile1 = new File(sourceDir, "file1.txt");
@@ -511,6 +580,9 @@ void testRunOneScan_TriggerNotNull() throws Exception {
.thenReturn(new URL("https://example.com/repo/files"));
when(githubservice_mock.getInternalQueueByPullRequest(anyString()))
.thenReturn(webhookConfig);
+ when(reportBuilder_mock.generateHtmlReportSingleScan(
+ anyString(), anyList(), anyList(), any(), any()))
+ .thenReturn("");
// Set up expected values
String expectedPullRequestUrl = "https://example.com/pull/1";
@@ -555,6 +627,9 @@ void testRunOneScan_TriggerNotNull_Branch2() throws Exception {
.thenReturn(new URL("https://example.com/repo/files"));
when(githubservice_mock.getInternalQueueByPullRequest(anyString()))
.thenReturn(webhookConfig);
+ when(reportBuilder_mock.generateHtmlReportSingleScan(
+ anyString(), anyList(), anyList(), any(), any()))
+ .thenReturn("");
// Set up expected values
String expectedPullRequestUrl = "https://example.com/pull/1";
@@ -598,6 +673,9 @@ void testRunOneScan_TriggerNotNull_Branch3() throws Exception {
when(mockCommitPointer.getRepository()).thenReturn(mockHeadRepository2);
when(githubservice_mock.getInternalQueueByPullRequest(anyString()))
.thenReturn(webhookConfig);
+ when(reportBuilder_mock.generateHtmlReportSingleScan(
+ anyString(), anyList(), anyList(), any(), any()))
+ .thenReturn("");
// Set up expected values
String expectedPullRequestUrl = "https://example.com/pull/1";
@@ -639,6 +717,9 @@ void testRunOneScan_TriggerNotNull_NoDirectory() throws Exception {
when(mockCommitPointer.getRepository()).thenReturn(mockHeadRepository2);
when(githubservice_mock.getInternalQueueByPullRequest(anyString()))
.thenReturn(webhookConfig);
+ when(reportBuilder_mock.generateHtmlReportSingleScan(
+ anyString(), anyList(), anyList(), any(), any()))
+ .thenReturn("");
// Set up expected values
String expectedPullRequestUrl = "https://example.com/pull/1";
@@ -667,11 +748,8 @@ void testCommentBuilder_ConflictFilePresent() {
List scanResults = new ArrayList<>();
String commentGitHub =
LPVSCommentUtil.reportCommentBuilder(webhookConfig, scanResults, expected);
- String commentHTML =
- LPVSCommentUtil.buildHTMLComment(webhookConfig, scanResults, expected);
assertNotNull(commentGitHub);
- assertNotNull(commentHTML);
}
@Test
@@ -681,11 +759,8 @@ void testCommentBuilder_NoConflictNoLicense() {
List scanResults = new ArrayList<>();
String commentGitHub =
LPVSCommentUtil.reportCommentBuilder(webhookConfig, scanResults, expected);
- String commentHTML =
- LPVSCommentUtil.buildHTMLComment(webhookConfig, scanResults, expected);
assertEquals(commentGitHub, "");
- assertEquals(commentHTML, "");
}
@Test
@@ -737,6 +812,7 @@ class TestRunScan__ScanossException {
LPVSLicenseService licenseservice_mock = mock(LPVSLicenseService.class);
LPVSGitHubService githubservice_mock = mock(LPVSGitHubService.class);
LPVSScanServiceFactory scanServiceFactory_mock = mock(LPVSScanServiceFactory.class);
+ LPVSReportBuilder reportBuilder_mock = mock(LPVSReportBuilder.class);
LPVSQueue webhookConfig;
final String test_path = "test_path";
@@ -751,7 +827,8 @@ void setUp() {
github_mock,
licenseservice_mock,
githubservice_mock,
- scanServiceFactory_mock);
+ scanServiceFactory_mock,
+ reportBuilder_mock);
webhookConfig = new LPVSQueue();
webhookConfig.setId(1L);
@@ -801,7 +878,7 @@ class TestRunScan__NotScanoss {
void setUp() {
detectService =
new LPVSDetectService(
- "not_scanoss", false, null, null, null, scanServiceFactory_mock);
+ "not_scanoss", false, null, null, null, scanServiceFactory_mock, null);
}
@Test
diff --git a/src/test/java/com/lpvs/util/LPVSCommentUtilTest.java b/src/test/java/com/lpvs/util/LPVSCommentUtilTest.java
index c94a99d0..0c7a2490 100644
--- a/src/test/java/com/lpvs/util/LPVSCommentUtilTest.java
+++ b/src/test/java/com/lpvs/util/LPVSCommentUtilTest.java
@@ -20,11 +20,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -152,48 +148,4 @@ void testReportCommentBuilder_HubLink() {
assertNotNull(comment);
}
-
- @Test
- void testBuildHTMLComment() {
- LPVSQueue webhookConfig = new LPVSQueue();
- List scanResults = new ArrayList<>();
- scanResults.add(createSampleFile("testPath1", "test1"));
- List> conflicts = new ArrayList<>();
-
- String htmlComment =
- LPVSCommentUtil.buildHTMLComment(webhookConfig, scanResults, conflicts);
-
- assertNotNull(htmlComment);
- }
-
- @Test
- void testBuildHTMLComment_HubLink() {
- LPVSQueue webhookConfig = new LPVSQueue();
- List scanResults = new ArrayList<>();
- scanResults.add(createSampleFile("testPath1", "test1"));
- LPVSLicenseService.Conflict conflict_1 =
- new LPVSLicenseService.Conflict<>("MIT", "Apache-2.0");
- List> conflicts =
- List.of(conflict_1, conflict_1);
- webhookConfig.setHubLink("some_link");
- String htmlComment =
- LPVSCommentUtil.buildHTMLComment(webhookConfig, scanResults, conflicts);
-
- assertNotNull(htmlComment);
- }
-
- @Test
- void testSaveHTMLToFile() throws IOException {
- String htmlContent = "Test HTML
";
- String filePath = "test-output.html";
-
- LPVSCommentUtil.saveHTMLToFile(htmlContent, filePath);
-
- assertTrue(Files.exists(Paths.get(filePath)));
- String fileContent = Files.readString(Paths.get(filePath));
- assertEquals(htmlContent, fileContent);
-
- // Clean up: delete the created file
- Files.deleteIfExists(Paths.get(filePath));
- }
}