Skip to content

Commit

Permalink
add mapper test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaconsalvi committed Dec 6, 2024
1 parent 64cfc2c commit f18c5c7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import it.gov.pagopa.rtp.activator.model.generated.epc.PaymentInstruction42EPC25922V30DS02Dto;
import it.gov.pagopa.rtp.activator.model.generated.epc.PaymentMethod7CodeDto;
import it.gov.pagopa.rtp.activator.model.generated.epc.PaymentTypeInformation26EPC25922V30DS02Dto;
import it.gov.pagopa.rtp.activator.model.generated.epc.Purpose2ChoiceEPC25922V30DS02Dto;
import it.gov.pagopa.rtp.activator.model.generated.epc.RemittanceInformation21EPC25922V30DS02Dto;
import it.gov.pagopa.rtp.activator.model.generated.epc.SepaRequestToPayRequestResourceDto;

Expand Down Expand Up @@ -166,6 +167,7 @@ public SepaRequestToPayRequestResourceDto toRequestToPay(Rtp rtp) {
.add(flgConfRefinstructionForCreditorAgent3EPC25922V30DS02Dto);

ExternalPurpose1CodeWrapperDto externalPurpose1CodeWrapperDto = new ExternalPurpose1CodeWrapperDto();

externalPurpose1CodeWrapperDto.setCd(rtp.noticeNumber());

List<String> lUstrd = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package it.gov.pagopa.rtp.activator.service.rtp;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.*;

import it.gov.pagopa.rtp.activator.domain.rtp.ResourceID;
import it.gov.pagopa.rtp.activator.domain.rtp.Rtp;
import it.gov.pagopa.rtp.activator.model.generated.epc.SepaRequestToPayRequestResourceDto;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

public class SepaRequestToPayMapperTest {

@Mock
private Rtp rtp;

@InjectMocks
private SepaRequestToPayMapper sepaRequestToPayMapper;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
void testToRequestToPay() {
ResourceID resourceId = ResourceID.createNew();
String payerId = "payerId123";
String payeeId = "payeeId123";
String payeeName = "Mario Rossi";
String rtpSpId = "BIC123456";
String iban = "IT60X0542811101000000123456";
String endToEndId = "endToEndId123";
BigDecimal amount = BigDecimal.valueOf(10);
LocalDateTime savingDateTime = LocalDateTime.now();
LocalDate expiryDate = LocalDate.now().plusDays(5);
String description = "Pagamento TARI";
String noticeNumber = "123456";
String payTrxRef = "payTrxRef123";
String flgConf = "flgConf123";

when(rtp.resourceID()).thenReturn(resourceId);
when(rtp.payerId()).thenReturn(payerId);
when(rtp.payeeId()).thenReturn(payeeId);
when(rtp.payeeName()).thenReturn(payeeName);
when(rtp.rtpSpId()).thenReturn(rtpSpId);
when(rtp.iban()).thenReturn(iban);
when(rtp.endToEndId()).thenReturn(endToEndId);
when(rtp.amount()).thenReturn(amount.intValue());
when(rtp.savingDateTime()).thenReturn(savingDateTime);
when(rtp.expiryDate()).thenReturn(expiryDate);
when(rtp.description()).thenReturn(description);
when(rtp.noticeNumber()).thenReturn(noticeNumber);
when(rtp.payTrxRef()).thenReturn(payTrxRef);
when(rtp.flgConf()).thenReturn(flgConf);

SepaRequestToPayRequestResourceDto result = sepaRequestToPayMapper.toRequestToPay(rtp);

assertNotNull(result);
assertEquals(resourceId.toString(), result.getResourceId());
assertEquals("http://spsrtp.api.cstar.pagopa.it", result.getCallbackUrl().toString());
assertEquals(resourceId.toString(), result.getDocument().getCdtrPmtActvtnReq().getGrpHdr().getMsgId());
assertTrue(result.getDocument().getCdtrPmtActvtnReq().getPmtInf().get(0).getCdtTrfTx().get(0).getRmtInf().getUstrd().contains(description));
}
}

0 comments on commit f18c5c7

Please sign in to comment.