diff --git a/src/main/java/com/lpvs/controller/LPVSWebController.java b/src/main/java/com/lpvs/controller/LPVSWebController.java index e4d9a8bd..ec714f80 100644 --- a/src/main/java/com/lpvs/controller/LPVSWebController.java +++ b/src/main/java/com/lpvs/controller/LPVSWebController.java @@ -242,7 +242,7 @@ public ResponseEntity newHistoryPageByUser( // Validate and sanitize user inputs to prevent XSS attacks sanitizeUserInputs(pr); - Boolean hasIssue = detectedLicenseRepository.existsIssue(pr); + Boolean hasIssue = detectedLicenseRepository.existsByIssueIsTrueAndPullRequest(pr); lpvsHistories.add( new LPVSHistory( @@ -289,11 +289,11 @@ public ResponseEntity resultPage( LPVSPullRequest pr = prOpt.get(); List distinctByLicense = - detectedLicenseRepository.findDistinctByLicense(pr); + detectedLicenseRepository.findDistinctByPullRequestAndLicense(pr); List detectedLicenses = new ArrayList<>(); Map licenseCountMap = new HashMap<>(); - List allSpdxId = licenseRepository.takeAllSpdxId(); + List allSpdxId = licenseRepository.findAllSpdxId(); for (String spdxId : allSpdxId) { licenseCountMap.put(spdxId, 0); } @@ -313,7 +313,7 @@ public ResponseEntity resultPage( detectedLicenseRepository.findByPullRequest(pr, pageable); List dlList = detectedLicenseRepository.findByPullRequest(pr); List lpvsResultFileList = new ArrayList<>(); - Boolean hasIssue = detectedLicenseRepository.existsIssue(pr); + Boolean hasIssue = detectedLicenseRepository.existsByIssueIsTrueAndPullRequest(pr); String licenseSpdxId; String status; @@ -343,7 +343,7 @@ public ResponseEntity resultPage( } } - Long count = detectedLicenseRepository.CountByDetectedLicenseWherePullRequestId(pr); + Long count = detectedLicenseRepository.countByPullRequestAndLicenseIsNotNull(pr); String[] tempPullNumber = pr.getPullRequestUrl().split("/"); LPVSResult lpvsResult = new LPVSResult( diff --git a/src/main/java/com/lpvs/repository/LPVSDetectedLicenseRepository.java b/src/main/java/com/lpvs/repository/LPVSDetectedLicenseRepository.java index 7bd3a925..a9f19084 100644 --- a/src/main/java/com/lpvs/repository/LPVSDetectedLicenseRepository.java +++ b/src/main/java/com/lpvs/repository/LPVSDetectedLicenseRepository.java @@ -12,7 +12,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import java.util.List; @@ -28,10 +27,7 @@ public interface LPVSDetectedLicenseRepository extends JpaRepository0 from LPVSDetectedLicense dl where dl.issue = True and dl.pullRequest = :pr") - Boolean existsIssue(@Param("pr") LPVSPullRequest pr); + Boolean existsByIssueIsTrueAndPullRequest(@Param("pr") LPVSPullRequest pr); /** * Find all detected licenses associated with a specific pull request. @@ -56,10 +52,7 @@ public interface LPVSDetectedLicenseRepository extends JpaRepository findDistinctByLicense(@Param("pr") LPVSPullRequest pr); + List findDistinctByPullRequestAndLicense(@Param("pr") LPVSPullRequest pr); /** * Find detected licenses associated with a specific pull request where the license is not null. @@ -78,8 +68,5 @@ public interface LPVSDetectedLicenseRepository extends JpaRepository findNotNullDLByPR(@Param("pr") LPVSPullRequest pr); + List findByPullRequestAndLicenseIsNotNull(@Param("pr") LPVSPullRequest pr); } diff --git a/src/main/java/com/lpvs/repository/LPVSLicenseConflictRepository.java b/src/main/java/com/lpvs/repository/LPVSLicenseConflictRepository.java index 5a636047..a76c4d33 100644 --- a/src/main/java/com/lpvs/repository/LPVSLicenseConflictRepository.java +++ b/src/main/java/com/lpvs/repository/LPVSLicenseConflictRepository.java @@ -12,7 +12,6 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import java.util.List; /** * Repository interface for managing {@link LPVSLicenseConflict} entities. @@ -21,14 +20,6 @@ @Repository public interface LPVSLicenseConflictRepository extends JpaRepository { - /** - * Retrieve all license conflicts from the database. - * - * @return List of {@link LPVSLicenseConflict} entities representing license conflicts. - */ - @Query("SELECT lc FROM LPVSLicenseConflict lc") - List takeAllLicenseConflicts(); - /** * Find a specific license conflict between two licenses. * diff --git a/src/main/java/com/lpvs/repository/LPVSLicenseRepository.java b/src/main/java/com/lpvs/repository/LPVSLicenseRepository.java index 0a86338d..80e0815f 100644 --- a/src/main/java/com/lpvs/repository/LPVSLicenseRepository.java +++ b/src/main/java/com/lpvs/repository/LPVSLicenseRepository.java @@ -21,22 +21,13 @@ @Repository public interface LPVSLicenseRepository extends JpaRepository { - /** - * Retrieve all licenses from the database. - * - * @return List of {@link LPVSLicense} entities representing licenses. - */ - @Query("SELECT l FROM LPVSLicense l") - List takeAllLicenses(); - /** * Search for a license by SPDX identifier. * * @param spdxId The SPDX identifier of the license. * @return The latest {@link LPVSLicense} entity with the specified SPDX identifier. */ - @Query("SELECT l FROM LPVSLicense l WHERE l.spdxId = :spdxId ORDER BY l.id DESC LIMIT 1") - LPVSLicense searchBySpdxId(@Param("spdxId") String spdxId); + LPVSLicense findFirstBySpdxIdOrderByIdDesc(@Param("spdxId") String spdxId); /** * Search for a license by alternative license names. @@ -54,6 +45,5 @@ public interface LPVSLicenseRepository extends JpaRepository * * @return List of SPDX identifiers as Strings. */ - @Query(value = "select licenses.spdxId from LPVSLicense licenses") - List takeAllSpdxId(); + List findAllSpdxId(); } diff --git a/src/main/java/com/lpvs/repository/LPVSPullRequestRepository.java b/src/main/java/com/lpvs/repository/LPVSPullRequestRepository.java index fefde0b1..945f0efa 100644 --- a/src/main/java/com/lpvs/repository/LPVSPullRequestRepository.java +++ b/src/main/java/com/lpvs/repository/LPVSPullRequestRepository.java @@ -60,7 +60,6 @@ LPVSPullRequest findLatestByPullRequestInfo( * @param pageable The pagination information. * @return Page of {@link LPVSPullRequest} entities with the specified base name. */ - @Query(value = "select pr from LPVSPullRequest pr where pr.pullRequestBase = :name") Page findByPullRequestBase(@Param("name") String name, Pageable pageable); /** @@ -69,7 +68,6 @@ LPVSPullRequest findLatestByPullRequestInfo( * @param name The name of the pull request base. * @return List of {@link LPVSPullRequest} entities with the specified base name. */ - @Query(value = "select pr from LPVSPullRequest pr where pr.pullRequestBase = :name") List findByPullRequestBase(@Param("name") String name); /** @@ -78,8 +76,7 @@ LPVSPullRequest findLatestByPullRequestInfo( * @param name The name of the pull request base. * @return The count of pull requests with the specified base name. */ - @Query(value = "select count(*) from LPVSPullRequest pr where pr.pullRequestBase = :name") - Long CountByPullRequestBase(@Param("name") String name); + Long countByPullRequestBase(@Param("name") String name); /** * Find all pull requests with the specified sender or pull request head, paginated. @@ -88,9 +85,6 @@ LPVSPullRequest findLatestByPullRequestInfo( * @param pageable The pagination information. * @return Page of {@link LPVSPullRequest} entities with the specified sender or pull request head. */ - @Query( - value = - "select pr from LPVSPullRequest pr where pr.sender = :name or pr.pullRequestHead = :name") Page findBySenderOrPullRequestHead( @Param("name") String name, Pageable pageable); @@ -100,9 +94,6 @@ Page findBySenderOrPullRequestHead( * @param name The name of the sender or pull request head. * @return List of {@link LPVSPullRequest} entities with the specified sender or pull request head. */ - @Query( - value = - "select pr from LPVSPullRequest pr where pr.sender = :name or pr.pullRequestHead = :name") List findBySenderOrPullRequestHead(@Param("name") String name); /** @@ -111,8 +102,5 @@ Page findBySenderOrPullRequestHead( * @param name The name of the sender or pull request head. * @return The count of pull requests with the specified sender or pull request head. */ - @Query( - value = - "select count(*) from LPVSPullRequest pr where pr.sender = :name or pr.pullRequestHead = :name") - Long CountBySenderOrPullRequestHead(@Param("name") String name); + Long countBySenderOrPullRequestHead(@Param("name") String name); } diff --git a/src/main/java/com/lpvs/repository/LPVSQueueRepository.java b/src/main/java/com/lpvs/repository/LPVSQueueRepository.java index 7d43e3ac..f7a41556 100644 --- a/src/main/java/com/lpvs/repository/LPVSQueueRepository.java +++ b/src/main/java/com/lpvs/repository/LPVSQueueRepository.java @@ -8,21 +8,10 @@ import com.lpvs.entity.LPVSQueue; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import java.util.List; /** * Repository interface for managing {@link LPVSQueue} entities. * Extends {@link org.springframework.data.jpa.repository.JpaRepository} for basic CRUD operations. */ -public interface LPVSQueueRepository extends JpaRepository { - - /** - * Retrieve the list of all entities from the "lpvs_queue" table. - * - * @return List of {@link LPVSQueue} entities representing the queue. - */ - @Query("SELECT q FROM LPVSQueue q") - List getQueueList(); -} +public interface LPVSQueueRepository extends JpaRepository {} diff --git a/src/main/java/com/lpvs/service/LPVSGitHubService.java b/src/main/java/com/lpvs/service/LPVSGitHubService.java index 1df181fd..1b8668ee 100644 --- a/src/main/java/com/lpvs/service/LPVSGitHubService.java +++ b/src/main/java/com/lpvs/service/LPVSGitHubService.java @@ -307,13 +307,19 @@ public void commentResults( commitCommentBuilder.append("
  • " + conflict.l1 + " and " + conflict.l2 + "
  • "); LPVSDetectedLicense detectedIssue = new LPVSDetectedLicense(); detectedIssue.setPullRequest(lpvsPullRequest); - Long l1 = lpvsLicenseRepository.searchBySpdxId(conflict.l1).getLicenseId(); - Long l2 = lpvsLicenseRepository.searchBySpdxId(conflict.l2).getLicenseId(); + Long l1 = + lpvsLicenseRepository + .findFirstBySpdxIdOrderByIdDesc(conflict.l1) + .getLicenseId(); + Long l2 = + lpvsLicenseRepository + .findFirstBySpdxIdOrderByIdDesc(conflict.l2) + .getLicenseId(); detectedIssue.setLicenseConflict( lpvsLicenseConflictRepository.findLicenseConflict(l1, l2)); if (webhookConfig.getRepositoryLicense() != null) { LPVSLicense repoLicense = - lpvsLicenseRepository.searchBySpdxId( + lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc( webhookConfig.getRepositoryLicense()); if (repoLicense == null) { repoLicense = diff --git a/src/main/java/com/lpvs/service/LPVSLicenseService.java b/src/main/java/com/lpvs/service/LPVSLicenseService.java index efc18bb6..93fdfd42 100644 --- a/src/main/java/com/lpvs/service/LPVSLicenseService.java +++ b/src/main/java/com/lpvs/service/LPVSLicenseService.java @@ -118,8 +118,7 @@ public LPVSLicenseService( * Load all license conflicts from the database. */ private void loadLicenseConflicts() { - List conflicts = - lpvsLicenseConflictRepository.takeAllLicenseConflicts(); + List conflicts = lpvsLicenseConflictRepository.findAll(); for (LPVSLicenseConflict conflict : conflicts) { Conflict conf = new Conflict<>( @@ -155,7 +154,7 @@ private void init() { } else { try { // 1. Load licenses from DB - licenses = lpvsLicenseRepository.takeAllLicenses(); + licenses = lpvsLicenseRepository.findAll(); // print info log.info("LICENSES: loaded " + licenses.size() + " licenses from DB."); @@ -186,7 +185,7 @@ private void init() { */ public void reloadFromTables() { if (licenses.isEmpty()) { - licenses = lpvsLicenseRepository.takeAllLicenses(); + licenses = lpvsLicenseRepository.findAll(); log.info("RELOADED " + licenses.size() + " licenses from DB."); loadLicenseConflicts(); @@ -376,7 +375,8 @@ public List> findConflicts( String repositoryLicense = webhookConfig.getRepositoryLicense(); if (repositoryLicense != null) { - LPVSLicense repoLicense = lpvsLicenseRepository.searchBySpdxId(repositoryLicense); + LPVSLicense repoLicense = + lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(repositoryLicense); if (repoLicense == null) { repoLicense = lpvsLicenseRepository.searchByAlternativeLicenseNames(repositoryLicense); diff --git a/src/main/java/com/lpvs/service/LPVSLoginCheckService.java b/src/main/java/com/lpvs/service/LPVSLoginCheckService.java index 9a9131b5..e732bbe7 100644 --- a/src/main/java/com/lpvs/service/LPVSLoginCheckService.java +++ b/src/main/java/com/lpvs/service/LPVSLoginCheckService.java @@ -119,10 +119,10 @@ public HistoryPageEntity pathCheck( if ((type.equals("own") && findNickName.equals(name)) || (type.equals("org") && findOrganization.equals(name))) { prPage = lpvsPullRequestRepository.findByPullRequestBase(name, pageable); - count = lpvsPullRequestRepository.CountByPullRequestBase(name); + count = lpvsPullRequestRepository.countByPullRequestBase(name); } else if (type.equals("send") && findNickName.equals(name)) { prPage = lpvsPullRequestRepository.findBySenderOrPullRequestHead(name, pageable); - count = lpvsPullRequestRepository.CountBySenderOrPullRequestHead(name); + count = lpvsPullRequestRepository.countBySenderOrPullRequestHead(name); } else { throw new WrongAccessException("WrongAccessException"); } diff --git a/src/main/java/com/lpvs/service/LPVSQueueService.java b/src/main/java/com/lpvs/service/LPVSQueueService.java index 97a98513..16bf80df 100644 --- a/src/main/java/com/lpvs/service/LPVSQueueService.java +++ b/src/main/java/com/lpvs/service/LPVSQueueService.java @@ -150,7 +150,7 @@ public BlockingDeque getQueue() { public void checkForQueue() throws InterruptedException { QUEUE.clear(); log.debug("Checking for previous queue"); - List webhookConfigList = queueRepository.getQueueList(); + List webhookConfigList = queueRepository.findAll(); for (LPVSQueue webhook : webhookConfigList) { log.info("Add WebHook id = " + webhook.getId() + " to the queue."); QUEUE.putFirst(webhook); diff --git a/src/main/java/com/lpvs/service/LPVSStatisticsService.java b/src/main/java/com/lpvs/service/LPVSStatisticsService.java index 778a55be..683a29f2 100644 --- a/src/main/java/com/lpvs/service/LPVSStatisticsService.java +++ b/src/main/java/com/lpvs/service/LPVSStatisticsService.java @@ -128,7 +128,7 @@ public Dashboard getDashboardEntity(String type, String name, Authentication aut List dashboardByDates = new ArrayList<>(); Map> datePrMap = new HashMap<>(); - List allSpdxId = lpvsLicenseRepository.takeAllSpdxId(); + List allSpdxId = lpvsLicenseRepository.findAllSpdxId(); for (String spdxId : allSpdxId) { licenseCountMap.put(spdxId, 0); } @@ -159,7 +159,7 @@ public Dashboard getDashboardEntity(String type, String name, Authentication aut Set senderSet = new HashSet<>(); for (LPVSPullRequest pr : entry.getValue()) { List dlList = - lpvsDetectedLicenseRepository.findNotNullDLByPR(pr); + lpvsDetectedLicenseRepository.findByPullRequestAndLicenseIsNotNull(pr); if (!(pr.getRepositoryName() == null || pr.getRepositoryName().isEmpty())) { senderSet.add(pr.getSender()); } diff --git a/src/test/java/com/lpvs/controller/LPVSWebControllerTest.java b/src/test/java/com/lpvs/controller/LPVSWebControllerTest.java index 4c339967..2e2df94e 100644 --- a/src/test/java/com/lpvs/controller/LPVSWebControllerTest.java +++ b/src/test/java/com/lpvs/controller/LPVSWebControllerTest.java @@ -167,7 +167,8 @@ public void testNewHistoryPageByUser() { when(loginCheckService.pathCheck(type, name, pageable, authentication)) .thenReturn(new HistoryPageEntity(prPage, 1L)); - when(detectedLicenseRepository.existsIssue(pullRequest)).thenReturn(false); + when(detectedLicenseRepository.existsByIssueIsTrueAndPullRequest(pullRequest)) + .thenReturn(false); HistoryEntity result = webController.new WebApiEndpoints() @@ -229,12 +230,13 @@ public void testResultPage() { when(loginCheckService.getMemberFromMemberMap(authentication)).thenReturn(new LPVSMember()); when(lpvsPullRequestRepository.findById(prId)).thenReturn(Optional.of(pullRequest)); - when(detectedLicenseRepository.findDistinctByLicense(pullRequest)).thenReturn(licenses); - when(licenseRepository.takeAllSpdxId()).thenReturn(List.of("MIT", "Apache-2.0")); + when(detectedLicenseRepository.findDistinctByPullRequestAndLicense(pullRequest)) + .thenReturn(licenses); + when(licenseRepository.findAllSpdxId()).thenReturn(List.of("MIT", "Apache-2.0")); when(detectedLicenseRepository.findByPullRequest(pullRequest, pageable)) .thenReturn(new PageImpl<>(detectedLicenses)); when(detectedLicenseRepository.findByPullRequest(pullRequest)).thenReturn(detectedLicenses); - when(detectedLicenseRepository.CountByDetectedLicenseWherePullRequestId(pullRequest)) + when(detectedLicenseRepository.countByPullRequestAndLicenseIsNotNull(pullRequest)) .thenReturn(1L); LPVSResult result = diff --git a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java index ed0fb87d..010f123b 100644 --- a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java +++ b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java @@ -2255,7 +2255,7 @@ void setUp() { null); conflict_1 = new LPVSLicenseService.Conflict<>(conflict_1_l1, conflict_1_l2); - when(mocked_lpvsLicenseRepository.searchBySpdxId(anyString())) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) .thenReturn(lpvs_license_1); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())) .thenReturn(null); @@ -2310,7 +2310,7 @@ public void testCommentResults__ProhibitedPresentConflictsPresentLicensePresent( throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_1); - when(mocked_lpvsLicenseRepository.searchBySpdxId(spdx_id_1)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_1)) .thenReturn( new LPVSLicense( 1L, @@ -2369,7 +2369,8 @@ public void testCommentResults__ProhibitedPresentConflictsPresentLicensePresentA throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_2); - when(mocked_lpvsLicenseRepository.searchBySpdxId(spdx_id_2)).thenReturn(null); + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_2)) + .thenReturn(null); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(spdx_id_2)) .thenReturn( new LPVSLicense( @@ -2584,7 +2585,7 @@ void setUp() { null); conflict_1 = new LPVSLicenseService.Conflict<>(conflict_1_l1, conflict_1_l2); - when(mocked_lpvsLicenseRepository.searchBySpdxId(anyString())) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) .thenReturn(lpvs_license_1); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())) .thenReturn(null); @@ -2639,7 +2640,7 @@ public void testCommentResults__EmptyPresentConflictsPresentLicensePresent() throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_1); - when(mocked_lpvsLicenseRepository.searchBySpdxId(spdx_id_1)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_1)) .thenReturn( new LPVSLicense( 1L, @@ -2698,7 +2699,8 @@ public void testCommentResults__EmptyPresentConflictsPresentLicensePresentAlt() throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_2); - when(mocked_lpvsLicenseRepository.searchBySpdxId(spdx_id_2)).thenReturn(null); + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_2)) + .thenReturn(null); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(spdx_id_2)) .thenReturn( new LPVSLicense( @@ -2916,7 +2918,7 @@ void setUp() { null); conflict_1 = new LPVSLicenseService.Conflict<>(conflict_1_l1, conflict_1_l2); - when(mocked_lpvsLicenseRepository.searchBySpdxId(anyString())) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) .thenReturn(lpvs_license_1); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())) .thenReturn(null); @@ -2971,7 +2973,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresent( throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_1); - when(mocked_lpvsLicenseRepository.searchBySpdxId(spdx_id_1)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_1)) .thenReturn( new LPVSLicense( 1L, @@ -3030,7 +3032,8 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresentA throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_2); - when(mocked_lpvsLicenseRepository.searchBySpdxId(spdx_id_2)).thenReturn(null); + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_2)) + .thenReturn(null); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(spdx_id_2)) .thenReturn( new LPVSLicense( @@ -3248,7 +3251,7 @@ void setUp() { null); conflict_1 = new LPVSLicenseService.Conflict<>(conflict_1_l1, conflict_1_l2); - when(mocked_lpvsLicenseRepository.searchBySpdxId(anyString())) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) .thenReturn(lpvs_license_1); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())) .thenReturn(null); @@ -3303,7 +3306,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresent( throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_1); - when(mocked_lpvsLicenseRepository.searchBySpdxId(spdx_id_1)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_1)) .thenReturn( new LPVSLicense( 1L, @@ -3362,7 +3365,8 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresentA throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_2); - when(mocked_lpvsLicenseRepository.searchBySpdxId(spdx_id_2)).thenReturn(null); + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_2)) + .thenReturn(null); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(spdx_id_2)) .thenReturn( new LPVSLicense( @@ -4294,7 +4298,7 @@ public void testCommentResults() throws Exception { } }; Mockito.when(repository.getPullRequests(GHIssueState.OPEN)).thenReturn(pullRequestList); - Mockito.when(mocked_lpvsLicenseRepository.searchBySpdxId(anyString())) + Mockito.when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) .thenReturn(license); gh_service.commentResults(webhookConfig, fileList, conflictList, lpvsPullRequest); diff --git a/src/test/java/com/lpvs/service/LPVSLicenseServiceTest.java b/src/test/java/com/lpvs/service/LPVSLicenseServiceTest.java index ff85c69e..9e7f50f9 100644 --- a/src/test/java/com/lpvs/service/LPVSLicenseServiceTest.java +++ b/src/test/java/com/lpvs/service/LPVSLicenseServiceTest.java @@ -155,7 +155,7 @@ public void testFindConflicts() { LPVSLicenseRepository lpvsLicenseRepository = Mockito.mock(LPVSLicenseRepository.class); ReflectionTestUtils.setField( licenseService, "lpvsLicenseRepository", lpvsLicenseRepository); - when(lpvsLicenseRepository.searchBySpdxId(anyString())).thenReturn(null); + when(lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())).thenReturn(null); when(lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())).thenReturn(null); Assertions.assertNotNull(licenseService.findConflicts(webhookConfig, fileList)); @@ -210,7 +210,7 @@ public void testInitDB() { List licenseList = new ArrayList<>(); licenseList.add(license1); licenseList.add(license2); - Mockito.when(lpvsLicenseRepository.takeAllLicenses()).thenReturn(licenseList); + Mockito.when(lpvsLicenseRepository.findAll()).thenReturn(licenseList); LPVSLicenseConflict licenseConflict = new LPVSLicenseConflict(); licenseConflict.setConflictId(1L); @@ -218,7 +218,7 @@ public void testInitDB() { licenseConflict.setRepositoryLicense(license2); List licenseConflictList = new ArrayList<>(); licenseConflictList.add(licenseConflict); - Mockito.when(lpvsLicenseConflictRepository.takeAllLicenseConflicts()) + Mockito.when(lpvsLicenseConflictRepository.findAll()) .thenReturn(licenseConflictList); Field lpvsLicenseRepositoryField = @@ -273,7 +273,7 @@ public void testReloadFromTables() licenseList.add(license1); licenseList.add(license2); - when(lpvsLicenseRepository.takeAllLicenses()).thenReturn(licenseList); + when(lpvsLicenseRepository.findAll()).thenReturn(licenseList); LPVSLicenseConflict licenseConflict = new LPVSLicenseConflict(); licenseConflict.setConflictId(1L); @@ -282,8 +282,7 @@ public void testReloadFromTables() List licenseConflictList = new ArrayList<>(); licenseConflictList.add(licenseConflict); - when(lpvsLicenseConflictRepository.takeAllLicenseConflicts()) - .thenReturn(licenseConflictList); + when(lpvsLicenseConflictRepository.findAll()).thenReturn(licenseConflictList); Field lpvsLicenseRepositoryField = LPVSLicenseService.class.getDeclaredField("lpvsLicenseRepository"); @@ -443,7 +442,8 @@ void setUp() throws NoSuchFieldException, IllegalAccessException { null, null); - when(lpvsLicenseRepository.searchBySpdxId(anyString())).thenReturn(null); + when(lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) + .thenReturn(null); when(lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())) .thenReturn(lpvs_license_1); diff --git a/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java b/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java index e718d1b0..302295fa 100644 --- a/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java +++ b/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java @@ -881,7 +881,7 @@ public void testCheckForQueue() { LPVSQueue webhookConfig = new LPVSQueue(); webhookConfig.setAttempts(100); webhookConfig.setDate(new Date()); - when(mocked_queueRepository.getQueueList()).thenReturn(List.of(webhookConfig)); + when(mocked_queueRepository.findAll()).thenReturn(List.of(webhookConfig)); assertDoesNotThrow(() -> queueService.checkForQueue()); } diff --git a/src/test/java/com/lpvs/service/LPVSStatisticsServiceTest.java b/src/test/java/com/lpvs/service/LPVSStatisticsServiceTest.java index ee6aaf15..c907bcec 100644 --- a/src/test/java/com/lpvs/service/LPVSStatisticsServiceTest.java +++ b/src/test/java/com/lpvs/service/LPVSStatisticsServiceTest.java @@ -171,11 +171,11 @@ public void testGetDashboardEntity(String match) { member.setNickname("testNickname"); when(loginCheckService.getMemberFromMemberMap(authentication)).thenReturn(member); when(pullRequestRepository.findByPullRequestBase("testNickname")).thenReturn(pullRequests); - when(licenseRepository.takeAllSpdxId()).thenReturn(Collections.singletonList("MIT")); + when(licenseRepository.findAllSpdxId()).thenReturn(Collections.singletonList("MIT")); when(mockRequest.getDate()).thenReturn(new Date()); when(mockRequest.getSender()).thenReturn(""); when(mockRequest.getRepositoryName()).thenReturn("name"); - when(detectedLicenseRepository.findNotNullDLByPR(mockRequest)) + when(detectedLicenseRepository.findByPullRequestAndLicenseIsNotNull(mockRequest)) .thenReturn( new ArrayList<>() { { @@ -196,9 +196,10 @@ public void testGetDashboardEntityWithDummyPRList() { member.setNickname("testNickname"); List prList = createMockPullRequestList(); List dlList = Collections.emptyList(); - when(licenseRepository.takeAllSpdxId()).thenReturn(Collections.emptyList()); + when(licenseRepository.findAllSpdxId()).thenReturn(Collections.emptyList()); when(pullRequestRepository.findByPullRequestBase("testNickname")).thenReturn(prList); - when(detectedLicenseRepository.findNotNullDLByPR(any())).thenReturn(dlList); + when(detectedLicenseRepository.findByPullRequestAndLicenseIsNotNull(any())) + .thenReturn(dlList); LPVSStatisticsServiceHelper statisticsServiceHelper = new LPVSStatisticsServiceHelper( pullRequestRepository,