generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SELC-6156] Added new DocumentController
- Loading branch information
1 parent
8f5acbc
commit 5593bc6
Showing
4 changed files
with
267 additions
and
0 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
67 changes: 67 additions & 0 deletions
67
...oarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/DocumentController.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,67 @@ | ||
package it.pagopa.selfcare.onboarding.controller; | ||
|
||
|
||
import io.quarkus.security.Authenticated; | ||
import io.smallrye.mutiny.Uni; | ||
import it.pagopa.selfcare.azurestorage.AzureBlobClient; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.eclipse.microprofile.openapi.annotations.Operation; | ||
import org.eclipse.microprofile.openapi.annotations.tags.Tag; | ||
|
||
@Authenticated | ||
@Path("/v1/documents") | ||
@Tag(name = "Document Controller") | ||
@AllArgsConstructor | ||
@Slf4j | ||
public class DocumentController { | ||
|
||
@Inject | ||
AzureBlobClient blobClient; | ||
|
||
/** | ||
* Retrieves the list of files by the path on the blob | ||
* | ||
* @return List of files on the storage * Code: 200, Message: successful operation * Code: 400, Message: Invalid ID supplied * Code: 404, Message: | ||
* Path not found | ||
*/ | ||
|
||
@Operation( | ||
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." | ||
) | ||
@GET | ||
@Tag(name = "internal-v1") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Uni<List<String>> getFiles() { | ||
return Uni.createFrom().item(blobClient.getFiles()); | ||
} | ||
|
||
/** | ||
* Retrieves the list of files by the path on the blob | ||
* | ||
* @param path path of the folder into azure storage | ||
* @return List of files on the storage * Code: 200, Message: successful operation * Code: 400, Message: Invalid ID supplied * Code: 404, Message: | ||
* Path not found | ||
*/ | ||
|
||
@Operation( | ||
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." | ||
) | ||
@GET | ||
@Tag(name = "internal-v1") | ||
@Path("/{path}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Uni<List<String>> getFiles(@PathParam(value = "path") String path) { | ||
return Uni.createFrom().item(blobClient.getFiles(path)); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...ing-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/DocumentControllerTest.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,73 @@ | ||
package it.pagopa.selfcare.onboarding.controller; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.quarkus.test.InjectMock; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.mongodb.MongoTestResource; | ||
import io.quarkus.test.security.TestSecurity; | ||
import io.restassured.http.ContentType; | ||
import it.pagopa.selfcare.azurestorage.AzureBlobClient; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(DocumentController.class) | ||
@QuarkusTestResource(MongoTestResource.class) | ||
class DocumentControllerTest { | ||
|
||
@InjectMock | ||
AzureBlobClient blobClient; | ||
|
||
@Test | ||
@TestSecurity(user = "userJwt") | ||
void getFiles_ByPath_OK() { | ||
// given | ||
final String path = "/test/test"; | ||
List<String> result = new ArrayList<>(); | ||
|
||
// when | ||
when(blobClient.getFiles(anyString())).thenReturn(result); | ||
|
||
given() | ||
.when() | ||
.contentType(ContentType.JSON) | ||
.pathParam("path", path) | ||
.get("{path}") | ||
.then() | ||
.statusCode(200); | ||
|
||
// then | ||
Mockito.verify(blobClient, times(1)).getFiles(anyString()); | ||
|
||
} | ||
|
||
@Test | ||
@TestSecurity(user = "userJwt") | ||
void getFiles_OK() { | ||
// given | ||
List<String> result = new ArrayList<>(); | ||
|
||
// when | ||
when(blobClient.getFiles()).thenReturn(result); | ||
|
||
given() | ||
.when() | ||
.contentType(ContentType.JSON) | ||
.get() | ||
.then() | ||
.statusCode(200); | ||
|
||
// then | ||
Mockito.verify(blobClient, times(1)).getFiles(); | ||
|
||
} | ||
|
||
} |