Repository navigation
Expand file tree
/
Copy pathGetBankCardsDataByIdIT.java
More file actions
131 lines (111 loc) · 5.61 KB
/
Copy pathGetBankCardsDataByIdIT.java
File metadata and controls
131 lines (111 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package integration.cards;
import elya.allure.*;
import elya.card.*;
import elya.card.constants.Currency;
import elya.card.constants.*;
import elya.restclient.exceptions.*;
import integration.*;
import io.qameta.allure.*;
import org.junit.jupiter.api.*;
import java.math.*;
import java.util.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;
/**
* Integration tests for retrieving a card by ID (GET /bank-cards/data/{id}).
* <ul>
* <li>Card found — returns the correct card with all fields matching</li>
* <li>Card not found — the server answers 404</li>
* <li>Multiple cards present — returns exactly the card with the requested ID</li>
* <li>Card with optional fields — all fields are returned correctly</li>
* </ul>
*/
@Epic("Bank Card API")
@Feature("GET /bank-cards/data/{id} — Retrieve Card By ID")
public class GetBankCardsDataByIdIT extends AbstractApiTest {
@Test
@Story("Card found")
@Severity(SeverityLevel.CRITICAL)
@Priority(PriorityLevel.CRITICAL)
@DisplayName("getApiBankCardById() - Should return specific card with all matching parameters")
void getApiBankCardById_ShouldReturnSpecificCard_WithAllParameters() {
String token = emulator.getAuthToken();
List<BankCard> seededCards = emulator.addBankCards(token, List.of(
BankCard.builder(4444555566667777L, CardType.DEBIT, Currency.USD).build(),
BankCard.builder(1111222233334444L, CardType.CREDIT, Currency.EUR).build()
));
attachJson("Seeded cards", seededCards);
BankCard target = seededCards.stream()
.filter(c -> c.getCardNumber().equals(4444555566667777L))
.findFirst()
.orElseThrow();
BankCard actualCard = clientApi.getApiBankCardById(token, target.getCardId());
attachJson("Response", actualCard);
verify("Verify all fields match exactly", () ->
assertThat(actualCard).usingRecursiveComparison().isEqualTo(target)
);
}
@Test
@Story("Card not found")
@Severity(SeverityLevel.CRITICAL)
@Priority(PriorityLevel.HIGH)
@DisplayName("getApiBankCardById() - Should return 404 when card ID does not exist")
void getApiBankCardById_ShouldReturn404_WhenCardIdDoesNotExist() {
String token = emulator.getAuthToken();
Long nonExistentId = 999999L;
String expectedDetail = "Card with ID [" + nonExistentId + "] not found";
var exception = assertThrows(ApiHttpStatusException.class,
() -> clientApi.getApiBankCardById(token, nonExistentId));
attachJson("Error response", exception.getResponseBody());
verify("A non-existent card ID must be answered with 404 and the missing ID", () -> assertAll(
() -> assertEquals(404, exception.getStatusCode(),
"Status code must be 404, got: " + exception.getStatusCode()),
() -> assertTrue(exception.getResponseBody().contains(expectedDetail),
"Body must name the missing card, got: " + exception.getResponseBody())
));
}
@Test
@Story("Card found")
@Severity(SeverityLevel.NORMAL)
@Priority(PriorityLevel.HIGH)
@DisplayName("getApiBankCardById() - Should return correct card when multiple cards are present")
void getApiBankCardById_ShouldReturnCorrectCard_WhenMultipleCardsPresent() {
String token = emulator.getAuthToken();
List<BankCard> seeded = emulator.addBankCards(token, List.of(
BankCard.builder(1111222233334444L, CardType.DEBIT, Currency.USD).build(),
BankCard.builder(5555666677778888L, CardType.CREDIT, Currency.EUR).build(),
BankCard.builder(9999888877776666L, CardType.DEBIT, Currency.JPY).build()
));
attachJson("Seeded cards", seeded);
BankCard target = seeded.get(1); // middle card
BankCard result = clientApi.getApiBankCardById(token, target.getCardId());
attachJson("Response", result);
verify("Must return exactly the card with the requested ID", () ->
assertThat(result).usingRecursiveComparison().isEqualTo(target)
);
}
@Test
@Story("Card found")
@Severity(SeverityLevel.NORMAL)
@Priority(PriorityLevel.MEDIUM)
@DisplayName("getApiBankCardById() - Returned card must have all fields populated")
void getApiBankCardById_ShouldReturnFullCardData() {
String token = emulator.getAuthToken();
var card = BankCard.builder(4444555566667777L, CardType.CREDIT, Currency.JPY)
.cardStatus(false).balance(BigDecimal.valueOf(12345.67)).build();
List<BankCard> seeded = emulator.addBankCards(token, List.of(card));
attachJson("Seeded card", seeded);
BankCard result = clientApi.getApiBankCardById(token, seeded.getFirst().getCardId());
attachJson("Response", result);
verify("All fields must match", () ->
assertAll("Full card data validation",
() -> assertNotNull(result.getCardId(), "cardId must not be null"),
() -> assertEquals(4444555566667777L, result.getCardNumber()),
() -> assertEquals(CardType.CREDIT, result.getCardType()),
() -> assertEquals(Currency.JPY, result.getCurrency()),
() -> assertEquals(false, result.getCardStatus()),
() -> assertEquals(0, BigDecimal.valueOf(12345.67).compareTo(result.getBalance()))
)
);
}
}