2
2
3
3
import static org .junit .jupiter .api .Assertions .*;
4
4
5
- import com .redis .testcontainers .RedisContainer ;
6
5
import com .workup .payments .models .PaymentRequest ;
7
6
import com .workup .payments .models .PaymentTransaction ;
8
7
import com .workup .payments .models .Wallet ;
12
11
import com .workup .payments .repositories .WalletRepository ;
13
12
import com .workup .payments .repositories .WalletTransactionRepository ;
14
13
import com .workup .shared .commands .payments .dto .PaymentRequestDTO ;
15
- import com .workup .shared .commands .payments .paymentrequest .requests .*;
16
- import com .workup .shared .commands .payments .paymentrequest .responses .*;
14
+ import com .workup .shared .commands .payments .paymentrequest .requests .CreatePaymentRequestRequest ;
15
+ import com .workup .shared .commands .payments .paymentrequest .requests .GetClientPaymentRequestsRequest ;
16
+ import com .workup .shared .commands .payments .paymentrequest .requests .GetFreelancerPaymentRequestsRequest ;
17
+ import com .workup .shared .commands .payments .paymentrequest .requests .PayPaymentRequestRequest ;
18
+ import com .workup .shared .commands .payments .paymentrequest .responses .CreatePaymentRequestResponse ;
19
+ import com .workup .shared .commands .payments .paymentrequest .responses .GetClientPaymentRequestsResponse ;
20
+ import com .workup .shared .commands .payments .paymentrequest .responses .GetFreelancerPaymentRequestsResponse ;
21
+ import com .workup .shared .commands .payments .paymentrequest .responses .PayPaymentRequestResponse ;
17
22
import com .workup .shared .commands .payments .wallet .requests .CreateWalletRequest ;
18
23
import com .workup .shared .commands .payments .wallet .requests .GetWalletRequest ;
19
24
import com .workup .shared .commands .payments .wallet .responses .CreateWalletResponse ;
31
36
import com .workup .shared .enums .payments .PaymentRequestStatus ;
32
37
import com .workup .shared .enums .payments .PaymentTransactionStatus ;
33
38
import com .workup .shared .enums .payments .WalletTransactionType ;
34
- import com .workup .shared .redis .RedisService ;
35
39
import java .util .Optional ;
36
40
import java .util .UUID ;
37
41
import org .junit .jupiter .api .AfterAll ;
47
51
import org .testcontainers .containers .RabbitMQContainer ;
48
52
import org .testcontainers .junit .jupiter .Container ;
49
53
import org .testcontainers .junit .jupiter .Testcontainers ;
50
- import org .testcontainers .utility .DockerImageName ;
51
54
52
55
@ SpringBootTest
53
56
@ Testcontainers
@@ -62,32 +65,24 @@ class PaymentsApplicationTests {
62
65
static final RabbitMQContainer rabbitMQContainer =
63
66
new RabbitMQContainer ("rabbitmq:3.13-management" );
64
67
65
- @ Container
66
- static final RedisContainer redisContainer =
67
- new RedisContainer (DockerImageName .parse ("redis:latest" ));
68
-
69
68
@ Autowired private AmqpTemplate template ;
70
69
@ Autowired private PaymentRequestRepository paymentRequestRepository ;
71
70
@ Autowired private PaymentTransactionRepository paymentTransactionRepository ;
72
71
@ Autowired private WalletRepository walletRepository ;
73
72
@ Autowired private WalletTransactionRepository walletTransactionRepository ;
74
- @ Autowired private RedisService redisService ;
75
73
76
74
@ BeforeEach
77
75
void clearAll () {
78
76
paymentRequestRepository .deleteAll ();
79
77
paymentTransactionRepository .deleteAll ();
80
78
walletRepository .deleteAll ();
81
79
walletTransactionRepository .deleteAll ();
82
-
83
- redisService .clearCache ();
84
80
}
85
81
86
82
@ AfterAll
87
83
static void stopContainers () {
88
84
postgreSQLContainer .stop ();
89
85
rabbitMQContainer .stop ();
90
- redisContainer .stop ();
91
86
}
92
87
93
88
@ DynamicPropertySource
@@ -101,9 +96,6 @@ static void setDatasourceProperties(DynamicPropertyRegistry registry) {
101
96
registry .add ("spring.rabbitmq.port" , rabbitMQContainer ::getFirstMappedPort );
102
97
registry .add ("spring.rabbitmq.username" , rabbitMQContainer ::getAdminUsername );
103
98
registry .add ("spring.rabbitmq.password" , rabbitMQContainer ::getAdminPassword );
104
-
105
- registry .add ("spring.redis.host" , redisContainer ::getHost );
106
- registry .add ("spring.redis.port" , () -> redisContainer .getMappedPort (6379 ));
107
99
}
108
100
109
101
@ Test
@@ -523,53 +515,6 @@ void testGetFreelancerPaymentRequests() {
523
515
() -> assertEquals (paymentRequest2 .getFreelancerId (), requestDTO2 .getFreelancerId ()));
524
516
}
525
517
526
- @ Test
527
- void testGetPaymentRequest () {
528
- PaymentRequest paymentRequest =
529
- PaymentRequest .builder ()
530
- .withAmount (1200 )
531
- .withDescription ("Payment for services rendered" )
532
- .withClientId ("3" )
533
- .withFreelancerId ("4" )
534
- .build ();
535
- paymentRequestRepository .save (paymentRequest );
536
-
537
- GetPaymentRequestRequest getPaymentRequest =
538
- GetPaymentRequestRequest .builder ().withPaymentRequestId (paymentRequest .getId ()).build ();
539
-
540
- GetPaymentRequestResponse response =
541
- (GetPaymentRequestResponse )
542
- template .convertSendAndReceive (ServiceQueueNames .PAYMENTS , getPaymentRequest );
543
-
544
- assertNotNull (response );
545
- assertEquals (HttpStatusCode .OK , response .getStatusCode ());
546
-
547
- PaymentRequestDTO requestDTO = response .getRequest ();
548
-
549
- assertNotNull (requestDTO );
550
-
551
- assertAll (
552
- () -> assertEquals (paymentRequest .getId (), requestDTO .getId ()),
553
- () -> assertEquals (paymentRequest .getAmount (), requestDTO .getAmount ()),
554
- () -> assertEquals (paymentRequest .getDescription (), requestDTO .getDescription ()),
555
- () -> assertEquals (paymentRequest .getClientId (), requestDTO .getClientId ()),
556
- () -> assertEquals (paymentRequest .getFreelancerId (), requestDTO .getFreelancerId ()));
557
- }
558
-
559
- @ Test
560
- void testGetPaymentRequestNotFound () {
561
- GetPaymentRequestRequest getPaymentRequest =
562
- GetPaymentRequestRequest .builder ().withPaymentRequestId ("123" ).build ();
563
-
564
- GetPaymentRequestResponse response =
565
- (GetPaymentRequestResponse )
566
- template .convertSendAndReceive (ServiceQueueNames .PAYMENTS , getPaymentRequest );
567
-
568
- assertNotNull (response );
569
- assertEquals (HttpStatusCode .NOT_FOUND , response .getStatusCode ());
570
- assertNull (response .getRequest ());
571
- }
572
-
573
518
@ Test
574
519
void testPayPaymentRequest () {
575
520
PaymentRequest paymentRequest =
@@ -744,51 +689,4 @@ void testGetInvalidWallet() {
744
689
assertNotNull (getWalletResponse );
745
690
assertEquals (HttpStatusCode .NOT_FOUND , getWalletResponse .getStatusCode ());
746
691
}
747
-
748
- @ Test
749
- void testGetPaymentRequestResponseFromCache () {
750
- PaymentRequest paymentRequest =
751
- PaymentRequest .builder ()
752
- .withAmount (1200 )
753
- .withDescription ("Payment for services rendered" )
754
- .withClientId ("3" )
755
- .withFreelancerId ("4" )
756
- .build ();
757
- paymentRequestRepository .save (paymentRequest );
758
-
759
- GetPaymentRequestRequest getPaymentRequest =
760
- GetPaymentRequestRequest .builder ().withPaymentRequestId (paymentRequest .getId ()).build ();
761
-
762
- GetPaymentRequestResponse response =
763
- (GetPaymentRequestResponse )
764
- template .convertSendAndReceive (ServiceQueueNames .PAYMENTS , getPaymentRequest );
765
-
766
- assertNotNull (response );
767
- assertEquals (HttpStatusCode .OK , response .getStatusCode ());
768
-
769
- GetPaymentRequestResponse cachedResponse =
770
- (GetPaymentRequestResponse )
771
- redisService .getValue (
772
- getPaymentRequest .getPaymentRequestId (), GetPaymentRequestResponse .class );
773
-
774
- assertNotNull (cachedResponse );
775
- assertEquals (HttpStatusCode .OK , cachedResponse .getStatusCode ());
776
-
777
- assertAll (
778
- () -> assertEquals (response .getRequest ().getId (), cachedResponse .getRequest ().getId ()),
779
- () ->
780
- assertEquals (
781
- response .getRequest ().getAmount (), cachedResponse .getRequest ().getAmount ()),
782
- () ->
783
- assertEquals (
784
- response .getRequest ().getDescription (),
785
- cachedResponse .getRequest ().getDescription ()),
786
- () ->
787
- assertEquals (
788
- response .getRequest ().getClientId (), cachedResponse .getRequest ().getClientId ()),
789
- () ->
790
- assertEquals (
791
- response .getRequest ().getFreelancerId (),
792
- cachedResponse .getRequest ().getFreelancerId ()));
793
- }
794
692
}
0 commit comments