-
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
c8fdcad
commit 833f6aa
Showing
5 changed files
with
136 additions
and
3 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
22 changes: 22 additions & 0 deletions
22
src/test/java/it/gov/pagopa/rtp/activator/domain/PayerIDTest.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,22 @@ | ||
package it.gov.pagopa.rtp.activator.domain; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import java.util.UUID; | ||
|
||
public class PayerIDTest { | ||
|
||
@Test | ||
public void testCreateNew() { | ||
PayerID payerID = PayerID.createNew(); | ||
assertNotNull(payerID); | ||
assertNotNull(payerID.getId()); | ||
} | ||
|
||
@Test | ||
public void testConstructor() { | ||
UUID uuid = UUID.randomUUID(); | ||
PayerID payerID = new PayerID(uuid); | ||
assertNotNull(payerID); | ||
assertEquals(uuid, payerID.getId()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/it/gov/pagopa/rtp/activator/repository/ActivationMapperTest.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,47 @@ | ||
package it.gov.pagopa.rtp.activator.repository; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import it.gov.pagopa.rtp.activator.domain.Payer; | ||
import it.gov.pagopa.rtp.activator.domain.PayerID; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
public class ActivationMapperTest { | ||
|
||
private ActivationMapper mapper = new ActivationMapper(); | ||
|
||
@Test | ||
public void testToDomain() { | ||
ActivationEntity activationEntity = new ActivationEntity(); | ||
activationEntity.setId(UUID.randomUUID().toString()); | ||
activationEntity.setRtpSpId("RTP_SP_ID"); | ||
activationEntity.setFiscalCode("FISCAL_CODE"); | ||
activationEntity.setEffectiveActivationDate(Instant.ofEpochSecond(1732517304)); | ||
|
||
Payer payer = mapper.toDomain(activationEntity); | ||
|
||
assertNotNull(payer); | ||
assertEquals(activationEntity.getId(), payer.payerID().getId().toString()); | ||
assertEquals(activationEntity.getRtpSpId(), payer.rtpSpId()); | ||
assertEquals(activationEntity.getFiscalCode(), payer.fiscalCode()); | ||
assertEquals(activationEntity.getEffectiveActivationDate(), payer.effectiveActivationDate()); | ||
} | ||
|
||
@Test | ||
public void testToDbEntity() { | ||
PayerID payerID = new PayerID(UUID.randomUUID()); | ||
Payer payer = new Payer(payerID, "RTP_SP_ID", "FISCAL_CODE", Instant.ofEpochSecond(1732517304)); | ||
|
||
ActivationEntity activationEntity = mapper.toDbEntity(payer); | ||
|
||
assertNotNull(activationEntity); | ||
assertEquals(payer.payerID().getId().toString(), activationEntity.getId()); | ||
assertEquals(payer.rtpSpId(), activationEntity.getRtpSpId()); | ||
assertEquals(payer.fiscalCode(), activationEntity.getFiscalCode()); | ||
assertEquals(payer.effectiveActivationDate(), activationEntity.getEffectiveActivationDate()); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/it/gov/pagopa/rtp/activator/service/ActivationPayerServiceImplTest.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,63 @@ | ||
package it.gov.pagopa.rtp.activator.service; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import it.gov.pagopa.rtp.activator.domain.Payer; | ||
import it.gov.pagopa.rtp.activator.domain.PayerID; | ||
import it.gov.pagopa.rtp.activator.domain.errors.PayerAlreadyExists; | ||
import it.gov.pagopa.rtp.activator.repository.ActivationDBRepository; | ||
|
||
import reactor.core.publisher.Mono; | ||
import reactor.test.StepVerifier; | ||
|
||
import java.time.Instant; | ||
|
||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class ActivationPayerServiceImplTest { | ||
|
||
@Mock | ||
private ActivationDBRepository activationDBRepository; | ||
|
||
@InjectMocks | ||
private ActivationPayerServiceImpl activationPayerService; | ||
|
||
private Payer payer; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
payer = new Payer(PayerID.createNew(), "RTP_SP_ID", "FISCAL_CODE", Instant.now()); | ||
|
||
} | ||
|
||
@Test | ||
public void testActivatePayerSuccessful() { | ||
when(activationDBRepository.findByFiscalCode("FISCAL_CODE")).thenReturn(Mono.empty()); | ||
when(activationDBRepository.save(any())).thenReturn(Mono.just(payer)); | ||
|
||
Mono<Payer> result = activationPayerService.activatePayer("RTP_SP_ID", "FISCAL_CODE"); | ||
|
||
StepVerifier.create(result) | ||
.expectNext(payer) | ||
.verifyComplete(); | ||
} | ||
|
||
@Test | ||
public void testActivatePayerAlreadyExists() { | ||
when(activationDBRepository.findByFiscalCode("FISCAL_CODE")).thenReturn(Mono.just(payer)); | ||
|
||
Mono<Payer> result = activationPayerService.activatePayer("RTP_SP_ID", "FISCAL_CODE"); | ||
|
||
StepVerifier.create(result) | ||
.expectError(PayerAlreadyExists.class) | ||
.verify(); | ||
} | ||
} |