-
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.
* Add testing setup * Delete old testing setup
- Loading branch information
1 parent
53fce39
commit 1d94842
Showing
9 changed files
with
159 additions
and
27 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
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
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
92 changes: 91 additions & 1 deletion
92
services/payments/src/test/java/com/workup/payments/PaymentsApplicationTests.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 |
---|---|---|
@@ -1,11 +1,101 @@ | ||
package com.workup.payments; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.workup.payments.repositories.PaymentRequestRepository; | ||
import com.workup.payments.repositories.PaymentTransactionRepository; | ||
import com.workup.payments.repositories.WalletRepository; | ||
import com.workup.payments.repositories.WalletTransactionRepository; | ||
import com.workup.shared.commands.payments.paymentrequest.requests.CreatePaymentRequestRequest; | ||
import com.workup.shared.commands.payments.paymentrequest.responses.CreatePaymentRequestResponse; | ||
import com.workup.shared.enums.HttpStatusCode; | ||
import com.workup.shared.enums.ServiceQueueNames; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.amqp.core.AmqpTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.containers.RabbitMQContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@SpringBootTest | ||
@Testcontainers | ||
@Import(TestConfigBase.class) | ||
class PaymentsApplicationTests { | ||
|
||
@Container | ||
static final PostgreSQLContainer<?> postgreSQLContainer = | ||
new PostgreSQLContainer<>("postgres:latest"); | ||
|
||
@Container | ||
static final RabbitMQContainer rabbitMQContainer = | ||
new RabbitMQContainer("rabbitmq:3.13-management"); | ||
|
||
@Autowired private AmqpTemplate template; | ||
@Autowired private PaymentRequestRepository paymentRequestRepository; | ||
@Autowired private PaymentTransactionRepository paymentTransactionRepository; | ||
@Autowired private WalletRepository walletRepository; | ||
@Autowired private WalletTransactionRepository walletTransactionRepository; | ||
|
||
@BeforeEach | ||
void clearAll() { | ||
paymentRequestRepository.deleteAll(); | ||
paymentTransactionRepository.deleteAll(); | ||
walletRepository.deleteAll(); | ||
walletTransactionRepository.deleteAll(); | ||
} | ||
|
||
@AfterAll | ||
static void stopContainers() { | ||
postgreSQLContainer.stop(); | ||
rabbitMQContainer.stop(); | ||
} | ||
|
||
@DynamicPropertySource | ||
static void setDatasourceProperties(DynamicPropertyRegistry registry) { | ||
registry.add("spring.datasource.url", postgreSQLContainer::getJdbcUrl); | ||
registry.add("spring.datasource.username", postgreSQLContainer::getUsername); | ||
registry.add("spring.datasource.password", postgreSQLContainer::getPassword); | ||
registry.add("spring.jpa.hibernate.ddl-auto", () -> "create-drop"); | ||
|
||
registry.add("spring.rabbitmq.host", rabbitMQContainer::getHost); | ||
registry.add("spring.rabbitmq.port", rabbitMQContainer::getFirstMappedPort); | ||
registry.add("spring.rabbitmq.username", rabbitMQContainer::getAdminUsername); | ||
registry.add("spring.rabbitmq.password", rabbitMQContainer::getAdminPassword); | ||
} | ||
|
||
@Test | ||
void contextLoads() {} | ||
void testCreatePaymentRequest() { | ||
CreatePaymentRequestRequest createPaymentRequest = | ||
CreatePaymentRequestRequest.builder() | ||
.withAmount(1200) | ||
.withDescription("Payment for services rendered") | ||
.withClientId("3") | ||
.withFreelancerId("4") | ||
.build(); | ||
CreatePaymentRequestResponse response = | ||
(CreatePaymentRequestResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.PAYMENTS, createPaymentRequest); | ||
|
||
assertNotNull(response); | ||
assertEquals(HttpStatusCode.CREATED, response.getStatusCode()); | ||
|
||
paymentRequestRepository | ||
.findById(String.valueOf(UUID.fromString(response.getPaymentRequestId()))) | ||
.ifPresentOrElse( | ||
paymentRequest -> { | ||
assertEquals(1200, paymentRequest.getAmount()); | ||
assertEquals("Payment for services rendered", paymentRequest.getDescription()); | ||
assertEquals("3", paymentRequest.getClientId()); | ||
assertEquals("4", paymentRequest.getFreelancerId()); | ||
}, | ||
() -> fail("Payment request not found")); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
services/payments/src/test/java/com/workup/payments/TestConfigBase.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,15 @@ | ||
package com.workup.payments; | ||
|
||
import com.workup.shared.enums.ServiceQueueNames; | ||
import org.springframework.amqp.core.Queue; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@TestConfiguration | ||
public class TestConfigBase { | ||
|
||
@Bean | ||
public Queue paymentsQueueMock() { | ||
return new Queue(ServiceQueueNames.PAYMENTS); | ||
} | ||
} |