Skip to content

Commit

Permalink
feat: promote to UAT (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: Vitolo-Andrea <[email protected]>
Co-authored-by: BaldiVi-1 <[email protected]>
Co-authored-by: BaldiVi <[email protected]>
  • Loading branch information
4 people authored Feb 3, 2025
1 parent 7b80417 commit c1aa942
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/controller/TppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ public interface TppController {
@GetMapping("/{tppId}/token")
Mono<ResponseEntity<TokenSectionDTO>> getTokenSection(@Valid @PathVariable String tppId);

@GetMapping("/entityId/{entityId}")
Mono<ResponseEntity<TppDTOWithoutTokenSection>> getTppByEntityId(@Valid @PathVariable String entityId);

@GetMapping("/network/connection/{tppName}")
Mono<ResponseEntity<NetworkResponseDTO>> testConnection(@Valid @PathVariable String tppName);


}
12 changes: 12 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/controller/TppControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ public Mono<ResponseEntity<TokenSectionDTO>> getTokenSection(String tppId) {
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<TppDTOWithoutTokenSection>> getTppByEntityId(String entityId) {
return tppService.getTppByEntityId(entityId)
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<NetworkResponseDTO>> testConnection(String tppName) {
return tppService.testConnection(tppName)
.map(ResponseEntity::ok);
}

}
9 changes: 9 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/dto/NetworkResponseDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.gov.pagopa.tpp.dto;

import lombok.Data;

@Data
public class NetworkResponseDTO {
private String code;
private String message;
}
7 changes: 7 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/dto/TppDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;
import java.util.HashMap;

@Data
@SuperBuilder
Expand Down Expand Up @@ -48,4 +49,10 @@ public class TppDTO {
private LocalDateTime lastUpdateDate;
private TokenSection tokenSection;

@NotNull(message = "Payment Button must not be null")
private String paymentButton;

@NotNull(message = "Agent Deep Link must not be null")
private HashMap<String, String> agentDeepLinks;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;
import java.util.HashMap;

@Data
@SuperBuilder
Expand Down Expand Up @@ -44,4 +45,10 @@ public class TppDTOWithoutTokenSection {
private Boolean state;
private LocalDateTime creationDate;
private LocalDateTime lastUpdateDate;

@NotNull(message = "Payment Button must not be null")
private String paymentButton;

@NotNull(message = "Agent Deep Link must not be null")
private HashMap<String, String> agentDeepLinks;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public TppDTO map(Tpp tpp){
.creationDate(tpp.getCreationDate())
.lastUpdateDate(tpp.getLastUpdateDate())
.tokenSection(tpp.getTokenSection())
.paymentButton(tpp.getPaymentButton())
.agentDeepLinks(tpp.getAgentDeepLinks())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public TppDTOWithoutTokenSection map(Tpp tpp){
.entityId(tpp.getEntityId())
.creationDate(tpp.getCreationDate())
.lastUpdateDate(tpp.getLastUpdateDate())
.paymentButton(tpp.getPaymentButton())
.agentDeepLinks(tpp.getAgentDeepLinks())
.build();
}
}
3 changes: 3 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/model/Tpp.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;
import java.util.HashMap;

@Document(collection = "tpp")
@Data
Expand All @@ -29,4 +30,6 @@ public class Tpp {
private TokenSection tokenSection;
private LocalDateTime creationDate;
private LocalDateTime lastUpdateDate;
private String paymentButton;
private HashMap<String, String> agentDeepLinks;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public Tpp map(TppDTO tppDTO){
.contact(tppDTO.getContact())
.entityId(tppDTO.getEntityId())
.tokenSection(tppDTO.getTokenSection())
.paymentButton(tppDTO.getPaymentButton())
.agentDeepLinks(tppDTO.getAgentDeepLinks())
.build();
}

}
5 changes: 5 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/service/TppService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.gov.pagopa.tpp.service;

import it.gov.pagopa.tpp.dto.NetworkResponseDTO;
import it.gov.pagopa.tpp.dto.TokenSectionDTO;
import it.gov.pagopa.tpp.dto.TppDTO;
import it.gov.pagopa.tpp.dto.TppDTOWithoutTokenSection;
Expand All @@ -23,4 +24,8 @@ public interface TppService {

Mono<TokenSectionDTO> getTokenSection(String tppId);

Mono<TppDTOWithoutTokenSection> getTppByEntityId(String entityId);

Mono<NetworkResponseDTO> testConnection(String tppName);

}
32 changes: 30 additions & 2 deletions src/main/java/it/gov/pagopa/tpp/service/TppServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import it.gov.pagopa.tpp.configuration.ExceptionMap;
import it.gov.pagopa.tpp.constants.TppConstants.ExceptionMessage;
import it.gov.pagopa.tpp.constants.TppConstants.ExceptionName;
import it.gov.pagopa.tpp.dto.NetworkResponseDTO;
import it.gov.pagopa.tpp.dto.TokenSectionDTO;
import it.gov.pagopa.tpp.dto.TppDTO;
import it.gov.pagopa.tpp.dto.TppDTOWithoutTokenSection;
Expand Down Expand Up @@ -40,6 +41,7 @@ public class TppServiceImpl implements TppService {
private final TokenSectionDTOToObjectMapper tokenSectionMapperToObject;
private final ExceptionMap exceptionMap;
private final AzureEncryptService azureEncryptService;
private static final String TPP_NOT_FOUND = "Tpp not found during get process";

public TppServiceImpl(TppRepository tppRepository, TppObjectToDTOMapper mapperToDTO, TppWithoutTokenSectionObjectToDTOMapper tppWithoutTokenSectionMapperToDTO, TokenSectionObjectToDTOMapper tokenSectionMapperToDTO,
TppDTOToObjectMapper mapperToObject, TokenSectionDTOToObjectMapper tokenSectionMapperToObject, ExceptionMap exceptionMap, AzureEncryptService azureEncryptService) {
Expand Down Expand Up @@ -185,19 +187,31 @@ public Mono<TppDTOWithoutTokenSection> getTppDetails(String tppId) {

return tppRepository.findByTppId(tppId)
.switchIfEmpty(Mono.error(exceptionMap.throwException(ExceptionName.TPP_NOT_ONBOARDED,
"Tpp not found during get process")))
TPP_NOT_FOUND)))
.map(tppWithoutTokenSectionMapperToDTO::map)
.doOnSuccess(tppDTO -> log.info("[TPP-SERVICE][GET] Found TPP with tppId: {}", tppId))
.doOnError(error -> log.error("[TPP-SERVICE][GET] Error retrieving TPP for tppId {}: {}", tppId, error.getMessage()));
}

@Override
public Mono<TppDTOWithoutTokenSection> getTppByEntityId(String entityId) {
log.info("[TPP-SERVICE][GET] Received request to get TPP for entityId: {}", inputSanify(entityId));

return tppRepository.findByEntityId(entityId)
.switchIfEmpty(Mono.error(exceptionMap.throwException(ExceptionName.TPP_NOT_ONBOARDED,
TPP_NOT_FOUND)))
.map(tppWithoutTokenSectionMapperToDTO::map)
.doOnSuccess(tppDTO -> log.info("[TPP-SERVICE][GET] Found TPP with entityId: {}", entityId))
.doOnError(error -> log.error("[TPP-SERVICE][GET] Error retrieving TPP for entityId {}: {}", entityId, error.getMessage()));
}

@Override
public Mono<TokenSectionDTO> getTokenSection(String tppId) {
log.info("[TPP-SERVICE][GET] Received request to get TokenSection for tppId: {}", inputSanify(tppId));

return tppRepository.findByTppId(tppId)
.switchIfEmpty(Mono.error(exceptionMap.throwException(ExceptionName.TPP_NOT_ONBOARDED,
"Tpp not found during get process")))
TPP_NOT_FOUND)))
.flatMap(tpp -> {
TokenSection tokenSection = tpp.getTokenSection();
keyDecrypt(tokenSection, tppId);
Expand All @@ -207,4 +221,18 @@ public Mono<TokenSectionDTO> getTokenSection(String tppId) {
.doOnError(error -> log.error("[TPP-SERVICE][GET] Error retrieving TokenSection for tppId {}: {}", tppId, error.getMessage()));
}


@Override
public Mono<NetworkResponseDTO> testConnection(String tppName) {
return Mono.just(createNetworkResponse(tppName));
}

private NetworkResponseDTO createNetworkResponse(String tppName){
NetworkResponseDTO networkResponseDTO = new NetworkResponseDTO();
networkResponseDTO.setCode("PAGOPA_NETWORK_TEST");
networkResponseDTO.setMessage(tppName+" ha raggiunto i nostri sistemi");
return networkResponseDTO;
}


}
36 changes: 36 additions & 0 deletions src/test/java/it/gov/pagopa/tpp/controller/TppControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.gov.pagopa.tpp.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import it.gov.pagopa.tpp.dto.NetworkResponseDTO;
import it.gov.pagopa.tpp.dto.TokenSectionDTO;
import it.gov.pagopa.tpp.dto.TppDTO;
import it.gov.pagopa.tpp.dto.TppDTOWithoutTokenSection;
Expand Down Expand Up @@ -126,6 +127,23 @@ void getTppDetails_Ok() {
});
}

