-
Notifications
You must be signed in to change notification settings - Fork 1
/
OioCachingTest.java
153 lines (116 loc) · 5.35 KB
/
OioCachingTest.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
package nl.contezza.drc.tests;
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.OIOService;
import nl.contezza.drc.service.ZRCService;
import nl.contezza.drc.service.ZTCService;
//@Log4j2
public class OioCachingTest extends RestTest {
/**
* Create necessary dependencies when creating enkelvoudiginformatieobject.
*/
@BeforeTest(groups = "OioCaching")
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);
// Create zaaktype
zaakTypeTestObject = new JsonPath(ztcService.createZaaktype(catalogusUrl).asString());
String zaaktypeUrl = zaakTypeTestObject.getString("url").replace(ZTC_BASE_URI, ZTC_DOCKER_URI);
// Create zaaktype-informatieobjecttype
Response res = ztcService.createZiot(zaaktypeUrl, informatieobjecttypeUrl);
Assert.assertEquals(res.getStatusCode(), 201);
// Publish informatieobjecttype
String id = informatieobjecttypeUrl.substring(informatieobjecttypeUrl.lastIndexOf('/') + 1).trim();
res = ztcService.publishInformatieObjectType(id);
Assert.assertEquals(res.getStatusCode(), 200);
// Publish zaaktype
res = ztcService.publishIZaaktype(zaaktypeUrl);
Assert.assertEquals(res.getStatusCode(), 200);
ZRCService zrcService = new ZRCService();
zaakTestObject = new JsonPath(zrcService.createZaak(zaaktypeUrl).asString());
}
/**
* See {@link <a href=
* "https://github.com/VNG-Realisatie/documenten-api/blob/1.3.0/src/drc/api/tests/test_caching.py#L55">python
* code</a>}.
*/
@Test(groups = "OioCaching")
public void test_oio_get_cache_header() {
ZRCService zrcService = new ZRCService();
EIOService eioService = new EIOService();
OIOService oioService = new OIOService();
String zaakUrl = zaakTestObject.getString("url").replace(ZRC_BASE_URI, ZRC_DOCKER_URI);
String eioUrl = new JsonPath(eioService.testCreate(informatieobjecttypeUrl).asString()).getString("url");
zrcService.createZio(eioUrl.replace(DRC_BASE_URI, DRC_DOCKER_URI), zaakUrl);
Response resOio = oioService.listOIO(zaakUrl, eioUrl);
String oioUrl = resOio.body().path("[0].url");
Response res = oioService.getOIO(oioUrl);
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#L62">python
* code</a>}.
*/
@Test(groups = "OioCaching")
public void test_oio_head_cache_header() {
ZRCService zrcService = new ZRCService();
EIOService eioService = new EIOService();
OIOService oioService = new OIOService();
String zaakUrl = zaakTestObject.getString("url").replace(ZRC_BASE_URI, ZRC_DOCKER_URI);
String eioUrl = new JsonPath(eioService.testCreate(informatieobjecttypeUrl).asString()).getString("url");
zrcService.createZio(eioUrl.replace(DRC_BASE_URI, DRC_DOCKER_URI), zaakUrl);
Response resOio = oioService.listOIO(zaakUrl, eioUrl);
String oioUrl = resOio.body().path("[0].url");
Response res = oioService.getHeadOIO(oioUrl);
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#L74">python
* code</a>}.
*/
@Test(groups = "OioCaching")
public void test_conditional_get_304() {
ZRCService zrcService = new ZRCService();
EIOService eioService = new EIOService();
OIOService oioService = new OIOService();
String zaakUrl = zaakTestObject.getString("url").replace(ZRC_BASE_URI, ZRC_DOCKER_URI);
String eioUrl = new JsonPath(eioService.testCreate(informatieobjecttypeUrl).asString()).getString("url");
zrcService.createZio(eioUrl.replace(DRC_BASE_URI, DRC_DOCKER_URI), zaakUrl);
Response resOio = oioService.listOIO(zaakUrl, eioUrl);
String oioUrl = resOio.body().path("[0].url");
Response res = oioService.getOIO(oioUrl);
String eTag = "" + res.getHeader("ETag") + "";
res = oioService.getOioIfNonMatch(oioUrl, 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#L118">python
* code</a>}.
*/
@Test(groups = "OioCaching")
public void test_conditional_get_stale() {
ZRCService zrcService = new ZRCService();
EIOService eioService = new EIOService();
OIOService oioService = new OIOService();
String zaakUrl = zaakTestObject.getString("url").replace(ZRC_BASE_URI, ZRC_DOCKER_URI);
String eioUrl = new JsonPath(eioService.testCreate(informatieobjecttypeUrl).asString()).getString("url");
zrcService.createZio(eioUrl.replace(DRC_BASE_URI, DRC_DOCKER_URI), zaakUrl);
Response resOio = oioService.listOIO(zaakUrl, eioUrl);
String oioUrl = resOio.body().path("[0].url");
Response res = oioService.getOioIfNonMatch(oioUrl, "" + "not-an-md5" + "");
Assert.assertEquals(res.getStatusCode(), 200);
}
}