From edc753596986bf879af845eff980774520cb3304 Mon Sep 17 00:00:00 2001 From: Luca Consalvi <117908483+lucaconsalvi@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:35:33 +0200 Subject: [PATCH] chore: [MCIL-29] postman get terminal list (#29) --- .github/workflows/pre-merge-postman-test.yaml | 2 +- build.gradle | 2 +- gradle.properties | 2 +- gradle/verification-metadata.xml | 13 +++ .../pagopa/swclient/mil/dao/PageMetadata.java | 3 + .../swclient/mil/dao/TerminalEntity.java | 17 ++-- .../mil/dao/TerminalPageResponse.java | 2 + .../swclient/mil/service/TerminalService.java | 13 +-- .../mil/service/TerminalServiceTest.java | 23 ++--- .../swclient/mil/util/TerminalTestData.java | 12 +-- ...-terminal-registry.postman_collection.json | 94 ++++++++++++++++--- 11 files changed, 136 insertions(+), 47 deletions(-) diff --git a/.github/workflows/pre-merge-postman-test.yaml b/.github/workflows/pre-merge-postman-test.yaml index df3446d..2c9eb9d 100644 --- a/.github/workflows/pre-merge-postman-test.yaml +++ b/.github/workflows/pre-merge-postman-test.yaml @@ -1,4 +1,4 @@ -name: Pull request review +name: Postman Test on: pull_request: diff --git a/build.gradle b/build.gradle index 944b49f..102e2b2 100644 --- a/build.gradle +++ b/build.gradle @@ -12,8 +12,8 @@ repositories { dependencies { implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") - implementation 'io.quarkus:quarkus-resteasy-reactive-jackson' implementation 'io.quarkus:quarkus-resteasy-reactive' + implementation 'io.quarkus:quarkus-resteasy-reactive-jackson' implementation 'io.quarkus:quarkus-arc' implementation "org.projectlombok:lombok:${lombokVersion}" implementation 'io.quarkus:quarkus-hibernate-validator' diff --git a/gradle.properties b/gradle.properties index f1b4458..caebdd6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ quarkusPlatformVersion=3.7.3 lombokVersion=1.18.30 jacocoToolVersion=0.8.11 -sonarPluginVersion=4.4.1.3373 +sonarPluginVersion=5.0.0.4638 sonarProjectKey=pagopa_mil-terminal-registry projectVersion=1.2.1 diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index d4ad450..f42552a 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -4902,6 +4902,11 @@ + + + + + @@ -4942,6 +4947,14 @@ + + + + + + + + diff --git a/src/main/java/it/pagopa/swclient/mil/dao/PageMetadata.java b/src/main/java/it/pagopa/swclient/mil/dao/PageMetadata.java index f001bfe..e7d210c 100644 --- a/src/main/java/it/pagopa/swclient/mil/dao/PageMetadata.java +++ b/src/main/java/it/pagopa/swclient/mil/dao/PageMetadata.java @@ -1,4 +1,7 @@ package it.pagopa.swclient.mil.dao; +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection public record PageMetadata(int size, long totalElements, int totalPages) { } diff --git a/src/main/java/it/pagopa/swclient/mil/dao/TerminalEntity.java b/src/main/java/it/pagopa/swclient/mil/dao/TerminalEntity.java index 91e094b..f017245 100644 --- a/src/main/java/it/pagopa/swclient/mil/dao/TerminalEntity.java +++ b/src/main/java/it/pagopa/swclient/mil/dao/TerminalEntity.java @@ -1,20 +1,19 @@ package it.pagopa.swclient.mil.dao; import io.quarkus.mongodb.panache.common.MongoEntity; -import lombok.*; +import org.bson.codecs.pojo.annotations.BsonProperty; -@ToString -@Data -@Builder -@Getter @MongoEntity(database = "mil", collection = "terminalRegistry") public class TerminalEntity { - private String terminalUuid; + @BsonProperty("terminalUuid") + public String terminalUuid; - private String terminalHandler; + @BsonProperty("terminalHandler") + public String terminalHandler; - private String serviceProviderId; + @BsonProperty("serviceProviderId") + public String serviceProviderId; - private Terminal terminal; + public Terminal terminal; } diff --git a/src/main/java/it/pagopa/swclient/mil/dao/TerminalPageResponse.java b/src/main/java/it/pagopa/swclient/mil/dao/TerminalPageResponse.java index f5c32ad..1efaba6 100644 --- a/src/main/java/it/pagopa/swclient/mil/dao/TerminalPageResponse.java +++ b/src/main/java/it/pagopa/swclient/mil/dao/TerminalPageResponse.java @@ -1,6 +1,8 @@ package it.pagopa.swclient.mil.dao; import java.util.List; +import io.quarkus.runtime.annotations.RegisterForReflection; +@RegisterForReflection public record TerminalPageResponse(List terminals, PageMetadata page) { } diff --git a/src/main/java/it/pagopa/swclient/mil/service/TerminalService.java b/src/main/java/it/pagopa/swclient/mil/service/TerminalService.java index f409090..7440bbf 100644 --- a/src/main/java/it/pagopa/swclient/mil/service/TerminalService.java +++ b/src/main/java/it/pagopa/swclient/mil/service/TerminalService.java @@ -76,11 +76,12 @@ private TerminalEntity createTerminalEntity(TerminalDto terminalDto, String serv .idpay(terminalDto.idpay()) .build(); - return TerminalEntity.builder() - .terminalUuid(terminalUuid) - .terminalHandler(terminalDto.terminalHandlerId()) - .serviceProviderId(serviceProviderId) - .terminal(terminal) - .build(); + TerminalEntity terminalEntity = new TerminalEntity(); + terminalEntity.terminalUuid = terminalUuid; + terminalEntity.terminalHandler = terminalDto.terminalHandlerId(); + terminalEntity.serviceProviderId = serviceProviderId; + terminalEntity.terminal = terminal; + + return terminalEntity; } } diff --git a/src/test/java/it/pagopa/swclient/mil/service/TerminalServiceTest.java b/src/test/java/it/pagopa/swclient/mil/service/TerminalServiceTest.java index 8deea48..b3f032d 100644 --- a/src/test/java/it/pagopa/swclient/mil/service/TerminalServiceTest.java +++ b/src/test/java/it/pagopa/swclient/mil/service/TerminalServiceTest.java @@ -73,17 +73,25 @@ void testCreateTerminal_Failure() { @Test void whenGetTerminalListThenSuccess() { + TerminalEntity terminalEntity1 = new TerminalEntity(); + TerminalEntity terminalEntity2 = new TerminalEntity(); + terminalEntity1.terminalUuid = "uuid1"; + terminalEntity1.serviceProviderId = "serviceProviderId"; + terminalEntity2.terminalUuid = "uuid2"; + terminalEntity2.serviceProviderId = "serviceProviderId"; + List terminalEntities= List.of(terminalEntity1,terminalEntity2); + ReactivePanacheQuery query = Mockito.mock(ReactivePanacheQuery.class); Mockito.when(query.page(anyInt(), anyInt())).thenReturn(query); - Mockito.when(query.list()).thenReturn(Uni.createFrom().item(mockedList())); + Mockito.when(query.list()).thenReturn(Uni.createFrom().item(terminalEntities)); Mockito.when(terminalRepository.find("serviceProviderId", "serviceProviderId")).thenReturn(query); var terminalList = terminalService.getTerminalListPaged("serviceProviderId", 0, 10); - terminalList .subscribe() .withSubscriber(UniAssertSubscriber.create()) - .assertItem(mockedList()); + .assertItem(terminalEntities); + } @Test @@ -99,12 +107,5 @@ void whenGetTerminalCountThenSuccess() { .assertItem(10L); } - private List mockedList() { - return List.of( - TerminalEntity.builder() - .terminalUuid("uuid1").build(), - TerminalEntity.builder() - .terminalUuid("uuid2").build() - ); - } + } diff --git a/src/test/java/it/pagopa/swclient/mil/util/TerminalTestData.java b/src/test/java/it/pagopa/swclient/mil/util/TerminalTestData.java index 021e568..e6615f7 100644 --- a/src/test/java/it/pagopa/swclient/mil/util/TerminalTestData.java +++ b/src/test/java/it/pagopa/swclient/mil/util/TerminalTestData.java @@ -21,11 +21,11 @@ public static TerminalEntity getCorrectTerminalEntity() { .pagoPaConf(null) .idpay(true) .build(); - - return TerminalEntity.builder() - .terminalUuid("c7a1b24b0583477292ebdbaa") - .terminalHandler("45856") - .terminal(terminal) - .build(); + + TerminalEntity terminalEntity = new TerminalEntity(); + terminalEntity.terminalUuid = "c7a1b24b0583477292ebdbaa"; + terminalEntity.terminalHandler = "45856"; + terminalEntity.terminal = terminal; + return terminalEntity; } } diff --git a/src/test/postman/mil-terminal-registry.postman_collection.json b/src/test/postman/mil-terminal-registry.postman_collection.json index 18ad60e..3ab44bf 100644 --- a/src/test/postman/mil-terminal-registry.postman_collection.json +++ b/src/test/postman/mil-terminal-registry.postman_collection.json @@ -8,7 +8,7 @@ }, "item": [ { - "name": "getTerminalRegistryAccessToken", + "name": "Get Terminal Registry Access Token", "event": [ { "listen": "test", @@ -57,7 +57,7 @@ "header": [ { "key": "RequestId", - "value": "{{$guid}}", + "value": "{{requestId}}", "type": "text" }, { @@ -99,22 +99,29 @@ "response": [] }, { - "name": "createTerminal", + "name": "Create New Terminal", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 201\", function () {", + " pm.response.to.have.status(201);", + "});", + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], "request": { "method": "POST", "header": [ { "description": "(Required) Request Id that will be logged by services", "key": "RequestId", - "value": "{{$guid}}" - }, - { - "key": "Content-Type", - "value": "application/json" - }, - { - "key": "Accept", - "value": "application/json" + "value": "{{requestId}}" } ], "body": { @@ -138,6 +145,57 @@ "description": "Creates a new terminal" }, "response": [] + }, + { + "name": "Get Terminal List", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "description": "(Required) Request Id that will be logged by services", + "key": "RequestId", + "value": "{{requestId}}" + } + ], + "url": { + "raw": "{{MIL_TR_BASE_URL}}/terminals?page={{getTerminalPage}}&size={{getTerminalPageSize}}", + "host": [ + "{{MIL_TR_BASE_URL}}" + ], + "path": [ + "terminals" + ], + "query": [ + { + "key": "page", + "value": "{{getTerminalPage}}", + "description": "(Required) Number of the requested page of data" + }, + { + "key": "size", + "value": "{{getTerminalPageSize}}", + "description": "(Required) Size of the requested page of data" + } + ] + }, + "description": "Returns a page of terminals" + }, + "response": [] } ], "auth": { @@ -224,6 +282,18 @@ { "key": "mil_auth_api_version", "value": "1.0.0" + }, + { + "key": "getTerminalPage", + "value": "0" + }, + { + "key": "getTerminalPageSize", + "value": "10" + }, + { + "key": "requestId", + "value": "d0d654e6-97da-4848-b568-99fedccb642b" } ] } \ No newline at end of file