@Test
void getTppByEntityId_Ok() {
Mockito.when(tppService.getTppByEntityId(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId()))
.thenReturn(Mono.just(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION));

webClient.get()
.uri("/emd/tpp/entityId/{entityId}",MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId())
.exchange()
.expectStatus().isOk()
.expectBody(TppDTOWithoutTokenSection.class)
.consumeWith(response -> {
TppDTOWithoutTokenSection resultResponse = response.getResponseBody();
Assertions.assertNotNull(resultResponse);
Assertions.assertEquals(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION,resultResponse);
});
}

@Test
void getTokenSection_Ok() {
Mockito.when(tppService.getTokenSection("tppId"))
Expand Down Expand Up @@ -161,4 +179,22 @@ void getEnabled_Ok() {
Assertions.assertTrue(resultResponse.containsAll(MOCK_TPP_DTO_LIST));
});
}

@Test
void testConnection() {
NetworkResponseDTO networkResponseDTO = new NetworkResponseDTO();
networkResponseDTO.setMessage("tppName ha raggiunto i nostri sistemi");
networkResponseDTO.setCode("PAGOPA_NETWORK_TEST");
Mockito.when(tppService.testConnection("tppName")).thenReturn(Mono.just(networkResponseDTO));

webClient.get()
.uri("/emd/tpp/network/connection/{tppName}","tppName")
.exchange()
.expectStatus().isOk()
.expectBody(NetworkResponseDTO.class)
.consumeWith(response -> {
NetworkResponseDTO resultResponse = response.getResponseBody();
Assertions.assertNotNull(resultResponse);
});
}
}
34 changes: 34 additions & 0 deletions src/test/java/it/gov/pagopa/tpp/service/TppServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import it.gov.pagopa.common.web.exception.ClientExceptionWithBody;
import it.gov.pagopa.tpp.configuration.ExceptionMap;
import it.gov.pagopa.tpp.dto.NetworkResponseDTO;
import it.gov.pagopa.tpp.dto.mapper.TokenSectionObjectToDTOMapper;
import it.gov.pagopa.tpp.dto.mapper.TppObjectToDTOMapper;
import it.gov.pagopa.tpp.dto.mapper.TppWithoutTokenSectionObjectToDTOMapper;
Expand Down Expand Up @@ -218,6 +219,28 @@ void getTppDetails_TppNotOnboarded() {
.verify();
}

