-
Notifications
You must be signed in to change notification settings - Fork 1
/
GebruiksrechtenReadTest.java
94 lines (70 loc) · 3.94 KB
/
GebruiksrechtenReadTest.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
package nl.contezza.drc.tests;
import org.json.JSONArray;
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.AuthService;
import nl.contezza.drc.service.DRCRequestSpecification;
import nl.contezza.drc.service.EIOService;
import nl.contezza.drc.service.GebruiksrechtenService;
import nl.contezza.drc.service.ZTCService;
//@Log4j2
public class GebruiksrechtenReadTest extends RestTest {
/**
* Create necessary dependencies.
*/
@BeforeTest(groups = "GebruiksrechtenRead")
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);
}
/**
* See {@link <a href="https://github.com/VNG-Realisatie/documenten-api/blob/1.0.0/src/drc/api/tests/test_auth.py#L148">python code</a>}.
*/
@Test(groups = "GebruiksrechtenRead")
public void test_list_gebruiksrechten_limited_to_authorized_zaken() {
EIOService eioService = new EIOService();
JsonPath json1 = new JsonPath(eioService.testCreate(informatieobjecttypeUrl, "beschrijving1", "inhoud1", "openbaar").asString());
JsonPath json2 = new JsonPath(eioService.testCreate(informatieobjecttypeUrl, "beschrijving2", "inhoud2", "vertrouwelijk").asString());
GebruiksrechtenService gebruiksrechtenService = new GebruiksrechtenService();
Response res1 = gebruiksrechtenService.create(json1.getString("url"));
Response res2 = gebruiksrechtenService.create(json2.getString("url"));
Assert.assertEquals(res1.getStatusCode(), 201);
Assert.assertEquals(res2.getStatusCode(), 201);
AuthService authService = new AuthService();
Response res = authService.list(DRCRequestSpecification.CLIENT_ID_READONLY, null);
String acUrl = res.body().path("results[0].url");
res = authService.updatePartial(acUrl, new JSONArray().put(DRCRequestSpecification.CLIENT_ID_READONLY), new JSONArray().put("documenten.lezen"), informatieobjecttypeUrl,
"openbaar");
Assert.assertEquals(res.getStatusCode(), 200);
wait(2000);
res = gebruiksrechtenService.get(DRCRequestSpecification.getReadonly(), new JsonPath(res1.asString()).getString("url"));
Assert.assertEquals(res.getStatusCode(), 200);
res = gebruiksrechtenService.get(DRCRequestSpecification.getReadonly(), new JsonPath(res2.asString()).getString("url"));
Assert.assertEquals(res.getStatusCode(), 403);
}
/**
* See {@link <a href="https://github.com/VNG-Realisatie/documenten-api/blob/1.0.0/src/drc/api/tests/test_auth.py#L175">python code</a>}.
*/
@Test(groups = "GebruiksrechtenRead")
public void test_create_gebruiksrechten_limited_to_authorized_zaken() {
EIOService eioService = new EIOService();
JsonPath json1 = new JsonPath(eioService.testCreate(informatieobjecttypeUrl, "beschrijving1", "inhoud1", "openbaar").asString());
JsonPath json2 = new JsonPath(eioService.testCreate(informatieobjecttypeUrl, "beschrijving2", "inhoud2", "vertrouwelijk").asString());
GebruiksrechtenService gebruiksrechtenService = new GebruiksrechtenService();
Response res1 = gebruiksrechtenService.create(DRCRequestSpecification.getWrongScope(), json1.getString("url"));
Response res2 = gebruiksrechtenService.create(DRCRequestSpecification.getWrongScope(), json2.getString("url"));
Assert.assertEquals(res1.getStatusCode(), 403);
Assert.assertEquals(res2.getStatusCode(), 403);
}
}