From 235f2312b77314c011f779907c117b62a1bff866 Mon Sep 17 00:00:00 2001 From: Giampiero Ferrara Date: Wed, 18 Dec 2024 12:06:00 +0100 Subject: [PATCH 1/2] Fixed path value --- .../controller/DocumentController.java | 4 +++- .../controller/DocumentControllerTest.java | 17 +++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) 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..16cbf446 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; @@ -61,7 +62,8 @@ public Uni> getFiles() { @Path("/{path}") @Produces(MediaType.APPLICATION_JSON) public Uni> getFiles(@PathParam(value = "path") String path) { - return Uni.createFrom().item(blobClient.getFiles(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..53fe627e 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) @@ -30,23 +33,25 @@ class DocumentControllerTest { @TestSecurity(user = "userJwt") void getFiles_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(); } From 9513854d6e17481f7b1e2f688d74eba72fd850bc Mon Sep 17 00:00:00 2001 From: Giampiero Ferrara Date: Wed, 18 Dec 2024 12:43:59 +0100 Subject: [PATCH 2/2] Renamed method getFilesFromPath --- apps/onboarding-ms/src/main/docs/openapi.json | 2 +- apps/onboarding-ms/src/main/docs/openapi.yaml | 2 +- .../selfcare/onboarding/controller/DocumentController.java | 2 +- .../selfcare/onboarding/controller/DocumentControllerTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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 16cbf446..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 @@ -61,7 +61,7 @@ public Uni> getFiles() { @Tag(name = "internal-v1") @Path("/{path}") @Produces(MediaType.APPLICATION_JSON) - public Uni> getFiles(@PathParam(value = "path") String path) { + public Uni> getFilesFromPath(@PathParam(value = "path") String path) { var buildPath = new String(Base64.getDecoder().decode(path)); return Uni.createFrom().item(blobClient.getFiles(buildPath)); } 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 53fe627e..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 @@ -31,7 +31,7 @@ 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";