diff --git a/src/main/java/com/lpvs/service/LPVSQueueService.java b/src/main/java/com/lpvs/service/LPVSQueueService.java index 7da3fd32..58fa547c 100644 --- a/src/main/java/com/lpvs/service/LPVSQueueService.java +++ b/src/main/java/com/lpvs/service/LPVSQueueService.java @@ -12,6 +12,7 @@ import com.lpvs.entity.enums.LPVSPullRequestStatus; import com.lpvs.repository.LPVSPullRequestRepository; import com.lpvs.repository.LPVSQueueRepository; +import com.lpvs.service.scan.LPVSDetectService; import com.lpvs.util.LPVSWebhookUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/com/lpvs/service/LPVSDetectService.java b/src/main/java/com/lpvs/service/scan/LPVSDetectService.java similarity index 84% rename from src/main/java/com/lpvs/service/LPVSDetectService.java rename to src/main/java/com/lpvs/service/scan/LPVSDetectService.java index 119fc187..a162f4b6 100644 --- a/src/main/java/com/lpvs/service/LPVSDetectService.java +++ b/src/main/java/com/lpvs/service/scan/LPVSDetectService.java @@ -4,7 +4,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. */ -package com.lpvs.service; +package com.lpvs.service.scan; import java.nio.file.Files; import java.nio.file.Path; @@ -12,6 +12,9 @@ import java.util.ArrayList; import java.util.List; +import com.lpvs.service.LPVSGitHubConnectionService; +import com.lpvs.service.LPVSGitHubService; +import com.lpvs.service.LPVSLicenseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; @@ -23,10 +26,8 @@ import com.lpvs.entity.LPVSFile; import com.lpvs.entity.LPVSQueue; -import com.lpvs.service.scanner.scanoss.LPVSScanossDetectService; import com.lpvs.util.LPVSCommentUtil; -import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; /** @@ -36,16 +37,6 @@ @Slf4j public class LPVSDetectService { - /** - * The type of license detection scanner. - */ - private String scannerType; - - /** - * Service responsible for performing license detection using the ScanOSS scanner. - */ - private LPVSScanossDetectService scanossDetectService; - /** * Service responsible for establishing and managing connections to the GitHub API. */ @@ -61,6 +52,11 @@ public class LPVSDetectService { */ private LPVSGitHubService gitHubService; + /** + * Service responsible for initialization of the scanner. + */ + private LPVSScanService scanService; + /** * GitHub pull request used to trigger a single license scan (optional). */ @@ -82,29 +78,24 @@ public class LPVSDetectService { * Constructs an instance of LPVSDetectService with the specified parameters. * * @param scannerType The type of license detection scanner. + * @param isInternal Flag indicating whether the scanner is internal or not. * @param gitHubConnectionService Service for connecting to the GitHub API. - * @param scanossDetectService Service for license detection using ScanOSS. * @param licenseService Service for license conflict analysis. * @param gitHubService Service for GitHub connection and operation. + * @param scanServiceFactory Service for creating instance of the scanner. */ + @Autowired public LPVSDetectService( @Value("${scanner:scanoss}") String scannerType, + @Value("${internal:false}") boolean isInternal, LPVSGitHubConnectionService gitHubConnectionService, - LPVSScanossDetectService scanossDetectService, LPVSLicenseService licenseService, - LPVSGitHubService gitHubService) { - this.scannerType = scannerType; + LPVSGitHubService gitHubService, + LPVSScanServiceFactory scanServiceFactory) { this.gitHubConnectionService = gitHubConnectionService; - this.scanossDetectService = scanossDetectService; this.licenseService = licenseService; this.gitHubService = gitHubService; - } - - /** - * Initializes the LPVSDetectService bean and logs the selected license detection scanner. - */ - @PostConstruct - private void init() { + this.scanService = scanServiceFactory.createScanService(scannerType, isInternal); log.info("License detection scanner: " + scannerType); } @@ -166,10 +157,12 @@ public void runOneScan() { * @throws Exception if an error occurs during the scan. */ public List runScan(LPVSQueue webhookConfig, String path) throws Exception { - if (scannerType.equals("scanoss")) { - scanossDetectService.runScan(webhookConfig, path); - return scanossDetectService.checkLicenses(webhookConfig); + try { + scanService.runScan(webhookConfig, path); + return scanService.checkLicenses(webhookConfig); + } catch (IllegalArgumentException | NullPointerException ex) { + log.error(ex.getMessage()); + return new ArrayList<>(); } - return new ArrayList<>(); } } diff --git a/src/main/java/com/lpvs/service/scan/LPVSScanService.java b/src/main/java/com/lpvs/service/scan/LPVSScanService.java new file mode 100644 index 00000000..8091c96a --- /dev/null +++ b/src/main/java/com/lpvs/service/scan/LPVSScanService.java @@ -0,0 +1,35 @@ +/** + * 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.service.scan; + +import com.lpvs.entity.LPVSFile; +import com.lpvs.entity.LPVSQueue; + +import java.util.List; + +/** + * Interface representing a service for scanning files and checking licenses. + */ +public interface LPVSScanService { + + /** + * Runs a scan on the specified path using the provided webhook configuration. + * + * @param webhookConfig The webhook configuration to use for the scan. + * @param path The path to the file or directory to scan. + * @throws Exception if an error occurs during the scan process. + */ + void runScan(LPVSQueue webhookConfig, String path) throws Exception; + + /** + * Checks licenses for files using the provided webhook configuration. + * + * @param webhookConfig The webhook configuration to use for checking licenses. + * @return A list of LPVSFile objects representing files with detected licenses. + */ + List checkLicenses(LPVSQueue webhookConfig); +} diff --git a/src/main/java/com/lpvs/service/scan/LPVSScanServiceFactory.java b/src/main/java/com/lpvs/service/scan/LPVSScanServiceFactory.java new file mode 100644 index 00000000..17f0bcac --- /dev/null +++ b/src/main/java/com/lpvs/service/scan/LPVSScanServiceFactory.java @@ -0,0 +1,82 @@ +/** + * 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.service.scan; + +import com.lpvs.repository.LPVSLicenseRepository; +import com.lpvs.service.LPVSLicenseService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.lang.reflect.Constructor; + +/** + * Factory class for creating instances of {@link LPVSScanService}. + */ +@Service +public class LPVSScanServiceFactory { + + /** + * Flag indicating whether the application is in debug mode. + */ + @Value("${debug:false}") + Boolean debug; + + /** + * The service for managing licenses, providing operations related to licenses. + */ + @Autowired LPVSLicenseService licenseService; + + /** + * The repository for LPVSLicense entities, allowing database interactions for licenses. + */ + @Autowired LPVSLicenseRepository lpvsLicenseRepository; + + /** + * Creates a scan service based on the specified scanner type and configuration. + * + * @param scannerType The type of scanner to create. + * @param isInternal Flag indicating whether the scanner is internal or not. + * @return An instance of {@link LPVSScanService} corresponding to the specified scanner type. + * @throws IllegalArgumentException if the specified scanner type is not supported or if an error occurs during + * the creation process. + */ + public LPVSScanService createScanService(String scannerType, boolean isInternal) { + try { + Class serviceClass = Class.forName(getServiceClassName(scannerType, isInternal)); + Constructor constructor = + serviceClass.getDeclaredConstructor( + Boolean.class, LPVSLicenseService.class, LPVSLicenseRepository.class); + return (LPVSScanService) + constructor.newInstance(debug, licenseService, lpvsLicenseRepository); + } catch (Exception e) { + throw new IllegalArgumentException( + "Error creating scan service for type: " + scannerType, e); + } + } + + /** + * Gets the fully qualified class name of the scan service based on the specified scanner type and configuration. + * + * @param scannerType The type of scanner. + * @param isInternal Flag indicating whether the scanner is internal or not. + * @return The fully qualified class name of the scan service. + * @throws IllegalArgumentException if the specified scanner type is null or empty string. + */ + protected String getServiceClassName(String scannerType, boolean isInternal) { + if (scannerType != null && !scannerType.isEmpty()) { + return "com.lpvs." + + (isInternal ? "internal." : "") + + "service.scan.scanner.LPVS" + + scannerType.substring(0, 1).toUpperCase() + + scannerType.substring(1) + + "DetectService"; + } else { + throw new IllegalArgumentException("Scanner type cannot be null or empty."); + } + } +} diff --git a/src/main/java/com/lpvs/service/scan/package-info.java b/src/main/java/com/lpvs/service/scan/package-info.java new file mode 100644 index 00000000..a1aade38 --- /dev/null +++ b/src/main/java/com/lpvs/service/scan/package-info.java @@ -0,0 +1,15 @@ +/** + * 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. + */ + +/** + * Provides services related to scanning operations. + *

+ * This package contains classes and interfaces that define services for performing scanning operations, + * such as checking licenses, and managing scanning configurations. + *

+ */ +package com.lpvs.service.scan; diff --git a/src/main/java/com/lpvs/service/scanner/scanoss/LPVSScanossDetectService.java b/src/main/java/com/lpvs/service/scan/scanner/LPVSScanossDetectService.java similarity index 98% rename from src/main/java/com/lpvs/service/scanner/scanoss/LPVSScanossDetectService.java rename to src/main/java/com/lpvs/service/scan/scanner/LPVSScanossDetectService.java index dfdbc2f1..c63b9346 100644 --- a/src/main/java/com/lpvs/service/scanner/scanoss/LPVSScanossDetectService.java +++ b/src/main/java/com/lpvs/service/scan/scanner/LPVSScanossDetectService.java @@ -4,7 +4,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. */ -package com.lpvs.service.scanner.scanoss; +package com.lpvs.service.scan.scanner; import com.google.gson.*; import com.google.gson.reflect.TypeToken; @@ -13,6 +13,7 @@ import com.lpvs.entity.LPVSQueue; import com.lpvs.repository.LPVSLicenseRepository; import com.lpvs.service.LPVSLicenseService; +import com.lpvs.service.scan.LPVSScanService; import com.lpvs.util.LPVSWebhookUtil; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -29,12 +30,12 @@ import static com.lpvs.util.LPVSFileUtil.getScanResultsJsonFilePath; /** - * Service class responsible for interacting with the Scanoss scanner to detect licenses in files. + * Service class responsible for interacting with the Scanoss scanner to scan licenses in files. * It handles the initiation of the scan, processing scan results, and checking for license conflicts. */ @Service @Slf4j -public class LPVSScanossDetectService { +public class LPVSScanossDetectService implements LPVSScanService { /** * The service for managing licenses, providing operations related to licenses. diff --git a/src/main/java/com/lpvs/service/scanner/scanoss/package-info.java b/src/main/java/com/lpvs/service/scan/scanner/package-info.java similarity index 59% rename from src/main/java/com/lpvs/service/scanner/scanoss/package-info.java rename to src/main/java/com/lpvs/service/scan/scanner/package-info.java index e312517a..0a5f6c91 100644 --- a/src/main/java/com/lpvs/service/scanner/scanoss/package-info.java +++ b/src/main/java/com/lpvs/service/scan/scanner/package-info.java @@ -6,10 +6,9 @@ */ /** - * The {@code scanoss} package contains services and utilities related to the Scanoss scanner integration. - * Scanoss is a tool used for scanning and analyzing open source software components to detect licenses, + * The package contains service related to the Scanoss scanner integration. + * Scanoss is a tool used for scanning and analyzing open source software components to scan licenses, * vulnerabilities, and other relevant information. This package encapsulates functionality for running * Scanoss scans, processing scan results, and handling license-related operations. - * The package also contains utility classes for handling file paths, reading scan results, and managing licenses. */ -package com.lpvs.service.scanner.scanoss; +package com.lpvs.service.scan.scanner; diff --git a/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java b/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java index 39be1a0a..e71ea211 100644 --- a/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java +++ b/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java @@ -14,6 +14,7 @@ import com.lpvs.entity.enums.LPVSPullRequestStatus; import com.lpvs.repository.LPVSPullRequestRepository; import com.lpvs.repository.LPVSQueueRepository; +import com.lpvs.service.scan.LPVSDetectService; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.AfterEach; diff --git a/src/test/java/com/lpvs/service/LPVSDetectServiceTest.java b/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java similarity index 87% rename from src/test/java/com/lpvs/service/LPVSDetectServiceTest.java rename to src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java index d1196c58..092c7e92 100644 --- a/src/test/java/com/lpvs/service/LPVSDetectServiceTest.java +++ b/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java @@ -4,11 +4,14 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. */ -package com.lpvs.service; +package com.lpvs.service.scan; import com.lpvs.entity.LPVSFile; import com.lpvs.entity.LPVSQueue; -import com.lpvs.service.scanner.scanoss.LPVSScanossDetectService; +import com.lpvs.service.LPVSGitHubConnectionService; +import com.lpvs.service.LPVSGitHubService; +import com.lpvs.service.LPVSLicenseService; +import com.lpvs.service.scan.scanner.LPVSScanossDetectService; import com.lpvs.util.LPVSCommentUtil; import com.lpvs.util.LPVSFileUtil; @@ -23,14 +26,10 @@ import org.kohsuke.github.GHPullRequest; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; -import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.io.IOException; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -47,27 +46,7 @@ @ExtendWith(MockitoExtension.class) public class LPVSDetectServiceTest { - @Mock private LPVSScanossDetectService scanossDetectService; - - @InjectMocks private LPVSDetectService lpvsDetectService; - - @Nested - class TestInit { - final LPVSDetectService detectService = - new LPVSDetectService("scanoss", null, null, null, null); - - @Test - public void testInit() { - try { - Method init_method = detectService.getClass().getDeclaredMethod("init"); - init_method.setAccessible(true); - init_method.invoke(detectService); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - log.error("LPVSDetectServiceTest::TestInit exception: " + e); - fail(); - } - } - } + private LPVSDetectService lpvsDetectService; @Nested class TestRunScan__Scanoss { @@ -76,6 +55,7 @@ class TestRunScan__Scanoss { LPVSScanossDetectService scanoss_mock = mock(LPVSScanossDetectService.class); LPVSLicenseService licenseservice_mock = mock(LPVSLicenseService.class); LPVSGitHubService githubservice_mock = mock(LPVSGitHubService.class); + LPVSScanServiceFactory scanServiceFactory_mock = mock(LPVSScanServiceFactory.class); GitHub mockGitHub = mock(GitHub.class); GHCommitPointer mockCommitPointer = mock(GHCommitPointer.class); GHRepository mockRepository = mock(GHRepository.class); @@ -93,10 +73,11 @@ void setUp() throws IOException { detectService = new LPVSDetectService( "scanoss", + false, github_mock, - scanoss_mock, licenseservice_mock, - githubservice_mock); + githubservice_mock, + scanServiceFactory_mock); webhookConfig = new LPVSQueue(); webhookConfig.setId(1L); @@ -117,9 +98,11 @@ void setUp() throws IOException { } @Test - void testRunOneScanWithNullTriger() throws NoSuchFieldException, IllegalAccessException { + void testRunOneScanWithNullTrigger() throws NoSuchFieldException, IllegalAccessException { lpvsDetectService = - spy(new LPVSDetectService("scanoss", null, scanossDetectService, null, null)); + spy( + new LPVSDetectService( + "scanoss", false, null, null, null, scanServiceFactory_mock)); setPrivateField(lpvsDetectService, "trigger", null); @@ -134,7 +117,9 @@ void testRunOneScanWithNullTriger() throws NoSuchFieldException, IllegalAccessEx void testRunOneScan_Default() throws NoSuchFieldException, IllegalAccessException { lpvsDetectService = - spy(new LPVSDetectService("scanoss", null, scanossDetectService, null, null)); + spy( + new LPVSDetectService( + "scanoss", false, null, null, null, scanServiceFactory_mock)); setPrivateField(lpvsDetectService, "trigger", "fake-trigger-value"); setPrivateField(lpvsDetectService, "ctx", mockApplicationContext); @@ -152,7 +137,9 @@ void testRunOneScan_Branch2() List.of(conflict_1, conflict_1); lpvsDetectService = - spy(new LPVSDetectService("scanoss", null, scanossDetectService, null, null)); + spy( + new LPVSDetectService( + "scanoss", false, null, null, null, scanServiceFactory_mock)); // Mock the necessary GitHub objects for LPVSQueue when(mockGitHub.getRepository(any())).thenReturn(mockRepository); @@ -169,7 +156,6 @@ void testRunOneScan_Branch2() when(mockPullRequest.getHtmlUrl()).thenReturn(new URL(expectedPullRequestUrl)); setPrivateField(detectService, "trigger", "github/owner/repo/branch/123"); - setPrivateField(detectService, "scannerType", "scanoss"); setPrivateField(detectService, "htmlReport", null); setPrivateField(detectService, "ctx", mockApplicationContext); @@ -190,10 +176,11 @@ void testRunOneScan_Branch3() List.of(conflict_1, conflict_1); lpvsDetectService = - spy(new LPVSDetectService("scanoss", null, scanossDetectService, null, null)); + spy( + new LPVSDetectService( + "scanoss", false, null, null, null, scanServiceFactory_mock)); setPrivateField(detectService, "trigger", "github/owner/repo/branch/123"); - setPrivateField(detectService, "scannerType", "scanoss"); setPrivateField(detectService, "htmlReport", "build"); setPrivateField(detectService, "ctx", mockApplicationContext); @@ -220,10 +207,10 @@ void testRunOneScan_Branch3() void testRunOneScan_trigerInternalQueueException() throws NoSuchFieldException, IllegalAccessException { - setPrivateField(lpvsDetectService, "trigger", "fake-trigger-value"); - setPrivateField(lpvsDetectService, "ctx", mockApplicationContext); + setPrivateField(detectService, "trigger", "fake-trigger-value"); + setPrivateField(detectService, "ctx", mockApplicationContext); - assertDoesNotThrow(() -> lpvsDetectService.runOneScan()); + assertDoesNotThrow(() -> detectService.runOneScan()); } @Test @@ -236,7 +223,6 @@ void testRunOneScan_TriggerNotNull() throws Exception { List.of(conflict_1, conflict_1); setPrivateField(detectService, "trigger", "github/owner/repo/branch/123"); - setPrivateField(detectService, "scannerType", "scanoss"); setPrivateField(detectService, "htmlReport", "build/report/test.html"); setPrivateField(detectService, "ctx", mockApplicationContext); @@ -269,7 +255,6 @@ void testRunOneScan_TriggerNotNull_Branch2() throws Exception { List.of(conflict_1, conflict_1); setPrivateField(detectService, "trigger", "github/owner/repo/branch/123"); - setPrivateField(detectService, "scannerType", "scanoss"); setPrivateField(detectService, "htmlReport", "build/report/test.html"); setPrivateField(detectService, "ctx", mockApplicationContext); @@ -303,7 +288,6 @@ void testRunOneScan_TriggerNotNull_Branch3() throws Exception { List.of(conflict_1, conflict_1); setPrivateField(detectService, "trigger", "github/owner/repo/branch/123"); - setPrivateField(detectService, "scannerType", "scanoss"); setPrivateField(detectService, "htmlReport", "build/report/test.html"); setPrivateField(detectService, "ctx", mockApplicationContext); @@ -318,7 +302,6 @@ void testRunOneScan_TriggerNotNull_Branch3() throws Exception { // Set up expected values String expectedPullRequestUrl = "https://example.com/pull/1"; when(mockRepository.getHtmlUrl()).thenReturn(new URL(expectedPullRequestUrl)); - // setPrivateField(mockPullRequest, "url", expectedPullRequestUrl); detectService.runOneScan(); @@ -364,6 +347,7 @@ public void testGetPathByPullRequest() { @Test public void testRunScan__Scanoss() { try { + setPrivateField(detectService, "scanService", scanoss_mock); // main test assertEquals( List.of(lpvs_file_1, lpvs_file_2), @@ -392,6 +376,7 @@ class TestRunScan__ScanossException { LPVSScanossDetectService scanoss_mock = mock(LPVSScanossDetectService.class); LPVSLicenseService licenseservice_mock = mock(LPVSLicenseService.class); LPVSGitHubService githubservice_mock = mock(LPVSGitHubService.class); + LPVSScanServiceFactory scanServiceFactory_mock = mock(LPVSScanServiceFactory.class); LPVSQueue webhookConfig; final String test_path = "test_path"; @@ -402,15 +387,17 @@ void setUp() { detectService = new LPVSDetectService( "scanoss", + false, github_mock, - scanoss_mock, licenseservice_mock, - githubservice_mock); + githubservice_mock, + scanServiceFactory_mock); webhookConfig = new LPVSQueue(); webhookConfig.setId(1L); try { + setPrivateField(detectService, "scanService", scanoss_mock); doThrow(new Exception(exc_msg)) .when(scanoss_mock) .runScan(webhookConfig, test_path); @@ -448,9 +435,13 @@ public void testRunScan__ScanossException() { class TestRunScan__NotScanoss { LPVSDetectService detectService; + LPVSScanServiceFactory scanServiceFactory_mock = mock(LPVSScanServiceFactory.class); + @BeforeEach void setUp() { - detectService = new LPVSDetectService("not_scanoss", null, null, null, null); + detectService = + new LPVSDetectService( + "not_scanoss", false, null, null, null, scanServiceFactory_mock); } @Test diff --git a/src/test/java/com/lpvs/service/scan/LPVSScanServiceFactoryTest.java b/src/test/java/com/lpvs/service/scan/LPVSScanServiceFactoryTest.java new file mode 100644 index 00000000..946ef7cd --- /dev/null +++ b/src/test/java/com/lpvs/service/scan/LPVSScanServiceFactoryTest.java @@ -0,0 +1,70 @@ +/** + * 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.service.scan; + +import com.lpvs.service.scan.scanner.LPVSScanossDetectService; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class LPVSScanServiceFactoryTest { + + private LPVSScanServiceFactory scanServiceFactory = new LPVSScanServiceFactory(); + + @Test + void testGetServiceClassName() { + String expected1 = "com.lpvs.internal.service.scan.scanner.LPVSFooDetectService"; + String actual1 = scanServiceFactory.getServiceClassName("foo", true); + assertEquals(expected1, actual1); + + String expected2 = "com.lpvs.service.scan.scanner.LPVSFooDetectService"; + String actual2 = scanServiceFactory.getServiceClassName("foo", false); + assertEquals(expected2, actual2); + } + + @Test + void testGetServiceClassName_NullScannerType_N() { + assertThrows( + IllegalArgumentException.class, + () -> scanServiceFactory.getServiceClassName(null, true)); + } + + @Test + void testGetServiceClassName_EmptyScannerType_N() { + assertThrows( + IllegalArgumentException.class, + () -> scanServiceFactory.getServiceClassName("", true)); + } + + @Test + void testCreateScanService() { + LPVSScanService service = scanServiceFactory.createScanService("scanoss", false); + assertNotNull(service); + assertTrue(service instanceof LPVSScanossDetectService); + } + + @Test + void testCreateScanService_NullScannerType_N() { + assertThrows( + IllegalArgumentException.class, + () -> scanServiceFactory.createScanService(null, true)); + } + + @Test + void testCreateScanService_EmptyScannerType_N() { + assertThrows( + IllegalArgumentException.class, + () -> scanServiceFactory.createScanService("", true)); + } + + @Test + void testCreateScanService_NoSuchScannerType_N() { + assertThrows( + IllegalArgumentException.class, + () -> scanServiceFactory.createScanService("baz", true)); + } +} diff --git a/src/test/java/com/lpvs/service/scanner/scanoss/LPVSScanossDetectServiceTest.java b/src/test/java/com/lpvs/service/scan/scanner/LPVSScanossDetectServiceTest.java similarity index 99% rename from src/test/java/com/lpvs/service/scanner/scanoss/LPVSScanossDetectServiceTest.java rename to src/test/java/com/lpvs/service/scan/scanner/LPVSScanossDetectServiceTest.java index f097bea5..ede7cf9e 100644 --- a/src/test/java/com/lpvs/service/scanner/scanoss/LPVSScanossDetectServiceTest.java +++ b/src/test/java/com/lpvs/service/scan/scanner/LPVSScanossDetectServiceTest.java @@ -4,7 +4,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. */ -package com.lpvs.service.scanner.scanoss; +package com.lpvs.service.scan.scanner; import com.lpvs.entity.LPVSLicense; import com.lpvs.entity.LPVSQueue;