 1 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 2 class SendMoneySystemTest {
 3
 4   @Autowired
 5   private TestRestTemplate restTemplate;
 6
 7   private static final String ENDPOINT
 8     = "/accounts/sendMoney/{sourceAccountId}/{targetAccountId}/{amount}";
 9
10   @Test
11   @Sql("SendMoneySystemTest.sql")
12   void sendMoney() {
13
14     Money initialSourceBalance = sourceAccount().calculateBalance();
15     Money initialTargetBalance = targetAccount().calculateBalance();
16
17     ResponseEntity response = whenSendMoney(
18         sourceAccountId(),
19         targetAccountId(),
20         transferredAmount());
2
22     then(response.getStatusCode())
23         .isEqualTo(HttpStatus.OK);
24
25     then(sourceAccount().calculateBalance())
26         .isEqualTo(initialSourceBalance.minus(transferredAmount()));
27
28     then(targetAccount().calculateBalance())
29         .isEqualTo(initialTargetBalance.plus(transferredAmount()));
30   }
31
32   private ResponseEntity whenSendMoney(
33       AccountId sourceAccountId,
34       AccountId targetAccountId,
35       Money amount) {
36     HttpHeaders headers = new HttpHeaders();
37     headers.add("Content-Type", "application/json");
38     HttpEntity<Void> request = new HttpEntity<>(null, headers);
39
40     return restTemplate.exchange(
41         ENDPOINT,
42         HttpMethod.POST,
43         request,
44         Object.class,
45         sourceAccountId.getValue(),
46         targetAccountId.getValue(),
47         amount.getAmount());
48   }
49
50   // Pominięto pewne metody pomocnicze
51 }
