-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGetStatesRequestTests.java
More file actions
201 lines (130 loc) · 6.24 KB
/
Copy pathGetStatesRequestTests.java
File metadata and controls
201 lines (130 loc) · 6.24 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* Copyright 2016-2023 Berry Cloud Ltd. All rights reserved.
*/
package dev.learning.xapi.client;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import dev.learning.xapi.client.GetStatesRequest.Builder;
import java.net.URI;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.web.util.UriComponentsBuilder;
/**
* GetStatesRequest Tests.
*
* @author Thomas Turrell-Croft
*/
@DisplayName("GetStatesRequest Tests")
class GetStatesRequestTests {
@Test
void whenBuildingGetStatesRequestWithAllParametersThenNoExceptionIsThrown() {
// When Building GetStatesRequest With All Parameters
final Builder<?, ?> builder = GetStatesRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")
.since(Instant.now());
// Then No Exception Is Thrown
assertDoesNotThrow(builder::build);
}
@Test
void whenBuildingGetStatesRequestWithoutSinceParameterThenNoExceptionIsThrown() {
// When Building GetStatesRequest Without Since Parameter
final Builder<?, ?> builder = GetStatesRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6");
// Then No Exception Is Thrown
assertDoesNotThrow(builder::build);
}
@Test
void whenBuildingGetStatesRequestWithoutRegistrationParameterThenNoExceptionIsThrown() {
// When Building GetStatesRequest Without Registration Parameter
final Builder<?, ?> builder = GetStatesRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"));
// Then No Exception Is Thrown
assertDoesNotThrow(builder::build);
}
@Test
void whenBuildingGetStatesRequestWithRequiredParametersThenNoExceptionIsThrown() {
// When Building GetStatesRequest With Required Parameters
final Builder<?, ?> builder = GetStatesRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"));
// Then No Exception Is Thrown
assertDoesNotThrow(builder::build);
}
@Test
void whenBuildingGetStatesRequestWithoutActivityIdThenNullPointerExceptionIsThrown() {
// When Building GetStatesRequest Without ActivityId
final Builder<?, ?> builder = GetStatesRequest.builder()
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"));
// Then Null Pointer Exception Is Thrown
assertThrows(NullPointerException.class, builder::build);
}
@Test
void whenBuildingGetStatesRequestWithoutAgentThenNullPointerExceptionIsThrown() {
// When Building GetStatesRequest Without Agent
final Builder<?, ?> builder = GetStatesRequest.builder()
.activityId("https://example.com/activity/1");
// Then Null Pointer Exception Is Thrown
assertThrows(NullPointerException.class, builder::build);
}
@Test
void givenGetStatesRequestWithAllParametersWhenGettingURLThenResultIsExpected() {
// Given GetStatesRequest With All Parameters
final GetStatesRequest request = GetStatesRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")
.since(Instant.parse("2016-01-01T00:00:00Z"))
.build();
final Map<String, Object> queryParams = new HashMap<>();
// When Getting URL
final var result =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
// Then Result Is Expected
assertThat(result, is(URI.create(
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22mailto%3Aanother%40example.com%22%7D®istration=67828e3a-d116-4e18-8af3-2d2c59e27be6&since=2016-01-01T00:00:00Z")));
}
@Test
void givenGetStatesRequestWithoutRegistrationParameterWhenGettingURLThenResultIsExpected() {
// Given GetStatesRequest Without Registration Parameter
final GetStatesRequest request = GetStatesRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))
.build();
final Map<String, Object> queryParams = new HashMap<>();
// When Getting URL
final var result =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
// Then Result Is Expected
assertThat(result, is(URI.create(
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22mailto%3Aanother%40example.com%22%7D")));
}
@Test
void givenGetStatesRequestWithoutSinceParameterWhenGettingURLThenResultIsExpected() {
// Given GetStatesRequest Without Since Parameter
final GetStatesRequest request = GetStatesRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")
.build();
final Map<String, Object> queryParams = new HashMap<>();
// When Getting URL
final var result =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
// Then Result Is Expected
assertThat(result, is(URI.create(
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22mailto%3Aanother%40example.com%22%7D®istration=67828e3a-d116-4e18-8af3-2d2c59e27be6")));
}
}