-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponseTest.java
More file actions
82 lines (63 loc) · 2.2 KB
/
Copy pathResponseTest.java
File metadata and controls
82 lines (63 loc) · 2.2 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
package com.retailsvc.http;
import static java.net.HttpURLConnection.HTTP_ACCEPTED;
import static java.net.HttpURLConnection.HTTP_CREATED;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import org.junit.jupiter.api.Test;
class ResponseTest {
@Test
void acceptedNoBody() {
Response r = Response.accepted();
assertThat(r.status()).isEqualTo(HTTP_ACCEPTED);
assertThat(r.body()).isNull();
assertThat(r.headers()).isEmpty();
}
@Test
void acceptedWithBody() {
Map<String, String> job = Map.of("id", "job-42");
Response r = Response.accepted(job);
assertThat(r.status()).isEqualTo(HTTP_ACCEPTED);
assertThat(r.body()).isEqualTo(job);
}
@Test
void createdWithBody() {
Map<String, String> resource = Map.of("id", "x-1");
Response r = Response.created(resource);
assertThat(r.status()).isEqualTo(HTTP_CREATED);
assertThat(r.body()).isEqualTo(resource);
assertThat(r.headers()).isEmpty();
}
@Test
void createdWithLocationViaWithHeader() {
Response r = Response.created(Map.of("id", "x-1")).withHeader("Location", "/things/x-1");
assertThat(r.status()).isEqualTo(HTTP_CREATED);
assertThat(r.headers()).containsEntry("Location", "/things/x-1");
}
@Test
void createdWithLocationViaWithLocation() {
Response r = Response.created(Map.of("id", "x-1")).withLocation("/things/x-1");
assertThat(r.status()).isEqualTo(HTTP_CREATED);
assertThat(r.headers()).containsEntry("Location", "/things/x-1");
}
@Test
void notFoundNoBody() {
Response r = Response.notFound();
assertThat(r.status()).isEqualTo(HTTP_NOT_FOUND);
assertThat(r.body()).isNull();
}
@Test
void notFoundWithBody() {
Map<String, String> problem = Map.of("title", "Missing");
Response r = Response.notFound(problem);
assertThat(r.status()).isEqualTo(HTTP_NOT_FOUND);
assertThat(r.body()).isEqualTo(problem);
}
@Test
void notImplementedNoBody() {
Response r = Response.notImplemented();
assertThat(r.status()).isEqualTo(HTTP_NOT_IMPLEMENTED);
assertThat(r.body()).isNull();
}
}