blob: 57dc847a99d7feacc12f5625fb4c910bf5568f8e [file] [log] [blame]
Akronda080152020-12-03 13:53:29 +01001package de.ids_mannheim.korap.web.controller;
2
Marc Kupietzd43a98d2023-09-22 17:11:46 +02003import static org.junit.jupiter.api.Assertions.assertEquals;
Akronda080152020-12-03 13:53:29 +01004
5import org.apache.http.entity.ContentType;
Marc Kupietzd43a98d2023-09-22 17:11:46 +02006import org.junit.jupiter.api.Test;
Akronda080152020-12-03 13:53:29 +01007import com.fasterxml.jackson.databind.JsonNode;
8import com.google.common.net.HttpHeaders;
margaretha96c309d2023-08-16 12:24:12 +02009import jakarta.ws.rs.ProcessingException;
10import jakarta.ws.rs.core.Response;
11import jakarta.ws.rs.core.Response.Status;
12import jakarta.ws.rs.client.Entity;
Akronda080152020-12-03 13:53:29 +010013
14import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
15import de.ids_mannheim.korap.config.Attributes;
16import de.ids_mannheim.korap.config.SpringJerseyTest;
margaretha652c4dc2021-02-12 17:07:44 +010017import de.ids_mannheim.korap.constant.ResourceType;
Akronda080152020-12-03 13:53:29 +010018import de.ids_mannheim.korap.exceptions.KustvaktException;
margaretha89bd8f52021-02-26 17:08:01 +010019import de.ids_mannheim.korap.exceptions.StatusCodes;
margaretha479a4472021-02-18 12:00:55 +010020import de.ids_mannheim.korap.user.User.CorpusAccess;
Akronda080152020-12-03 13:53:29 +010021import de.ids_mannheim.korap.utils.JsonUtils;
22
margaretha652c4dc2021-02-12 17:07:44 +010023public class QueryReferenceControllerTest extends SpringJerseyTest {
Akronda080152020-12-03 13:53:29 +010024
25 private String testUser = "qRefControllerTest";
Marc Kupietzd43a98d2023-09-22 17:11:46 +020026
margaretha89bd8f52021-02-26 17:08:01 +010027 private String adminUser = "admin";
Marc Kupietzd43a98d2023-09-22 17:11:46 +020028
margarethab3ecbe32021-08-16 12:55:54 +020029 private String system = "system";
margaretha652c4dc2021-02-12 17:07:44 +010030
margaretha35e1ca22023-11-16 22:00:01 +010031 private void testRetrieveQueryByName (String qName, String query,
32 String queryCreator, String username, ResourceType resourceType,
33 CorpusAccess access) throws KustvaktException {
34 Response response = target().path(API_VERSION).path("query")
35 .path("~" + queryCreator).path(qName).request()
36 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
37 .createBasicAuthorizationHeaderValue(username, "pass"))
38 .get();
abcpro173fe8f22022-11-08 19:56:52 +000039 String entity = response.readEntity(String.class);
margarethab3ecbe32021-08-16 12:55:54 +020040 // System.out.println(entity);
41 assertEquals(Status.OK.getStatusCode(), response.getStatus());
margarethab3ecbe32021-08-16 12:55:54 +020042 JsonNode node = JsonUtils.readTree(entity);
margaretha3b6972a2021-08-12 11:22:07 +020043 assertEquals(qName, node.at("/name").asText());
44 assertEquals(resourceType.displayName(), node.at("/type").asText());
margarethab3ecbe32021-08-16 12:55:54 +020045 assertEquals(queryCreator, node.at("/createdBy").asText());
margaretha3b6972a2021-08-12 11:22:07 +020046 assertEquals(query, node.at("/query").asText());
Marc Kupietzd43a98d2023-09-22 17:11:46 +020047 assertEquals(node.at("/queryLanguage").asText(), "poliqarp");
margaretha3b6972a2021-08-12 11:22:07 +020048 assertEquals(access.name(), node.at("/requiredAccess").asText());
margaretha3b6972a2021-08-12 11:22:07 +020049 }
Marc Kupietzd43a98d2023-09-22 17:11:46 +020050
margaretha35e1ca22023-11-16 22:00:01 +010051 private void testUpdateQuery (String qName, String qCreator,
52 String username, ResourceType type)
53 throws ProcessingException, KustvaktException {
54 String json = "{\"query\": \"Sonne\""
55 + ",\"queryLanguage\": \"poliqarp\"}";
56 Response response = target().path(API_VERSION).path("query")
57 .path("~" + qCreator).path(qName).request()
58 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
59 .createBasicAuthorizationHeaderValue(username, "pass"))
60 .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
61 .put(Entity.json(json));
margarethab3ecbe32021-08-16 12:55:54 +020062 assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
margaretha35e1ca22023-11-16 22:00:01 +010063 testRetrieveQueryByName(qName, "Sonne", qCreator, username, type,
64 CorpusAccess.PUB);
margarethab3ecbe32021-08-16 12:55:54 +020065 }
Marc Kupietzd43a98d2023-09-22 17:11:46 +020066
Akronda080152020-12-03 13:53:29 +010067 @Test
margaretha35e1ca22023-11-16 22:00:01 +010068 public void testCreatePrivateQuery () throws KustvaktException {
69 String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\""
70 + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"der\"}";
margaretha652c4dc2021-02-12 17:07:44 +010071 String qName = "new_query";
margaretha35e1ca22023-11-16 22:00:01 +010072 Response response = target().path(API_VERSION).path("query")
73 .path("~" + testUser).path(qName).request()
74 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
75 .createBasicAuthorizationHeaderValue(testUser, "pass"))
76 .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
77 .put(Entity.json(json));
Akronda080152020-12-03 13:53:29 +010078 assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
margaretha35e1ca22023-11-16 22:00:01 +010079 testRetrieveQueryByName(qName, "der", testUser, testUser,
80 ResourceType.PRIVATE, CorpusAccess.PUB);
Marc Kupietzd43a98d2023-09-22 17:11:46 +020081 testUpdateQuery(qName, testUser, testUser, ResourceType.PRIVATE);
margarethab3ecbe32021-08-16 12:55:54 +020082 testDeleteQueryByName(qName, testUser, testUser);
margaretha89bd8f52021-02-26 17:08:01 +010083 }
84
85 @Test
margaretha35e1ca22023-11-16 22:00:01 +010086 public void testCreatePublishQuery () throws KustvaktException {
87 String json = "{\"type\": \"PUBLISHED\"" + ",\"queryType\": \"QUERY\""
88 + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"Regen\"}";
margaretha1703c162021-08-13 17:13:42 +020089 String qName = "publish_query";
margaretha35e1ca22023-11-16 22:00:01 +010090 Response response = target().path(API_VERSION).path("query")
91 .path("~" + testUser).path(qName).request()
92 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
93 .createBasicAuthorizationHeaderValue(testUser, "pass"))
94 .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
95 .put(Entity.json(json));
margaretha1703c162021-08-13 17:13:42 +020096 assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
margaretha35e1ca22023-11-16 22:00:01 +010097 testRetrieveQueryByName(qName, "Regen", testUser, testUser,
98 ResourceType.PUBLISHED, CorpusAccess.PUB);
margarethab3ecbe32021-08-16 12:55:54 +020099 testDeleteQueryByName(qName, testUser, testUser);
margaretha1703c162021-08-13 17:13:42 +0200100 // check if hidden group has been created
margaretha1703c162021-08-13 17:13:42 +0200101 }
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200102
margaretha1703c162021-08-13 17:13:42 +0200103 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100104 public void testCreateUserQueryByAdmin () throws KustvaktException {
105 String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\""
106 + ",\"queryLanguage\": \"poliqarp\""
107 + ",\"query\": \"Sommer\"}";
margaretha89bd8f52021-02-26 17:08:01 +0100108 String qName = "marlin-query";
margaretha35e1ca22023-11-16 22:00:01 +0100109 Response response = target().path(API_VERSION).path("query")
110 .path("~marlin").path(qName).request()
111 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
112 .createBasicAuthorizationHeaderValue(adminUser, "pass"))
113 .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
114 .put(Entity.json(json));
margaretha89bd8f52021-02-26 17:08:01 +0100115 assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
margaretha35e1ca22023-11-16 22:00:01 +0100116 testRetrieveQueryByName(qName, "Sommer", "marlin", adminUser,
117 ResourceType.PRIVATE, CorpusAccess.PUB);
margarethab3ecbe32021-08-16 12:55:54 +0200118 testUpdateQuery(qName, "marlin", adminUser, ResourceType.PRIVATE);
119 testDeleteQueryByName(qName, "marlin", adminUser);
margaretha89bd8f52021-02-26 17:08:01 +0100120 }
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200121
margaretha89bd8f52021-02-26 17:08:01 +0100122 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100123 public void testCreateSystemQuery () throws KustvaktException {
124 String json = "{\"type\": \"SYSTEM\"" + ",\"queryType\": \"QUERY\""
125 + ",\"queryLanguage\": \"poliqarp\""
126 + ",\"query\": \"Sommer\"}";
margaretha89bd8f52021-02-26 17:08:01 +0100127 String qName = "system-query";
margaretha35e1ca22023-11-16 22:00:01 +0100128 Response response = target().path(API_VERSION).path("query")
129 .path("~system").path(qName).request()
130 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
131 .createBasicAuthorizationHeaderValue(adminUser, "pass"))
132 .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
133 .put(Entity.json(json));
margaretha89bd8f52021-02-26 17:08:01 +0100134 assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
margaretha35e1ca22023-11-16 22:00:01 +0100135 testRetrieveQueryByName(qName, "Sommer", system, adminUser,
136 ResourceType.SYSTEM, CorpusAccess.PUB);
margarethab3ecbe32021-08-16 12:55:54 +0200137 testUpdateQuery(qName, system, adminUser, ResourceType.SYSTEM);
138 testDeleteSystemQueryUnauthorized(qName);
139 testDeleteQueryByName(qName, system, adminUser);
margaretha89bd8f52021-02-26 17:08:01 +0100140 }
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200141
margaretha89bd8f52021-02-26 17:08:01 +0100142 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100143 public void testCreateSystemQueryUnauthorized () throws KustvaktException {
144 String json = "{\"type\": \"SYSTEM\"" + ",\"queryType\": \"QUERY\""
145 + ",\"queryLanguage\": \"poliqarp\""
146 + ",\"query\": \"Sommer\"}";
147 Response response = target().path(API_VERSION).path("query")
148 .path("~" + testUser).path("system-query").request()
149 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
150 .createBasicAuthorizationHeaderValue(testUser, "pass"))
151 .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
152 .put(Entity.json(json));
margaretha89bd8f52021-02-26 17:08:01 +0100153 assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
abcpro173fe8f22022-11-08 19:56:52 +0000154 String entity = response.readEntity(String.class);
margaretha89bd8f52021-02-26 17:08:01 +0100155 JsonNode node = JsonUtils.readTree(entity);
margaretha35e1ca22023-11-16 22:00:01 +0100156 assertEquals(StatusCodes.AUTHORIZATION_FAILED,
157 node.at("/errors/0/0").asInt());
158 assertEquals("Unauthorized operation for user: " + testUser,
159 node.at("/errors/0/1").asText());
margaretha89bd8f52021-02-26 17:08:01 +0100160 }
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200161
margaretha89bd8f52021-02-26 17:08:01 +0100162 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100163 public void testCreateQueryMissingQueryType () throws KustvaktException {
164 String json = "{\"type\": \"PRIVATE\""
165 + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"Sohn\"}";
margaretha3b6972a2021-08-12 11:22:07 +0200166 String qName = "new_query";
margaretha35e1ca22023-11-16 22:00:01 +0100167 Response response = target().path(API_VERSION).path("query")
168 .path("~" + testUser).path(qName).request()
169 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
170 .createBasicAuthorizationHeaderValue(testUser, "pass"))
171 .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
172 .put(Entity.json(json));
margaretha3b6972a2021-08-12 11:22:07 +0200173 assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
margaretha35e1ca22023-11-16 22:00:01 +0100174 testRetrieveQueryByName(qName, "Sohn", testUser, testUser,
175 ResourceType.PRIVATE, CorpusAccess.PUB);
margarethab3ecbe32021-08-16 12:55:54 +0200176 testDeleteQueryByName(qName, testUser, testUser);
margaretha3b6972a2021-08-12 11:22:07 +0200177 }
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200178
margaretha3b6972a2021-08-12 11:22:07 +0200179 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100180 public void testCreateQueryMissingQueryLanguage ()
181 throws KustvaktException {
182 String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\""
183 + ",\"query\": \"Sohn\"}";
margaretha3b6972a2021-08-12 11:22:07 +0200184 String qName = "new_query";
margaretha35e1ca22023-11-16 22:00:01 +0100185 Response response = target().path(API_VERSION).path("query")
186 .path("~" + testUser).path(qName).request()
187 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
188 .createBasicAuthorizationHeaderValue(testUser, "pass"))
189 .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
190 .put(Entity.json(json));
margaretha3b6972a2021-08-12 11:22:07 +0200191 assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
abcpro173fe8f22022-11-08 19:56:52 +0000192 String entity = response.readEntity(String.class);
margaretha3b6972a2021-08-12 11:22:07 +0200193 JsonNode node = JsonUtils.readTree(entity);
margaretha35e1ca22023-11-16 22:00:01 +0100194 assertEquals(StatusCodes.INVALID_ARGUMENT,
195 node.at("/errors/0/0").asInt());
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200196 assertEquals(node.at("/errors/0/1").asText(), "queryLanguage is null");
197 assertEquals(node.at("/errors/0/2").asText(), "queryLanguage");
margaretha3b6972a2021-08-12 11:22:07 +0200198 }
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200199
margaretha3b6972a2021-08-12 11:22:07 +0200200 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100201 public void testCreateQueryMissingQuery () throws KustvaktException {
202 String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\""
203 + ",\"queryLanguage\": \"poliqarp\"}";
margaretha3b6972a2021-08-12 11:22:07 +0200204 String qName = "new_query";
margaretha35e1ca22023-11-16 22:00:01 +0100205 Response response = target().path(API_VERSION).path("query")
206 .path("~" + testUser).path(qName).request()
207 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
208 .createBasicAuthorizationHeaderValue(testUser, "pass"))
209 .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
210 .put(Entity.json(json));
margaretha3b6972a2021-08-12 11:22:07 +0200211 assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
abcpro173fe8f22022-11-08 19:56:52 +0000212 String entity = response.readEntity(String.class);
margaretha3b6972a2021-08-12 11:22:07 +0200213 JsonNode node = JsonUtils.readTree(entity);
margaretha35e1ca22023-11-16 22:00:01 +0100214 assertEquals(StatusCodes.INVALID_ARGUMENT,
215 node.at("/errors/0/0").asInt());
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200216 assertEquals(node.at("/errors/0/1").asText(), "query is null");
217 assertEquals(node.at("/errors/0/2").asText(), "query");
margaretha3b6972a2021-08-12 11:22:07 +0200218 }
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200219
margaretha3b6972a2021-08-12 11:22:07 +0200220 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100221 public void testCreateQueryMissingResourceType () throws KustvaktException {
222 String json = "{\"query\": \"Wind\""
223 + ",\"queryLanguage\": \"poliqarp\"}";
margaretha3b6972a2021-08-12 11:22:07 +0200224 String qName = "new_query";
margaretha35e1ca22023-11-16 22:00:01 +0100225 Response response = target().path(API_VERSION).path("query")
226 .path("~" + testUser).path(qName).request()
227 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
228 .createBasicAuthorizationHeaderValue(testUser, "pass"))
229 .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
230 .put(Entity.json(json));
margaretha3b6972a2021-08-12 11:22:07 +0200231 assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
abcpro173fe8f22022-11-08 19:56:52 +0000232 String entity = response.readEntity(String.class);
margaretha3b6972a2021-08-12 11:22:07 +0200233 JsonNode node = JsonUtils.readTree(entity);
margaretha35e1ca22023-11-16 22:00:01 +0100234 assertEquals(StatusCodes.INVALID_ARGUMENT,
235 node.at("/errors/0/0").asInt());
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200236 assertEquals(node.at("/errors/0/1").asText(), "type is null");
237 assertEquals(node.at("/errors/0/2").asText(), "type");
margaretha3b6972a2021-08-12 11:22:07 +0200238 }
margarethab3ecbe32021-08-16 12:55:54 +0200239
margaretha35e1ca22023-11-16 22:00:01 +0100240 private void testDeleteQueryByName (String qName, String qCreator,
241 String username) throws KustvaktException {
242 Response response = target().path(API_VERSION).path("query")
243 .path("~" + qCreator).path(qName).request()
244 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
245 .createBasicAuthorizationHeaderValue(username, "pass"))
246 .delete();
margarethab3ecbe32021-08-16 12:55:54 +0200247 assertEquals(Status.OK.getStatusCode(), response.getStatus());
248 }
margaretha89bd8f52021-02-26 17:08:01 +0100249
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200250 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100251 public void testDeleteQueryUnauthorized () throws KustvaktException {
252 Response response = target().path(API_VERSION).path("query")
253 .path("~dory").path("dory-q").request()
254 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
255 .createBasicAuthorizationHeaderValue(testUser, "pass"))
256 .delete();
abcpro173fe8f22022-11-08 19:56:52 +0000257 String entity = response.readEntity(String.class);
margaretha89bd8f52021-02-26 17:08:01 +0100258 JsonNode node = JsonUtils.readTree(entity);
margaretha89bd8f52021-02-26 17:08:01 +0100259 assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
margaretha35e1ca22023-11-16 22:00:01 +0100260 assertEquals(StatusCodes.AUTHORIZATION_FAILED,
261 node.at("/errors/0/0").asInt());
262 assertEquals("Unauthorized operation for user: " + testUser,
263 node.at("/errors/0/1").asText());
margaretha89bd8f52021-02-26 17:08:01 +0100264 }
margarethab3ecbe32021-08-16 12:55:54 +0200265
margaretha35e1ca22023-11-16 22:00:01 +0100266 private void testDeleteSystemQueryUnauthorized (String qName)
267 throws KustvaktException {
268 Response response = target().path(API_VERSION).path("query")
269 .path("~system").path(qName).request()
270 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
271 .createBasicAuthorizationHeaderValue(testUser, "pass"))
272 .delete();
abcpro173fe8f22022-11-08 19:56:52 +0000273 String entity = response.readEntity(String.class);
margarethab3ecbe32021-08-16 12:55:54 +0200274 JsonNode node = JsonUtils.readTree(entity);
margarethab3ecbe32021-08-16 12:55:54 +0200275 assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
margaretha35e1ca22023-11-16 22:00:01 +0100276 assertEquals(StatusCodes.AUTHORIZATION_FAILED,
277 node.at("/errors/0/0").asInt());
278 assertEquals("Unauthorized operation for user: " + testUser,
279 node.at("/errors/0/1").asText());
margarethab3ecbe32021-08-16 12:55:54 +0200280 }
margaretha89bd8f52021-02-26 17:08:01 +0100281
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200282 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100283 public void testDeleteNonExistingQuery () throws KustvaktException {
284 Response response = target().path(API_VERSION).path("query")
285 .path("~dory").path("non-existing-query").request()
286 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
287 .createBasicAuthorizationHeaderValue("dory", "pass"))
288 .delete();
margaretha89bd8f52021-02-26 17:08:01 +0100289 assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
abcpro173fe8f22022-11-08 19:56:52 +0000290 String entity = response.readEntity(String.class);
margaretha89bd8f52021-02-26 17:08:01 +0100291 JsonNode node = JsonUtils.readTree(entity);
margaretha35e1ca22023-11-16 22:00:01 +0100292 assertEquals(StatusCodes.NO_RESOURCE_FOUND,
293 node.at("/errors/0/0").asInt());
294 assertEquals(node.at("/errors/0/1").asText(),
295 "Query dory/non-existing-query is not found.");
296 assertEquals(node.at("/errors/0/2").asText(),
297 "dory/non-existing-query");
Akronda080152020-12-03 13:53:29 +0100298 }
margaretha652c4dc2021-02-12 17:07:44 +0100299
300 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100301 public void testListAvailableQueryForDory ()
302 throws ProcessingException, KustvaktException {
margaretha90adf312021-02-17 10:12:41 +0100303 JsonNode node = testListAvailableQuery("dory");
304 assertEquals(2, node.size());
305 }
306
307 @Test
margaretha35e1ca22023-11-16 22:00:01 +0100308 public void testListAvailableQueryForPearl ()
309 throws ProcessingException, KustvaktException {
margaretha90adf312021-02-17 10:12:41 +0100310 JsonNode node = testListAvailableQuery("pearl");
margaretha90adf312021-02-17 10:12:41 +0100311 assertEquals(1, node.size());
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200312 assertEquals(node.at("/0/name").asText(), "system-q");
margaretha35e1ca22023-11-16 22:00:01 +0100313 assertEquals(ResourceType.SYSTEM.displayName(),
314 node.at("/0/type").asText());
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200315 assertEquals(node.at("/0/description").asText(), "\"system\" query");
316 assertEquals(node.at("/0/query").asText(), "[]");
margaretha35e1ca22023-11-16 22:00:01 +0100317 assertEquals(CorpusAccess.FREE.name(),
318 node.at("/0/requiredAccess").asText());
Marc Kupietzd43a98d2023-09-22 17:11:46 +0200319 // assertEquals("koral:token", node.at("/0/koralQuery/@type").asText());
margaretha90adf312021-02-17 10:12:41 +0100320 }
321
margaretha35e1ca22023-11-16 22:00:01 +0100322 private JsonNode testListAvailableQuery (String username)
323 throws ProcessingException, KustvaktException {
324 Response response = target().path(API_VERSION).path("query").request()
325 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
326 .createBasicAuthorizationHeaderValue(username, "pass"))
327 .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
margaretha652c4dc2021-02-12 17:07:44 +0100328 assertEquals(Status.OK.getStatusCode(), response.getStatus());
abcpro173fe8f22022-11-08 19:56:52 +0000329 String entity = response.readEntity(String.class);
margaretha90adf312021-02-17 10:12:41 +0100330 // System.out.println(entity);
margaretha652c4dc2021-02-12 17:07:44 +0100331 JsonNode node = JsonUtils.readTree(entity);
margaretha90adf312021-02-17 10:12:41 +0100332 return node;
margaretha652c4dc2021-02-12 17:07:44 +0100333 }
Akronda080152020-12-03 13:53:29 +0100334}