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
14
import com .workup .shared .commands .payments .paymentrequest .requests .CreatePaymentRequestRequest ;
17
- import com .workup .shared .commands .payments .paymentrequest .responses .*;
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
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 ;
19
22
import com .workup .shared .commands .payments .wallet .requests .CreateWalletRequest ;
20
23
import com .workup .shared .commands .payments .wallet .requests .GetWalletRequest ;
21
24
import com .workup .shared .commands .payments .wallet .responses .CreateWalletResponse ;
33
36
import com .workup .shared .enums .payments .PaymentRequestStatus ;
34
37
import com .workup .shared .enums .payments .PaymentTransactionStatus ;
35
38
import com .workup .shared .enums .payments .WalletTransactionType ;
36
- import com .workup .shared .redis .RedisService ;
37
39
import java .util .Optional ;
38
40
import java .util .UUID ;
39
41
import org .junit .jupiter .api .AfterAll ;
49
51
import org .testcontainers .containers .RabbitMQContainer ;
50
52
import org .testcontainers .junit .jupiter .Container ;
51
53
import org .testcontainers .junit .jupiter .Testcontainers ;
52
- import org .testcontainers .utility .DockerImageName ;
53
54
54
55
@ SpringBootTest
55
56
@ Testcontainers
@@ -64,32 +65,24 @@ class PaymentsApplicationTests {
64
65
static final RabbitMQContainer rabbitMQContainer =
65
66
new RabbitMQContainer ("rabbitmq:3.13-management" );
66
67
67
- @ Container
68
- static final RedisContainer redisContainer =
69
- new RedisContainer (DockerImageName .parse ("redis:latest" )).withExposedPorts (6379 );
70
-
71
68
@ Autowired private AmqpTemplate template ;
72
69
@ Autowired private PaymentRequestRepository paymentRequestRepository ;
73
70
@ Autowired private PaymentTransactionRepository paymentTransactionRepository ;
74
71
@ Autowired private WalletRepository walletRepository ;
75
72
@ Autowired private WalletTransactionRepository walletTransactionRepository ;
76
- @ Autowired private RedisService redisService ;
77
73
78
74
@ BeforeEach
79
75
void clearAll () {
80
76
paymentRequestRepository .deleteAll ();
81
77
paymentTransactionRepository .deleteAll ();
82
78
walletRepository .deleteAll ();
83
79
walletTransactionRepository .deleteAll ();
84
-
85
- redisService .clearCache ();
86
80
}
87
81
88
82
@ AfterAll
89
83
static void stopContainers () {
90
84
postgreSQLContainer .stop ();
91
85
rabbitMQContainer .stop ();
92
- redisContainer .stop ();
93
86
}
94
87
95
88
@ DynamicPropertySource
@@ -103,9 +96,6 @@ static void setDatasourceProperties(DynamicPropertyRegistry registry) {
103
96
registry .add ("spring.rabbitmq.port" , rabbitMQContainer ::getFirstMappedPort );
104
97
registry .add ("spring.rabbitmq.username" , rabbitMQContainer ::getAdminUsername );
105
98
registry .add ("spring.rabbitmq.password" , rabbitMQContainer ::getAdminPassword );
106
-
107
- registry .add ("spring.redis.host" , redisContainer ::getHost );
108
- registry .add ("spring.redis.port" , () -> redisContainer .getMappedPort (6379 ));
109
99
}
110
100
111
101
@ Test
@@ -330,7 +320,6 @@ void testWithdrawFromWalletRequest() {
330
320
WithdrawFromWalletRequest .builder ()
331
321
.withAmount (withdrawAmount )
332
322
.withFreelancerId ("1" )
333
- .withPaymentTransactionId ("1" )
334
323
.build ();
335
324
336
325
WithdrawFromWalletResponse response =
@@ -356,11 +345,7 @@ void testNotFoundWithdrawFromWalletRequest() {
356
345
Wallet savedWallet = walletRepository .save (wallet );
357
346
358
347
WithdrawFromWalletRequest withdrawFromWalletRequest =
359
- WithdrawFromWalletRequest .builder ()
360
- .withAmount (200 )
361
- .withFreelancerId ("2" )
362
- .withPaymentTransactionId ("1" )
363
- .build ();
348
+ WithdrawFromWalletRequest .builder ().withAmount (200 ).withFreelancerId ("2" ).build ();
364
349
365
350
WithdrawFromWalletResponse response =
366
351
(WithdrawFromWalletResponse )
@@ -382,7 +367,6 @@ void testInvalidBiggerAmountWithdrawFromWalletRequest() {
382
367
WithdrawFromWalletRequest .builder ()
383
368
.withAmount (withdrawAmount )
384
369
.withFreelancerId ("1" )
385
- .withPaymentTransactionId ("1" )
386
370
.build ();
387
371
388
372
WithdrawFromWalletResponse response =
@@ -413,7 +397,6 @@ void testInvalidNegativeAmountWithdrawFromWalletRequest() {
413
397
WithdrawFromWalletRequest .builder ()
414
398
.withAmount (withdrawAmount )
415
399
.withFreelancerId ("1" )
416
- .withPaymentTransactionId ("1" )
417
400
.build ();
418
401
419
402
WithdrawFromWalletResponse response =
@@ -532,53 +515,6 @@ void testGetFreelancerPaymentRequests() {
532
515
() -> assertEquals (paymentRequest2 .getFreelancerId (), requestDTO2 .getFreelancerId ()));
533
516
}
534
517
535
- @ Test
536
- void testGetPaymentRequest () {
537
- PaymentRequest paymentRequest =
538
- PaymentRequest .builder ()
539
- .withAmount (1200 )
540
- .withDescription ("Payment for services rendered" )
541
- .withClientId ("3" )
542
- .withFreelancerId ("4" )
543
- .build ();
544
- paymentRequestRepository .save (paymentRequest );
545
-
546
- GetPaymentRequestRequest getPaymentRequest =
547
- GetPaymentRequestRequest .builder ().withPaymentRequestId (paymentRequest .getId ()).build ();
548
-
549
- GetPaymentRequestResponse response =
550
- (GetPaymentRequestResponse )
551
- template .convertSendAndReceive (ServiceQueueNames .PAYMENTS , getPaymentRequest );
552
-
553
- assertNotNull (response );
554
- assertEquals (HttpStatusCode .OK , response .getStatusCode ());
555
-
556
- PaymentRequestDTO requestDTO = response .getRequest ();
557
-
558
- assertNotNull (requestDTO );
559
-
560
- assertAll (
561
- () -> assertEquals (paymentRequest .getId (), requestDTO .getId ()),
562
- () -> assertEquals (paymentRequest .getAmount (), requestDTO .getAmount ()),
563
- () -> assertEquals (paymentRequest .getDescription (), requestDTO .getDescription ()),
564
- () -> assertEquals (paymentRequest .getClientId (), requestDTO .getClientId ()),
565
- () -> assertEquals (paymentRequest .getFreelancerId (), requestDTO .getFreelancerId ()));
566
- }
567
-
568
- @ Test
569
- void testGetPaymentRequestNotFound () {
570
- GetPaymentRequestRequest getPaymentRequest =
571
- GetPaymentRequestRequest .builder ().withPaymentRequestId ("123" ).build ();
572
-
573
- GetPaymentRequestResponse response =
574
- (GetPaymentRequestResponse )
575
- template .convertSendAndReceive (ServiceQueueNames .PAYMENTS , getPaymentRequest );
576
-
577
- assertNotNull (response );
578
- assertEquals (HttpStatusCode .NOT_FOUND , response .getStatusCode ());
579
- assertNull (response .getRequest ());
580
- }
581
-
582
518
@ Test
583
519
void testPayPaymentRequest () {
584
520
PaymentRequest paymentRequest =
@@ -753,51 +689,4 @@ void testGetInvalidWallet() {
753
689
assertNotNull (getWalletResponse );
754
690
assertEquals (HttpStatusCode .NOT_FOUND , getWalletResponse .getStatusCode ());
755
691
}
756
-
757
- @ Test
758
- void testGetPaymentRequestResponseFromCache () {
759
- PaymentRequest paymentRequest =
760
- PaymentRequest .builder ()
761
- .withAmount (1200 )
762
- .withDescription ("Payment for services rendered" )
763
- .withClientId ("3" )
764
- .withFreelancerId ("4" )
765
- .build ();
766
- paymentRequestRepository .save (paymentRequest );
767
-
768
- GetPaymentRequestRequest getPaymentRequest =
769
- GetPaymentRequestRequest .builder ().withPaymentRequestId (paymentRequest .getId ()).build ();
770
-
771
- GetPaymentRequestResponse response =
772
- (GetPaymentRequestResponse )
773
- template .convertSendAndReceive (ServiceQueueNames .PAYMENTS , getPaymentRequest );
774
-
775
- assertNotNull (response );
776
- assertEquals (HttpStatusCode .OK , response .getStatusCode ());
777
-
778
- GetPaymentRequestResponse cachedResponse =
779
- (GetPaymentRequestResponse )
780
- redisService .getValue (
781
- getPaymentRequest .getPaymentRequestId (), GetPaymentRequestResponse .class );
782
-
783
- assertNotNull (cachedResponse );
784
- assertEquals (HttpStatusCode .OK , cachedResponse .getStatusCode ());
785
-
786
- assertAll (
787
- () -> assertEquals (response .getRequest ().getId (), cachedResponse .getRequest ().getId ()),
788
- () ->
789
- assertEquals (
790
- response .getRequest ().getAmount (), cachedResponse .getRequest ().getAmount ()),
791
- () ->
792
- assertEquals (
793
- response .getRequest ().getDescription (),
794
- cachedResponse .getRequest ().getDescription ()),
795
- () ->
796
- assertEquals (
797
- response .getRequest ().getClientId (), cachedResponse .getRequest ().getClientId ()),
798
- () ->
799
- assertEquals (
800
- response .getRequest ().getFreelancerId (),
801
- cachedResponse .getRequest ().getFreelancerId ()));
802
- }
803
692
}
0 commit comments