-
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
921567a
commit 64cfc2c
Showing
8 changed files
with
239 additions
and
21 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
3 changes: 1 addition & 2 deletions
3
...tion/ActivationAPIControllerImplTest.java → ...ller/ActivationAPIControllerImplTest.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
111 changes: 111 additions & 0 deletions
111
src/test/java/it/gov/pagopa/rtp/activator/controller/SendAPIControllerImplTest.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,111 @@ | ||
package it.gov.pagopa.rtp.activator.controller; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
import org.springframework.test.context.aot.DisabledInAotMode; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
import it.gov.pagopa.rtp.activator.configuration.SecurityConfig; | ||
|
||
import it.gov.pagopa.rtp.activator.model.generated.send.CreateRtpDto; | ||
import it.gov.pagopa.rtp.activator.model.generated.send.PayeeDto; | ||
import it.gov.pagopa.rtp.activator.service.rtp.SendRTPService; | ||
import it.gov.pagopa.rtp.activator.utils.Users; | ||
import reactor.core.publisher.Mono; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyInt; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.springSecurity; | ||
|
||
import java.time.LocalDate; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@WebFluxTest(controllers = { SendAPIControllerImpl.class }) | ||
@Import({ SecurityConfig.class }) | ||
@DisabledInAotMode | ||
public class SendAPIControllerImplTest { | ||
|
||
@MockBean | ||
private SendRTPService sendRTPService; | ||
|
||
private WebTestClient webTestClient; | ||
|
||
@Autowired | ||
private ApplicationContext context; | ||
|
||
@BeforeEach | ||
void setup() { | ||
webTestClient = WebTestClient | ||
.bindToApplicationContext(context) | ||
.apply(springSecurity()) | ||
.configureClient() | ||
.build(); | ||
} | ||
|
||
@Test | ||
@Users.RtpSenderWriter | ||
void testSendRtpSuccessful() { | ||
|
||
when(sendRTPService.send(anyString(), anyInt(), anyString(), any(), anyString(), anyString(), anyString(), | ||
anyString(), anyString(), anyString(), anyString())) | ||
.thenReturn(Mono.empty()); | ||
|
||
webTestClient.post() | ||
.uri("/rtps") | ||
.bodyValue(generateSendRequest()) | ||
.exchange() | ||
.expectStatus() | ||
.isCreated() | ||
.expectBody() | ||
.isEmpty(); | ||
} | ||
|
||
@Test | ||
@Users.RtpSenderWriter | ||
void testSendRtpWithWrongBody() { | ||
|
||
when(sendRTPService.send(anyString(), anyInt(), anyString(), any(), anyString(), anyString(), anyString(), | ||
anyString(), anyString(), anyString(), anyString())) | ||
.thenReturn(Mono.empty()); | ||
|
||
webTestClient.post() | ||
.uri("/rtps") | ||
.bodyValue(generateWrongSendRequest()) | ||
.exchange() | ||
.expectStatus() | ||
.isEqualTo(HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
@Test | ||
@WithMockUser | ||
void userWithoutEnoughPermissionShouldNotSendRtp() { | ||
webTestClient.post() | ||
.uri("/rtps") | ||
.bodyValue(generateSendRequest()) | ||
.exchange() | ||
.expectStatus() | ||
.isEqualTo(HttpStatus.FORBIDDEN); | ||
} | ||
|
||
private CreateRtpDto generateSendRequest() { | ||
return new CreateRtpDto("311111111112222222", 1, "description", LocalDate.now(), "payerId", | ||
new PayeeDto("77777777777", "payeeName")); | ||
} | ||
|
||
private CreateRtpDto generateWrongSendRequest() { | ||
return new CreateRtpDto("noticenumber", 1, "description", LocalDate.now(), "payerId", | ||
new PayeeDto("dsds", "payeeName")); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/java/it/gov/pagopa/rtp/activator/domain/rtp/ResourceIDTest.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,26 @@ | ||
package it.gov.pagopa.rtp.activator.domain.rtp; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.util.UUID; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ResourceIDTest { | ||
@Test | ||
void testCreateNew() { | ||
ResourceID resourceID = ResourceID.createNew(); | ||
assertNotNull(resourceID); | ||
assertNotNull(resourceID.getId()); | ||
} | ||
|
||
@Test | ||
void testConstructor() { | ||
UUID uuid = UUID.randomUUID(); | ||
ResourceID resourceID = new ResourceID(uuid); | ||
assertNotNull(resourceID); | ||
assertEquals(uuid, resourceID.getId()); | ||
} | ||
|
||
} |
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
78 changes: 78 additions & 0 deletions
78
src/test/java/it/gov/pagopa/rtp/activator/service/rtp/SendRTPServiceTest.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,78 @@ | ||
package it.gov.pagopa.rtp.activator.service.rtp; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.net.URI; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
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.MockitoAnnotations; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
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 reactor.core.publisher.Mono; | ||
import reactor.test.StepVerifier; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class SendRTPServiceTest { | ||
|
||
@Mock | ||
private SepaRequestToPayMapper sepaRequestToPayMapper; | ||
|
||
@InjectMocks | ||
private SendRTPServiceImpl sendRTPService; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
public void testSend() { | ||
String noticeNumber = "12345"; | ||
Integer amount = 100; | ||
String description = "Payment Description"; | ||
LocalDate expiryDate = LocalDate.now(); | ||
String payerId = "payerId"; | ||
String payeeName = "Payee Name"; | ||
String payeeId = "payeeId"; | ||
String endToEndId = "endToEndId"; | ||
String iban = "IT60X0542811101000000123456"; | ||
String payTrxRef = "payTrxRef"; | ||
String flgConf = "flgConf"; | ||
|
||
Rtp expectedRtp = new Rtp(noticeNumber, amount, description, expiryDate, payerId, payeeName, payeeId, | ||
ResourceID.createNew(), LocalDateTime.now(), payeeId, endToEndId, iban, payTrxRef, flgConf); | ||
|
||
SepaRequestToPayRequestResourceDto mockSepaRequestToPayRequestResource = new SepaRequestToPayRequestResourceDto( | ||
URI.create("http://callback.url")); | ||
|
||
when(sepaRequestToPayMapper.toRequestToPay(any(Rtp.class))).thenReturn(mockSepaRequestToPayRequestResource); | ||
|
||
Mono<Rtp> result = sendRTPService.send(noticeNumber, amount, description, expiryDate, payerId, payeeName, | ||
payeeId, endToEndId, iban, payTrxRef, flgConf); | ||
StepVerifier.create(result) | ||
.expectNextMatches(rtp -> rtp.noticeNumber().equals(expectedRtp.noticeNumber()) | ||
&& rtp.amount().equals(expectedRtp.amount()) | ||
&& rtp.description().equals(expectedRtp.description()) | ||
&& rtp.expiryDate().equals(expectedRtp.expiryDate()) | ||
&& rtp.payerId().equals(expectedRtp.payerId()) | ||
&& rtp.payeeName().equals(expectedRtp.payeeName()) | ||
&& rtp.payeeId().equals(expectedRtp.payeeId()) | ||
&& rtp.endToEndId().equals(expectedRtp.endToEndId()) | ||
&& rtp.iban().equals(expectedRtp.iban()) && rtp.payTrxRef().equals(expectedRtp.payTrxRef()) | ||
&& rtp.flgConf().equals(expectedRtp.flgConf())) | ||
.verifyComplete(); | ||
verify(sepaRequestToPayMapper, times(1)).toRequestToPay(any(Rtp.class)); | ||
} | ||
} |
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