forked from Contezza/drc-tas-restapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnkelvoudigInformatieObjectCachingTest.java
147 lines (122 loc) · 4.86 KB
/
EnkelvoudigInformatieObjectCachingTest.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
package nl.contezza.drc.tests;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import nl.contezza.drc.rest.RestTest;
import nl.contezza.drc.service.EIOService;
import nl.contezza.drc.service.ZTCService;
//@Log4j2
public class EnkelvoudigInformatieObjectCachingTest extends RestTest {
/**
* Create necessary dependencies.
*/
@BeforeTest(groups = "EnkelvoudigInformatieObjectCaching")
public void init() {
// Create random catalogi
ZTCService ztcService = new ZTCService();
JsonPath json = new JsonPath(ztcService.createCatalogus().asString());
// Create informatieobjecttype
String catalogusUrl = json.getString("url").replace(ZTC_BASE_URI, ZTC_DOCKER_URI);
json = new JsonPath(ztcService.createInformatieObjectType(catalogusUrl).asString());
informatieobjecttypeUrl = json.getString("url").replace(ZTC_BASE_URI, ZTC_DOCKER_URI);
// @formatter:off
Response res = ztcService.publishInformatieObjectType(informatieobjecttypeUrl.substring(informatieobjecttypeUrl.lastIndexOf('/') + 1).trim());
Assert.assertEquals(res.getStatusCode(), 200);
// @formatter:on
}
/**
* See {@link <a href=
* "https://github.com/VNG-Realisatie/documenten-api/blob/1.3.0/src/drc/api/tests/test_caching.py#L19">python
* code</a>}.
*/
@Test(groups = "EnkelvoudigInformatieObjectCaching")
public void test_eio_get_cache_header() {
EIOService eioService = new EIOService();
String eioUrl = new JsonPath(eioService.testCreate(informatieobjecttypeUrl).asString()).getString("url");
Response res = eioService.getEIO(eioUrl, null);
Assert.assertNotNull(res.getHeader("ETag"));
}
/**
* See {@link <a href=
* "https://github.com/VNG-Realisatie/documenten-api/blob/1.3.0/src/drc/api/tests/test_caching.py#L26">python
* code</a>}.
*/
@Test(groups = "EnkelvoudigInformatieObjectCaching")
public void test_eio_head_cache_header() {
EIOService eioService = new EIOService();
String eioUrl = new JsonPath(eioService.testCreate(informatieobjecttypeUrl).asString()).getString("url");
Response res = eioService.getHeadEIO(eioUrl);
Assert.assertNotNull(res.getHeader("ETag"));
Assert.assertEquals(res.getStatusCode(), 200);
}
/**
* See {@link <a href=
* "https://github.com/VNG-Realisatie/documenten-api/blob/1.3.0/src/drc/api/tests/test_caching.py#L38">python
* code</a>}.
*/
@Test(groups = "EnkelvoudigInformatieObjectCaching")
public void test_conditional_get_304() {
EIOService eioService = new EIOService();
String eioUrl = new JsonPath(eioService.testCreate(informatieobjecttypeUrl).asString()).getString("url");
// get ETag
Response res = eioService.getEIO(eioUrl, null);
String eTag = "" + res.getHeader("ETag") + "";
// Not modified for get
res = eioService.getEioIfNonMatch(eioUrl, eTag);
Assert.assertEquals(res.getStatusCode(), 304);
// Not modified for head
res = eioService.getHeadEioIfNonMatch(eioUrl, eTag);
Assert.assertEquals(res.getStatusCode(), 304);
}
/**
* See {@link <a href=
* "https://github.com/VNG-Realisatie/documenten-api/blob/1.3.0/src/drc/api/tests/test_caching.py#L44">python
* code</a>}.
*/
@Test(groups = "EnkelvoudigInformatieObjectCaching")
public void test_conditional_get_stale() {
EIOService eioService = new EIOService();
String eioUrl = new JsonPath(eioService.testCreate(informatieobjecttypeUrl).asString()).getString("url");
Response res = eioService.getEioIfNonMatch(eioUrl, "" + "not-an-md5" + "");
Assert.assertEquals(res.getStatusCode(), 200);
}
/**
* See {@link <a href=
* "https://github.com/VNG-Realisatie/documenten-api/blob/1.3.0/src/drc/api/tests/test_caching.py#L142">python
* code</a>}.
*/
@Test(groups = "EnkelvoudigInformatieObjectCaching")
public void test_invalidate_etag_after_change() {
wait(5000);
EIOService eioService = new EIOService();
String eioUrl = new JsonPath(eioService.testCreate(informatieobjecttypeUrl).asString()).getString("url");
// get ETag
Response res = eioService.getEIO(eioUrl, null);
String eTag = "" + res.getHeader("ETag") + "";
updateEIO(eioUrl, "aangepast");
Response res1 = eioService.getEioIfNonMatch(eioUrl, eTag);
Assert.assertEquals(res1.getStatusCode(), 200);
}
/**
* Update title.
*
* @param eioUrl String url of EIO
* @param titel String title
* @return Response response
*/
private Response updateEIO(String eioUrl, String titel) {
EIOService eioService = new EIOService();
String lock = new JsonPath(eioService.lock(eioUrl).asString()).getString("lock");
JSONObject body = new JSONObject();
body.put("titel", titel);
body.put("lock", lock);
Response res = eioService.partialUpdate(eioUrl, body);
Assert.assertEquals(res.getStatusCode(), 200);
res = eioService.unlock(eioUrl, lock);
Assert.assertEquals(res.getStatusCode(), 204);
return res;
}
}