-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fabien
committed
Dec 16, 2024
1 parent
b30796f
commit 8a4e279
Showing
2 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
...-api-tenant/src/test/java/fr/dossierfacile/api/front/service/DocumentServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package fr.dossierfacile.api.front.service; | ||
|
||
import fr.dossierfacile.api.front.amqp.Producer; | ||
import fr.dossierfacile.api.front.repository.DocumentRepository; | ||
import fr.dossierfacile.common.entity.Document; | ||
import fr.dossierfacile.common.enums.DocumentCategory; | ||
import fr.dossierfacile.common.enums.DocumentStatus; | ||
import fr.dossierfacile.common.repository.DocumentAnalysisReportRepository; | ||
import fr.dossierfacile.common.service.interfaces.FileStorageService; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mockito.junit.jupiter.MockitoSettings; | ||
import org.mockito.quality.Strictness; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
class DocumentServiceImplTest { | ||
{ | ||
MockitoAnnotations.openMocks(this); | ||
Mockito.lenient(); | ||
} | ||
|
||
@Mock | ||
private DocumentRepository documentRepository; | ||
@Mock | ||
private DocumentAnalysisReportRepository documentAnalysisReportRepository; | ||
@Mock | ||
private FileStorageService fileStorageService; | ||
@Mock | ||
private Producer producer; | ||
@InjectMocks | ||
private DocumentServiceImpl documentService; | ||
|
||
public DocumentServiceImplTest() { | ||
MockitoAnnotations.openMocks(this); | ||
Mockito.lenient(); | ||
} | ||
|
||
@Test | ||
void testResetValidatedOrInProgressDocumentsForValidatedDocument() { | ||
List<Document> documentList = new ArrayList<>(); | ||
Document document = new Document(); | ||
document.setId(1L); | ||
document.setDocumentCategory(DocumentCategory.PROFESSIONAL); | ||
document.setDocumentStatus(DocumentStatus.VALIDATED); | ||
documentList.add(document); | ||
|
||
List<DocumentCategory> categoriesToChange = List.of(DocumentCategory.PROFESSIONAL); | ||
|
||
when(documentRepository.save(any(Document.class))).thenReturn(document); | ||
|
||
documentService.resetValidatedOrInProgressDocumentsAccordingCategories(documentList, categoriesToChange); | ||
|
||
assertEquals(DocumentStatus.TO_PROCESS, document.getDocumentStatus()); | ||
assertNull(document.getDocumentDeniedReasons()); | ||
} | ||
|
||
@Test | ||
void testResetValidatedOrInProgressDocumentsForNoDocumentWithWatermark() { | ||
List<Document> documentList = new ArrayList<>(); | ||
Document document = new Document(); | ||
document.setId(1L); | ||
document.setDocumentCategory(DocumentCategory.PROFESSIONAL); | ||
document.setDocumentStatus(DocumentStatus.VALIDATED); | ||
document.setNoDocument(true); | ||
document.setWatermarkFile(null); | ||
documentList.add(document); | ||
|
||
List<DocumentCategory> categoriesToChange = List.of(DocumentCategory.PROFESSIONAL); | ||
|
||
when(documentRepository.save(any(Document.class))).thenReturn(document); | ||
|
||
documentService.resetValidatedOrInProgressDocumentsAccordingCategories(documentList, categoriesToChange); | ||
|
||
assertEquals(DocumentStatus.TO_PROCESS, document.getDocumentStatus()); | ||
assertNull(document.getWatermarkFile()); | ||
|
||
} | ||
|
||
@Test | ||
void testResetValidatedOrInProgressDocumentsForNonMatchingCategory() { | ||
List<Document> documentList = new ArrayList<>(); | ||
Document document = new Document(); | ||
document.setId(1L); | ||
document.setDocumentCategory(DocumentCategory.IDENTIFICATION); | ||
document.setDocumentStatus(DocumentStatus.VALIDATED); | ||
documentList.add(document); | ||
|
||
List<DocumentCategory> categoriesToChange = List.of(DocumentCategory.PROFESSIONAL); | ||
|
||
documentService.resetValidatedOrInProgressDocumentsAccordingCategories(documentList, categoriesToChange); | ||
|
||
verifyNoInteractions(documentRepository); | ||
verifyNoInteractions(fileStorageService); | ||
verifyNoInteractions(producer); | ||
assertEquals(DocumentStatus.VALIDATED, document.getDocumentStatus()); | ||
} | ||
|
||
@Test | ||
void testResetValidatedOrInProgressDocumentsForEmptyList() { | ||
List<Document> documentList = new ArrayList<>(); | ||
List<DocumentCategory> categoriesToChange = List.of(DocumentCategory.PROFESSIONAL); | ||
|
||
documentService.resetValidatedOrInProgressDocumentsAccordingCategories(documentList, categoriesToChange); | ||
|
||
verifyNoInteractions(documentRepository); | ||
verifyNoInteractions(fileStorageService); | ||
verifyNoInteractions(producer); | ||
verifyNoMoreInteractions(documentRepository, fileStorageService, producer); | ||
} | ||
|
||
@Test | ||
void testResetValidatedOrInProgressDocumentsForNullList() { | ||
List<DocumentCategory> categoriesToChange = List.of(DocumentCategory.PROFESSIONAL); | ||
|
||
documentService.resetValidatedOrInProgressDocumentsAccordingCategories(null, categoriesToChange); | ||
|
||
verifyNoInteractions(documentRepository); | ||
verifyNoInteractions(fileStorageService); | ||
verifyNoInteractions(producer); | ||
verifyNoMoreInteractions(documentRepository, fileStorageService, producer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters