-
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.
- Loading branch information
1 parent
c5c8a6b
commit 58777de
Showing
9 changed files
with
386 additions
and
39 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
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
55 changes: 55 additions & 0 deletions
55
src/test/java/it/gov/pagopa/arc/dto/mapper/BizEventsTransactionDTO2TransactionDTOTest.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,55 @@ | ||
package it.gov.pagopa.arc.dto.mapper; | ||
|
||
import it.gov.pagopa.arc.connector.bizevents.dto.BizEventsTransactionDTO; | ||
import it.gov.pagopa.arc.fakers.BizEventsTransactionDTOFaker; | ||
import it.gov.pagopa.arc.model.generated.TransactionDTO; | ||
import it.gov.pagopa.arc.utils.Utilities; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class BizEventsTransactionDTO2TransactionDTOTest { | ||
|
||
private BizEventsTransactionDTO2TransactionDTO transactionDTOMapper; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
transactionDTOMapper = new BizEventsTransactionDTO2TransactionDTO(); | ||
} | ||
|
||
@Test | ||
void givenApplyWhenBizEventsTransactionDTOIsCartFalseThenReturnMappedDTO() { | ||
//given | ||
BizEventsTransactionDTO bizEventsTransaction = BizEventsTransactionDTOFaker.mockInstance(1,false); | ||
//when | ||
TransactionDTO dtoMapped = transactionDTOMapper.apply(bizEventsTransaction); | ||
|
||
//then | ||
commonAssert(bizEventsTransaction, dtoMapped); | ||
} | ||
|
||
@Test | ||
void givenApplyWhenBizEventsTransactionDTOIsCartTrueThenReturnMappedDTO() { | ||
//given | ||
BizEventsTransactionDTO bizEventsTransaction = BizEventsTransactionDTOFaker.mockInstance(1,true); | ||
//when | ||
TransactionDTO dtoMapped = transactionDTOMapper.apply(bizEventsTransaction); | ||
|
||
//then | ||
commonAssert(bizEventsTransaction, dtoMapped); | ||
} | ||
|
||
private static void commonAssert(BizEventsTransactionDTO bizEventsTransaction, TransactionDTO dtoMapped) { | ||
assertAll( () -> { | ||
assertEquals(bizEventsTransaction.getTransactionId(), dtoMapped.getTransactionId()); | ||
assertEquals(bizEventsTransaction.getPayeeName(), dtoMapped.getPayeeName()); | ||
assertEquals(bizEventsTransaction.getPayeeTaxCode(), dtoMapped.getPayeeTaxCode()); | ||
assertEquals(Utilities.euroToCents(bizEventsTransaction.getAmount()), dtoMapped.getAmount()); | ||
assertEquals(Utilities.dateStringToZonedDateTime(bizEventsTransaction.getTransactionDate()), dtoMapped.getTransactionDate()); | ||
assertEquals(bizEventsTransaction.getIsCart(), dtoMapped.getIsCart()); | ||
assertEquals(bizEventsTransaction.getIsPayer(), dtoMapped.getPayedByMe()); | ||
assertEquals(bizEventsTransaction.getIsDebtor(), dtoMapped.getRegisteredToMe()); | ||
}); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...va/it/gov/pagopa/arc/dto/mapper/BizEventsTransactionsListDTO2TransactionsListDTOTest.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,39 @@ | ||
package it.gov.pagopa.arc.dto.mapper; | ||
|
||
import it.gov.pagopa.arc.fakers.TransactionDTOFaker; | ||
import it.gov.pagopa.arc.model.generated.TransactionDTO; | ||
import it.gov.pagopa.arc.model.generated.TransactionsListDTO; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
class BizEventsTransactionsListDTO2TransactionsListDTOTest { | ||
private BizEventsTransactionsListDTO2TransactionsListDTO transactionsListDTOMapper; | ||
|
||
|
||
@BeforeEach | ||
void setUp() { | ||
transactionsListDTOMapper = new BizEventsTransactionsListDTO2TransactionsListDTO(); | ||
} | ||
@Test | ||
void givenApplyWhenBizEventsTransactionsListDTOThenReturnMappedDTO() { | ||
//given | ||
List<TransactionDTO> transactionsList = List.of( | ||
TransactionDTOFaker.mockInstance(1,false), | ||
TransactionDTOFaker.mockInstance(2,true)); | ||
//when | ||
TransactionsListDTO mappedTransactionsListDTO = transactionsListDTOMapper.apply(transactionsList, 2); | ||
//then | ||
assertAll( () -> { | ||
Assertions.assertEquals(transactionsList, mappedTransactionsListDTO.getTransactions()); | ||
Assertions.assertEquals(1, mappedTransactionsListDTO.getCurrentPage()); | ||
Assertions.assertEquals(2, mappedTransactionsListDTO.getItemsForPage()); | ||
Assertions.assertEquals(1, mappedTransactionsListDTO.getTotalPages()); | ||
Assertions.assertEquals(10, mappedTransactionsListDTO.getTotalItems()); | ||
}); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/java/it/gov/pagopa/arc/fakers/BizEventsTransactionDTOFaker.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,33 @@ | ||
package it.gov.pagopa.arc.fakers; | ||
|
||
import it.gov.pagopa.arc.connector.bizevents.dto.BizEventsTransactionDTO; | ||
|
||
public class BizEventsTransactionDTOFaker { | ||
public static BizEventsTransactionDTO mockInstance(Integer bias, boolean isCart){ | ||
return mockInstanceBuilder(bias, isCart).build(); | ||
} | ||
public static BizEventsTransactionDTO.BizEventsTransactionDTOBuilder mockInstanceBuilder(Integer bias, boolean isCart) { | ||
if (!isCart) { | ||
return BizEventsTransactionDTO | ||
.builder() | ||
.transactionId("TRANSACTION_ID%d" .formatted(bias)) | ||
.payeeName("PAYEE_NAME%d" .formatted(bias)) | ||
.payeeTaxCode("PAYEE_TAX_CODE%d" .formatted(bias)) | ||
.amount("2.681,52") | ||
.transactionDate("2024-05-31T13:07:25Z") | ||
.isCart(false) | ||
.isPayer(true) | ||
.isDebtor(true); | ||
} else { | ||
return BizEventsTransactionDTO | ||
.builder() | ||
.transactionId("TRANSACTION_ID%d" .formatted(bias)) | ||
.payeeName("Pagamento Multiplo") | ||
.payeeTaxCode("") | ||
.transactionDate("2024-05-31T13:07:25Z") | ||
.isCart(true) | ||
.isPayer(false) | ||
.isDebtor(true); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/java/it/gov/pagopa/arc/fakers/TransactionDTOFaker.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,36 @@ | ||
package it.gov.pagopa.arc.fakers; | ||
|
||
import it.gov.pagopa.arc.model.generated.TransactionDTO; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class TransactionDTOFaker { | ||
public static TransactionDTO mockInstance(Integer bias, boolean isCart){ | ||
return mockInstanceBuilder(bias, isCart).build(); | ||
} | ||
public static TransactionDTO.TransactionDTOBuilder mockInstanceBuilder(Integer bias, boolean isCart) { | ||
if (!isCart) { | ||
return TransactionDTO | ||
.builder() | ||
.transactionId("TRANSACTION_ID%d" .formatted(bias)) | ||
.payeeName("PAYEE_NAME%d" .formatted(bias)) | ||
.payeeTaxCode("PAYEE_TAX_CODE%d" .formatted(bias)) | ||
.amount(268152L) | ||
.transactionDate(ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS)) | ||
.isCart(false) | ||
.payedByMe(true) | ||
.registeredToMe(true); | ||
} else { | ||
return TransactionDTO | ||
.builder() | ||
.transactionId("TRANSACTION_ID%d" .formatted(bias)) | ||
.payeeName("Pagamento Multiplo") | ||
.payeeTaxCode("") | ||
.transactionDate(ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS)) | ||
.isCart(true) | ||
.payedByMe(false) | ||
.registeredToMe(true); | ||
} | ||
} | ||
} |
Oops, something went wrong.