-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.java
54 lines (47 loc) · 1.93 KB
/
Tests.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
import api.Api;
import api.ApiRequest;
import api.ApiResponse;
import api.user.RegisterRequest;
import api.user.RegisterResponse;
import api.user.RegisterResponseError;
import org.testng.annotations.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class Tests {
private final Api api = new Api("https://reqres.in/");
@Test
private void registerSuccessful() {
//arrange
RegisterRequest requestBody = RegisterRequest.builder()
.email("eve.holt@reqres.in")
.password("pistol")
.build();
RegisterResponse expectedResponse = RegisterResponse.builder()
.id("4")
.token("QpwL5tke4Pnpja7X4")
.build();
//act
ApiRequest<RegisterRequest> apiRequest = new ApiRequest<>(requestBody);
ApiResponse<RegisterResponse, RegisterResponseError> apiResponse = api.register(apiRequest);
//assert
assertThat("response code is 200", apiResponse.getCode(), is(200));
assertThat("response body is expected", apiResponse.getBody(), is(expectedResponse));
}
@Test
private void registerUnsuccessful() {
//arrange
RegisterRequest requestBody = RegisterRequest.builder()
.email("eve.holt@reqres.in")
// .password("pistol")
.build();
RegisterResponseError expectedResponseError = RegisterResponseError.builder()
.error("Missing password")
.build();
//act
ApiRequest<RegisterRequest> apiRequest = new ApiRequest<>(requestBody);
ApiResponse<RegisterResponse, RegisterResponseError> apiResponse = api.register(apiRequest);
//assert
assertThat("response code is 400", apiResponse.getCode(), is(400));
assertThat("response body is expected", apiResponse.getErrorBody(), is(expectedResponseError));
}
}