-
Notifications
You must be signed in to change notification settings - Fork 25
/
AccountResourceTest.java
159 lines (139 loc) · 4.92 KB
/
AccountResourceTest.java
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package quarkus.accounts;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.math.BigDecimal;
import java.util.List;
@QuarkusTest
@TestMethodOrder(OrderAnnotation.class)
public class AccountResourceTest {
@Test
@Order(1)
void testRetrieveAll() {
Response result =
given()
.when().get("/accounts")
.then()
.statusCode(200)
.body(
containsString("George Baird"),
containsString("Mary Taylor"),
containsString("Diana Rigg")
)
.extract()
.response();
List<Account> accounts = result.jsonPath().getList("$");
assertThat(accounts, not(empty()));
assertThat(accounts, hasSize(3));
}
@Test
@Order(2)
void testGetAccount() {
Account account =
given()
.when().get("/accounts/{accountNumber}", 545454545)
.then()
.statusCode(200)
.extract()
.as(Account.class);
assertThat(account.getAccountNumber(), equalTo(545454545L));
assertThat(account.getCustomerName(), equalTo("Diana Rigg"));
assertThat(account.getBalance(), equalTo(new BigDecimal("422.00")));
assertThat(account.getAccountStatus(), equalTo(AccountStatus.OPEN));
}
@Test
@Order(3)
void testCreateAccount() {
Account newAccount = new Account(324324L, 112244L, "Sandy Holmes", new BigDecimal("154.55"));
Account returnedAccount =
given()
.contentType(ContentType.JSON)
.body(newAccount)
.when().post("/accounts")
.then()
.statusCode(201)
.extract()
.as(Account.class);
assertThat(returnedAccount, notNullValue());
assertThat(returnedAccount, equalTo(newAccount));
Response result =
given()
.when().get("/accounts")
.then()
.statusCode(200)
.body(
containsString("George Baird"),
containsString("Mary Taylor"),
containsString("Diana Rigg"),
containsString("Sandy Holmes")
)
.extract()
.response();
List<Account> accounts = result.jsonPath().getList("$");
assertThat(accounts, not(empty()));
assertThat(accounts, hasSize(4));
}
@Test
@Order(4)
void testAccountWithdraw() {
Account account =
given()
.when().get("/accounts/{accountNumber}", 545454545)
.then()
.statusCode(200)
.extract()
.as(Account.class);
assertThat(account.getAccountNumber(), equalTo(545454545L));
assertThat(account.getCustomerName(), equalTo("Diana Rigg"));
assertThat(account.getBalance(), equalTo(new BigDecimal("422.00")));
assertThat(account.getAccountStatus(), equalTo(AccountStatus.OPEN));
Account result =
given()
.body("56.21")
.when().put("/accounts/{accountNumber}/withdrawal", 545454545)
.then()
.statusCode(200)
.extract()
.as(Account.class);
assertThat(result.getAccountNumber(), equalTo(545454545L));
assertThat(result.getCustomerName(), equalTo("Diana Rigg"));
assertThat(result.getBalance(), equalTo(account.getBalance().subtract(new BigDecimal("56.21"))));
assertThat(result.getAccountStatus(), equalTo(AccountStatus.OPEN));
}
@Test
@Order(4)
void testAccountDeposit() {
Account account =
given()
.when().get("/accounts/{accountNumber}", 123456789)
.then()
.statusCode(200)
.extract()
.as(Account.class);
assertThat(account.getAccountNumber(), equalTo(123456789L));
assertThat(account.getCustomerName(), equalTo("George Baird"));
assertThat(account.getBalance(), equalTo(new BigDecimal("354.23")));
assertThat(account.getAccountStatus(), equalTo(AccountStatus.OPEN));
Account result =
given()
.body("28.42")
.when().put("/accounts/{accountNumber}/deposit", 123456789)
.then()
.statusCode(200)
.extract()
.as(Account.class);
assertThat(result.getAccountNumber(), equalTo(123456789L));
assertThat(result.getCustomerName(), equalTo("George Baird"));
assertThat(result.getBalance(), equalTo(account.getBalance().add(new BigDecimal("28.42"))));
assertThat(result.getAccountStatus(), equalTo(AccountStatus.OPEN));
}
}