@Test
void getTppByEntityId_Ok() {
Mockito.when(tppRepository.findByEntityId(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId()))
.thenReturn(Mono.just(MOCK_TPP));

StepVerifier.create(tppService.getTppByEntityId(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId()))
.expectNextCount(1)
.verifyComplete();
}

@Test
void getTppByEntityId_TppNotOnboarded() {
Mockito.when(tppRepository.findByEntityId(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId()))
.thenReturn(Mono.empty());

StepVerifier.create(tppService.getTppByEntityId(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId()))
.expectErrorMatches(throwable ->
throwable instanceof ClientExceptionWithBody &&
((ClientExceptionWithBody) throwable).getCode().equals("TPP_NOT_ONBOARDED"))
.verify();
}

@Test
void getTokenSection_Ok() {
Mockito.when(tppRepository.findByTppId(MOCK_TPP_DTO.getTppId()))
Expand All @@ -240,6 +263,17 @@ void getTokenSection_TppNotFound() {
throwable.getMessage().contains("Tpp not found during get process"))
.verify();
}


@Test
void testConnection(){
NetworkResponseDTO networkResponseDTO = new NetworkResponseDTO();
networkResponseDTO.setMessage("tppName ha raggiunto i nostri sistemi");
networkResponseDTO.setCode("PAGOPA_NETWORK_TEST");
StepVerifier.create(tppService.testConnection("tppName"))
.expectNext(networkResponseDTO)
.verifyComplete();
}
}


