-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomInputValidationTest.java
223 lines (173 loc) · 7.03 KB
/
CustomInputValidationTest.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package nl.contezza.drc.tests.custom;
import static io.restassured.RestAssured.given;
import java.util.Base64;
import java.util.Date;
import java.util.UUID;
import org.json.JSONArray;
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.dataprovider.DRCDataProvider;
import nl.contezza.drc.rest.RestTest;
import nl.contezza.drc.service.AuthService;
import nl.contezza.drc.service.DRCRequestSpecification;
import nl.contezza.drc.service.EIOService;
import nl.contezza.drc.service.ZTCService;
import nl.contezza.drc.utils.StringDate;
/**
* Some custom unit tests which are not mapped to any python scripts.
*/
// @Log4j2
public class CustomInputValidationTest extends RestTest {
/**
* Create necessary dependencies.
*/
@BeforeTest(groups = "CustomInputValidation")
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);
Response res = ztcService.publishInformatieObjectType(
informatieobjecttypeUrl.substring(informatieobjecttypeUrl.lastIndexOf('/') + 1).trim());
Assert.assertEquals(res.getStatusCode(), 200);
}
@Test(groups = "CustomInputValidation")
public void empty_body_patch() {
EIOService eioService = new EIOService();
// Create EIO
JsonPath json = new JsonPath(eioService
.testCreate(informatieobjecttypeUrl, "beschrijving0", "some content0", new Date()).asString());
String eioUrl = json.getString("url");
String id = eioUrl.substring(eioUrl.lastIndexOf('/') + 1).trim();
Response res = given().spec(DRCRequestSpecification.getDefault()).when()
.patch("/enkelvoudiginformatieobjecten/" + id +
"/unlock")
.then().extract().response();
Assert.assertEquals(res.getStatusCode(), 405);
}
@Test(groups = "CustomInputValidation")
public void create_eio_with_only_required_items() {
AuthService authService = new AuthService();
authService.updateReadOnlyClientScope(new JSONArray().put("documenten.aanmaken"), "zeer_geheim",
informatieobjecttypeUrl);
wait(2000);
EIOService eioService = new EIOService();
Response res = eioService.testCreateReqOnly(informatieobjecttypeUrl, DRCRequestSpecification.getReadonly());
Assert.assertEquals(res.getStatusCode(), 201);
}
@Test(groups = "CustomInputValidation")
public void create_eio_with_empty_strings() {
EIOService eioService = new EIOService();
JSONObject json = new JSONObject();
json.put("identificatie", UUID.randomUUID().toString());
json.put("bronorganisatie", "159351741");
json.put("creatiedatum", StringDate.formatDate(new Date()));
// json.put("ontvangstdatum", "");
// json.put("verzenddatum", "");
json.put("titel", "detailed summary");
json.put("auteur", "test_auteur");
json.put("formaat", "");
json.put("taal", "eng");
json.put("bestandsnaam", "");
json.put("inhoud", Base64.getEncoder().encodeToString("some file content".getBytes()));
json.put("bestandsomvang", "some file content".getBytes().length);
json.put("link", "");
json.put("beschrijving", "");
json.put("informatieobjecttype", informatieobjecttypeUrl);
json.put("vertrouwelijkheidaanduiding", "");
json.put("indicatieGebruiksrecht", "");
// json.put("ondertekening", "");
// json.put("integriteit", "");
json.put("status", "");
Response res = eioService.testCreate(json);
Assert.assertEquals(res.getStatusCode(), 201);
}
@Test(groups = "CustomInputValidation")
public void create_with_path_in_title() {
EIOService eioService = new EIOService();
JSONObject jsonObject = new JSONObject(DRCDataProvider.testCreate(informatieobjecttypeUrl));
String foo = "foo" + randomString(10);
jsonObject.put("identificatie", foo);
jsonObject.put("titel",
"L:\\Tekeningen W\\Projecten\\Pro\\Data\\2013\\13113 Renovatie sporthal te Utrecht\\Revisie\\PS-00 PS01 (2) (1)");
Response res = eioService.testCreate(jsonObject);
Assert.assertEquals(res.getStatusCode(), 201);
wait(20000);
res = eioService.listEIO(foo, null, null);
Assert.assertEquals(res.getStatusCode(), 200);
Assert.assertEquals((int) res.body().path("results.size()"), 1);
Assert.assertEquals((String) res.body().path("results[0].identificatie"), foo);
}
@Test(groups = "CustomInputValidation")
public void validate_count_with_102_eios() {
EIOService eioService = new EIOService();
JSONObject jsonObject = new JSONObject(DRCDataProvider.testCreate(informatieobjecttypeUrl));
String foo = "search" + randomString(10);
jsonObject.put("identificatie", foo);
int createdItems = 102;
int i = 0;
Response res = null;
while (i < createdItems) {
res = eioService.testCreate(jsonObject);
Assert.assertEquals(res.getStatusCode(), 201);
i++;
}
wait(30000);
// first page
res = eioService.listEIO(foo, null, null);
Assert.assertEquals(res.getStatusCode(), 200);
Assert.assertEquals((int) res.body().path("results.size()"), 100);
JsonPath json = new JsonPath(res.asString());
Assert.assertEquals(json.getInt("count"), createdItems);
Assert.assertNotNull(json.get("next"));
// second page
res = eioService.listEIO(foo, null, 2);
Assert.assertEquals(res.getStatusCode(), 200);
Assert.assertEquals((int) res.body().path("results.size()"), 2);
json = new JsonPath(res.asString());
Assert.assertEquals(json.getInt("count"), createdItems);
Assert.assertNull(json.get("next"));
}
@Test(groups = "CustomInputValidation")
public void wrong_page_number() {
EIOService eioService = new EIOService();
JSONObject jsonObject = new JSONObject(DRCDataProvider.testCreate(informatieobjecttypeUrl));
String foo = "doc" + randomString(10);
jsonObject.put("identificatie", foo);
int createdItems = 3;
int i = 0;
Response res = null;
while (i < createdItems) {
res = eioService.testCreate(jsonObject);
Assert.assertEquals(res.getStatusCode(), 201);
i++;
}
wait(30000);
// first page
res = eioService.listEIO(foo, null, null);
Assert.assertEquals(res.getStatusCode(), 200);
// Assert.assertEquals((int) res.body().path("results.size()"), createdItems);
// wrong page
res = eioService.listEIO(foo, null, 2);
JsonPath json = new JsonPath(res.asString());
Assert.assertEquals(res.getStatusCode(), 404);
Assert.assertEquals(json.getString("code"), "not_found");
// cannot find
res = eioService.listEIO(foo + 1, null, null);
json = new JsonPath(res.asString());
Assert.assertEquals(res.getStatusCode(), 200);
Assert.assertNull(json.getString("next"));
Assert.assertNull(json.getString("previous"));
// also wrong page
res = eioService.listEIO(foo + 1, null, 2);
json = new JsonPath(res.asString());
Assert.assertEquals(res.getStatusCode(), 404);
}
}