-
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.
fix(hotfix no information about minio objects reported in error) WIP
- Modify exception message to log more information - Adapt exception handler to process these exceptions - Start writing test
- Loading branch information
Fabrice B
committed
Dec 12, 2024
1 parent
3aa58f6
commit bee1204
Showing
7 changed files
with
135 additions
and
22 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
17 changes: 16 additions & 1 deletion
17
src/main/java/fr/insee/rmes/exceptions/RmesFileException.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 |
---|---|---|
@@ -1,7 +1,22 @@ | ||
package fr.insee.rmes.exceptions; | ||
|
||
public class RmesFileException extends RuntimeException { | ||
public RmesFileException(String message, Throwable cause) { | ||
|
||
private final String fileName; | ||
|
||
public RmesFileException(String filename, String message, Throwable cause) { | ||
super(message, cause); | ||
this.fileName = filename; | ||
} | ||
|
||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RmesFileException{" + | ||
"fileName='" + fileName + '\'' + | ||
'}'; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/test/java/fr/insee/rmes/integration/TestDocumentsResourcesWithMinio.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,91 @@ | ||
package fr.insee.rmes.integration; | ||
|
||
import fr.insee.rmes.bauhaus_services.FilesOperations; | ||
import fr.insee.rmes.bauhaus_services.operations.ParentUtils; | ||
import fr.insee.rmes.bauhaus_services.operations.documentations.documents.DocumentsImpl; | ||
import fr.insee.rmes.bauhaus_services.operations.documentations.documents.DocumentsUtils; | ||
import fr.insee.rmes.bauhaus_services.rdf_utils.PublicationUtils; | ||
import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryGestion; | ||
import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryPublication; | ||
import fr.insee.rmes.bauhaus_services.stamps.StampsRestrictionServiceImpl; | ||
import fr.insee.rmes.config.BaseConfigForMvcTests; | ||
import fr.insee.rmes.config.Config; | ||
import fr.insee.rmes.exceptions.RmesFileException; | ||
import fr.insee.rmes.utils.IdGenerator; | ||
import fr.insee.rmes.webservice.operations.DocumentsResources; | ||
import io.minio.errors.MinioException; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@WebMvcTest(DocumentsResources.class) | ||
@Import({BaseConfigForMvcTests.class, DocumentsImpl.class}) | ||
class TestDocumentsResourcesWithMinio { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
// @MockBean | ||
// private ParentUtils parentUtils; | ||
// @MockBean | ||
// private RepositoryPublication repositoryPublication; | ||
// @MockBean | ||
// private StampsRestrictionServiceImpl stampsRestrictionService; | ||
// @MockBean | ||
// private IdGenerator idGenerator; | ||
// @MockBean | ||
// private PublicationUtils publicationUtils; | ||
// @MockBean | ||
// private Config config; | ||
// @MockBean | ||
// private RepositoryGestion repositoryGestion; | ||
|
||
@MockBean | ||
FilesOperations filesOperations; | ||
|
||
private final String fichierId="ID"; | ||
|
||
private static final String nomFichier = "nomFichier"; | ||
|
||
@Test | ||
void shouldLogAndReturnInternalException_WhenErrorOccursInMinio() throws Exception { | ||
|
||
String objectName = "directoryGestion/"+nomFichier; | ||
String bucketName = "metadata_bucket"; | ||
when(filesOperations.read(anyString())).thenThrow(new RmesFileException(nomFichier, "Error reading file: " + nomFichier+ | ||
" as object `"+objectName+"` in bucket "+bucketName, new MinioException())); | ||
|
||
|
||
mockMvc.perform(MockMvcRequestBuilders.get("/documents/document/" + fichierId + "/file")) | ||
.andExpect(status().isInternalServerError()) | ||
.andExpect(content().string(containsString("fileName='" + nomFichier + "'"))); | ||
} | ||
|
||
@TestConfiguration | ||
static class ConfigurationForTest{ | ||
|
||
@Bean | ||
public DocumentsUtils documentsUtils(FilesOperations filesOperations) { | ||
return new DocumentsUtils(null, filesOperations){ | ||
@Override | ||
protected String getDocumentFilename(String id){ | ||
return nomFichier; | ||
} | ||
}; | ||
} | ||
|
||
} | ||
|
||
} |
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