6 changes: 6 additions & 0 deletions src/test/java/it/gov/pagopa/tpp/utils/faker/TppDTOFaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import it.gov.pagopa.tpp.enums.AuthenticationType;
import it.gov.pagopa.tpp.model.Contact;

import java.util.HashMap;

public class TppDTOFaker {

private TppDTOFaker(){}
Expand All @@ -26,6 +28,10 @@ public static TppDTO mockInstance(Boolean bias) {
.lastUpdateDate(null)
.creationDate(null)
.tokenSection(TokenSectionFaker.mockInstance())
.paymentButton("#button")
.agentDeepLinks(new HashMap<>() {{
put("agent", "link");
}})
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import it.gov.pagopa.tpp.enums.AuthenticationType;
import it.gov.pagopa.tpp.model.Contact;

import java.util.HashMap;

public class TppDTOWithoutTokenSectionFaker {

private TppDTOWithoutTokenSectionFaker(){}
Expand All @@ -25,6 +27,10 @@ public static TppDTOWithoutTokenSection mockInstance(Boolean bias) {
.contact(contact)
.lastUpdateDate(null)
.creationDate(null)
.paymentButton("#button")
.agentDeepLinks(new HashMap<>() {{
put("agent", "link");
}})
.build();
}

Expand All @@ -45,6 +51,10 @@ public static TppDTOWithoutTokenSection mockInstanceWithNoTppId(Boolean bias) {
.contact(contact)
.lastUpdateDate(null)
.creationDate(null)
.paymentButton("#button")
.agentDeepLinks(new HashMap<>() {{
put("agent", "link");
}})
.build();
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/it/gov/pagopa/tpp/utils/faker/TppFaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import it.gov.pagopa.tpp.model.Contact;
import it.gov.pagopa.tpp.model.Tpp;

import java.util.HashMap;

public class TppFaker {

private TppFaker(){}
Expand All @@ -26,6 +28,10 @@ public static Tpp mockInstance(Boolean bias){
.lastUpdateDate(null)
.creationDate(null)
.tokenSection(TokenSectionFaker.mockInstance())
.paymentButton("#button")
.agentDeepLinks(new HashMap<>() {{
put("agent", "link");
}})
.build();
}
}

0 comments on commit c1aa942

Please sign in to comment.