diff --git a/apps/onboarding-ms/src/main/docs/openapi.json b/apps/onboarding-ms/src/main/docs/openapi.json index 04f5c352..20318bdd 100644 --- a/apps/onboarding-ms/src/main/docs/openapi.json +++ b/apps/onboarding-ms/src/main/docs/openapi.json @@ -246,7 +246,7 @@ "tags" : [ "internal-v1" ], "summary" : "Retrieves the list of files on the azure storage on the given path", "description" : "Fetches a list of files associated with the specified path on the storage.", - "operationId" : "getFiles", + "operationId" : "getFilesFromPath", "parameters" : [ { "name" : "path", "in" : "path", diff --git a/apps/onboarding-ms/src/main/docs/openapi.yaml b/apps/onboarding-ms/src/main/docs/openapi.yaml index f43a0005..d6e50d6b 100644 --- a/apps/onboarding-ms/src/main/docs/openapi.yaml +++ b/apps/onboarding-ms/src/main/docs/openapi.yaml @@ -183,7 +183,7 @@ paths: summary: Retrieves the list of files on the azure storage on the given path description: Fetches a list of files associated with the specified path on the storage. - operationId: getFiles + operationId: getFilesFromPath parameters: - name: path in: path diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/DocumentController.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/DocumentController.java index b3378ce6..fda712f8 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/DocumentController.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/DocumentController.java @@ -10,6 +10,7 @@ import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; +import java.util.Base64; import java.util.List; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -60,8 +61,9 @@ public Uni> getFiles() { @Tag(name = "internal-v1") @Path("/{path}") @Produces(MediaType.APPLICATION_JSON) - public Uni> getFiles(@PathParam(value = "path") String path) { - return Uni.createFrom().item(blobClient.getFiles(path)); + public Uni> getFilesFromPath(@PathParam(value = "path") String path) { + var buildPath = new String(Base64.getDecoder().decode(path)); + return Uni.createFrom().item(blobClient.getFiles(buildPath)); } } \ No newline at end of file diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/DocumentControllerTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/DocumentControllerTest.java index 8e3baf4e..69059639 100644 --- a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/DocumentControllerTest.java +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/DocumentControllerTest.java @@ -1,8 +1,10 @@ package it.pagopa.selfcare.onboarding.controller; import static io.restassured.RestAssured.given; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.quarkus.test.InjectMock; @@ -14,9 +16,10 @@ import io.restassured.http.ContentType; import it.pagopa.selfcare.azurestorage.AzureBlobClient; import java.util.ArrayList; +import java.util.Base64; import java.util.List; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; +import org.mockito.ArgumentCaptor; @QuarkusTest @TestHTTPEndpoint(DocumentController.class) @@ -28,25 +31,27 @@ class DocumentControllerTest { @Test @TestSecurity(user = "userJwt") - void getFiles_ByPath_OK() { + void getFilesFromPath_ByPath_OK() { // given + ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); final String path = "/test/test"; + var builderPath = Base64.getEncoder().encodeToString(path.getBytes()); List result = new ArrayList<>(); // when - when(blobClient.getFiles(anyString())).thenReturn(result); + when(blobClient.getFiles(captor.capture())).thenReturn(result); given() .when() .contentType(ContentType.JSON) - .pathParam("path", path) + .pathParam("path", builderPath) .get("{path}") .then() .statusCode(200); // then - Mockito.verify(blobClient, times(1)).getFiles(anyString()); - + verify(blobClient, times(1)).getFiles(anyString()); + assertEquals(captor.getValue(), path); } @Test @@ -66,7 +71,7 @@ void getFiles_OK() { .statusCode(200); // then - Mockito.verify(blobClient, times(1)).getFiles(); + verify(blobClient, times(1)).getFiles(); }