-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve error message when downloading a missing document (#403)
* feat: improve error message when downloading a missing document * feat: update tes
- Loading branch information
1 parent
73a9f63
commit f666e9a
Showing
5 changed files
with
65 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
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
50 changes: 50 additions & 0 deletions
50
src/test/java/fr/insee/rmes/webservice/DocumentsResourcesTest.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,50 @@ | ||
package fr.insee.rmes.webservice; | ||
|
||
import fr.insee.rmes.bauhaus_services.DocumentsService; | ||
import fr.insee.rmes.exceptions.RmesException; | ||
import fr.insee.rmes.webservice.operations.DocumentsResources; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.NoSuchFileException; | ||
|
||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.when; | ||
|
||
|
||
class DocumentsResourcesTest { | ||
|
||
@Mock | ||
private DocumentsService documentsService; | ||
|
||
@InjectMocks | ||
private DocumentsResources documentsResources; | ||
|
||
@BeforeEach | ||
public void init() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
|
||
@Test | ||
void shouldReturnNotFoundException() throws RmesException, IOException { | ||
when(documentsService.downloadDocument(anyString())).thenThrow(new NoSuchFileException("id")); | ||
ResponseEntity<Object> response = documentsResources.downloadDocument("id"); | ||
Assertions.assertEquals(HttpStatus.NOT_FOUND.value(), response.getStatusCode().value()); | ||
Assertions.assertEquals("id does not exist", response.getBody()); | ||
} | ||
|
||
@Test | ||
void shouldReturnInternalException() throws RmesException, IOException { | ||
when(documentsService.downloadDocument(anyString())).thenThrow(new IOException(anyString())); | ||
ResponseEntity<Object> response = documentsResources.downloadDocument("id"); | ||
Assertions.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), response.getStatusCode().value()); | ||
} | ||
} |