Jersey 2: Migrate requests made in unittests
This commit is a set of simple migrations for client requests made in
unittests.
The javax.ws.rs.core.Response class is the default object returned by
the request methods: get, post, put, and delete; This class can be a replacement
for com.sun.jersey.api.client.ClientResponse from Jersey 1.x.
Why not use org.glassfish.jersey.client.ClientResponse as a replacement instead?
When trying to return a org.glassfish.jersey.client.ClientResponse from the
request methods, the Jersey implementation for some reason attempts to use
the Jackson ObjectMapper to convert the do the conversion which by default will fail
with an exception.
Other simple migrations in this commit include replacing MultivaluedMap with
javax.ws.rs.core.Form for form query parameters; And conforming to the new signature
for put() and post() methods a javax.ws.rs.client.Entity is always supplied.
diff --git a/full/src/main/java/de/ids_mannheim/korap/oauth2/oltu/service/OltuAuthorizationService.java b/full/src/main/java/de/ids_mannheim/korap/oauth2/oltu/service/OltuAuthorizationService.java
index 6aa82d1..cb72f53 100644
--- a/full/src/main/java/de/ids_mannheim/korap/oauth2/oltu/service/OltuAuthorizationService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/oauth2/oltu/service/OltuAuthorizationService.java
@@ -15,7 +15,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import com.sun.jersey.api.client.ClientResponse.Status;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.encryption.RandomCodeGenerator;
import de.ids_mannheim.korap.exceptions.KustvaktException;
diff --git a/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java b/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java
index 449268b..4873674 100644
--- a/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java
@@ -5,7 +5,7 @@
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.config.SpringJerseyTest;
@@ -17,13 +17,13 @@
@Test
public void testAuthenticationWithUnknownScheme ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
.request()
.header(Attributes.AUTHORIZATION, "Blah blah")
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode n = JsonUtils.readTree(entity);
assertEquals("2001", n.at("/errors/0/0").asText());
diff --git a/full/src/test/java/de/ids_mannheim/korap/authentication/LdapOAuth2Test.java b/full/src/test/java/de/ids_mannheim/korap/authentication/LdapOAuth2Test.java
index 5e531e4..ea19da9 100644
--- a/full/src/test/java/de/ids_mannheim/korap/authentication/LdapOAuth2Test.java
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/LdapOAuth2Test.java
@@ -5,6 +5,7 @@
import java.net.URI;
import java.security.GeneralSecurityException;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
import org.apache.http.entity.ContentType;
@@ -20,8 +21,9 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.client.Entity;
import com.unboundid.ldap.sdk.LDAPException;
import de.ids_mannheim.korap.config.Attributes;
@@ -79,12 +81,12 @@
public void testRequestTokenPasswordUnknownUser ()
throws KustvaktException {
- ClientResponse response = requestTokenWithPassword(superClientId,
+ Response response = requestTokenWithPassword(superClientId,
clientSecret, "unknown", "password");
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2023, node.at("/errors/0/0").asInt());
@@ -95,9 +97,9 @@
@Test
public void testMapUsernameToEmail () throws KustvaktException {
- ClientResponse response = requestTokenWithPassword(superClientId,
+ Response response = requestTokenWithPassword(superClientId,
clientSecret, "testUser", "password");
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -126,14 +128,14 @@
json.setDescription(
"Test registering a public client with LDAP authentication");
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("register")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).post(ClientResponse.class);
+ .post(Entity.json(json));
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String clientId = node.at("/client_id").asText();
@@ -151,14 +153,14 @@
json.setDescription(
"Test registering a confidential client with LDAP authentication");
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("register")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).post(ClientResponse.class);
+ .post(Entity.json(json));
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String clientId = node.at("/client_id").asText();
@@ -170,14 +172,14 @@
private void testRequestTokenWithAuthorization (String clientId,
String clientSecret, String accessToken) throws KustvaktException {
String authHeader = "Bearer " + accessToken;
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("authorize")
.queryParam("response_type", "code")
.queryParam("client_id", clientId)
.queryParam("client_secret", clientSecret)
.request()
.header(Attributes.AUTHORIZATION, authHeader)
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
@@ -188,7 +190,7 @@
String code = params.getFirst("code");
response = requestTokenWithAuthorizationCodeAndForm(clientId, clientSecret, code);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String at = node.at("/access_token").asText();
AccessToken accessTokenObj = accessDao.retrieveAccessToken(at);
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/FoundryRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/FoundryRewriteTest.java
index 4d91607..677201c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/FoundryRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/FoundryRewriteTest.java
@@ -5,14 +5,15 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -49,27 +50,26 @@
String json = "{\"pos-foundry\":\"opennlp\"}";
String username = "foundryRewriteTest";
String pathUsername = "~" + username;
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path(pathUsername).path("setting")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .type(MediaType.APPLICATION_JSON).entity(json)
- .put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
// search
- response = resource().path(API_VERSION).path("search")
+ response = target().path(API_VERSION).path("search")
.queryParam("q", "[pos=ADJA]").queryParam("ql", "poliqarp")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+ .accept(MediaType.APPLICATION_JSON).get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals("opennlp", node.at("/query/wrap/foundry").asText());
assertEquals("foundry",
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
index 6f22b3a..810ef7b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
@@ -5,7 +5,7 @@
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -23,13 +23,13 @@
public void testRewriteRefNotFound ()
throws KustvaktException, Exception {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]{%23examplequery} Baum")
.queryParam("ql", "poliqarp")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals("Query system/examplequery is not found.",
node.at("/errors/0/1").asText());
@@ -39,13 +39,13 @@
public void testRewriteSystemQuery ()
throws KustvaktException, Exception {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]{%23system-q} Baum")
.queryParam("ql", "poliqarp")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
// System.out.println(ent);
JsonNode node = JsonUtils.readTree(ent);
}
@@ -55,15 +55,15 @@
throws KustvaktException, Exception {
// Added in the database migration sql for tests
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]{%23dory/dory-q} Baum")
.queryParam("ql", "poliqarp")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals("koral:token", node.at("/query/operands/1/@type").asText());
assertEquals("@type(koral:queryRef)",
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
index f0b771e..84a5056 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
@@ -12,7 +12,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.cache.VirtualCorpusCache;
@@ -42,13 +42,13 @@
vcLoader.loadVCToCache("named-vc1", "/vc/named-vc1.jsonld");
assertTrue(VirtualCorpusCache.contains("named-vc1"));
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo named-vc1")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
node = node.at("/collection");
@@ -68,13 +68,13 @@
private void testRefCachedVCWithUsername ()
throws KustvaktException, IOException, QueryException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"system/named-vc1\"")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
node = node.at("/collection");
assertEquals("koral:docGroup", node.at("/@type").asText());
@@ -89,13 +89,13 @@
@Test
public void testRewriteFreeAndSystemVCRef ()
throws KustvaktException, Exception {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"system-vc\"")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
node = node.at("/collection");
@@ -115,16 +115,16 @@
@Test
public void testRewritePubAndSystemVCRef () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"system/system-vc\"")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("user", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
node = node.at("/collection");
assertEquals("koral:docGroup", node.at("/@type").asText());
@@ -141,15 +141,15 @@
public void testRewriteWithDoryVCRef ()
throws KustvaktException, IOException, QueryException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Fisch").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"dory/dory-vc\"")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
node = node.at("/collection");
assertEquals("koral:docGroup", node.at("/@type").asText());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java b/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java
index e5f9eb9..d83400a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java
@@ -9,7 +9,7 @@
import org.eclipse.jetty.http.HttpStatus;
import org.junit.Test;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -22,10 +22,10 @@
@Test
public void testSearchWithoutVersion () throws KustvaktException {
- ClientResponse response = resource().path("api").path("search")
+ Response response = target().path("api").path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.request()
- .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+ .accept(MediaType.APPLICATION_JSON).get();
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
assertEquals("/api/"+API_VERSION+"/search", location.getPath());
@@ -33,12 +33,12 @@
@Test
public void testSearchWrongVersion () throws KustvaktException {
- ClientResponse response = resource().path("api").path("v0.2")
+ Response response = target().path("api").path("v0.2")
.path("search").queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
.request()
.accept(MediaType.APPLICATION_JSON)
- .get(ClientResponse.class);
+ .get();
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
assertEquals("/api/"+API_VERSION+"/search", location.getPath());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/InitialSuperClientTest.java b/full/src/test/java/de/ids_mannheim/korap/web/InitialSuperClientTest.java
index 46e2526..fbb1d19 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/InitialSuperClientTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/InitialSuperClientTest.java
@@ -12,7 +12,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.FullConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -54,10 +54,10 @@
private void testLogin (String superClientId, String superClientSecret)
throws KustvaktException {
- ClientResponse response = requestTokenWithPassword(superClientId,
+ Response response = requestTokenWithPassword(superClientId,
superClientSecret, "username", "password");
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
assertTrue(!node.at("/access_token").isMissingNode());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/AnnotationControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/AnnotationControllerTest.java
index caec944..e005476 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/AnnotationControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/AnnotationControllerTest.java
@@ -6,12 +6,12 @@
import java.util.Iterator;
import java.util.Map.Entry;
-import javax.ws.rs.core.MediaType;
+import javax.ws.rs.client.Entity;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -20,12 +20,12 @@
public class AnnotationControllerTest extends SpringJerseyTest {
@Test
public void testAnnotationLayers () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("annotation").path("layers")
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode n = JsonUtils.readTree(entity);
assertEquals(31, n.size());
@@ -39,14 +39,14 @@
@Test
public void testAnnotationFoundry () throws KustvaktException {
- ClientResponse response =
- resource().path(API_VERSION).path("annotation")
- .path("description").type(MediaType.APPLICATION_JSON)
- .entity("{\"codes\":[\"opennlp/*\"], \"language\":\"en\"}")
+ String json = "{\"codes\":[\"opennlp/*\"], \"language\":\"en\"}";
+ Response response =
+ target().path(API_VERSION).path("annotation")
+ .path("description")
.request()
- .post(ClientResponse.class);
+ .post(Entity.json(json));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode n = JsonUtils.readTree(entity);
n = n.get(0);
@@ -67,14 +67,14 @@
@Test
public void testAnnotationValues () throws KustvaktException {
- ClientResponse response =
- resource().path(API_VERSION).path("annotation")
- .path("description").type(MediaType.APPLICATION_JSON)
- .entity("{\"codes\":[\"mate/m\"], \"language\":\"en\"}")
+ String json = "{\"codes\":[\"mate/m\"], \"language\":\"en\"}";
+ Response response =
+ target().path(API_VERSION).path("annotation")
+ .path("description")
.request()
- .post(ClientResponse.class);
+ .post(Entity.json(json));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode n = JsonUtils.readTree(entity);
n = n.get(0);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/AuthenticationControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/AuthenticationControllerTest.java
index 80bd635..8ebe6a6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/AuthenticationControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/AuthenticationControllerTest.java
@@ -10,7 +10,8 @@
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -34,13 +35,14 @@
public void testSessionToken() throws KustvaktException {
String auth = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
credentials[0], credentials[1]);
- ClientResponse response = resource().path("auth")
- .path("sessionToken").header(Attributes.AUTHORIZATION, auth)
+ Response response = target().path("auth")
+ .path("sessionToken")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .header(Attributes.AUTHORIZATION, auth)
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String en = response.getEntity(String.class);
+ String en = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(en);
assertNotNull(node);
@@ -52,22 +54,23 @@
assertNotEquals("", token_type);
assertFalse(TimeUtils.isExpired(ex.getMillis()));
- response = resource().path("user")
- .path("info").header(Attributes.AUTHORIZATION, token_type + " "+ token)
+ response = target().path("user")
+ .path("info")
.request()
- .get(ClientResponse.class);
- en = response.getEntity(String.class);
+ .header(Attributes.AUTHORIZATION, token_type + " "+ token)
+ .get();
+ en = response.readEntity(String.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- response = resource().path("auth")
+ response = target().path("auth")
.path("logout")
.request()
.header(Attributes.AUTHORIZATION, token_type + " "+ token)
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
}
@@ -75,13 +78,14 @@
public void testSessionTokenExpire() throws KustvaktException {
String auth = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
credentials[0], credentials[1]);
- ClientResponse response = resource().path("auth")
- .path("sessionToken").header(Attributes.AUTHORIZATION, auth)
+ Response response = target().path("auth")
+ .path("sessionToken")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .header(Attributes.AUTHORIZATION, auth)
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String en = response.getEntity(String.class);
+ String en = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(en);
assertNotNull(node);
@@ -96,17 +100,17 @@
if (TimeUtils.isExpired(ex.getMillis()))
break;
}
- response = resource().path("user")
+ response = target().path("user")
.path("info")
.request()
.header(Attributes.AUTHORIZATION, token_type + " "+ token)
- .get(ClientResponse.class);
- en = response.getEntity(String.class);
+ .get();
+ en = response.readEntity(String.class);
node = JsonUtils.readTree(en);
assertNotNull(node);
assertEquals(StatusCodes.BAD_CREDENTIALS, node.at("/errors/0/0").asInt());
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java
index 6e49b48..a6b6e42 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java
@@ -9,8 +9,9 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -137,18 +138,18 @@
- private ClientResponse searchQuery (String collectionQuery) {
- return resource().path(API_VERSION).path("search").queryParam("q", "[orth=das]")
+ private Response searchQuery (String collectionQuery) {
+ return target().path(API_VERSION).path("search").queryParam("q", "[orth=das]")
.queryParam("ql", "poliqarp").queryParam("cq", collectionQuery)
.request()
- .get(ClientResponse.class);
+ .get();
}
- private ClientResponse searchQueryWithIP (String collectionQuery, String ip)
+ private Response searchQueryWithIP (String collectionQuery, String ip)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- return resource().path(API_VERSION).path("search").queryParam("q", "[orth=das]")
+ return target().path(API_VERSION).path("search").queryParam("q", "[orth=das]")
.queryParam("ql", "poliqarp").queryParam("cq", collectionQuery)
.request()
.header(Attributes.AUTHORIZATION,
@@ -156,60 +157,60 @@
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, ip)
- .get(ClientResponse.class);
+ .get();
}
@Test
public void testAvailabilityFreeAuthorized () throws KustvaktException {
- ClientResponse response = searchQuery("availability = CC-BY-SA");
+ Response response = searchQuery("availability = CC-BY-SA");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testAvailabilityRegexFreeAuthorized ()
throws KustvaktException {
- ClientResponse response = searchQuery("availability = /.*BY.*/");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ Response response = searchQuery("availability = /.*BY.*/");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testAvailabilityFreeUnauthorized () throws KustvaktException {
- ClientResponse response = searchQuery("availability = ACA-NC");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ Response response = searchQuery("availability = ACA-NC");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testAvailabilityRegexFreeUnauthorized ()
throws KustvaktException {
- ClientResponse response = searchQuery("availability = /ACA.*/");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ Response response = searchQuery("availability = /ACA.*/");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testAvailabilityRegexNoRewrite () throws KustvaktException {
- ClientResponse response = searchQuery(
+ Response response = searchQuery(
"availability = /CC-BY.*/ & availability = /ACA.*/");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String json = response.getEntity(String.class);
+ String json = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(json);
assertEquals("operation:and",
@@ -232,11 +233,11 @@
@Test
public void testAvailabilityRegexFreeUnauthorized3 ()
throws KustvaktException {
- ClientResponse response = searchQuery("availability = /.*NC.*/");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ Response response = searchQuery("availability = /.*NC.*/");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- // System.out.println(response.getEntity(String.class));
- checkAndFree(response.getEntity(String.class));
+ // System.out.println(response.readEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@@ -244,186 +245,186 @@
@Test
public void testNegationAvailabilityFreeUnauthorized ()
throws KustvaktException {
- ClientResponse response = searchQuery("availability != /CC-BY.*/");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ Response response = searchQuery("availability != /CC-BY.*/");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testNegationAvailabilityFreeUnauthorized2 ()
throws KustvaktException {
- ClientResponse response = searchQuery("availability != /.*BY.*/");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ Response response = searchQuery("availability != /.*BY.*/");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testNegationAvailabilityWithOperationOrUnauthorized ()
throws KustvaktException {
- ClientResponse response = searchQuery(
+ Response response = searchQuery(
"availability = /CC-BY.*/ | availability != /CC-BY.*/");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testComplexNegationAvailabilityFreeUnauthorized ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQuery("textClass=politik & availability != /CC-BY.*/");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testComplexAvailabilityFreeUnauthorized ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQuery("textClass=politik & availability=ACA-NC");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testComplexAvailabilityFreeUnauthorized3 ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQuery("textClass=politik & availability=/.*NC.*/");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testAvailabilityPublicAuthorized () throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQueryWithIP("availability=ACA-NC", "149.27.0.32");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndPublic(response.getEntity(String.class));
+ checkAndPublic(response.readEntity(String.class));
}
@Test
public void testAvailabilityPublicUnauthorized () throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQueryWithIP("availability=QAO-NC-LOC:ids", "149.27.0.32");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndPublic(response.getEntity(String.class));
+ checkAndPublic(response.readEntity(String.class));
}
@Test
public void testAvailabilityRegexPublicAuthorized ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQueryWithIP("availability= /ACA.*/", "149.27.0.32");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndPublicWithACA(response.getEntity(String.class));
+ checkAndPublicWithACA(response.readEntity(String.class));
}
@Test
public void testNegationAvailabilityPublicUnauthorized ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQueryWithIP("availability != ACA-NC", "149.27.0.32");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndPublic(response.getEntity(String.class));
+ checkAndPublic(response.readEntity(String.class));
}
@Test
public void testNegationAvailabilityRegexPublicUnauthorized ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQueryWithIP("availability != /ACA.*/", "149.27.0.32");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndPublic(response.getEntity(String.class));
+ checkAndPublic(response.readEntity(String.class));
}
@Test
public void testComplexAvailabilityPublicUnauthorized ()
throws KustvaktException {
- ClientResponse response = searchQueryWithIP(
+ Response response = searchQueryWithIP(
"textClass=politik & availability=QAO-NC-LOC:ids",
"149.27.0.32");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndPublic(response.getEntity(String.class));
+ checkAndPublic(response.readEntity(String.class));
}
@Test
public void testNegationComplexAvailabilityPublicUnauthorized ()
throws KustvaktException {
- ClientResponse response = searchQueryWithIP(
+ Response response = searchQueryWithIP(
"textClass=politik & availability!=QAO-NC-LOC:ids",
"149.27.0.32");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndPublic(response.getEntity(String.class));
+ checkAndPublic(response.readEntity(String.class));
}
@Test
public void testAvailabilityRegexAllAuthorized () throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQueryWithIP("availability= /ACA.*/", "10.27.0.32");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndAllWithACA(response.getEntity(String.class));
+ checkAndAllWithACA(response.readEntity(String.class));
}
@Test
public void testAvailabilityOr () throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQuery("availability=/CC-BY.*/ | availability=/ACA.*/");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testRedundancyOrPub () throws KustvaktException {
- ClientResponse response = searchQueryWithIP(
+ Response response = searchQueryWithIP(
"availability=/CC-BY.*/ | availability=/ACA.*/ | availability=/QAO-NC/",
"149.27.0.32");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String json = response.getEntity(String.class);
+ String json = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(json);
assertTrue(node.at("/collection/rewrites").isMissingNode());
assertEquals("operation:or", node.at("/collection/operation").asText());
@@ -431,33 +432,33 @@
@Test
public void testAvailabilityOrCorpusSigle () throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQuery("availability=/CC-BY.*/ | corpusSigle=GOE");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testOrWithoutAvailability () throws KustvaktException {
- ClientResponse response =
+ Response response =
searchQuery("corpusSigle=GOE | textClass=politik");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
@Test
public void testWithoutAvailability () throws KustvaktException {
- ClientResponse response = searchQuery("corpusSigle=GOE");
+ Response response = searchQuery("corpusSigle=GOE");
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- checkAndFree(response.getEntity(String.class));
+ checkAndFree(response.readEntity(String.class));
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java
index d684c94..dbe693a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java
@@ -6,7 +6,7 @@
import org.springframework.test.context.ContextConfiguration;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -17,12 +17,12 @@
@Test
public void testResource () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("resource")
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode n = JsonUtils.readTree(entity).get(0);
assertEquals("WPD17",n.at("/resourceId").asText());
assertEquals("Deutsche Wikipedia Artikel 2017", n.at("/titles/de").asText());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java
index 80587f6..dc9dcaa 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java
@@ -10,16 +10,16 @@
import java.nio.file.Path;
import java.nio.file.Paths;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
import org.apache.http.HttpStatus;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -57,13 +57,13 @@
searchKrill.getStatistics(null);
assertEquals(true, searchKrill.getIndex().isReaderOpen());
- MultivaluedMap<String, String> m = new MultivaluedMapImpl();
- m.add("token", "secret");
+ Form form = new Form();
+ form.param("token", "secret");
- ClientResponse response = resource().path(API_VERSION).path("index")
- .path("close").type(MediaType.APPLICATION_FORM_URLENCODED)
+ Response response = target().path(API_VERSION).path("index")
+ .path("close")
.request()
- .post(ClientResponse.class, m);
+ .post(Entity.form(form));
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertEquals(false, searchKrill.getIndex().isReaderOpen());
@@ -73,19 +73,19 @@
Thread.sleep(200);
- response = resource().path(API_VERSION).path("vc").path("~system")
+ response = target().path(API_VERSION).path("vc").path("~system")
.path("named-vc1")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("admin", "pass"))
- .delete(ClientResponse.class);
+ .delete();
- response = resource().path(API_VERSION).path("vc").path("~system")
+ response = target().path(API_VERSION).path("vc").path("~system")
.path("named-vc1")
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NO_RESOURCE_FOUND,node.at("/errors/0/0").asInt());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java
index a1a83b7..113fe5b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java
@@ -6,8 +6,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.config.SpringJerseyTest;
@@ -26,13 +26,13 @@
@Test
public void testInfo () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("info")
+ Response response = target().path(API_VERSION).path("info")
.request()
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(config.getCurrentVersion(),
node.at("/latest_api_version").asText());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
index cd62baf..efe1faf 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
@@ -8,7 +8,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -22,15 +23,15 @@
@Test
public void testGetMatchInfoPublicCorpus () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGA").path("01784").path("p36-100")
.path("matchInfo").queryParam("foundry", "*")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
@@ -46,15 +47,15 @@
@Test
public void testGetMatchInfoNotAllowed () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGI").path("04846").path("p36875-36876")
.path("matchInfo").queryParam("foundry", "*")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
@@ -68,7 +69,7 @@
@Test
public void testGetMatchInfoWithAuthentication () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGI").path("04846").path("p36875-36876")
.path("matchInfo").queryParam("foundry", "*")
.request()
@@ -77,10 +78,10 @@
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32")
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ String entity = response.readEntity(String.class);
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -100,7 +101,7 @@
@Test
public void testAvailabilityAll () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGD").path("00000").path("p75-76")
.request()
.header(Attributes.AUTHORIZATION,
@@ -108,15 +109,15 @@
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "10.27.0.32")
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
}
@Test
public void testAvailabilityAllUnauthorized () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGD").path("00000").path("p75-76")
.request()
.header(Attributes.AUTHORIZATION,
@@ -124,9 +125,9 @@
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "170.27.0.32")
- .get(ClientResponse.class);
+ .get();
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
assertEquals(
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
index 5d6ddeb..5fab35d 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
@@ -8,7 +8,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -21,15 +22,15 @@
@Test
public void testRetrieveMetadataWithField () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGA").path("01784")
.queryParam("fields", "author")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("author", node.at("/document/fields/0/key").asText());
@@ -38,15 +39,15 @@
@Test
public void testRetrieveMetadataWithMultipleFields () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGA").path("01784")
.queryParam("fields", "author,title")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("author", node.at("/document/fields/0/key").asText());
@@ -56,14 +57,14 @@
@Test
public void testFreeMetadata () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGA").path("01784")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertTrue(!node.at("/document").isMissingNode());
@@ -75,14 +76,14 @@
@Ignore
public void testMetadataUnauthorized () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGI").path("04846")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
@@ -95,7 +96,7 @@
@Test
public void testMetadataWithAuthentication () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGI").path("04846")
.request()
.header(Attributes.AUTHORIZATION,
@@ -103,15 +104,15 @@
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32")
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
}
@Test
public void testMetadataAvailabilityAll () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGI").path("00000")
.request()
.header(Attributes.AUTHORIZATION,
@@ -119,9 +120,9 @@
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "10.27.0.32")
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
}
@@ -130,7 +131,7 @@
@Ignore
public void testMetadataAvailabilityAllUnauthorized ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus")
+ Response response = target().path(API_VERSION).path("corpus")
.path("GOE").path("AGD").path("00000")
.request()
.header(Attributes.AUTHORIZATION,
@@ -138,9 +139,9 @@
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "170.27.0.32")
- .get(ClientResponse.class);
+ .get();
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
assertEquals(
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/MultipleCorpusQueryTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/MultipleCorpusQueryTest.java
index 6f2a5f0..23fd917 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/MultipleCorpusQueryTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/MultipleCorpusQueryTest.java
@@ -7,8 +7,9 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -19,15 +20,15 @@
@Test
public void testSearchGet () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "das").queryParam("ql", "poliqarp")
.queryParam("cq", "pubPlace=München")
.queryParam("cq", "textSigle=\"GOE/AGA/01784\"")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
node = node.at("/collection/operands/1");
assertEquals("koral:docGroup", node.at("/@type").asText());
@@ -45,14 +46,14 @@
public void testStatisticsWithMultipleCq ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics").queryParam("cq", "textType=Abhandlung")
.queryParam("cq", "corpusSigle=GOE")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/documents").asInt());
assertEquals(138180, node.at("/tokens").asInt());
@@ -66,15 +67,15 @@
public void testStatisticsWithMultipleCorpusQuery ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response =
- resource().path(API_VERSION).path("statistics")
+ Response response =
+ target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", "textType=Autobiographie")
.queryParam("corpusQuery", "corpusSigle=GOE")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(9, node.at("/documents").asInt());
assertEquals(527662, node.at("/tokens").asInt());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
index d7b11a5..ba2497f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
@@ -7,7 +7,9 @@
import java.io.IOException;
import java.net.URI;
-import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
import org.apache.http.entity.ContentType;
@@ -18,8 +20,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -44,27 +45,27 @@
@Test
public void testScopeWithSuperClient () throws KustvaktException {
- ClientResponse response =
+ Response response =
requestTokenWithDoryPassword(superClientId, clientSecret);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals("all", node.at("/scope").asText());
String accessToken = node.at("/access_token").asText();
// test list user group
- response = resource().path(API_VERSION).path("group")
+ response = target().path(API_VERSION).path("group")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(2, node.size());
}
@Test
public void testCustomScope () throws KustvaktException {
- ClientResponse response =
+ Response response =
requestAuthorizationCode("code", confidentialClientId, "",
OAuth2Scope.VC_INFO.toString(), "", userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
@@ -76,31 +77,31 @@
response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, clientSecret, code);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String token = node.at("/access_token").asText();
assertTrue(node.at("/scope").asText()
.contains(OAuth2Scope.VC_INFO.toString()));
// test list vc using the token
- response = resource().path(API_VERSION).path("vc")
+ response = target().path(API_VERSION).path("vc")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + token)
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(4, node.size());
}
@Test
public void testDefaultScope () throws KustvaktException, IOException {
String code = requestAuthorizationCode(confidentialClientId, userAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, clientSecret, code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken = node.at("/access_token").asText();
testScopeNotAuthorized(accessToken);
testScopeNotAuthorize2(accessToken);
@@ -109,14 +110,14 @@
private void testScopeNotAuthorized (String accessToken)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -126,14 +127,14 @@
private void testScopeNotAuthorize2 (String accessToken)
throws KustvaktException {
- ClientResponse response =
- resource().path(API_VERSION).path("vc").path("access")
+ Response response =
+ target().path(API_VERSION).path("vc").path("access")
.request()
.header(Attributes.AUTHORIZATION,
"Bearer " + accessToken)
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
+ .get();
+ String entity = response.readEntity(String.class);
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
@@ -145,13 +146,13 @@
@Test
public void testSearchWithUnknownToken ()
throws KustvaktException, IOException {
- ClientResponse response =
+ Response response =
searchWithAccessToken("ljsa8tKNRSczJhk20öhq92zG8z350");
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
node.at("/errors/0/0").asInt());
@@ -168,16 +169,16 @@
confidentialClientId, code, clientAuthHeader);
String accessToken = node.at("/access_token").asText();
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("token", accessToken);
- form.add("client_id", confidentialClientId);
- form.add("client_secret", "secret");
+ Form form = new Form();
+ form.param("token", accessToken);
+ form.param("client_id", confidentialClientId);
+ form.param("client_secret", "secret");
- ClientResponse response = resource().path(API_VERSION).path("oauth2").path("revoke")
+ Response response = target().path(API_VERSION).path("oauth2").path("revoke")
.request()
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -189,10 +190,10 @@
throws KustvaktException {
String code = requestAuthorizationCode(publicClientId,
userAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
publicClientId, "", code);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken = node.at("/access_token").asText();
testRevokeTokenViaSuperClient(accessToken, userAuthHeader);
testSearchWithRevokedAccessToken(accessToken);
@@ -209,20 +210,20 @@
String accessToken = node.at("/access_token").asText();
String refreshToken = node.at("/refresh_token").asText();
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", GrantType.REFRESH_TOKEN.toString());
- form.add("client_id", confidentialClientId);
- form.add("client_secret", "secret");
- form.add("refresh_token", refreshToken);
+ Form form = new Form();
+ form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
+ form.param("client_id", confidentialClientId);
+ form.param("client_secret", "secret");
+ form.param("refresh_token", refreshToken);
- ClientResponse response = resource().path(API_VERSION).path("oauth2").path("token")
+ Response response = target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(entity);
@@ -241,12 +242,12 @@
confidentialClientId, code, clientAuthHeader);
String userAuthToken = node.at("/access_token").asText();
- ClientResponse response = requestAuthorizationCode("code",
+ Response response = requestAuthorizationCode("code",
confidentialClientId, "", "", "", "Bearer " + userAuthToken);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
assertEquals("Scope authorize is not authorized",
@@ -256,9 +257,9 @@
@Test
public void testRequestAuthorizationWithBearerToken ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
requestTokenWithDoryPassword(superClientId, clientSecret);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
String userAuthToken = node.at("/access_token").asText();
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AdminControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AdminControllerTest.java
index 7049ad6..3464dfd 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AdminControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AdminControllerTest.java
@@ -3,7 +3,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.MediaType;
import org.apache.http.entity.ContentType;
import org.junit.Test;
@@ -12,10 +13,10 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.ClientResponse.Status;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -43,18 +44,18 @@
.createBasicAuthorizationHeaderValue("dory", "password");
}
- private ClientResponse updateClientPrivilege (String username,
- MultivaluedMap<String, String> form)
+ private Response updateClientPrivilege (String username,
+ Form form)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("admin").path("client").path("privilege")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
return response;
}
@@ -62,12 +63,12 @@
private void updateClientPriviledge (String clientId, boolean isSuper)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("client_id", clientId);
- form.add("super", Boolean.toString(isSuper));
+ Form form = new Form();
+ form.param("client_id", clientId);
+ form.param("super", Boolean.toString(isSuper));
- ClientResponse response = updateClientPrivilege(username, form);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ Response response = updateClientPrivilege(username, form);
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -85,11 +86,11 @@
int accessTokensBefore = accessDao.retrieveInvalidAccessTokens().size();
assertTrue(accessTokensBefore > 0);
- resource().path(API_VERSION).path("oauth2").path("admin").path("token")
+ target().path(API_VERSION).path("oauth2").path("admin").path("token")
.path("clean")
.request()
.header(Attributes.AUTHORIZATION, adminAuthHeader)
- .get(ClientResponse.class);
+ .get();
assertEquals(0, refreshDao.retrieveInvalidRefreshTokens().size());
assertEquals(0, accessDao.retrieveInvalidAccessTokens().size());
@@ -101,9 +102,9 @@
int accessTokensBefore = accessDao.retrieveInvalidAccessTokens().size();
String code = requestAuthorizationCode(publicClientId, userAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
publicClientId, clientSecret, code);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
String accessToken = node.at("/access_token").asText();
@@ -112,11 +113,11 @@
int accessTokensAfter = accessDao.retrieveInvalidAccessTokens().size();
assertEquals(accessTokensAfter, accessTokensBefore + 1);
- resource().path(API_VERSION).path("oauth2").path("admin").path("token")
+ target().path(API_VERSION).path("oauth2").path("admin").path("token")
.path("clean")
.request()
.header(Attributes.AUTHORIZATION, adminAuthHeader)
- .get(ClientResponse.class);
+ .get();
assertEquals(0, accessDao.retrieveInvalidAccessTokens().size());
}
@@ -124,8 +125,8 @@
@Test
public void testUpdateClientPrivilege () throws KustvaktException {
// register a client
- ClientResponse response = registerConfidentialClient(username);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ Response response = registerConfidentialClient(username);
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String clientId = node.at("/client_id").asText();
String clientSecret = node.at("/client_secret").asText();
@@ -154,14 +155,14 @@
assertTrue(node.at("/super").asBoolean());
// list vc
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -178,11 +179,11 @@
JsonNode node = retrieveClientInfo(clientId, username);
assertTrue(node.at("/isSuper").isMissingNode());
- ClientResponse response = searchWithAccessToken(accessToken);
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
+ Response response = searchWithAccessToken(accessToken);
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
node.at("/errors/0/0").asInt());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationPostTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationPostTest.java
index f58126d..67b5cbb 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationPostTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationPostTest.java
@@ -5,6 +5,9 @@
import java.net.URI;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import org.apache.http.entity.ContentType;
@@ -15,10 +18,9 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
-import com.sun.jersey.api.uri.UriComponent;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.glassfish.jersey.uri.UriComponent;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -34,27 +36,27 @@
.createBasicAuthorizationHeaderValue("dory", "password");
}
- private ClientResponse requestAuthorizationCode (
- MultivaluedMap<String, String> form, String authHeader)
+ private Response requestAuthorizationCode (
+ Form form, String authHeader)
throws KustvaktException {
- return resource().path(API_VERSION).path("oauth2").path("authorize")
+ return target().path(API_VERSION).path("oauth2").path("authorize")
.request()
.header(Attributes.AUTHORIZATION, authHeader)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
}
@Test
public void testAuthorizeConfidentialClient () throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("response_type", "code");
- form.add("client_id", confidentialClientId);
- form.add("state", "thisIsMyState");
+ Form form = new Form();
+ form.param("response_type", "code");
+ form.param("client_id", confidentialClientId);
+ form.param("state", "thisIsMyState");
- ClientResponse response =
+ Response response =
requestAuthorizationCode(form, userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
@@ -70,12 +72,12 @@
public void testRequestTokenAuthorizationConfidential ()
throws KustvaktException {
- MultivaluedMap<String, String> authForm = new MultivaluedMapImpl();
- authForm.add("response_type", "code");
- authForm.add("client_id", confidentialClientId);
- authForm.add("scope", "search");
+ Form authForm = new Form();
+ authForm.param("response_type", "code");
+ authForm.param("client_id", confidentialClientId);
+ authForm.param("scope", "search");
- ClientResponse response =
+ Response response =
requestAuthorizationCode(authForm, userAuthHeader);
URI redirectUri = response.getLocation();
MultivaluedMap<String, String> params =
@@ -87,7 +89,7 @@
response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, clientSecret, code);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
assertNotNull(node.at("/refresh_token").asText());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java
index d52bba7..f158fb6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java
@@ -12,7 +12,8 @@
import java.util.Map.Entry;
import java.util.Set;
-import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.MediaType;
import org.apache.commons.io.IOUtils;
import org.apache.http.entity.ContentType;
@@ -22,11 +23,12 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-import com.sun.jersey.spi.container.ContainerRequest;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.client.Entity;
+
+import org.glassfish.jersey.server.ContainerRequest;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -51,11 +53,11 @@
.createBasicAuthorizationHeaderValue("dory", "password");
}
- private void checkWWWAuthenticateHeader (ClientResponse response) {
- Set<Entry<String, List<String>>> headers =
+ private void checkWWWAuthenticateHeader (Response response) {
+ Set<Entry<String, List<Object>>> headers =
response.getHeaders().entrySet();
- for (Entry<String, List<String>> header : headers) {
+ for (Entry<String, List<Object>> header : headers) {
if (header.getKey().equals(ContainerRequest.WWW_AUTHENTICATE)) {
assertEquals("Basic realm=\"Kustvakt\"",
header.getValue().get(0));
@@ -112,8 +114,8 @@
@Test
public void testRegisterConfidentialClient () throws KustvaktException {
- ClientResponse response = registerConfidentialClient(username);
- String entity = response.getEntity(String.class);
+ Response response = registerConfidentialClient(username);
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
String clientId = node.at("/client_id").asText();
@@ -135,8 +137,8 @@
OAuth2ClientJson clientJson =
createOAuth2ClientJson("R", OAuth2ClientType.PUBLIC, null);
- ClientResponse response = registerClient(username, clientJson);
- String entity = response.getEntity(String.class);
+ Response response = registerClient(username, clientJson);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("client_name must contain at least 3 characters",
node.at("/error_description").asText());
@@ -150,8 +152,8 @@
OAuth2ClientJson clientJson =
createOAuth2ClientJson("", OAuth2ClientType.PUBLIC, null);
- ClientResponse response = registerClient(username, clientJson);
- String entity = response.getEntity(String.class);
+ Response response = registerClient(username, clientJson);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("client_name must contain at least 3 characters",
node.at("/error_description").asText());
@@ -166,8 +168,8 @@
OAuth2ClientJson clientJson =
createOAuth2ClientJson(null, OAuth2ClientType.PUBLIC, null);
- ClientResponse response = registerClient(username, clientJson);
- String entity = response.getEntity(String.class);
+ Response response = registerClient(username, clientJson);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("client_name is null",
node.at("/error_description").asText());
@@ -182,8 +184,8 @@
OAuth2ClientJson clientJson = createOAuth2ClientJson("R client",
OAuth2ClientType.PUBLIC, null);
- ClientResponse response = registerClient(username, clientJson);
- String entity = response.getEntity(String.class);
+ Response response = registerClient(username, clientJson);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("client_description is null",
node.at("/error_description").asText());
@@ -198,8 +200,8 @@
OAuth2ClientJson clientJson =
createOAuth2ClientJson("R client", null, null);
- ClientResponse response = registerClient(username, clientJson);
- String entity = response.getEntity(String.class);
+ Response response = registerClient(username, clientJson);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("client_type is null",
node.at("/error_description").asText());
@@ -217,22 +219,22 @@
createOAuth2ClientJson("OAuth2PublicClient",
OAuth2ClientType.PUBLIC, "A public test client.");
clientJson.setRedirectURI(redirectUri);
- ClientResponse response = registerClient(username, clientJson);
- testInvalidRedirectUri(response.getEntity(String.class), false,
+ Response response = registerClient(username, clientJson);
+ testInvalidRedirectUri(response.readEntity(String.class), false,
response.getStatus());
// localhost is not allowed
redirectUri = "http://localhost:1410";
clientJson.setRedirectURI(redirectUri);
response = registerClient(username, clientJson);
- testInvalidRedirectUri(response.getEntity(String.class), false,
+ testInvalidRedirectUri(response.readEntity(String.class), false,
response.getStatus());
// fragment is not allowed
redirectUri = "https://public.client.com/redirect.html#bar";
clientJson.setRedirectURI(redirectUri);
response = registerClient(username, clientJson);
- testInvalidRedirectUri(response.getEntity(String.class), false,
+ testInvalidRedirectUri(response.readEntity(String.class), false,
response.getStatus());
}
@@ -244,8 +246,8 @@
createOAuth2ClientJson("OAuth2PublicClient",
OAuth2ClientType.PUBLIC, "A public test client.");
clientJson.setRefreshTokenExpiry(31535000);
- ClientResponse response = registerClient(username, clientJson);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ Response response = registerClient(username, clientJson);
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals("invalid_request", node.at("/error").asText());
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@@ -259,8 +261,8 @@
createOAuth2ClientJson("OAuth2 Confidential Client",
OAuth2ClientType.CONFIDENTIAL, "A confidential client.");
clientJson.setRefreshTokenExpiry(expiry);
- ClientResponse response = registerClient(username, clientJson);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ Response response = registerClient(username, clientJson);
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String clientId = node.at("/client_id").asText();
JsonNode clientInfo = retrieveClientInfo(clientId, username);
assertEquals(expiry, clientInfo.at("/refresh_token_expiry").asInt());
@@ -276,8 +278,8 @@
"OAuth2 Confidential Client", OAuth2ClientType.CONFIDENTIAL,
"A confidential client.");
clientJson.setRefreshTokenExpiry(31537000);
- ClientResponse response = registerClient(username, clientJson);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ Response response = registerClient(username, clientJson);
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(
"Maximum refresh token expiry is 31536000 seconds (1 year)",
node.at("/error_description").asText());
@@ -295,14 +297,14 @@
createOAuth2ClientJson("OAuth2PublicClient",
OAuth2ClientType.PUBLIC, "A public test client.");
clientJson.setUrl(url);
- ClientResponse response = registerClient(username, clientJson);
- testInvalidUrl(response.getEntity(String.class), response.getStatus());
+ Response response = registerClient(username, clientJson);
+ testInvalidUrl(response.readEntity(String.class), response.getStatus());
// localhost is not allowed
url = "http://localhost:1410";
clientJson.setRedirectURI(url);
response = registerClient(username, clientJson);
- testInvalidUrl(response.getEntity(String.class), response.getStatus());
+ testInvalidUrl(response.readEntity(String.class), response.getStatus());
}
private void testInvalidUrl (String entity,
@@ -326,9 +328,9 @@
clientJson.setUrl("http://public.client.com/index.html#bar");
clientJson.setRedirectURI(redirectUri);
- ClientResponse response = registerClient(username, clientJson);
+ Response response = registerClient(username, clientJson);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
String clientId = node.at("/client_id").asText();
@@ -347,25 +349,25 @@
String userAuthHeader = HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "password");
String code = requestAuthorizationCode(clientId, userAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
clientId, clientSecret, code);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals("match_info search", node.at("/scope").asText());
String accessToken = node.at("/access_token").asText();
OAuth2ClientJson clientJson = createOAuth2ClientJson("R client",
- OAuth2ClientType.PUBLIC, null);
+ OAuth2ClientType.PUBLIC, null);
- response = resource().path(API_VERSION).path("oauth2").path("client")
+ response = target().path(API_VERSION).path("oauth2").path("client")
.path("register")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(clientJson).post(ClientResponse.class);
+ .post(Entity.json(clientJson));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -383,7 +385,7 @@
.getResourceAsStream("json/oauth2_public_client.json");
String json = IOUtils.toString(is, Charset.defaultCharset());
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("register")
.request()
.header(Attributes.AUTHORIZATION,
@@ -391,9 +393,9 @@
.createBasicAuthorizationHeaderValue(username,
"password"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).post(ClientResponse.class);
+ .post(Entity.json(json));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
String clientId = node.at("/client_id").asText();
@@ -411,9 +413,9 @@
"OAuth2DesktopClient", OAuth2ClientType.PUBLIC,
"This is a desktop test client.");
- ClientResponse response = registerClient(username, clientJson);
+ Response response = registerClient(username, clientJson);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
String clientId = node.at("/client_id").asText();
@@ -435,9 +437,9 @@
createOAuth2ClientJson("OAuth2DesktopClient1",
OAuth2ClientType.PUBLIC, "A desktop test client.");
- ClientResponse response = registerClient(username, clientJson);
+ Response response = registerClient(username, clientJson);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
String clientId1 = node.at("/client_id").asText();
@@ -450,7 +452,7 @@
response = registerClient(username, clientJson);
- entity = response.getEntity(String.class);
+ entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(entity);
String clientId2 = node.at("/client_id").asText();
@@ -472,9 +474,9 @@
String code = requestAuthorizationCode(clientId, redirectUri, userAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
clientId, clientSecret, code, redirectUri);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken = node.at("/access_token").asText();
response = searchWithAccessToken(accessToken);
@@ -486,13 +488,13 @@
response = requestTokenWithAuthorizationCodeAndForm(clientId,
clientSecret, code, redirectUri);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(OAuth2Error.INVALID_CLIENT.toString(),
node.at("/error").asText());
response = searchWithAccessToken(accessToken);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
node.at("/errors/0/0").asInt());
assertEquals("Access token is invalid",
@@ -503,14 +505,14 @@
String clientId) throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("deregister").path(clientId)
.request()
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -520,12 +522,12 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("deregister")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.METHOD_NOT_ALLOWED.getStatusCode(),
response.getStatus());
@@ -535,12 +537,12 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("deregister").path(clientId)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@@ -548,19 +550,19 @@
private void testResetPublicClientSecret (String clientId)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("client_id", clientId);
+ Form form = new Form();
+ form.param("client_id", clientId);
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("reset")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
@@ -571,20 +573,20 @@
private String testResetConfidentialClientSecret (String clientId,
String clientSecret) throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("client_id", clientId);
- form.add("client_secret", clientSecret);
+ Form form = new Form();
+ form.param("client_id", clientId);
+ form.param("client_secret", clientSecret);
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("reset")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -598,20 +600,20 @@
private void requestAuthorizedClientList (String userAuthHeader)
throws KustvaktException {
- MultivaluedMap<String, String> form = getSuperClientForm();
- form.add("authorized_only", "true");
+ Form form = getSuperClientForm();
+ form.param("authorized_only", "true");
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("list")
.request()
.header(Attributes.AUTHORIZATION, userAuthHeader)
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.size());
@@ -674,7 +676,7 @@
.createBasicAuthorizationHeaderValue(username, password);
// super client
- ClientResponse response = requestTokenWithPassword(superClientId,
+ Response response = requestTokenWithPassword(superClientId,
clientSecret, username, password);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -684,7 +686,7 @@
code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken = node.at("/access_token").asText();
// client 2
@@ -704,7 +706,7 @@
accessToken);
// revoke client 2
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
accessToken = node.at("/access_token").asText();
refreshToken = node.at("/refresh_token").asText();
testRevokeAllTokenViaSuperClient(confidentialClientId, userAuthHeader,
@@ -718,7 +720,7 @@
// client 2
String code =
requestAuthorizationCode(confidentialClientId, userAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, clientSecret, code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -730,7 +732,7 @@
String userAuthHeader) throws KustvaktException {
// client 1
String code = requestAuthorizationCode(publicClientId, userAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
publicClientId, "", code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -746,10 +748,10 @@
// client 1
String code = requestAuthorizationCode(publicClientId, aaaAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
publicClientId, "", code);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken1 = node.at("/access_token").asText();
// client 2
@@ -757,7 +759,7 @@
response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, clientSecret, code);
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken2 = node.at("/access_token").asText();
String refreshToken = node.at("/refresh_token").asText();
@@ -776,26 +778,26 @@
String userAuthHeader, String accessToken)
throws KustvaktException {
// check token before revoking
- ClientResponse response = searchWithAccessToken(accessToken);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ Response response = searchWithAccessToken(accessToken);
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertTrue(node.at("/matches").size() > 0);
- MultivaluedMap<String, String> form = getSuperClientForm();
- form.add("client_id", clientId);
+ Form form = getSuperClientForm();
+ form.param("client_id", clientId);
- response = resource().path(API_VERSION).path("oauth2").path("revoke")
+ response = target().path(API_VERSION).path("oauth2").path("revoke")
.path("super").path("all")
.request()
.header(Attributes.AUTHORIZATION, userAuthHeader)
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- assertEquals("SUCCESS", response.getEntity(String.class));
+ assertEquals("SUCCESS", response.readEntity(String.class));
response = searchWithAccessToken(accessToken);
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
node.at("/errors/0/0").asInt());
assertEquals("Access token is invalid",
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java
index 38ed47c..bfd0ad9 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java
@@ -8,6 +8,9 @@
import java.time.ZonedDateTime;
import java.util.Set;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response.Status;
@@ -19,8 +22,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -46,7 +48,7 @@
@Test
public void testAuthorizeConfidentialClient () throws KustvaktException {
// with registered redirect URI
- ClientResponse response =
+ Response response =
requestAuthorizationCode("code", confidentialClientId, "",
"match_info search client_info", state, userAuthHeader);
@@ -69,7 +71,7 @@
@Test
public void testAuthorizeWithRedirectUri () throws KustvaktException {
- ClientResponse response =
+ Response response =
requestAuthorizationCode("code", publicClientId2,
"https://public.com/redirect", "", "", userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
@@ -87,7 +89,7 @@
@Test
public void testAuthorizeWithoutScope () throws KustvaktException {
- ClientResponse response = requestAuthorizationCode("code",
+ Response response = requestAuthorizationCode("code",
confidentialClientId, "", "", "", userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
@@ -104,10 +106,10 @@
@Test
public void testAuthorizeMissingClientId () throws KustvaktException {
- ClientResponse response = requestAuthorizationCode("code", "", "", "",
+ Response response = requestAuthorizationCode("code", "", "", "",
"", userAuthHeader);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("Missing parameters: client_id",
node.at("/error_description").asText());
@@ -115,11 +117,11 @@
@Test
public void testAuthorizeMissingRedirectUri () throws KustvaktException {
- ClientResponse response = requestAuthorizationCode("code",
+ Response response = requestAuthorizationCode("code",
publicClientId2, "", "", state, userAuthHeader);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuthError.CodeResponse.INVALID_REQUEST,
node.at("/error").asText());
@@ -130,7 +132,7 @@
@Test
public void testAuthorizeMissingResponseType() throws KustvaktException {
- ClientResponse response = requestAuthorizationCode("",
+ Response response = requestAuthorizationCode("",
confidentialClientId, "", "", "", userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
@@ -142,12 +144,12 @@
@Test
public void testAuthorizeMissingResponseTypeWithoutClientId () throws KustvaktException {
- ClientResponse response = requestAuthorizationCode("",
+ Response response = requestAuthorizationCode("",
"", "", "", "", userAuthHeader);
assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuthError.CodeResponse.INVALID_REQUEST,
@@ -158,10 +160,10 @@
@Test
public void testAuthorizeInvalidClientId () throws KustvaktException {
- ClientResponse response = requestAuthorizationCode("code",
+ Response response = requestAuthorizationCode("code",
"unknown-client-id", "", "", "", userAuthHeader);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_CLIENT, node.at("/error").asText());
assertEquals("Unknown client: unknown-client-id",
@@ -171,28 +173,28 @@
@Test
public void testAuthorizeDifferentRedirectUri () throws KustvaktException {
String redirectUri = "https://different.uri/redirect";
- ClientResponse response = requestAuthorizationCode("code",
+ Response response = requestAuthorizationCode("code",
confidentialClientId, redirectUri, "", state, userAuthHeader);
- testInvalidRedirectUri(response.getEntity(String.class), true,
+ testInvalidRedirectUri(response.readEntity(String.class), true,
response.getStatus());
}
@Test
public void testAuthorizeWithRedirectUriLocalhost ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
requestAuthorizationCode("code", publicClientId2,
"http://localhost:1410", "", state, userAuthHeader);
- testInvalidRedirectUri(response.getEntity(String.class), true,
+ testInvalidRedirectUri(response.readEntity(String.class), true,
response.getStatus()); }
@Test
public void testAuthorizeWithRedirectUriFragment ()
throws KustvaktException {
- ClientResponse response = requestAuthorizationCode("code",
+ Response response = requestAuthorizationCode("code",
publicClientId2, "http://public.com/index.html#redirect", "",
state, userAuthHeader);
- testInvalidRedirectUri(response.getEntity(String.class), true,
+ testInvalidRedirectUri(response.readEntity(String.class), true,
response.getStatus());
}
@@ -200,16 +202,16 @@
public void testAuthorizeInvalidRedirectUri () throws KustvaktException {
// host not allowed by Apache URI Validator
String redirectUri = "https://public.uri/redirect";
- ClientResponse response = requestAuthorizationCode("code",
+ Response response = requestAuthorizationCode("code",
publicClientId2, redirectUri, "", state, userAuthHeader);
- testInvalidRedirectUri(response.getEntity(String.class), true,
+ testInvalidRedirectUri(response.readEntity(String.class), true,
response.getStatus());
}
@Test
public void testAuthorizeInvalidResponseType () throws KustvaktException {
// without redirect URI in the request
- ClientResponse response = requestAuthorizationCode("string",
+ Response response = requestAuthorizationCode("string",
confidentialClientId, "", "", state, userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
@@ -236,7 +238,7 @@
redirectUri, "", state, userAuthHeader);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(OAuthError.CodeResponse.INVALID_REQUEST,
node.at("/error").asText());
assertEquals("Invalid redirect URI",
@@ -249,7 +251,7 @@
state, userAuthHeader);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(OAuthError.CodeResponse.INVALID_REQUEST,
node.at("/error").asText());
assertEquals("Missing parameter: redirect URI",
@@ -260,7 +262,7 @@
@Test
public void testAuthorizeInvalidScope () throws KustvaktException {
String scope = "read_address";
- ClientResponse response = requestAuthorizationCode("code",
+ Response response = requestAuthorizationCode("code",
confidentialClientId, "", scope, state, userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
@@ -275,7 +277,7 @@
@Test
public void testAuthorizeUnsupportedTokenResponseType ()
throws KustvaktException {
- ClientResponse response = requestAuthorizationCode("token",
+ Response response = requestAuthorizationCode("token",
confidentialClientId, "", "", state, userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
@@ -291,9 +293,9 @@
throws KustvaktException {
String code = requestAuthorizationCode(publicClientId, userAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
publicClientId, clientSecret, code);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
String accessToken = node.at("/access_token").asText();
@@ -312,7 +314,7 @@
throws KustvaktException {
String scope = "search";
- ClientResponse response = requestAuthorizationCode("code",
+ Response response = requestAuthorizationCode("code",
confidentialClientId, "", scope, state, userAuthHeader);
MultivaluedMap<String, String> params =
getQueryParamsFromURI(response.getLocation());
@@ -323,7 +325,7 @@
response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, clientSecret, code);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
assertNotNull(node.at("/refresh_token").asText());
@@ -346,9 +348,9 @@
private void testRequestTokenWithUsedAuthorization (String code)
throws KustvaktException {
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, clientSecret, code);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -362,9 +364,9 @@
@Test
public void testRequestTokenInvalidAuthorizationCode ()
throws KustvaktException {
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, clientSecret, "blahblah");
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -379,7 +381,7 @@
String redirect_uri = "https://third.party.com/confidential/redirect";
String scope = "search";
- ClientResponse response =
+ Response response =
requestAuthorizationCode("code", confidentialClientId,
redirect_uri, scope, state, userAuthHeader);
MultivaluedMap<String, String> params =
@@ -393,39 +395,39 @@
private void testRequestTokenAuthorizationInvalidClient (String code)
throws KustvaktException {
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, "wrong_secret", code);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_CLIENT, node.at("/error").asText());
}
private void testRequestTokenAuthorizationInvalidRedirectUri (String code)
throws KustvaktException {
- MultivaluedMap<String, String> tokenForm = new MultivaluedMapImpl();
- tokenForm.add("grant_type", "authorization_code");
- tokenForm.add("client_id", confidentialClientId);
- tokenForm.add("client_secret", "secret");
- tokenForm.add("code", code);
- tokenForm.add("redirect_uri", "https://blahblah.com");
+ Form tokenForm = new Form();
+ tokenForm.param("grant_type", "authorization_code");
+ tokenForm.param("client_id", confidentialClientId);
+ tokenForm.param("client_secret", "secret");
+ tokenForm.param("code", code);
+ tokenForm.param("redirect_uri", "https://blahblah.com");
- ClientResponse response = requestToken(tokenForm);
- String entity = response.getEntity(String.class);
+ Response response = requestToken(tokenForm);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_GRANT, node.at("/error").asText());
}
private void testRequestTokenAuthorizationRevoked (String code, String uri)
throws KustvaktException {
- MultivaluedMap<String, String> tokenForm = new MultivaluedMapImpl();
- tokenForm.add("grant_type", "authorization_code");
- tokenForm.add("client_id", confidentialClientId);
- tokenForm.add("client_secret", "secret");
- tokenForm.add("code", code);
- tokenForm.add("redirect_uri", uri);
+ Form tokenForm = new Form();
+ tokenForm.param("grant_type", "authorization_code");
+ tokenForm.param("client_id", confidentialClientId);
+ tokenForm.param("client_secret", "secret");
+ tokenForm.param("code", code);
+ tokenForm.param("redirect_uri", uri);
- ClientResponse response = requestToken(tokenForm);
- String entity = response.getEntity(String.class);
+ Response response = requestToken(tokenForm);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuthError.TokenResponse.INVALID_GRANT,
node.at("/error").asText());
@@ -436,12 +438,12 @@
@Test
public void testRequestTokenPasswordGrantConfidentialSuper ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
requestTokenWithDoryPassword(superClientId, clientSecret);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
assertEquals(TokenType.BEARER.toString(),
@@ -461,9 +463,9 @@
@Test
public void testRequestTokenPasswordGrantConfidentialNonSuper ()
throws KustvaktException {
- ClientResponse response = requestTokenWithDoryPassword(
+ Response response = requestTokenWithDoryPassword(
confidentialClientId, clientSecret);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -476,9 +478,9 @@
@Test
public void testRequestTokenPasswordGrantPublic ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
requestTokenWithDoryPassword(publicClientId, "");
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -492,21 +494,21 @@
@Test
public void testRequestTokenPasswordGrantAuthorizationHeader ()
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "password");
- form.add("client_id", superClientId);
- form.add("username", "dory");
- form.add("password", "password");
+ Form form = new Form();
+ form.param("grant_type", "password");
+ form.param("client_id", superClientId);
+ form.param("username", "dory");
+ form.param("password", "password");
- ClientResponse response =
- resource().path(API_VERSION).path("oauth2").path("token")
+ Response response =
+ target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.AUTHORIZATION,
"Basic ZkNCYlFrQXlZekk0TnpVeE1nOnNlY3JldA==")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .post(Entity.form(form));
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
assertNotNull(node.at("/refresh_token").asText());
@@ -524,21 +526,21 @@
@Test
public void testRequestTokenPasswordGrantDifferentClientIds ()
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "password");
- form.add("client_id", "9aHsGW6QflV13ixNpez");
- form.add("username", "dory");
- form.add("password", "password");
+ Form form = new Form();
+ form.param("grant_type", "password");
+ form.param("client_id", "9aHsGW6QflV13ixNpez");
+ form.param("username", "dory");
+ form.param("password", "password");
- ClientResponse response =
- resource().path(API_VERSION).path("oauth2").path("token")
+ Response response =
+ target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.AUTHORIZATION,
"Basic ZkNCYlFrQXlZekk0TnpVeE1nOnNlY3JldA==")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .post(Entity.form(form));
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
assertNotNull(node.at("/refresh_token").asText());
@@ -550,11 +552,11 @@
@Test
public void testRequestTokenPasswordGrantMissingClientSecret ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
requestTokenWithDoryPassword(confidentialClientId, "");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuthError.TokenResponse.INVALID_REQUEST,
node.at("/error").asText());
@@ -565,9 +567,9 @@
@Test
public void testRequestTokenPasswordGrantMissingClientId ()
throws KustvaktException {
- ClientResponse response =
+ Response response =
requestTokenWithDoryPassword(null, clientSecret);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -581,12 +583,12 @@
public void testRequestTokenClientCredentialsGrant ()
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "client_credentials");
- form.add("client_id", confidentialClientId);
- form.add("client_secret", "secret");
- ClientResponse response = requestToken(form);
- String entity = response.getEntity(String.class);
+ Form form = new Form();
+ form.param("grant_type", "client_credentials");
+ form.param("client_id", confidentialClientId);
+ form.param("client_secret", "secret");
+ Response response = requestToken(form);
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -606,13 +608,13 @@
public void testRequestTokenClientCredentialsGrantPublic ()
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "client_credentials");
- form.add("client_id", publicClientId);
- form.add("client_secret", "");
- ClientResponse response = requestToken(form);
+ Form form = new Form();
+ form.param("grant_type", "client_credentials");
+ form.param("client_id", publicClientId);
+ form.param("client_secret", "");
+ Response response = requestToken(form);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuthError.TokenResponse.INVALID_REQUEST,
@@ -625,14 +627,14 @@
public void testRequestTokenClientCredentialsGrantReducedScope ()
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "client_credentials");
- form.add("client_id", confidentialClientId);
- form.add("client_secret", "secret");
- form.add("scope", "preferred_username client_info");
+ Form form = new Form();
+ form.param("grant_type", "client_credentials");
+ form.param("client_id", confidentialClientId);
+ form.param("client_secret", "secret");
+ form.param("scope", "preferred_username client_info");
- ClientResponse response = requestToken(form);
- String entity = response.getEntity(String.class);
+ Response response = requestToken(form);
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -647,11 +649,11 @@
@Test
public void testRequestTokenMissingGrantType () throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- ClientResponse response = requestToken(form);
+ Form form = new Form();
+ Response response = requestToken(form);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuthError.TokenResponse.INVALID_REQUEST,
node.at("/error").asText());
@@ -660,18 +662,18 @@
@Test
public void testRequestTokenUnsupportedGrant () throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "blahblah");
+ Form form = new Form();
+ form.param("grant_type", "blahblah");
- ClientResponse response =
- resource().path(API_VERSION).path("oauth2").path("token")
+ Response response =
+ target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -683,43 +685,43 @@
private void testRequestRefreshTokenInvalidScope (String clientId,
String refreshToken) throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", GrantType.REFRESH_TOKEN.toString());
- form.add("client_id", clientId);
- form.add("client_secret", clientSecret);
- form.add("refresh_token", refreshToken);
- form.add("scope", "search serialize_query");
+ Form form = new Form();
+ form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
+ form.param("client_id", clientId);
+ form.param("client_secret", clientSecret);
+ form.param("refresh_token", refreshToken);
+ form.param("scope", "search serialize_query");
- ClientResponse response =
- resource().path(API_VERSION).path("oauth2").path("token")
+ Response response =
+ target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_SCOPE, node.at("/error").asText());
}
private void testRequestRefreshToken (String clientId, String clientSecret,
String refreshToken) throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", GrantType.REFRESH_TOKEN.toString());
- form.add("client_id", clientId);
- form.add("client_secret", clientSecret);
- form.add("refresh_token", refreshToken);
+ Form form = new Form();
+ form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
+ form.param("client_id", clientId);
+ form.param("client_secret", clientSecret);
+ form.param("refresh_token", refreshToken);
- ClientResponse response =
- resource().path(API_VERSION).path("oauth2").path("token")
+ Response response =
+ target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -744,67 +746,67 @@
private void testRequestRefreshTokenInvalidClient (String refreshToken)
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", GrantType.REFRESH_TOKEN.toString());
- form.add("client_id", "iBr3LsTCxOj7D2o0A5m");
- form.add("refresh_token", refreshToken);
+ Form form = new Form();
+ form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
+ form.param("client_id", "iBr3LsTCxOj7D2o0A5m");
+ form.param("refresh_token", refreshToken);
- ClientResponse response =
- resource().path(API_VERSION).path("oauth2").path("token")
+ Response response =
+ target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_CLIENT, node.at("/error").asText());
}
private void testRequestRefreshTokenInvalidRefreshToken (String clientId)
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", GrantType.REFRESH_TOKEN.toString());
- form.add("client_id", clientId);
- form.add("client_secret", clientSecret);
- form.add("refresh_token", "Lia8s8w8tJeZSBlaQDrYV8ion3l");
+ Form form = new Form();
+ form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
+ form.param("client_id", clientId);
+ form.param("client_secret", clientSecret);
+ form.param("refresh_token", "Lia8s8w8tJeZSBlaQDrYV8ion3l");
- ClientResponse response =
- resource().path(API_VERSION).path("oauth2").path("token")
+ Response response =
+ target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_GRANT, node.at("/error").asText());
}
private JsonNode requestTokenList (String userAuthHeader, String tokenType,
String clientId) throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("super_client_id", superClientId);
- form.add("super_client_secret", clientSecret);
- form.add("token_type", tokenType);
+ Form form = new Form();
+ form.param("super_client_id", superClientId);
+ form.param("super_client_secret", clientSecret);
+ form.param("token_type", tokenType);
if (clientId != null && !clientId.isEmpty()) {
- form.add("client_id", clientId);
+ form.param("client_id", clientId);
}
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("token").path("list")
.request()
.header(Attributes.AUTHORIZATION, userAuthHeader)
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
@@ -822,10 +824,10 @@
.createBasicAuthorizationHeaderValue(username, password);
// super client
- ClientResponse response = requestTokenWithPassword(superClientId,
+ Response response = requestTokenWithPassword(superClientId,
clientSecret, username, password);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String refreshToken1 = node.at("/refresh_token").asText();
// client 1
@@ -868,7 +870,7 @@
response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, clientSecret, code);
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
String refreshToken5 = node.at("/refresh_token").asText();
// list all refresh tokens
@@ -915,10 +917,10 @@
// access token 1
String code = requestAuthorizationCode(publicClientId, userAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
publicClientId, "", code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken1 = node.at("/access_token").asText();
// access token 2
@@ -926,7 +928,7 @@
response = requestTokenWithAuthorizationCodeAndForm(publicClientId, "",
code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- node = JsonUtils.readTree(response.getEntity(String.class));
+ node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken2 = node.at("/access_token").asText();
// list access tokens
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2OpenIdControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2OpenIdControllerTest.java
index 0f83a0e..01f70e1 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2OpenIdControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2OpenIdControllerTest.java
@@ -10,8 +10,8 @@
import java.text.ParseException;
import java.util.Date;
+import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
import org.apache.http.entity.ContentType;
import org.apache.oltu.oauth2.common.message.types.TokenType;
@@ -31,9 +31,9 @@
import com.nimbusds.jwt.SignedJWT;
import com.nimbusds.oauth2.sdk.GrantType;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.client.Entity;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -52,9 +52,9 @@
"https://korap.ids-mannheim.de/confidential/redirect";
private String username = "dory";
- private ClientResponse sendAuthorizationRequest (
- MultivaluedMap<String, String> form) throws KustvaktException {
- return resource().path(API_VERSION).path("oauth2").path("openid").path("authorize")
+ private Response sendAuthorizationRequest (
+ Form form) throws KustvaktException {
+ return target().path(API_VERSION).path("oauth2").path("openid").path("authorize")
.request()
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
@@ -63,17 +63,17 @@
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
}
- private ClientResponse sendTokenRequest (
- MultivaluedMap<String, String> form) throws KustvaktException {
- return resource().path(API_VERSION).path("oauth2").path("openid").path("token")
+ private Response sendTokenRequest (
+ Form form) throws KustvaktException {
+ return target().path(API_VERSION).path("oauth2").path("openid").path("token")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
}
@Test
@@ -81,20 +81,20 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("response_type", "code");
- form.add("client_id", "fCBbQkAyYzI4NzUxMg");
+ Form form = new Form();
+ form.param("response_type", "code");
+ form.param("client_id", "fCBbQkAyYzI4NzUxMg");
testRequestAuthorizationCodeWithoutOpenID(form, redirectUri);
- form.add("scope", "openid");
+ form.param("scope", "openid");
testRequestAuthorizationCodeMissingRedirectUri(form);
testRequestAuthorizationCodeInvalidRedirectUri(form);
- form.add("redirect_uri", redirectUri);
+ form.param("redirect_uri", redirectUri);
- form.add("state", "thisIsMyState");
+ form.param("state", "thisIsMyState");
- ClientResponse response = sendAuthorizationRequest(form);
+ Response response = sendAuthorizationRequest(form);
URI location = response.getLocation();
assertEquals(redirectUri, location.getScheme() + "://"
+ location.getHost() + location.getPath());
@@ -106,9 +106,9 @@
}
private void testRequestAuthorizationCodeWithoutOpenID (
- MultivaluedMap<String, String> form, String redirectUri)
+ Form form, String redirectUri)
throws KustvaktException {
- ClientResponse response = sendAuthorizationRequest(form);
+ Response response = sendAuthorizationRequest(form);
URI location = response.getLocation();
// System.out.println(location.toString());
assertEquals(redirectUri, location.getScheme() + "://"
@@ -116,9 +116,9 @@
}
private void testRequestAuthorizationCodeMissingRedirectUri (
- MultivaluedMap<String, String> form) throws KustvaktException {
- ClientResponse response = sendAuthorizationRequest(form);
- String entity = response.getEntity(String.class);
+ Form form) throws KustvaktException {
+ Response response = sendAuthorizationRequest(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
@@ -127,25 +127,25 @@
}
private void testRequestAuthorizationCodeInvalidRedirectUri (
- MultivaluedMap<String, String> form) throws KustvaktException {
- form.add("redirect_uri", "blah");
- ClientResponse response = sendAuthorizationRequest(form);
- String entity = response.getEntity(String.class);
+ Form form) throws KustvaktException {
+ form.param("redirect_uri", "blah");
+ Response response = sendAuthorizationRequest(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Invalid redirect URI",
node.at("/error_description").asText());
- form.remove("redirect_uri");
+ form.asMap().remove("redirect_uri");
}
@Test
public void testRequestAuthorizationCodeMissingClientID ()
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("scope", "openid");
- form.add("redirect_uri", redirectUri);
+ Form form = new Form();
+ form.param("scope", "openid");
+ form.param("redirect_uri", redirectUri);
// error response is represented in JSON because redirect URI
// cannot be verified without client id
@@ -154,8 +154,8 @@
// before redirect_uri. see
// com.nimbusds.oauth2.sdk.AuthorizationRequest
- ClientResponse response = sendAuthorizationRequest(form);
- String entity = response.getEntity(String.class);
+ Response response = sendAuthorizationRequest(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Invalid request: Missing client_id parameter",
@@ -166,17 +166,17 @@
@Test
public void testRequestAuthorizationCodeMissingResponseType ()
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("scope", "openid");
- form.add("redirect_uri", redirectUri);
- form.add("client_id", "blah");
+ Form form = new Form();
+ form.param("scope", "openid");
+ form.param("redirect_uri", redirectUri);
+ form.param("client_id", "blah");
// client_id has not been verified yet
// MUST NOT automatically redirect the user-agent to the
// invalid redirection URI.
- ClientResponse response = sendAuthorizationRequest(form);
- String entity = response.getEntity(String.class);
+ Response response = sendAuthorizationRequest(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Invalid request: Missing response_type parameter",
@@ -184,13 +184,13 @@
}
private void testRequestAuthorizationCodeUnsupportedResponseType (
- MultivaluedMap<String, String> form, String type)
+ Form form, String type)
throws KustvaktException {
- ClientResponse response = sendAuthorizationRequest(form);
+ Response response = sendAuthorizationRequest(form);
URI location = response.getLocation();
assertEquals(MediaType.APPLICATION_FORM_URLENCODED,
- response.getType().toString());
+ response.getMediaType().toString());
MultiValueMap<String, String> params =
UriComponentsBuilder.fromUri(location).build().getQueryParams();
@@ -212,17 +212,17 @@
@Test
public void testRequestAuthorizationCodeUnsupportedImplicitFlow ()
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("scope", "openid");
- form.add("redirect_uri", redirectUri);
- form.add("response_type", "id_token");
- form.add("client_id", "fCBbQkAyYzI4NzUxMg");
- form.add("nonce", "nonce");
+ Form form = new Form();
+ form.param("scope", "openid");
+ form.param("redirect_uri", redirectUri);
+ form.param("response_type", "id_token");
+ form.param("client_id", "fCBbQkAyYzI4NzUxMg");
+ form.param("nonce", "nonce");
testRequestAuthorizationCodeUnsupportedResponseType(form, "id_token");
- form.remove("response_type");
- form.add("response_type", "id_token token");
+ form.asMap().remove("response_type");
+ form.param("response_type", "id_token token");
testRequestAuthorizationCodeUnsupportedResponseType(form, "id_token");
}
@@ -242,16 +242,16 @@
@Test
public void testRequestAuthorizationCodeUnsupportedHybridFlow ()
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("scope", "openid");
- form.add("redirect_uri", redirectUri);
- form.add("response_type", "code id_token");
- form.add("client_id", "fCBbQkAyYzI4NzUxMg");
- form.add("nonce", "nonce");
+ Form form = new Form();
+ form.param("scope", "openid");
+ form.param("redirect_uri", redirectUri);
+ form.param("response_type", "code id_token");
+ form.param("client_id", "fCBbQkAyYzI4NzUxMg");
+ form.param("nonce", "nonce");
testRequestAuthorizationCodeUnsupportedResponseType(form, "id_token");
- form.remove("response_type");
- form.add("response_type", "code token");
+ form.asMap().remove("response_type");
+ form.param("response_type", "code token");
testRequestAuthorizationCodeUnsupportedResponseType(form, "token");
}
@@ -261,33 +261,33 @@
NoSuchAlgorithmException, JOSEException {
String client_id = "fCBbQkAyYzI4NzUxMg";
String nonce = "thisIsMyNonce";
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("response_type", "code");
- form.add("client_id", client_id);
- form.add("redirect_uri", redirectUri);
- form.add("scope", "openid");
- form.add("state", "thisIsMyState");
- form.add("nonce", nonce);
+ Form form = new Form();
+ form.param("response_type", "code");
+ form.param("client_id", client_id);
+ form.param("redirect_uri", redirectUri);
+ form.param("scope", "openid");
+ form.param("state", "thisIsMyState");
+ form.param("nonce", nonce);
- ClientResponse response = sendAuthorizationRequest(form);
+ Response response = sendAuthorizationRequest(form);
URI location = response.getLocation();
MultiValueMap<String, String> params =
UriComponentsBuilder.fromUri(location).build().getQueryParams();
assertEquals("thisIsMyState", params.getFirst("state"));
String code = params.getFirst("code");
- MultivaluedMap<String, String> tokenForm = new MultivaluedMapImpl();
+ Form tokenForm = new Form();
testRequestAccessTokenMissingGrant(tokenForm);
- tokenForm.add("grant_type", "authorization_code");
- tokenForm.add("code", code);
+ tokenForm.param("grant_type", "authorization_code");
+ tokenForm.param("code", code);
testRequestAccessTokenMissingClientId(tokenForm);
- tokenForm.add("client_id", client_id);
+ tokenForm.param("client_id", client_id);
testRequestAccessTokenMissingClientSecret(tokenForm);
- tokenForm.add("client_secret", "secret");
- tokenForm.add("redirect_uri", redirectUri);
+ tokenForm.param("client_secret", "secret");
+ tokenForm.param("redirect_uri", redirectUri);
- ClientResponse tokenResponse = sendTokenRequest(tokenForm);
- String entity = tokenResponse.getEntity(String.class);
+ Response tokenResponse = sendTokenRequest(tokenForm);
+ String entity = tokenResponse.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
@@ -302,9 +302,9 @@
}
private void testRequestAccessTokenMissingGrant (
- MultivaluedMap<String, String> tokenForm) throws KustvaktException {
- ClientResponse response = sendTokenRequest(tokenForm);
- String entity = response.getEntity(String.class);
+ Form tokenForm) throws KustvaktException {
+ Response response = sendTokenRequest(tokenForm);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Invalid request: Missing grant_type parameter",
@@ -312,9 +312,9 @@
}
private void testRequestAccessTokenMissingClientId (
- MultivaluedMap<String, String> tokenForm) throws KustvaktException {
- ClientResponse response = sendTokenRequest(tokenForm);
- String entity = response.getEntity(String.class);
+ Form tokenForm) throws KustvaktException {
+ Response response = sendTokenRequest(tokenForm);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Invalid request: Missing required client_id "
@@ -322,9 +322,9 @@
}
private void testRequestAccessTokenMissingClientSecret (
- MultivaluedMap<String, String> tokenForm) throws KustvaktException {
- ClientResponse response = sendTokenRequest(tokenForm);
- String entity = response.getEntity(String.class);
+ Form tokenForm) throws KustvaktException {
+ Response response = sendTokenRequest(tokenForm);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Missing parameter: client_secret",
@@ -357,20 +357,20 @@
NoSuchAlgorithmException, JOSEException {
// public client
String client_id = "8bIDtZnH6NvRkW2Fq";
- MultivaluedMap<String, String> tokenForm = new MultivaluedMapImpl();
+ Form tokenForm = new Form();
testRequestAccessTokenMissingGrant(tokenForm);
- tokenForm.add("grant_type", GrantType.PASSWORD.toString());
+ tokenForm.param("grant_type", GrantType.PASSWORD.toString());
testRequestAccessTokenMissingUsername(tokenForm);
- tokenForm.add("username", username);
+ tokenForm.param("username", username);
testRequestAccessTokenMissingPassword(tokenForm);
- tokenForm.add("password", "pass");
- tokenForm.add("client_id", client_id);
+ tokenForm.param("password", "pass");
+ tokenForm.param("client_id", client_id);
- ClientResponse tokenResponse = sendTokenRequest(tokenForm);
- String entity = tokenResponse.getEntity(String.class);
+ Response tokenResponse = sendTokenRequest(tokenForm);
+ String entity = tokenResponse.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.UNAUTHORIZED_CLIENT,
@@ -380,9 +380,9 @@
}
private void testRequestAccessTokenMissingUsername (
- MultivaluedMap<String, String> tokenForm) throws KustvaktException {
- ClientResponse response = sendTokenRequest(tokenForm);
- String entity = response.getEntity(String.class);
+ Form tokenForm) throws KustvaktException {
+ Response response = sendTokenRequest(tokenForm);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Invalid request: Missing or empty username parameter",
@@ -390,9 +390,9 @@
}
private void testRequestAccessTokenMissingPassword (
- MultivaluedMap<String, String> tokenForm) throws KustvaktException {
- ClientResponse response = sendTokenRequest(tokenForm);
- String entity = response.getEntity(String.class);
+ Form tokenForm) throws KustvaktException {
+ Response response = sendTokenRequest(tokenForm);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Invalid request: Missing or empty password parameter",
@@ -401,11 +401,11 @@
@Test
public void testPublicKeyAPI () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("oauth2").path("openid")
+ Response response = target().path(API_VERSION).path("oauth2").path("openid")
.path("jwks")
.request()
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(1, node.at("/keys").size());
node = node.at("/keys/0");
@@ -417,11 +417,11 @@
@Test
public void testOpenIDConfiguration () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("oauth2").path("openid")
+ Response response = target().path(API_VERSION).path("oauth2").path("openid")
.path("config")
.request()
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/issuer"));
assertNotNull(node.at("/authorization_endpoint"));
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2PluginTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2PluginTest.java
index bbc6cf7..c1cecb8 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2PluginTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2PluginTest.java
@@ -7,7 +7,8 @@
import java.io.IOException;
-import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.MediaType;
import org.apache.http.entity.ContentType;
import org.junit.Test;
@@ -16,10 +17,10 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.client.Entity;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -54,9 +55,9 @@
json.setSource(source);
json.setRefreshTokenExpiry(refreshTokenExpiry);
- ClientResponse response = registerClient(username, json);
+ Response response = registerClient(username, json);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String clientId = node.at("/client_id").asText();
String clientSecret = node.at("/client_secret").asText();
assertNotNull(clientId);
@@ -85,8 +86,8 @@
json.setDescription("This is a public plugin.");
json.setSource(source);
- ClientResponse response = registerClient(username, json);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ Response response = registerClient(username, json);
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
@@ -139,8 +140,8 @@
public void testListPluginsUnauthorizedPublic ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("super_client_id", publicClientId);
+ Form form = new Form();
+ form.param("super_client_id", publicClientId);
testListPluginsClientUnauthorized(form);
}
@@ -148,9 +149,9 @@
public void testListPluginsUnauthorizedConfidential ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("super_client_id", confidentialClientId2);
- form.add("super_client_secret", clientSecret);
+ Form form = new Form();
+ form.param("super_client_id", confidentialClientId2);
+ form.param("super_client_secret", clientSecret);
testListPluginsClientUnauthorized(form);
}
@@ -158,18 +159,18 @@
public void testListPluginsMissingClientSecret ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("super_client_id", confidentialClientId);
+ Form form = new Form();
+ form.param("super_client_id", confidentialClientId);
- ClientResponse response = resource().path(API_VERSION).path("plugins")
+ Response response = target().path(API_VERSION).path("plugins")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -179,18 +180,18 @@
}
private void testListPluginsClientUnauthorized (
- MultivaluedMap<String, String> form)
+ Form form)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("plugins")
+ Response response = target().path(API_VERSION).path("plugins")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -205,14 +206,15 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("plugins")
+ Form form = getSuperClientForm();
+ Response response = target().path(API_VERSION).path("plugins")
.request()
.header(Attributes.AUTHORIZATION, "Bearer blahblah")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(getSuperClientForm()).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -241,32 +243,32 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = getSuperClientForm();
+ Form form = getSuperClientForm();
if (permitted_only) {
- form.add("permitted_only", Boolean.toString(permitted_only));
+ form.param("permitted_only", Boolean.toString(permitted_only));
}
- ClientResponse response = resource().path(API_VERSION).path("plugins")
+ Response response = target().path(API_VERSION).path("plugins")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
private void testInstallConfidentialPlugin (String superClientId,
String clientId, String username) throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- MultivaluedMap<String, String> form = getSuperClientForm();
- form.add("client_id", clientId);
- ClientResponse response = installPlugin(form);
+ Form form = getSuperClientForm();
+ form.param("client_id", clientId);
+ Response response = installPlugin(form);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(clientId, node.at("/client_id").asText());
assertEquals(superClientId, node.at("/super_client_id").asText());
@@ -284,11 +286,11 @@
@Test
public void testInstallPublicPlugin () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- MultivaluedMap<String, String> form = getSuperClientForm();
- form.add("client_id", publicClientId2);
- ClientResponse response = installPlugin(form);
+ Form form = getSuperClientForm();
+ form.param("client_id", publicClientId2);
+ Response response = installPlugin(form);
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(publicClientId2, node.at("/client_id").asText());
assertEquals(superClientId, node.at("/super_client_id").asText());
@@ -311,11 +313,11 @@
}
private void testInstallPluginRedundant (
- MultivaluedMap<String, String> form)
+ Form form)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = installPlugin(form);
- String entity = response.getEntity(String.class);
+ Response response = installPlugin(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PLUGIN_HAS_BEEN_INSTALLED,
node.at("/errors/0/0").asInt());
@@ -325,10 +327,10 @@
private void testInstallPluginNotPermitted (String clientId)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = getSuperClientForm();
- form.add("client_id", clientId);
- ClientResponse response = installPlugin(form);
- String entity = response.getEntity(String.class);
+ Form form = getSuperClientForm();
+ form.param("client_id", clientId);
+ Response response = installPlugin(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PLUGIN_NOT_PERMITTED,
node.at("/errors/0/0").asInt());
@@ -339,9 +341,9 @@
public void testInstallPluginMissingClientId ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = getSuperClientForm();
- ClientResponse response = installPlugin(form);
- String entity = response.getEntity(String.class);
+ Form form = getSuperClientForm();
+ Response response = installPlugin(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT,
node.at("/errors/0/0").asInt());
@@ -352,10 +354,10 @@
public void testInstallPluginInvalidClientId ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = getSuperClientForm();
- form.add("client_id", "unknown");
- ClientResponse response = installPlugin(form);
- String entity = response.getEntity(String.class);
+ Form form = getSuperClientForm();
+ form.param("client_id", "unknown");
+ Response response = installPlugin(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("Unknown client: unknown",
node.at("/error_description").asText());
@@ -367,11 +369,11 @@
public void testInstallPluginMissingSuperClientSecret ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("super_client_id", superClientId);
+ Form form = new Form();
+ form.param("super_client_id", superClientId);
- ClientResponse response = installPlugin(form);
- String entity = response.getEntity(String.class);
+ Response response = installPlugin(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("Missing parameter: super_client_secret",
@@ -385,9 +387,9 @@
public void testInstallPluginMissingSuperClientId ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- ClientResponse response = installPlugin(form);
- String entity = response.getEntity(String.class);
+ Form form = new Form();
+ Response response = installPlugin(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("Missing parameter: super_client_id",
@@ -401,44 +403,44 @@
public void testInstallPluginUnauthorizedClient ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("super_client_id", confidentialClientId);
- form.add("super_client_secret", clientSecret);
+ Form form = new Form();
+ form.param("super_client_id", confidentialClientId);
+ form.param("super_client_secret", clientSecret);
- ClientResponse response = installPlugin(form);
- String entity = response.getEntity(String.class);
+ Response response = installPlugin(form);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("unauthorized_client", node.at("/error").asText());
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
}
- private ClientResponse installPlugin (MultivaluedMap<String, String> form)
+ private Response installPlugin (Form form)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- return resource().path(API_VERSION).path("plugins").path("install")
+ return target().path(API_VERSION).path("plugins").path("install")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
}
- private ClientResponse uninstallPlugin (String clientId, String username)
+ private Response uninstallPlugin (String clientId, String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = getSuperClientForm();
- form.add("client_id", clientId);
+ Form form = getSuperClientForm();
+ form.param("client_id", clientId);
- return resource().path(API_VERSION).path("plugins").path("uninstall")
+ return target().path(API_VERSION).path("plugins").path("uninstall")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
}
private void testRetrieveInstalledPlugin (String superClientId,
@@ -472,7 +474,7 @@
node = retrieveUserInstalledPlugin(getSuperClientForm());
assertEquals(2, node.size());
- ClientResponse response =
+ Response response =
uninstallPlugin(confidentialClientId, username);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = retrieveUserInstalledPlugin(getSuperClientForm());
@@ -494,9 +496,9 @@
String userAuthHeader = HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "password");
String code = requestAuthorizationCode(clientId, userAuthHeader);
- ClientResponse response = requestTokenWithAuthorizationCodeAndForm(
+ Response response = requestTokenWithAuthorizationCodeAndForm(
clientId, clientSecret, code);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
return node;
@@ -505,29 +507,29 @@
private void testUninstallNotInstalledPlugin ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response =
+ Response response =
uninstallPlugin(confidentialClientId2, username);
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(StatusCodes.NO_RESOURCE_FOUND,
node.at("/errors/0/0").asInt());
}
private JsonNode retrieveUserInstalledPlugin (
- MultivaluedMap<String, String> form)
+ Form form)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("plugins")
+ Response response = target().path(API_VERSION).path("plugins")
.path("installed")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2TestBase.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2TestBase.java
index 452066c..d1bd166 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2TestBase.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2TestBase.java
@@ -7,6 +7,8 @@
import java.io.IOException;
import java.net.URI;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response.Status;
@@ -20,11 +22,12 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.uri.UriComponent;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.uri.UriComponent;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -71,19 +74,19 @@
return UriComponent.decodeQuery(uri, true);
};
- protected MultivaluedMap<String, String> getSuperClientForm () {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("super_client_id", superClientId);
- form.add("super_client_secret", clientSecret);
+ protected Form getSuperClientForm () {
+ Form form = new Form();
+ form.param("super_client_id", superClientId);
+ form.param("super_client_secret", clientSecret);
return form;
}
- protected ClientResponse requestAuthorizationCode (String responseType,
+ protected Response requestAuthorizationCode (String responseType,
String clientId, String redirectUri, String scope, String state,
String authHeader) throws KustvaktException {
- WebResource request =
- resource().path(API_VERSION).path("oauth2").path("authorize");
+ WebTarget request =
+ target().path(API_VERSION).path("oauth2").path("authorize");
if (!responseType.isEmpty()) {
request = request.queryParam("response_type", responseType);
@@ -102,13 +105,13 @@
}
return request.request().header(Attributes.AUTHORIZATION, authHeader)
- .get(ClientResponse.class);
+ .get();
}
protected String requestAuthorizationCode (String clientId,
String authHeader) throws KustvaktException {
- ClientResponse response = requestAuthorizationCode("code", clientId, "",
+ Response response = requestAuthorizationCode("code", clientId, "",
"", "", authHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
@@ -121,7 +124,7 @@
protected String requestAuthorizationCode (String clientId,
String redirect_uri, String authHeader) throws KustvaktException {
- ClientResponse response = requestAuthorizationCode("code", clientId,
+ Response response = requestAuthorizationCode("code", clientId,
redirect_uri, "", "", authHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
@@ -132,124 +135,124 @@
return params.getFirst("code");
}
- protected ClientResponse requestToken (MultivaluedMap<String, String> form)
+ protected Response requestToken (Form form)
throws KustvaktException {
- return resource().path(API_VERSION).path("oauth2").path("token")
+ return target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
}
// client credentials as form params
- protected ClientResponse requestTokenWithAuthorizationCodeAndForm (
+ protected Response requestTokenWithAuthorizationCodeAndForm (
String clientId, String clientSecret, String code)
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "authorization_code");
- form.add("client_id", clientId);
- form.add("client_secret", clientSecret);
- form.add("code", code);
+ Form form = new Form();
+ form.param("grant_type", "authorization_code");
+ form.param("client_id", clientId);
+ form.param("client_secret", clientSecret);
+ form.param("code", code);
- return resource().path(API_VERSION).path("oauth2").path("token")
+ return target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
}
- protected ClientResponse requestTokenWithAuthorizationCodeAndForm (
+ protected Response requestTokenWithAuthorizationCodeAndForm (
String clientId, String clientSecret, String code,
String redirectUri) throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "authorization_code");
- form.add("client_id", clientId);
- form.add("client_secret", clientSecret);
- form.add("code", code);
+ Form form = new Form();
+ form.param("grant_type", "authorization_code");
+ form.param("client_id", clientId);
+ form.param("client_secret", clientSecret);
+ form.param("code", code);
if (redirectUri != null) {
- form.add("redirect_uri", redirectUri);
+ form.param("redirect_uri", redirectUri);
}
- return resource().path(API_VERSION).path("oauth2").path("token")
+ return target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
}
// client credentials in authorization header
protected JsonNode requestTokenWithAuthorizationCodeAndHeader (
String clientId, String code, String authHeader)
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "authorization_code");
- form.add("client_id", clientId);
- form.add("code", code);
+ Form form = new Form();
+ form.param("grant_type", "authorization_code");
+ form.param("client_id", clientId);
+ form.param("code", code);
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("token")
.request()
.header(Attributes.AUTHORIZATION, authHeader)
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
- protected ClientResponse requestTokenWithDoryPassword (String clientId,
+ protected Response requestTokenWithDoryPassword (String clientId,
String clientSecret) throws KustvaktException {
return requestTokenWithPassword(clientId, clientSecret, "dory",
"password");
}
- protected ClientResponse requestTokenWithPassword (String clientId,
+ protected Response requestTokenWithPassword (String clientId,
String clientSecret, String username, String password)
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "password");
- form.add("client_id", clientId);
- form.add("client_secret", clientSecret);
- form.add("username", username);
- form.add("password", password);
+ Form form = new Form();
+ form.param("grant_type", "password");
+ form.param("client_id", clientId);
+ form.param("client_secret", clientSecret);
+ form.param("username", username);
+ form.param("password", password);
return requestToken(form);
}
protected void testRequestTokenWithRevokedRefreshToken (String clientId,
String clientSecret, String refreshToken) throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", GrantType.REFRESH_TOKEN.toString());
- form.add("client_id", clientId);
- form.add("client_secret", clientSecret);
- form.add("refresh_token", refreshToken);
+ Form form = new Form();
+ form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
+ form.param("client_id", clientId);
+ form.param("client_secret", clientSecret);
+ form.param("refresh_token", refreshToken);
if (clientSecret != null) {
- form.add("client_secret", clientSecret);
+ form.param("client_secret", clientSecret);
}
- ClientResponse response =
- resource().path(API_VERSION).path("oauth2").path("token")
+ Response response =
+ target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_GRANT, node.at("/error").asText());
assertEquals("Refresh token has been revoked",
node.at("/error_description").asText());
}
- protected ClientResponse registerClient (String username,
+ protected Response registerClient (String username,
OAuth2ClientJson json) throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- return resource().path(API_VERSION).path("oauth2").path("client")
+ return target().path(API_VERSION).path("oauth2").path("client")
.path("register")
.request()
.header(Attributes.AUTHORIZATION,
@@ -258,10 +261,10 @@
"password"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).post(ClientResponse.class);
+ .post(Entity.json(json));
}
- protected ClientResponse registerConfidentialClient (String username)
+ protected Response registerConfidentialClient (String username)
throws KustvaktException {
OAuth2ClientJson json = new OAuth2ClientJson();
@@ -300,12 +303,12 @@
String clientId) throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("deregister").path(clientId)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@@ -313,33 +316,33 @@
protected JsonNode retrieveClientInfo (String clientId, String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path(clientId)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
- protected ClientResponse searchWithAccessToken (String accessToken) {
- return resource().path(API_VERSION).path("search")
+ protected Response searchWithAccessToken (String accessToken) {
+ return target().path(API_VERSION).path("search")
.queryParam("q", "Wasser").queryParam("ql", "poliqarp")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
}
protected void testSearchWithOAuth2Token (String accessToken)
throws KustvaktException, IOException {
- ClientResponse response = searchWithAccessToken(accessToken);
- String entity = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ Response response = searchWithAccessToken(accessToken);
+ String entity = response.readEntity(String.class);
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
@@ -348,9 +351,9 @@
protected void testSearchWithRevokedAccessToken (String accessToken)
throws KustvaktException {
- ClientResponse response = searchWithAccessToken(accessToken);
- String entity = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
+ Response response = searchWithAccessToken(accessToken);
+ String entity = response.readEntity(String.class);
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -363,59 +366,60 @@
protected void testRevokeTokenViaSuperClient (String token,
String userAuthHeader) {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("token", token);
- form.add("super_client_id", superClientId);
- form.add("super_client_secret", clientSecret);
+ Form form = new Form();
+ form.param("token", token);
+ form.param("super_client_id", superClientId);
+ form.param("super_client_secret", clientSecret);
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Response response = target().path(API_VERSION).path("oauth2")
.path("revoke").path("super")
.request()
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .header(Attributes.AUTHORIZATION, userAuthHeader).entity(form)
- .post(ClientResponse.class);
+ .header(Attributes.AUTHORIZATION, userAuthHeader)
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- assertEquals("SUCCESS", response.getEntity(String.class));
+ assertEquals("SUCCESS", response.readEntity(String.class));
}
protected void testRevokeToken (String token, String clientId,
String clientSecret, String tokenType) {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("token_type", tokenType);
- form.add("token", token);
- form.add("client_id", clientId);
+ Form form = new Form();
+ form.param("token_type", tokenType);
+ form.param("token", token);
+ form.param("client_id", clientId);
if (clientSecret != null) {
- form.add("client_secret", clientSecret);
+ form.param("client_secret", clientSecret);
}
- ClientResponse response =
- resource().path(API_VERSION).path("oauth2").path("revoke")
+ Response response =
+ target().path(API_VERSION).path("oauth2").path("revoke")
.request()
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- assertEquals("SUCCESS", response.getEntity(String.class));
+ assertEquals("SUCCESS", response.readEntity(String.class));
}
protected JsonNode listUserRegisteredClients (String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ Form form = getSuperClientForm();
+ Response response = target().path(API_VERSION).path("oauth2")
.path("client").path("list")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pwd"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(getSuperClientForm()).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
index d8c67a5..9b256c7 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
@@ -8,9 +8,10 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.client.Entity;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -31,13 +32,13 @@
String queryCreator, String username, ResourceType resourceType,
CorpusAccess access) throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~" + queryCreator).path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -58,13 +59,13 @@
String json = "{\"query\": \"Sonne\""
+ ",\"queryLanguage\": \"poliqarp\"}";
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~"+qCreator).path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -79,13 +80,13 @@
+ ",\"query\": \"der\"}";
String qName = "new_query";
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~" + testUser).path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -104,13 +105,13 @@
+ ",\"query\": \"Regen\"}";
String qName = "publish_query";
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~" + testUser).path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -129,13 +130,13 @@
+ ",\"query\": \"Sommer\"}";
String qName = "marlin-query";
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~marlin").path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -153,13 +154,13 @@
+ ",\"query\": \"Sommer\"}";
String qName = "system-query";
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~system").path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -176,17 +177,17 @@
+ ",\"queryLanguage\": \"poliqarp\""
+ ",\"query\": \"Sommer\"}";
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~"+testUser).path("system-query")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -201,13 +202,13 @@
+ ",\"query\": \"Sohn\"}";
String qName = "new_query";
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~" + testUser).path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -223,17 +224,17 @@
+ ",\"query\": \"Sohn\"}";
String qName = "new_query";
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~" + testUser).path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
assertEquals("queryLanguage is null", node.at("/errors/0/1").asText());
@@ -247,17 +248,17 @@
+ ",\"queryLanguage\": \"poliqarp\"}";
String qName = "new_query";
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~" + testUser).path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
assertEquals("query is null", node.at("/errors/0/1").asText());
@@ -270,17 +271,17 @@
+ ",\"queryLanguage\": \"poliqarp\"}";
String qName = "new_query";
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~" + testUser).path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
assertEquals("type is null", node.at("/errors/0/1").asText());
@@ -289,26 +290,26 @@
private void testDeleteQueryByName (String qName, String qCreator, String username)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~" + qCreator).path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@Test
public void testDeleteQueryUnauthorized () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~dory").path("dory-q")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
- .delete(ClientResponse.class);
+ .delete();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -319,14 +320,14 @@
}
private void testDeleteSystemQueryUnauthorized (String qName) throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~system").path(qName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
- .delete(ClientResponse.class);
+ .delete();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -338,16 +339,16 @@
@Test
public void testDeleteNonExistingQuery () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.path("~dory").path("non-existing-query")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NO_RESOURCE_FOUND,
@@ -386,16 +387,16 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
return node;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceSearchTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceSearchTest.java
index 8732aef..00a8077 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceSearchTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceSearchTest.java
@@ -5,7 +5,7 @@
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -14,12 +14,12 @@
/*@Test
public void testSearchWithVCRefEqual () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"dory/dory-q\"")
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertTrue(node.at("/matches").size() > 0);
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java
index 2d872ee..87fd5bd 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java
@@ -12,11 +12,14 @@
import java.util.Iterator;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Response.Status;
+
import org.junit.Ignore;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -32,15 +35,15 @@
@Test
public void testQuerySerializationFilteredPublic ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("corpus/WPD13/query").queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp").queryParam("context", "base/s:s")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("corpusSigle", node.at("/collection/key").asText());
@@ -52,14 +55,14 @@
@Test
public void testQuerySerializationUnexistingResource ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("corpus/ZUW19/query")
+ Response response = target().path(API_VERSION).path("corpus/ZUW19/query")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("context", "base/s:s")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(101, node.at("/errors/0/0").asInt());
assertEquals("[Cannot found public Corpus with ids: [ZUW19]]",
@@ -70,15 +73,15 @@
@Test
public void testQuerySerializationWithNonPublicCorpus ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("corpus/BRZ10/query").queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp").queryParam("context", "base/s:s")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(101, node.at("/errors/0/0").asInt());
assertEquals("[Cannot found public Corpus with ids: [BRZ10]]",
@@ -89,7 +92,7 @@
@Test
public void testQuerySerializationWithAuthentication ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("corpus/BRZ10/query").queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
@@ -98,10 +101,10 @@
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("koral:doc", node.at("/collection/@type").asText());
@@ -114,7 +117,7 @@
public void testQuerySerializationWithNewCollection ()
throws KustvaktException {
// Add Virtual Collection
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("virtualcollection").queryParam("filter", "false")
.queryParam("query",
@@ -126,19 +129,19 @@
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
- .post(ClientResponse.class);
+ .post(Entity.json(""));
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertTrue(node.isObject());
assertEquals("Weimarer Werke", node.path("name").asText());
// Get virtual collections
- response = resource().path(API_VERSION)
+ response = target().path(API_VERSION)
.path("collection")
.request()
@@ -146,10 +149,10 @@
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- ent = response.getEntity(String.class);
+ ent = response.readEntity(String.class);
node = JsonUtils.readTree(ent);
assertNotNull(node);
@@ -164,7 +167,7 @@
assertFalse(id.isEmpty());
// query serialization service
- response = resource().path(API_VERSION)
+ response = target().path(API_VERSION)
.path("collection").path(id).path("query")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
@@ -174,10 +177,10 @@
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- ent = response.getEntity(String.class);
+ ent = response.readEntity(String.class);
node = JsonUtils.readTree(ent);
assertNotNull(node);
// System.out.println("NODE " + ent);
@@ -205,15 +208,15 @@
@Test
public void testQuerySerializationOfVirtualCollection ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("collection/GOE-VC/query").queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp").queryParam("context", "base/s:s")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("koral:doc",
@@ -233,18 +236,18 @@
@Test
public void testMetaQuerySerialization () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("query").queryParam("context", "sentence")
.queryParam("count", "20").queryParam("page", "5")
.queryParam("cutoff", "true").queryParam("q", "[pos=ADJA]")
.queryParam("ql", "poliqarp")
.request()
- .method("GET", ClientResponse.class);
+ .method("GET");
assertEquals(response.getStatus(),
- ClientResponse.Status.OK.getStatusCode());
+ Status.OK.getStatusCode());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals("sentence", node.at("/meta/context").asText());
@@ -262,18 +265,18 @@
@Test
public void testMetaQuerySerializationWithOffset ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("query").queryParam("context", "sentence")
.queryParam("count", "20").queryParam("page", "5")
.queryParam("offset", "2").queryParam("cutoff", "true")
.queryParam("q", "[pos=ADJA]").queryParam("ql", "poliqarp")
.request()
- .method("GET", ClientResponse.class);
+ .method("GET");
assertEquals(response.getStatus(),
- ClientResponse.Status.OK.getStatusCode());
+ Status.OK.getStatusCode());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals("sentence", node.at("/meta/context").asText());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java
index 11e8976..53a9957 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java
@@ -5,11 +5,13 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import javax.ws.rs.core.Response.Status;
+
import org.junit.Ignore;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -27,13 +29,13 @@
@Test
public void testGetPublicVirtualCollectionInfo () throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("collection")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertEquals(1, node.size());
@@ -43,18 +45,18 @@
@Test
public void testGetVirtualCollectionInfoWithAuthentication ()
throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("collection")
.request()
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertNotNull(node);
assertTrue(node.isArray());
assertEquals(3, node.size());
@@ -63,13 +65,13 @@
@Test
public void testGetVirtualCollectionInfoById () throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("collection").path("GOE-VC")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.size());
@@ -81,13 +83,13 @@
@Test
public void testGetVirtualCollectionInfoByIdUnauthorized ()
throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("collection").path("WPD15-VC")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ .get();
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.size());
@@ -99,13 +101,13 @@
@Test
public void testGetPublicCorporaInfo () throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("corpus")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertTrue(node.isArray());
@@ -115,14 +117,14 @@
@Test
public void testGetCorpusInfoById () throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("corpus").path("WPD13")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
// System.out.println(ent);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
@@ -133,13 +135,13 @@
@Test
public void testGetCorpusInfoById2 () throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("corpus").path("GOE")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertTrue(node.isObject());
@@ -149,13 +151,13 @@
@Test
public void testGetPublicFoundriesInfo () throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("foundry")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertTrue(node.isArray());
@@ -165,12 +167,12 @@
@Test
public void testGetFoundryInfoById () throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("foundry").path("tt")
.request()
- .get(ClientResponse.class);
- String ent = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ String ent = response.readEntity(String.class);
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
@@ -181,13 +183,13 @@
@Test
public void testGetUnexistingCorpusInfo () throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("corpus").path("ZUW19")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ .get();
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.size());
@@ -203,13 +205,13 @@
// exception instead?
@Test
public void testGetUnauthorizedCorpusInfo () throws KustvaktException {
- ClientResponse response = resource().path(getAPIVersion())
+ Response response = target().path(getAPIVersion())
.path("corpus").path("BRZ10")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ .get();
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.size());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
index facf1b0..968861f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
@@ -6,7 +6,9 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import org.junit.Ignore;
@@ -14,7 +16,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -36,15 +38,15 @@
private KustvaktConfiguration config;
private JsonNode requestSearchWithFields(String fields) throws KustvaktException{
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("fields", fields)
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
return node;
}
@@ -59,17 +61,17 @@
@Test
public void testApiWelcomeMessage () {
- ClientResponse response = resource().path(API_VERSION).path("")
+ Response response = target().path(API_VERSION).path("")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
assertEquals(
"Wes8Bd4h1OypPqbWF5njeQ==",
response.getHeaders().getFirst("X-Index-Revision")
);
- String message = response.getEntity(String.class);
+ String message = response.readEntity(String.class);
assertEquals(message, config.getApiWelcomeMessage());
}
@@ -91,13 +93,13 @@
@Test
public void testSearchQueryPublicCorpora () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.request()
- .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .accept(MediaType.APPLICATION_JSON).get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("koral:doc", node.at("/collection/@type").asText());
@@ -111,17 +113,17 @@
@Test
public void testSearchQueryFailure () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der").queryParam("ql", "poliqarp")
.queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE")
.queryParam("count", "13")
.request()
.accept(MediaType.APPLICATION_JSON)
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ .get();
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals(302, node.at("/errors/0/0").asInt());
@@ -133,15 +135,15 @@
@Test
public void testSearchQueryWithMeta () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cutoff", "true").queryParam("count", "5")
.queryParam("page", "1").queryParam("context", "40-t,30-t")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertTrue(node.at("/meta/cutOff").asBoolean());
@@ -155,14 +157,14 @@
@Test
public void testSearchQueryFreeExtern () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
@@ -177,14 +179,14 @@
@Test
public void testSearchQueryFreeIntern () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32")
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
@@ -199,7 +201,7 @@
@Test
public void testSearchQueryExternAuthorized () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
.request()
.header(Attributes.AUTHORIZATION,
@@ -207,10 +209,10 @@
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
// System.out.println(entity);
assertNotNull(node);
@@ -231,7 +233,7 @@
@Test
public void testSearchQueryInternAuthorized () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
.request()
.header(Attributes.AUTHORIZATION,
@@ -239,10 +241,10 @@
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32")
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
@@ -268,7 +270,7 @@
@Test
public void testSearchQueryWithCollectionQueryAuthorizedWithoutIP ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("cq", "textClass=politik & corpusSigle=BRZ10")
.request()
@@ -276,11 +278,11 @@
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertNotNull(node);
assertEquals("operation:insertion",
node.at("/collection/rewrites/0/operation").asText());
@@ -300,17 +302,17 @@
@Test
@Ignore
public void testSearchQueryAuthorizedWithoutIP () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
.request()
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
@@ -325,14 +327,14 @@
@Test
public void testSearchWithInvalidPage () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
.queryParam("page", "0")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ .get();
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
assertEquals("page must start from 1",node.at("/errors/0/1").asText());
@@ -340,14 +342,14 @@
@Test
public void testSearchSentenceMeta () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("context", "sentence")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("base/s:s", node.at("/meta/context").asText());
@@ -361,12 +363,12 @@
QuerySerializer s = new QuerySerializer();
s.setQuery("(der) or (das)", "CQL");
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.request()
- .post(ClientResponse.class, s.toJSON());
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .post(Entity.json(s.toJSON()));
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
@@ -378,12 +380,12 @@
@Test
@Ignore
public void testSearchRawQuery () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.request()
- .post(ClientResponse.class, createJsonQuery());
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .post(Entity.json(createJsonQuery()));
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
@@ -397,17 +399,17 @@
@Test
@Ignore
public void testSearchPostAll () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "10.27.0.32")
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
- .post(ClientResponse.class, createJsonQuery());
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .post(Entity.json(createJsonQuery()));
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
@@ -421,17 +423,17 @@
@Test
@Ignore
public void testSearchPostPublic () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
- .post(ClientResponse.class, createJsonQuery());
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .post(Entity.json(createJsonQuery()));
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchNetworkEndpointTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchNetworkEndpointTest.java
index 51c3eab..f35260a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchNetworkEndpointTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchNetworkEndpointTest.java
@@ -9,6 +9,8 @@
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
+import javax.ws.rs.core.Response.Status;
+
import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.Before;
@@ -19,7 +21,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.config.SpringJerseyTest;
@@ -75,16 +77,16 @@
"application/json; charset=utf-8"))
.withBody(searchResult).withStatusCode(200));
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("engine", "network")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/matches").size());
@@ -95,17 +97,17 @@
public void testSearchWithUnknownURL ()
throws IOException, KustvaktException {
config.setNetworkEndpointURL("http://localhost:1040/search");
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("engine", "network")
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED,
node.at("/errors/0/0").asInt());
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
}
@@ -113,17 +115,17 @@
public void testSearchWithUnknownHost () throws KustvaktException {
config.setNetworkEndpointURL("http://search.com");
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("engine", "network")
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED,
node.at("/errors/0/0").asInt());
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
index 3940708..10149d3 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
@@ -16,6 +16,8 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
+import javax.ws.rs.core.Response.Status;
+
import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.Before;
@@ -25,7 +27,7 @@
import org.mockserver.model.Header;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -111,16 +113,16 @@
"application/json; charset=utf-8"))
.withBody(pipeJson).withStatusCode(200));
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", glemmUri)
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
@@ -159,13 +161,13 @@
glemmUri = URLEncoder.encode(glemmUri, "utf-8");
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", glemmUri)
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
}
@@ -185,16 +187,16 @@
.withBody(pipeWithParamJson).withStatusCode(200));
String glemmUri2 = glemmUri + "?param=blah";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", glemmUri + "," + glemmUri2)
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(3, node.at("/query/wrap/key").size());
}
@@ -203,16 +205,16 @@
public void testSearchWithUnknownURL ()
throws IOException, KustvaktException {
String url =
- resource().getURI().toString() + API_VERSION + "/test/tralala";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ target().getUri().toString() + API_VERSION + "/test/tralala";
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", url)
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PIPE_FAILED, node.at("/warnings/0/0").asInt());
@@ -221,16 +223,16 @@
@Test
public void testSearchWithUnknownHost () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", "http://glemm")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PIPE_FAILED, node.at("/warnings/0/0").asInt());
@@ -245,14 +247,14 @@
String pipeUri = "http://localhost:"+port+"/non-json-pipe";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", pipeUri)
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ String entity = response.readEntity(String.class);
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -264,17 +266,17 @@
@Test
public void testSearchWithMultiplePipeWarnings () throws KustvaktException {
String url =
- resource().getURI().toString() + API_VERSION + "/test/tralala";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ target().getUri().toString() + API_VERSION + "/test/tralala";
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", url + "," + "http://glemm")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/warnings").size());
@@ -301,14 +303,14 @@
"application/json; charset=utf-8")));
String pipeUri = "http://localhost:"+port+"/invalid-response";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", pipeUri)
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ String entity = response.readEntity(String.class);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -327,14 +329,14 @@
.respond(response().withBody("blah").withStatusCode(200));
String pipeUri = "http://localhost:"+port+"/plain-text";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", pipeUri)
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ String entity = response.readEntity(String.class);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -357,30 +359,30 @@
"application/json; charset=utf-8"))
.withBody(pipeJson).withStatusCode(200));
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", "http://unknown" + "," + glemmUri)
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
assertTrue(node.at("/warnings").isMissingNode());
- response = resource().path(API_VERSION).path("search")
+ response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", glemmUri + ",http://unknown")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- entity = response.getEntity(String.class);
+ entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PIPE_FAILED, node.at("/warnings/0/0").asInt());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java
index def3be9..7281f28 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java
@@ -3,12 +3,15 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Response.Status;
+
import org.junit.Ignore;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -21,14 +24,14 @@
@Test
public void testSearchPublicMetadata () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Sonne").queryParam("ql", "poliqarp")
.queryParam("access-rewrite-disabled", "true")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("availability(ALL)",
@@ -39,15 +42,15 @@
@Test
public void testSearchPublicMetadataExtern () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Sonne").queryParam("ql", "poliqarp")
.queryParam("access-rewrite-disabled", "true")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("availability(ALL)",
@@ -58,15 +61,15 @@
@Test
public void testSearchPublicMetadataWithCustomFields () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Sonne").queryParam("ql", "poliqarp")
.queryParam("fields", "author,title")
.queryParam("access-rewrite-disabled", "true")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("availability(ALL)",
@@ -82,15 +85,15 @@
@Test
public void testSearchPublicMetadataWithNonPublicField () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Sonne").queryParam("ql", "poliqarp")
.queryParam("fields", "author,title,snippet")
.queryParam("access-rewrite-disabled", "true")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NON_PUBLIC_FIELD_IGNORED,
@@ -114,12 +117,12 @@
meta.addEntry("snippets", "true");
s.setMeta(meta);
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.request()
- .post(ClientResponse.class, s.toJSON());
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .post(Entity.json(s.toJSON()));
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals("availability(ALL)",
@@ -131,15 +134,15 @@
public void testSearchPublicMetadataWithSystemVC ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Sonne").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo system-vc")
.queryParam("access-rewrite-disabled", "true")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals("operation:and",
@@ -166,14 +169,14 @@
@Test
public void testSearchPublicMetadataWithPrivateVC ()
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Sonne").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"dory/dory-vc\"")
.queryParam("access-rewrite-disabled", "true")
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java
index 49a5b9d..bfebdf0 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java
@@ -4,10 +4,12 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import javax.ws.rs.core.Response.Status;
+
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -18,16 +20,16 @@
@Test
public void testSearchWithTokens () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("show-tokens", "true")
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertTrue(node.at("/matches/0/hasSnippet").asBoolean());
@@ -39,16 +41,16 @@
@Test
public void testSearchWithoutTokens () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("show-tokens", "false")
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertTrue(node.at("/matches/0/hasSnippet").asBoolean());
@@ -58,17 +60,17 @@
@Test
public void testSearchPublicMetadataWithTokens () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("access-rewrite-disabled", "true")
.queryParam("show-tokens", "true")
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertFalse(node.at("/matches/0/hasSnippet").asBoolean());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/ShibbolethUserControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/ShibbolethUserControllerTest.java
index 6e8e0e4..1259041 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/ShibbolethUserControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/ShibbolethUserControllerTest.java
@@ -10,8 +10,11 @@
import java.util.HashMap;
import java.util.Map;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response.Status;
import org.apache.commons.collections.map.LinkedMap;
import org.junit.Ignore;
@@ -21,8 +24,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jwt.SignedJWT;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -52,10 +54,10 @@
@Test
public void loginHTTP() throws KustvaktException {
String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- ClientResponse response = resource().path("user").path("info")
+ Response response = target().path("user").path("info")
.request()
- .header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .header(Attributes.AUTHORIZATION, enc).get();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
// EM: This test require VPN / IDS Intranet
@@ -64,23 +66,23 @@
public void loginJWT() throws KustvaktException{
String en = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
/* lauffähige Version von Hanl: */
- ClientResponse response = resource().path("auth").path("apiToken")
+ Response response = target().path("auth").path("apiToken")
.request()
- .header(Attributes.AUTHORIZATION, en).get(ClientResponse.class);
+ .header(Attributes.AUTHORIZATION, en).get();
/**/
/*
- * Test : ClientResponse response = null; WebResource webRes =
- * resource().path("auth") .path("apiToken");
+ * Test : Response response = null; WebResource webRes =
+ * target().path("auth") .path("apiToken");
* webRes.header(Attributes.AUTHORIZATION, en);
*
* System.out.printf("resource: " + webRes.toString());
*
- * response = webRes.get(ClientResponse.class);
+ * response = webRes.get();
*
*/
-// assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+// assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2022, node.at("/errors/0/0").asInt());
@@ -94,13 +96,13 @@
assertTrue(BeansFactory.getKustvaktContext().getConfiguration().getTokenTTL() < 10);
String en = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- ClientResponse response = resource().path("auth").path("apiToken")
+ Response response = target().path("auth").path("apiToken")
.request()
- .header(Attributes.AUTHORIZATION, en).get(ClientResponse.class);
+ .header(Attributes.AUTHORIZATION, en).get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertNotNull(node);
String token = node.path("token").asText();
@@ -114,20 +116,20 @@
break;
}
- response = resource().path("user").path("info")
+ response = target().path("user").path("info")
.request()
- .header(Attributes.AUTHORIZATION, "api_token " + token).get(ClientResponse.class);
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
+ .header(Attributes.AUTHORIZATION, "api_token " + token).get();
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
}
@Test
public void testGetUserDetails() throws KustvaktException {
String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- ClientResponse response = resource().path("user").path("details")
+ Response response = target().path("user").path("details")
.request()
- .header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .header(Attributes.AUTHORIZATION, enc).get();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@Test
@@ -136,17 +138,17 @@
Map m = new LinkedMap();
m.put("test", "[100, \"error message\", true, \"another message\"]");
- ClientResponse response = resource().path("user").path("details")
+ Response response = target().path("user").path("details")
.request()
.header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
- .post(ClientResponse.class, m);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .post(Entity.json(m));
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- response = resource().path("user").path("details").queryParam("pointer", "test")
+ response = target().path("user").path("details").queryParam("pointer", "test")
.request()
- .header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
- String ent = response.getEntity(String.class);
+ .header(Attributes.AUTHORIZATION, enc).get();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ String ent = response.readEntity(String.class);
assertEquals("[100, \"error message\", true, \"another message\"]", ent);
}
@@ -156,18 +158,18 @@
Map m = new LinkedMap();
m.put("test", "test value 1");
- ClientResponse response = resource().path("user").path("details")
+ Response response = target().path("user").path("details")
.request()
.header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
- .post(ClientResponse.class, m);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .post(Entity.json(m));
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- response = resource().path("user").path("details")
+ response = target().path("user").path("details")
.request()
- .header(Attributes.AUTHORIZATION, enc)
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
- String ent = response.getEntity(String.class);
+ .header(Attributes.AUTHORIZATION, enc)
+ .get();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("test value 1", node.at("/test").asText());
@@ -178,13 +180,12 @@
@Test
public void testGetUserDetailsPointer() throws KustvaktException {
String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- ClientResponse response = resource().path("user").path("details")
+ Response response = target().path("user").path("details")
.queryParam("pointer", "email")
.request()
- .header(Attributes.AUTHORIZATION, enc)
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
- String ent = response.getEntity(String.class);
+ .header(Attributes.AUTHORIZATION, enc).get();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ String ent = response.readEntity(String.class);
assertEquals("test@ids-mannheim.de", ent);
}
@@ -193,11 +194,11 @@
// helper().setupSimpleAccount("userservicetest", "servicepass");
String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("userservicetest", "servicepass");
- ClientResponse response = resource().path("user").path("details")
+ Response response = target().path("user").path("details")
.request()
- .header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ .header(Attributes.AUTHORIZATION, enc).get();
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
@@ -207,10 +208,10 @@
@Test
public void testGetUserSettings() throws KustvaktException {
String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- ClientResponse response = resource().path("user").path("settings")
+ Response response = target().path("user").path("settings")
.request()
- .header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .header(Attributes.AUTHORIZATION, enc).get();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@Test
@@ -221,19 +222,19 @@
m.put("lastName", "newLastName");
m.put("email", "newtest@ids-mannheim.de");
- ClientResponse response = resource().path("user").path("details")
+ Response response = target().path("user").path("details")
.request()
.header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
- .post(ClientResponse.class, m);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .post(Entity.json(m));
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- response = resource().path("user").path("details")
+ response = target().path("user").path("details")
.request()
.header(Attributes.AUTHORIZATION, enc)
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertNotNull(node);
assertEquals("newName", node.path("firstName").asText());
assertEquals("newLastName", node.path("lastName").asText());
@@ -245,54 +246,56 @@
m.put("lastName", "user");
m.put("email", "test@ids-mannheim.de");
- response = resource().path("user").path("details")
+ response = target().path("user").path("details")
.request()
.header(Attributes.AUTHORIZATION, enc)
- .header("Content-Type", MediaType.APPLICATION_JSON).post(ClientResponse.class, m);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .post(Entity.json(m));
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@Test
@Ignore
public void testUpdateUserSettingsForm() throws IOException, KustvaktException{
String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- MultivaluedMap m = new MultivaluedMapImpl();
- m.putSingle("queryLanguage", "poliqarp_test");
- m.putSingle("pageLength", "200");
+ Form m = new Form();
+ m.param("queryLanguage", "poliqarp_test");
+ m.param("pageLength", "200");
- ClientResponse response = resource().path("user").path("settings")
+ Response response = target().path("user").path("settings")
.request()
.header(Attributes.AUTHORIZATION, enc).header("Content-Type", "application/x-www-form-urlencodeBase64d")
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode map = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode map = JsonUtils.readTree(response.readEntity(String.class));
assertNotNull(map);
- assertNotEquals(m.getFirst("queryLanguage"), map.get("queryLanguage"));
- assertNotEquals(m.get("pageLength"), Integer.valueOf((String) m.getFirst("pageLength")));
+ assertNotEquals(m.asMap().getFirst("queryLanguage"), map.get("queryLanguage"));
+ assertNotEquals(m.asMap().get("pageLength"), Integer.valueOf((String) m.asMap().getFirst("pageLength")));
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- response = resource().path("user").path("settings")
+ response = target().path("user").path("settings")
.request()
.header(Attributes.AUTHORIZATION, enc)
.header("Content-Type", "application/x-www-form-urlencodeBase64d")
- .post(ClientResponse.class, m);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .post(Entity.form(m));
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- response = resource().path("user").path("settings").header(Attributes.AUTHORIZATION, enc)
+ response = target().path("user").path("settings")
.request()
- .header("Content-Type", "application/x-www-form-urlencodeBase64d").get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .header(Attributes.AUTHORIZATION, enc)
+ .header("Content-Type", "application/x-www-form-urlencodeBase64d").get();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- map = JsonUtils.readTree(response.getEntity(String.class));
+ map = JsonUtils.readTree(response.readEntity(String.class));
assertNotNull(map);
- assertEquals(map.get("queryLanguage"), m.getFirst("queryLanguage"));
+ assertEquals(map.get("queryLanguage"), m.asMap().getFirst("queryLanguage"));
int p1 = map.path("pageLength").asInt();
- int p2 = Integer.valueOf((String) m.getFirst("pageLength"));
+ int p2 = Integer.valueOf((String) m.asMap().getFirst("pageLength"));
assertEquals(p1, p2);
}
@@ -304,35 +307,35 @@
m.put("pageLength", "200");
m.put("setting_1", "value_1");
- ClientResponse response = resource().path("user").path("settings")
+ Response response = target().path("user").path("settings")
.request()
.header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode map = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode map = JsonUtils.readTree(response.readEntity(String.class));
assertNotNull(map);
assertNotEquals(m.get("queryLanguage"), map.get("queryLanguage"));
assertNotEquals(m.get("pageLength"), Integer.valueOf((String) m.get("pageLength")));
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- response = resource().path("user").path("settings")
+ response = target().path("user").path("settings")
.request()
.header(Attributes.AUTHORIZATION, enc)
.header("Content-Type", MediaType.APPLICATION_JSON)
- .post(ClientResponse.class, m);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .post(Entity.json(m));
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- response = resource().path("user").path("settings")
+ response = target().path("user").path("settings")
.request()
.header(Attributes.AUTHORIZATION, enc)
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
+ .get();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
- map = JsonUtils.readTree(response.getEntity(String.class));
+ map = JsonUtils.readTree(response.readEntity(String.class));
assertNotNull(map);
assertEquals(map.path("queryLanguage").asText(), m.get("queryLanguage"));
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
index 490f072..29471a0 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
@@ -5,13 +5,15 @@
import java.io.IOException;
+import javax.ws.rs.client.Entity;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.Status;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -28,20 +30,20 @@
public void testGetStatisticsNoResource ()
throws IOException, KustvaktException {
String corpusQuery = "corpusSigle=WPD15";
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("corpusQuery", corpusQuery)
.request()
- .get(ClientResponse.class);
+ .get();
- assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
+ assert Status.OK.getStatusCode() == response.getStatus();
assertEquals(
"Wes8Bd4h1OypPqbWF5njeQ==",
response.getHeaders().getFirst("X-Index-Revision")
);
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.get("documents").asInt(),0);
assertEquals(node.get("tokens").asInt(),0);
@@ -49,14 +51,14 @@
@Test
public void testStatisticsWithCq () throws KustvaktException{
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertEquals(2, node.at("/documents").asInt());
assertEquals(138180, node.at("/tokens").asInt());
@@ -68,15 +70,15 @@
@Test
public void testStatisticsWithCqAndCorpusQuery () throws KustvaktException{
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
.queryParam("corpusQuery", "textType=Autobiographie & corpusSigle=GOE")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertEquals(2, node.at("/documents").asInt());
assertEquals(138180, node.at("/tokens").asInt());
@@ -90,15 +92,15 @@
public void testGetStatisticsWithcorpusQuery1 ()
throws IOException, KustvaktException {
String corpusQuery = "corpusSigle=GOE";
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("corpusQuery", corpusQuery)
.request()
- .get(ClientResponse.class);
+ .get();
- assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
+ assert Status.OK.getStatusCode() == response.getStatus();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.get("documents").asInt(),11);
assertEquals(node.get("tokens").asInt(),665842);
@@ -113,14 +115,14 @@
@Test
public void testGetStatisticsWithcorpusQuery2 ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("corpusQuery", "creationDate since 1810")
.request()
- .get(ClientResponse.class);
- String ent = response.getEntity(String.class);
+ .get();
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
+ assert Status.OK.getStatusCode() == response.getStatus();
assertEquals(node.get("documents").asInt(),7);
assertEquals(node.get("tokens").asInt(),279402);
assertEquals(node.get("sentences").asInt(), 11047);
@@ -131,15 +133,15 @@
@Test
public void testGetStatisticsWithWrongcorpusQuery ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("corpusQuery", "creationDate geq 1810")
.request()
- .get(ClientResponse.class);
+ .get();
- assert ClientResponse.Status.BAD_REQUEST.getStatusCode() == response
+ assert Status.BAD_REQUEST.getStatusCode() == response
.getStatus();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/errors/0/0").asInt(), 302);
assertEquals(node.at("/errors/0/1").asText(),
@@ -152,14 +154,14 @@
@Test
public void testGetStatisticsWithWrongcorpusQuery2 ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("corpusQuery", "creationDate >= 1810")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ String ent = response.readEntity(String.class);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
@@ -173,14 +175,14 @@
@Test
public void testGetStatisticsWithoutcorpusQuery ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(11, node.at("/documents").asInt());
@@ -192,23 +194,23 @@
@Test
public void testGetStatisticsWithKoralQuery ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.request()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .post(ClientResponse.class,"{ \"collection\" : {\"@type\": "
+ .post(Entity.json("{ \"collection\" : {\"@type\": "
+ "\"koral:doc\", \"key\": \"availability\", \"match\": "
+ "\"match:eq\", \"type\": \"type:regex\", \"value\": "
- + "\"CC-BY.*\"} }");
+ + "\"CC-BY.*\"} }"));
assertEquals(
"Wes8Bd4h1OypPqbWF5njeQ==",
response.getHeaders().getFirst("X-Index-Revision")
);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(2, node.at("/documents").asInt());
@@ -220,15 +222,15 @@
@Test
public void testGetStatisticsWithEmptyCollection ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.request()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .post(ClientResponse.class,"{}");
+ .post(Entity.json("{}"));
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/errors/0/0").asInt(),
de.ids_mannheim.korap.util.StatusCodes.MISSING_COLLECTION);
@@ -239,15 +241,15 @@
@Test
public void testGetStatisticsWithIncorrectJson ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.request()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .post(ClientResponse.class,"{ \"collection\" : }");
+ .post(Entity.json("{ \"collection\" : }"));
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(StatusCodes.DESERIALIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -258,13 +260,13 @@
@Test
public void testGetStatisticsWithoutKoralQuery ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.request()
- .post(ClientResponse.class);
+ .post(Entity.json(""));
- String ent = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ String ent = response.readEntity(String.class);
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/TokenExpiryTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/TokenExpiryTest.java
index 099027a..3b1d086 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/TokenExpiryTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/TokenExpiryTest.java
@@ -4,7 +4,9 @@
import java.io.IOException;
-import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.Response.Status;
import org.apache.http.HttpStatus;
import org.apache.http.entity.ContentType;
@@ -12,8 +14,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.config.SpringJerseyTest;
@@ -34,20 +35,20 @@
@Test
public void requestToken ()
throws KustvaktException, InterruptedException, IOException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("grant_type", "password");
- form.add("client_id", "fCBbQkAyYzI4NzUxMg");
- form.add("client_secret", "secret");
- form.add("username", "dory");
- form.add("password", "password");
+ Form form = new Form();
+ form.param("grant_type", "password");
+ form.param("client_id", "fCBbQkAyYzI4NzUxMg");
+ form.param("client_secret", "secret");
+ form.param("username", "dory");
+ form.param("password", "password");
- ClientResponse response = resource().path(API_VERSION).path("oauth2").path("token")
+ Response response = target().path(API_VERSION).path("oauth2").path("token")
.request()
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
String token = node.at("/access_token").asText();
@@ -65,15 +66,15 @@
// does not work.
private void testSearchWithExpiredToken (String token)
throws KustvaktException, IOException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Wasser").queryParam("ql", "poliqarp")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + token)
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
@@ -85,25 +86,25 @@
// cannot be tested dynamically
private void testRequestAuthorizationCodeAuthenticationTooOld (String token)
throws KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("response_type", "code");
- form.add("client_id", "fCBbQkAyYzI4NzUxMg");
- form.add("redirect_uri",
+ Form form = new Form();
+ form.param("response_type", "code");
+ form.param("client_id", "fCBbQkAyYzI4NzUxMg");
+ form.param("redirect_uri",
"https://korap.ids-mannheim.de/confidential/redirect");
- form.add("scope", "openid");
- form.add("max_age", "1");
+ form.param("scope", "openid");
+ form.param("max_age", "1");
- ClientResponse response =
- resource().path(API_VERSION).path("oauth2").path("openid").path("authorize")
+ Response response =
+ target().path(API_VERSION).path("oauth2").path("openid").path("authorize")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + token)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.USER_REAUTHENTICATION_REQUIRED,
node.at("/errors/0/0").asInt());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
index 2980ca2..617757c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
@@ -2,18 +2,17 @@
import static org.junit.Assert.assertEquals;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Form;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.client.Entity;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -35,32 +34,32 @@
private JsonNode listGroup (String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
return node;
}
@Test
public void testListDoryGroups () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("list").path("system-admin")
.queryParam("username", "dory")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(3, node.size());
@@ -68,17 +67,17 @@
@Test
public void testListDoryActiveGroups () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("list").path("system-admin")
.queryParam("username", "dory").queryParam("status", "ACTIVE")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.size());
@@ -88,31 +87,31 @@
@Test
public void testListWithoutUsername () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals("[]", entity);
}
@Test
public void testListByStatusAll () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("list").path("system-admin")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
boolean containsHiddenStatus = false;
@@ -127,17 +126,17 @@
@Test
public void testListByStatusHidden () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("list").path("system-admin")
.queryParam("status", "HIDDEN")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(1, node.size());
assertEquals(3, node.at("/0/id").asInt());
@@ -149,16 +148,15 @@
String groupName = "admin-test-group";
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@" + groupName)
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser,
"password"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .put(ClientResponse.class);
+ .put(Entity.form(new Form()));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -179,7 +177,7 @@
KustvaktException {
// accept invitation
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@" + groupName).path("subscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -187,7 +185,7 @@
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(
memberUsername, "pass"))
- .post(ClientResponse.class);
+ .post(Entity.form(new Form()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -198,21 +196,20 @@
private void testAddMemberRoles (String groupName, String memberUsername)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> map = new MultivaluedMapImpl();
- map.add("memberUsername", memberUsername);
- map.add("roleId", "1"); // USER_GROUP_ADMIN
- map.add("roleId", "2"); // USER_GROUP_MEMBER
+ Form form = new Form();
+ form.param("memberUsername", memberUsername);
+ form.param("roleId", "1"); // USER_GROUP_ADMIN
+ form.param("roleId", "2"); // USER_GROUP_MEMBER
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@" + groupName).path("role").path("add")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser,
"password"))
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").entity(map)
- .post(ClientResponse.class);
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -232,20 +229,19 @@
private void testDeleteMemberRoles (String groupName, String memberUsername)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> map = new MultivaluedMapImpl();
- map.add("memberUsername", memberUsername);
- map.add("roleId", "1"); // USER_GROUP_ADMIN
+ Form form = new Form();
+ form.param("memberUsername", memberUsername);
+ form.param("roleId", "1"); // USER_GROUP_ADMIN
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@" + groupName).path("role").path("delete")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser,
"password"))
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").entity(map)
- .post(ClientResponse.class);
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -263,17 +259,17 @@
private JsonNode retrieveGroup (String groupName)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@" + groupName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
return node;
}
@@ -282,13 +278,13 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
// delete group
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@" + groupName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -301,13 +297,13 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
// delete marlin from group
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@" + groupName).path("~marlin")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -323,17 +319,16 @@
private void testInviteMember (String groupName)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("members", "marlin,nemo,darla");
+ Form form = new Form();
+ form.param("members", "marlin,nemo,darla");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@" + groupName).path("invite")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(adminUser, "pass"))
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
index c0ffafd..b827408 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
@@ -4,8 +4,7 @@
import java.util.Set;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Form;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -13,10 +12,10 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.client.Entity;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -45,13 +44,13 @@
private JsonNode retrieveUserGroups (String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -59,13 +58,13 @@
}
private void deleteGroupByName (String groupName) throws KustvaktException{
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@"+groupName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@@ -73,13 +72,13 @@
// dory is a group admin in dory-group
@Test
public void testListDoryGroups () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -94,13 +93,13 @@
// nemo is a group member in dory-group
@Test
public void testListNemoGroups () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("nemo", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
@@ -115,13 +114,13 @@
// marlin has 2 groups
@Test
public void testListMarlinGroups () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.size());
@@ -129,11 +128,11 @@
@Test
public void testListGroupGuest () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -148,7 +147,7 @@
public void testCreateGroupEmptyDescription () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
String groupName = "empty_group";
- ClientResponse response = testCreateUserGroup(groupName,"");
+ Response response = testCreateUserGroup(groupName,"");
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
deleteGroupByName(groupName);
@@ -160,38 +159,38 @@
ClientHandlerException, KustvaktException {
String groupName = "missing-desc-group";
- ClientResponse response = testCreateGroupWithoutDescription(groupName);
+ Response response = testCreateGroupWithoutDescription(groupName);
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
deleteGroupByName(groupName);
}
- private ClientResponse testCreateUserGroup (String groupName, String description)
+ private Response testCreateUserGroup (String groupName, String description)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("description", description);
+ Form form = new Form();
+ form.param("description", description);
- ClientResponse response = resource().path(API_VERSION).path("group")
- .path("@"+groupName).type(MediaType.APPLICATION_FORM_URLENCODED)
- .request()
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue(username, "pass"))
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").entity(form)
- .put(ClientResponse.class);
-
- return response;
- }
-
- private ClientResponse testCreateGroupWithoutDescription (String groupName)
- throws UniformInterfaceException, ClientHandlerException,
- KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
- .path("@"+groupName).type(MediaType.APPLICATION_FORM_URLENCODED)
+ Response response = target().path(API_VERSION).path("group")
+ .path("@"+groupName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .put(ClientResponse.class);
+ .put(Entity.form(form));
+
+ return response;
+ }
+
+ private Response testCreateGroupWithoutDescription (String groupName)
+ throws UniformInterfaceException, ClientHandlerException,
+ KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@"+groupName)
+ .request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .put(Entity.form(new Form()));
return response;
}
@@ -201,10 +200,10 @@
ClientHandlerException, KustvaktException {
String groupName = "invalid-group-name$";
- ClientResponse response = testCreateGroupWithoutDescription(groupName);
+ Response response = testCreateGroupWithoutDescription(groupName);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
// assertEquals("User-group name must only contains letters, numbers, "
// + "underscores, hypens and spaces", node.at("/errors/0/1").asText());
@@ -216,10 +215,10 @@
ClientHandlerException, KustvaktException {
String groupName = "a";
- ClientResponse response = testCreateGroupWithoutDescription(groupName);
+ Response response = testCreateGroupWithoutDescription(groupName);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
assertEquals("groupName must contain at least 3 characters",
node.at("/errors/0/1").asText());
@@ -233,7 +232,7 @@
String groupName = "new-user-group";
String description= "This is new-user-group.";
- ClientResponse response =
+ Response response =
testCreateUserGroup(groupName, description);
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
// same name
@@ -272,7 +271,7 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
String description = "Description is updated.";
- ClientResponse response = testCreateUserGroup(groupName, description);
+ Response response = testCreateUserGroup(groupName, description);
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
JsonNode node = retrieveUserGroups(username);
@@ -284,22 +283,22 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
// delete darla from group
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@"+groupName).path("~darla")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
// check group member
- response = resource().path(API_VERSION).path("group")
+ response = target().path(API_VERSION).path("group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
node = node.get(0);
assertEquals(1, node.get("members").size());
@@ -309,15 +308,15 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
// nemo is a group member
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@"+groupName).path("~darla")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("nemo", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -331,13 +330,13 @@
private void testDeletePendingMember () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
// dory delete pearl
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("~pearl")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -349,15 +348,15 @@
@Test
public void testDeleteDeletedMember () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("~pearl")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -372,30 +371,30 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
// delete group
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@"+groupName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// EM: this is so complicated because the group retrieval are not allowed
// for delete groups
// check group
- response = resource().path(API_VERSION).path("group").path("list")
+ response = target().path(API_VERSION).path("group").path("list")
.path("system-admin").queryParam("username", username)
.queryParam("status", "DELETED")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
for (int j = 0; j < node.size(); j++){
JsonNode group = node.get(j);
@@ -411,15 +410,15 @@
public void testDeleteGroupUnauthorized () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
// dory is a group admin in marlin-group
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@marlin-group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -432,17 +431,17 @@
@Test
public void testDeleteDeletedGroup () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@deleted-group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
assertEquals("Group deleted-group has been deleted.",
@@ -455,15 +454,15 @@
ClientHandlerException, KustvaktException {
// delete marlin from marlin-group
// dory is a group admin in marlin-group
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@marlin-group").path("~marlin")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -475,29 +474,28 @@
private void testInviteMember (String groupName)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("members", "darla");
+ Form form = new Form();
+ form.param("members", "darla");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@"+groupName).path("invite")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// list group
- response = resource().path(API_VERSION).path("group")
+ response = target().path(API_VERSION).path("group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
node = node.get(0);
@@ -511,17 +509,16 @@
private void testInviteDeletedMember () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("members", "marlin");
+ Form form = new Form();
+ form.param("members", "marlin");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("invite")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -538,17 +535,16 @@
public void testInviteDeletedMember2 () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
// pearl has status deleted in dory-group
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("members", "pearl");
+ Form form = new Form();
+ form.param("members", "pearl");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("invite")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -566,18 +562,17 @@
public void testInvitePendingMember () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
// marlin has status PENDING in dory-group
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("members", "marlin");
+ Form form = new Form();
+ form.param("members", "marlin");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("invite")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
- .entity(form).post(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .post(Entity.form(form));
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -595,21 +590,20 @@
public void testInviteActiveMember () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
// nemo has status active in dory-group
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("members", "nemo");
+ Form form = new Form();
+ form.param("members", "nemo");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("invite")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_MEMBER_EXISTS,
node.at("/errors/0/0").asInt());
@@ -625,21 +619,20 @@
public void testInviteMemberToDeletedGroup ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("members", "nemo");
+ Form form = new Form();
+ form.param("members", "nemo");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@deleted-group").path("invite")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
assertEquals("Group deleted-group has been deleted.",
@@ -650,13 +643,13 @@
// marlin has GroupMemberStatus.PENDING in dory-group
@Test
public void testSubscribePendingMember () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("subscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
- .post(ClientResponse.class);
+ .post(Entity.form(new Form()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -690,14 +683,14 @@
// pearl has GroupMemberStatus.DELETED in dory-group
@Test
public void testSubscribeDeletedMember () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("subscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
- .post(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .post(Entity.form(new Form()));
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -709,27 +702,27 @@
@Test
public void testSubscribeMissingGroupName() throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("subscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("bruce", "pass"))
- .post(ClientResponse.class);
+ .post(Entity.form(new Form()));
assertEquals(Status.NOT_FOUND.getStatusCode(),
response.getStatus());
}
@Test
public void testSubscribeNonExistentMember () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("subscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("bruce", "pass"))
- .post(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .post(Entity.form(new Form()));
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
@@ -742,14 +735,14 @@
@Test
public void testSubscribeToNonExistentGroup () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@non-existent").path("subscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
- .post(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .post(Entity.form(new Form()));
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
@@ -762,17 +755,17 @@
private void testSubscribeToDeletedGroup (String groupName)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@"+groupName).path("subscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("nemo", "pass"))
- .post(ClientResponse.class);
+ .post(Entity.form(new Form()));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
assertEquals("Group new-user-group has been deleted.",
@@ -782,13 +775,13 @@
private void testUnsubscribeActiveMember (String groupName)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@"+groupName).path("unsubscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -798,14 +791,14 @@
private void checkGroupMemberRole (String groupName, String deletedMemberName)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@"+groupName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -825,15 +818,15 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
// pearl unsubscribes from dory-group
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("unsubscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
- .delete(ClientResponse.class);
+ .delete();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -852,13 +845,13 @@
JsonNode node = retrieveUserGroups("marlin");
assertEquals(2, node.size());
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("unsubscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -872,30 +865,30 @@
@Test
public void testUnsubscribeMissingGroupName () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("unsubscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
@Test
public void testUnsubscribeNonExistentMember () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@dory-group").path("unsubscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("bruce", "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
@@ -906,17 +899,17 @@
@Test
public void testUnsubscribeToNonExistentGroup () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@tralala-group").path("unsubscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NO_RESOURCE_FOUND,
@@ -929,17 +922,17 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@"+groupName).path("unsubscribe")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("nemo", "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
assertEquals("Group new-user-group has been deleted.",
@@ -949,17 +942,16 @@
@Test
public void testAddSameMemberRole () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("memberUsername", "dory");
- form.add("roleId", "1");
+ Form form = new Form();
+ form.param("memberUsername", "dory");
+ form.param("roleId", "1");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@marlin-group").path("role").path("add")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -971,17 +963,16 @@
@Test
public void testDeleteAddMemberRole () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("memberUsername", "dory");
- form.add("roleId", "1");
+ Form form = new Form();
+ form.param("memberUsername", "dory");
+ form.param("roleId", "1");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@marlin-group").path("role").path("delete")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -995,16 +986,15 @@
@Test
public void testEditMemberRoleEmpty () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("memberUsername", "dory");
+ Form form = new Form();
+ form.param("memberUsername", "dory");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@marlin-group").path("role").path("edit")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
- .post(ClientResponse.class, form);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -1018,18 +1008,17 @@
private void testEditMemberRole ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- form.add("memberUsername", "dory");
- form.add("roleId", "1");
- form.add("roleId", "3");
+ Form form = new Form();
+ form.param("memberUsername", "dory");
+ form.param("roleId", "1");
+ form.param("roleId", "3");
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@marlin-group").path("role").path("edit")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
- .entity(form).post(ClientResponse.class);
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
index 2272488..40fa517 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
@@ -6,14 +6,14 @@
import java.util.HashMap;
import java.util.Map;
-import javax.ws.rs.core.MediaType;
+import javax.ws.rs.client.Entity;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -31,15 +31,14 @@
private String username = "UserSetting_Test";
private String username2 = "UserSetting.Test2";
- public ClientResponse sendPutRequest (String username,
+ public Response sendPutRequest (String username,
Map<String, Object> map) throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .type(MediaType.APPLICATION_JSON).entity(map)
- .put(ClientResponse.class);
+ .put(Entity.json(map));
return response;
}
@@ -50,13 +49,12 @@
"{\"pos-foundry\":\"opennlp\",\"metadata\":[\"author\", \"title\","
+ "\"textSigle\", \"availability\"],\"resultPerPage\":25}";
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .type(MediaType.APPLICATION_JSON).entity(json)
- .put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -79,7 +77,7 @@
map.put("resultPerPage", 25);
map.put("metadata", "author title textSigle availability");
- ClientResponse response = sendPutRequest(username2, map);
+ Response response = sendPutRequest(username2, map);
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
testRetrieveSettings(username2, "opennlp", 25,
@@ -94,10 +92,10 @@
Map<String, Object> map = new HashMap<>();
map.put("key/", "invalidKey");
- ClientResponse response = sendPutRequest(username2, map);
+ Response response = sendPutRequest(username2, map);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(StatusCodes.INVALID_ARGUMENT,
node.at("/errors/0/0").asInt());
assertEquals("key/", node.at("/errors/0/2").asText());
@@ -109,16 +107,15 @@
"{\"pos-foundry\":\"opennlp\",\"metadata\":\"author title "
+ "textSigle availability\",\"resultPerPage\":25}";
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username2, "pass"))
- .type(MediaType.APPLICATION_JSON).entity(json)
- .put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT,
node.at("/errors/0/0").asInt());
@@ -126,15 +123,15 @@
@Test
public void testGetDifferentUsername () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username2, "pass"))
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT,
node.at("/errors/0/0").asInt());
@@ -143,16 +140,16 @@
@Test
public void testGetSettingNotExist () throws KustvaktException {
String username = "tralala";
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NO_RESOURCE_FOUND,
@@ -166,52 +163,52 @@
@Test
public void testDeleteSettingNotExist () throws KustvaktException {
String username = "tralala";
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@Test
public void testDeleteKeyDifferentUsername () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting").path("pos-foundry")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username2, "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT,
node.at("/errors/0/0").asInt());
}
private void testDeleteSetting (String username) throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- response = resource().path(API_VERSION).path("~" + username)
+ response = target().path(API_VERSION).path("~" + username)
.path("setting")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NO_RESOURCE_FOUND,
node.at("/errors/0/0").asInt());
@@ -223,12 +220,12 @@
// the purpose of the request has been achieved.
private void testDeleteKeyNotExist (String username)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting").path("lemma-foundry")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@@ -236,12 +233,12 @@
private void testDeleteKey (String username, int numOfResult,
String metadata, boolean isMetadataArray) throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting").path("pos-foundry")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
testRetrieveSettings(username, null, numOfResult, metadata,
@@ -254,7 +251,7 @@
map.put("resultPerPage", 15);
map.put("metadata", "author title");
- ClientResponse response = sendPutRequest(username, map);
+ Response response = sendPutRequest(username, map);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
testRetrieveSettings(username, "malt", 15, "author title", false);
@@ -263,15 +260,15 @@
private void testRetrieveSettings (String username, String posFoundry,
int numOfResult, String metadata, boolean isMetadataArray)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("~" + username).path("setting")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
if (posFoundry == null) {
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java
index a3ca5cb..128d6a5 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java
@@ -12,8 +12,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.cache.VirtualCorpusCache;
@@ -82,14 +82,14 @@
}
private int testSearchWithoutRef_VC1 () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq",
"textSigle=\"GOE/AGF/00000\" | textSigle=\"GOE/AGA/01784\"")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
int size = node.at("/matches").size();
assertTrue(size > 0);
@@ -97,14 +97,14 @@
}
private int testSearchWithoutRef_VC2 () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq",
"textSigle!=\"GOE/AGI/04846\" & textSigle!=\"GOE/AGA/01784\"")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
int size = node.at("/matches").size();
assertTrue(size > 0);
@@ -112,37 +112,37 @@
}
private JsonNode testSearchWithRef_VC1 () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"system/named-vc1\"")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
return JsonUtils.readTree(ent);
}
private JsonNode testSearchWithRef_VC2 () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo named-vc2")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
return JsonUtils.readTree(ent);
}
@Test
public void testStatisticsWithRef () throws KustvaktException {
String corpusQuery = "availability = /CC-BY.*/ & referTo named-vc1";
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics").queryParam("corpusQuery", corpusQuery)
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(2, node.at("/documents").asInt());
@@ -152,13 +152,13 @@
@Test
public void testRefVcNotExist () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"username/vc1\"")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(StatusCodes.NO_RESOURCE_FOUND,
node.at("/errors/0/0").asInt());
@@ -167,13 +167,13 @@
@Test
public void testRefNotAuthorized() throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"dory/dory-vc\"")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -182,13 +182,13 @@
@Test
public void testSearchWithRefPublishedVcGuest () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"marlin/published-vc\"")
.request()
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertTrue(node.at("/matches").size() > 0);
@@ -208,30 +208,30 @@
@Test
public void testSearchWithRefPublishedVc () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"marlin/published-vc\"")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("squirt", "pass"))
- .get(ClientResponse.class);
+ .get();
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertTrue(node.at("/matches").size() > 0);
// check dory in the hidden group of the vc
- response = resource().path(API_VERSION).path("group")
+ response = target().path(API_VERSION).path("group")
.path("list").path("system-admin")
.queryParam("status", "HIDDEN")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("admin", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
assertEquals(3, node.at("/0/id").asInt());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
index 4b2afdd..f15499a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
@@ -2,7 +2,7 @@
import static org.junit.Assert.assertEquals;
-import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Form;
import org.apache.http.entity.ContentType;
import org.junit.Test;
@@ -10,9 +10,10 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.client.Entity;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -32,17 +33,17 @@
@Test
public void testSearchPrivateVC () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~dory").path("dory-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(1, node.at("/id").asInt());
@@ -53,14 +54,14 @@
public void testSearchProjectVC () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~dory").path("group-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -73,35 +74,35 @@
@Test
public void testListDoryVC () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.queryParam("username", "dory")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(4, node.size());
}
private JsonNode testListSystemVC () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("list").path("system-admin").queryParam("type", "SYSTEM")
.queryParam("createdBy", "system")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
@@ -111,13 +112,13 @@
+ ",\"queryType\": \"VIRTUAL_CORPUS\""
+ ",\"corpusQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~system").path("new-system-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -130,13 +131,13 @@
private void testDeleteSystemVC (String vcCreator, String vcName)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~system").path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -152,14 +153,14 @@
+ ",\"corpusQuery\": \"corpusSigle=GOE\"}";
String vcName = "new-vc";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+username).path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -173,18 +174,18 @@
private JsonNode testListUserVC (String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("list").path("system-admin")
.queryParam("createdBy", username)
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
@@ -194,14 +195,14 @@
String json = "{\"description\": \"edited vc\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+vcCreator).path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -212,13 +213,13 @@
private void testDeletePrivateVC (String vcCreator, String vcName)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+vcCreator).path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -228,16 +229,16 @@
// @Deprecated
// private String testlistAccessByVC (String groupName) throws KustvaktException {
-// ClientResponse response = resource().path(API_VERSION).path("vc")
+// Response response = target().path(API_VERSION).path("vc")
// .path("access")
// .queryParam("groupName", groupName)
// .request()
// .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
// .createBasicAuthorizationHeaderValue(admin, "pass"))
// .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
-// .get(ClientResponse.class);
+// .get();
//
-// String entity = response.getEntity(String.class);
+// String entity = response.readEntity(String.class);
// JsonNode node = JsonUtils.readTree(entity);
// assertEquals(1, node.size());
// node = node.get(0);
@@ -253,15 +254,15 @@
private JsonNode testlistAccessByGroup (String groupName)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("access")
.queryParam("groupName", groupName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.size());
return node.get(node.size()-1);
@@ -286,16 +287,15 @@
private void testCreateVCAccess (String vcCreator, String vcName,
String groupName) throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response;
+ Response response;
// share VC
- response = resource().path(API_VERSION).path("vc").path("~"+vcCreator)
+ response = target().path(API_VERSION).path("vc").path("~"+vcCreator)
.path(vcName).path("share").path("@"+groupName)
- .type(MediaType.APPLICATION_FORM_URLENCODED)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .post(ClientResponse.class);
+ .post(Entity.form(new Form()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -305,13 +305,13 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("access").path(accessId)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
index 2750fae..ac0ed0a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
@@ -18,10 +18,12 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.spi.container.ContainerRequest;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.client.Entity;
+import org.glassfish.jersey.server.ContainerRequest;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -39,11 +41,11 @@
private String testUser = "vcControllerTest";
- private void checkWWWAuthenticateHeader (ClientResponse response) {
- Set<Entry<String, List<String>>> headers =
+ private void checkWWWAuthenticateHeader (Response response) {
+ Set<Entry<String, List<Object>>> headers =
response.getHeaders().entrySet();
- for (Entry<String, List<String>> header : headers) {
+ for (Entry<String, List<Object>> header : headers) {
if (header.getKey().equals(ContainerRequest.WWW_AUTHENTICATE)) {
assertEquals("Api realm=\"Kustvakt\"",
header.getValue().get(0));
@@ -58,15 +60,15 @@
private JsonNode testListVC (String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
return JsonUtils.readTree(entity);
}
@@ -74,43 +76,43 @@
private JsonNode testListOwnerVC (String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~" + username)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
private void testDeleteVC (String vcName, String vcCreator, String username)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~" + vcCreator).path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
private JsonNode testlistAccessByGroup (String username, String groupName)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("access").queryParam("groupName", groupName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
return node;
}
@@ -132,11 +134,11 @@
public void testRetrieveSystemVCGuest () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~system").path("system-vc")
.request()
- .get(ClientResponse.class);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ .get();
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals("system-vc", node.at("/name").asText());
assertEquals(ResourceType.SYSTEM.displayName(),
node.at("/type").asText());
@@ -161,14 +163,14 @@
public void testRetrievePrivateVCInfoUnauthorized ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~dory").path("dory-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
@@ -194,14 +196,14 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~dory").path("group-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
@@ -222,17 +224,17 @@
node.at("/type").asText());
// check gill in the hidden group of the vc
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("list").path("system-admin")
.queryParam("status", "HIDDEN")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("admin", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
assertEquals(3, node.at("/0/id").asInt());
String members = node.at("/0/members").toString();
@@ -266,14 +268,14 @@
public void testListAvailableVCByOtherUser ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~dory")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -288,10 +290,10 @@
@Test
public void testListAvailableVCByGuest () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.request()
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -304,13 +306,13 @@
}
private void testListSystemVC () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~system")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.size());
assertEquals(ResourceType.SYSTEM.displayName(),
@@ -325,14 +327,14 @@
+ ",\"queryType\": \"VIRTUAL_CORPUS\""
+ ",\"corpusQuery\": \"corpusSigle=GOE\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("new_vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -357,14 +359,14 @@
String vcName = "new-published-vc";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -401,15 +403,15 @@
private JsonNode testCheckHiddenGroup (String groupName)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group")
+ Response response = target().path(API_VERSION).path("group")
.path("@"+groupName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("admin", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
@@ -428,7 +430,7 @@
authToken = reader.readLine();
}
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("new_vc")
.request()
.header(Attributes.AUTHORIZATION,
@@ -436,8 +438,8 @@
+ authToken)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .put(Entity.json(json));
+ String entity = response.readEntity(String.class);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -461,7 +463,7 @@
+ "UiLCJleHAiOjE1MzA2MTgyOTR9.JUMvTQZ4tvdRXFBpQKzoNxrq7"
+ "CuYAfytr_LWqY8woJs";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("new_vc")
.request()
.header(Attributes.AUTHORIZATION,
@@ -469,9 +471,9 @@
+ authToken)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
+ .put(Entity.json(json));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -489,13 +491,13 @@
+ ",\"corpusQuery\": \"pubDate since 1820\"}";
String vcName = "new_system_vc";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~system").path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("admin", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -509,17 +511,17 @@
+ ",\"queryType\": \"VIRTUAL_CORPUS\""
+ ",\"corpusQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("new_vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -535,14 +537,14 @@
+ ",\"queryType\": \"VIRTUAL_CORPUS\""
+ ",\"corpusQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("new $vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .put(Entity.json(json));
+ String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -557,14 +559,14 @@
+ ",\"queryType\": \"VIRTUAL_CORPUS\""
+ ",\"corpusQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("ne")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .put(Entity.json(json));
+ String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -579,15 +581,15 @@
String json = "{\"type\": \"PRIVATE\","
+ "\"corpusQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("new_vc")
.request()
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
+ .put(Entity.json(json));
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -603,14 +605,14 @@
+ ",\"queryType\": \"VIRTUAL_CORPUS\""
+ "}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("new_vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .put(Entity.json(json));
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -623,14 +625,14 @@
@Test
public void testCreateVCWithoutEntity () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("new_vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .put(Entity.json(""));
+ String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -646,14 +648,14 @@
+ ",\"queryType\": \"VIRTUAL_CORPUS\""
+ "}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("new_vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .put(Entity.json(json));
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -670,15 +672,15 @@
+ ",\"queryType\": \"VIRTUAL_CORPUS\""
+ ",\"corpusQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+testUser).path("new_vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .entity(json).put(ClientResponse.class);
+ .put(Entity.json(json));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -691,16 +693,16 @@
@Test
public void testDeleteVCUnauthorized () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~dory").path("dory-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -718,14 +720,14 @@
// 1st edit
String json = "{\"description\": \"edited vc\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~dory").path("dory-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -736,14 +738,14 @@
// 2nd edit
json = "{\"description\": \"test vc\"}";
- response = resource().path(API_VERSION).path("vc").path("~dory")
+ response = target().path(API_VERSION).path("vc").path("~dory")
.path("dory-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -762,13 +764,13 @@
String json = "{\"corpusQuery\": \"corpusSigle=WPD17\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~dory").path("dory-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -781,16 +783,16 @@
private JsonNode testRetrieveKoralQuery (String username, String vcName)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("koralQuery").path("~" + username).path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
return node;
}
@@ -799,15 +801,15 @@
public void testEditVCNotOwner () throws KustvaktException {
String json = "{\"description\": \"edited vc\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~dory").path("dory-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
- String entity = response.getEntity(String.class);
+ .put(Entity.json(json));
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -831,14 +833,14 @@
// edit vc
String json = "{\"type\": \"PUBLISHED\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~dory").path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
// check VC
@@ -858,14 +860,14 @@
// edit 2nd
json = "{\"type\": \"PROJECT\"}";
- response = resource().path(API_VERSION).path("vc").path("~dory")
+ response = target().path(API_VERSION).path("vc").path("~dory")
.path("group-vc")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -890,16 +892,16 @@
// @Test
// public void testlistAccessMissingId () throws KustvaktException
// {
- // ClientResponse response =
- // resource().path(API_VERSION).path("vc")
+ // Response response =
+ // target().path(API_VERSION).path("vc")
// .path("access")
// .request().header(Attributes.AUTHORIZATION,
// HttpAuthorizationHandler
// .createBasicAuthorizationHeaderValue(
// testUser, "pass"))
// .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- // .get(ClientResponse.class);
- // String entity = response.getEntity(String.class);
+ // .get();
+ // String entity = response.readEntity(String.class);
// JsonNode node = JsonUtils.readTree(entity);
// assertEquals(Status.BAD_REQUEST.getStatusCode(),
// response.getStatus());
@@ -910,14 +912,14 @@
@Test
public void testlistAccessByGroup () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("access").queryParam("groupName", "dory-group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(1, node.at("/0/accessId").asInt());
@@ -940,7 +942,7 @@
assertEquals(vcName, node.at("/name").asText());
assertEquals("private", node.at("/type").asText());
- ClientResponse response =
+ Response response =
testShareVCByCreator("marlin", vcName, groupName);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -974,25 +976,25 @@
testEditVCType("marlin", "marlin", vcName, ResourceType.PRIVATE);
}
- private ClientResponse testShareVCByCreator (String vcCreator,
+ private Response testShareVCByCreator (String vcCreator,
String vcName, String groupName) throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- return resource().path(API_VERSION).path("vc").path("~"+vcCreator)
+ return target().path(API_VERSION).path("vc").path("~"+vcCreator)
.path(vcName).path("share").path("@"+groupName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(vcCreator, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .post(ClientResponse.class);
+ .post(Entity.form(new Form()));
}
private void testShareVCNonUniqueAccess (String vcCreator, String vcName,
String groupName) throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response =
+ Response response =
testShareVCByCreator(vcCreator, vcName, groupName);
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
assertEquals(StatusCodes.DB_INSERT_FAILED,
node.at("/errors/0/0").asInt());
@@ -1006,9 +1008,9 @@
@Test
public void testShareUnknownVC () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = testShareVCByCreator("marlin",
+ Response response = testShareVCByCreator("marlin",
"non-existing-vc", "marlin group");
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
assertEquals(StatusCodes.NO_RESOURCE_FOUND,
node.at("/errors/0/0").asInt());
@@ -1017,9 +1019,9 @@
@Test
public void testShareUnknownGroup () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = testShareVCByCreator("marlin", "marlin-vc",
+ Response response = testShareVCByCreator("marlin", "marlin-vc",
"non-existing-group");
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
assertEquals(StatusCodes.NO_RESOURCE_FOUND,
node.at("/errors/0/0").asInt());
@@ -1030,16 +1032,16 @@
ClientHandlerException, KustvaktException {
// dory is VCA in marlin group
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~marlin").path("marlin-vc").path("share")
.path("@marlin group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .post(ClientResponse.class);
+ .post(Entity.form(new Form()));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
@@ -1053,15 +1055,15 @@
ClientHandlerException, KustvaktException {
// nemo is not VCA in marlin group
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~nemo").path("nemo-vc").path("share").path("@marlin-group")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("nemo", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .post(ClientResponse.class);
+ .post(Entity.form(new Form()));
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
@@ -1070,16 +1072,16 @@
node.at("/errors/0/1").asText());
}
- private ClientResponse testDeleteAccess (String username, String accessId)
+ private Response testDeleteAccess (String username, String accessId)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("access").path(accessId)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
return response;
}
@@ -1087,15 +1089,15 @@
private void testDeleteAccessUnauthorized (String accessId)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("access").path(accessId)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .delete(ClientResponse.class);
+ .delete();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -1108,10 +1110,10 @@
@Test
public void testDeleteNonExistingAccess () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = testDeleteAccess("dory", "100");
+ Response response = testDeleteAccess("dory", "100");
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(StatusCodes.NO_RESOURCE_FOUND,
node.at("/errors/0/0").asInt());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java
index 3761a54..e75e700 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java
@@ -11,9 +11,9 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.cache.VirtualCorpusCache;
@@ -36,17 +36,17 @@
private JsonNode testRetrieveField (String username, String vcName,
String field) throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("field").path("~" + username).path(vcName)
.queryParam("fieldName", field)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("admin", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
return node;
}
@@ -54,17 +54,17 @@
private void testRetrieveProhibitedField (String username, String vcName,
String field) throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("field").path("~" + username).path(vcName)
.queryParam("fieldName", field)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("admin", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NOT_ALLOWED, node.at("/errors/0/0").asInt());
}
@@ -139,17 +139,17 @@
public void testRetrieveFieldUnauthorized () throws KustvaktException, IOException, QueryException {
vcLoader.loadVCToCache("named-vc3", "/vc/named-vc3.jsonld");
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("field").path("~system").path("named-vc3")
.queryParam("fieldName", "textSigle")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
assertEquals("Unauthorized operation for user: dory", node.at("/errors/0/1").asText());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java
index bcb6b5c..403ee7c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java
@@ -7,9 +7,10 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.client.Entity;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -23,14 +24,14 @@
protected JsonNode testSearchVC (String username, String vcCreator, String vcName)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+vcCreator).path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
- String entity = response.getEntity(String.class);
+ .get();
+ String entity = response.readEntity(String.class);
// System.out.println(entity);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -42,14 +43,14 @@
throws KustvaktException {
String json = "{\"type\": \"" + type + "\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc")
+ Response response = target().path(API_VERSION).path("vc")
.path("~"+vcCreator).path(vcName)
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
- .put(ClientResponse.class, json);
+ .put(Entity.json(json));
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/InfoControllerTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/InfoControllerTest.java
index ded6871..9a1df6a 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/InfoControllerTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/InfoControllerTest.java
@@ -6,8 +6,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.config.LiteJerseyTest;
@@ -26,13 +27,13 @@
@Test
public void testInfo () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("info")
+ Response response = target().path(API_VERSION).path("info")
.request()
- .get(ClientResponse.class);
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(config.getCurrentVersion(),
node.at("/latest_api_version").asText());
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteMultipleCorpusQueryTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteMultipleCorpusQueryTest.java
index 0b253e4..0ae5fb1 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteMultipleCorpusQueryTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteMultipleCorpusQueryTest.java
@@ -7,9 +7,11 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
import de.ids_mannheim.korap.config.LiteJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
@@ -19,15 +21,15 @@
@Test
public void testSearchGet () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "das").queryParam("ql", "poliqarp")
.queryParam("cq", "pubPlace=München")
.queryParam("cq", "textSigle=\"GOE/AGA/01784\"")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
node = node.at("/collection");
assertEquals("koral:docGroup", node.at("/@type").asText());
@@ -45,14 +47,14 @@
public void testStatisticsWithMultipleCq ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("statistics")
+ Response response = target().path(API_VERSION).path("statistics")
.queryParam("cq", "textType=Abhandlung")
.queryParam("cq", "corpusSigle=GOE")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/documents").asInt());
assertEquals(138180, node.at("/tokens").asInt());
@@ -66,14 +68,14 @@
public void testStatisticsWithMultipleCorpusQuery ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("statistics")
+ Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", "textType=Autobiographie")
.queryParam("corpusQuery", "corpusSigle=GOE")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(9, node.at("/documents").asInt());
assertEquals(527662, node.at("/tokens").asInt());
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
index c1b14a1..9378ed8 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
@@ -10,8 +10,11 @@
import java.net.URI;
import java.util.Iterator;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.Ignore;
@@ -20,8 +23,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -44,14 +45,14 @@
@Ignore
@Test
public void testGetJSONQuery () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals("orth", node.at("/query/wrap/layer").asText());
@@ -64,37 +65,37 @@
@Ignore
@Test
public void testbuildAndPostQuery () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
- response = resource().path(API_VERSION).path("search")
+ response = target().path(API_VERSION).path("search")
.request()
- .post(ClientResponse.class, query);
+ .post(Entity.json(query));
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String matches = response.getEntity(String.class);
+ String matches = response.readEntity(String.class);
JsonNode match_node = JsonUtils.readTree(matches);
assertNotEquals(0, match_node.path("matches").size());
}
@Test
public void testApiWelcomeMessage () {
- ClientResponse response = resource().path(API_VERSION).path("")
+ Response response = target().path(API_VERSION).path("")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String message = response.getEntity(String.class);
+ String message = response.readEntity(String.class);
assertEquals(
"Wes8Bd4h1OypPqbWF5njeQ==",
response.getHeaders().getFirst("X-Index-Revision")
@@ -104,14 +105,14 @@
@Test
public void testQueryGet () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals("orth", node.at("/query/wrap/layer").asText());
@@ -122,15 +123,15 @@
@Test
public void testQueryFailure () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das").queryParam("ql", "poliqarp")
.queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE")
.queryParam("count", "13")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ .get();
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
@@ -143,14 +144,14 @@
@Test
public void testFoundryRewrite () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals("orth", node.at("/query/wrap/layer").asText());
@@ -164,12 +165,12 @@
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=das]", "poliqarp");
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.request()
- .post(ClientResponse.class, s.toJSON());
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .post(Entity.json(s.toJSON()));
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals("orth", node.at("/query/wrap/layer").asText());
@@ -178,15 +179,15 @@
@Test
public void testParameterField () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("fields", "author,docSigle")
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals("orth", node.at("/query/wrap/layer").asText());
@@ -197,14 +198,14 @@
@Test
public void testMatchInfoGetWithoutSpans () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
.queryParam("foundry", "*").queryParam("spans", "false")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("GOE/AGA/01784", node.at("/textSigle").asText());
@@ -215,14 +216,14 @@
@Test
public void testMatchInfoGetWithoutHighlights () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
.queryParam("foundry", "xy").queryParam("spans", "false")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals(
@@ -236,15 +237,15 @@
@Test
public void testMatchInfoWithoutExtension () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42")
.queryParam("foundry", "-").queryParam("spans", "false")
.queryParam("expand","false")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("GOE/AGA/01784", node.at("/textSigle").asText());
@@ -258,15 +259,15 @@
@Test
public void testMatchInfoGetWithHighlights () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
.queryParam("foundry", "xy").queryParam("spans", "false")
.queryParam("hls", "true")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("GOE/AGA/01784", node.at("/textSigle").asText());
@@ -287,15 +288,15 @@
@Test
public void testMatchInfoGet2 () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("corpus/GOE/AGA/01784/p36-46/matchInfo")
.queryParam("foundry", "*")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("GOE/AGA/01784", node.at("/textSigle").asText());
@@ -306,16 +307,16 @@
@Ignore
@Test
public void testCollectionQueryParameter () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("query")
+ Response response = target().path(API_VERSION).path("query")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("fields", "author, docSigle")
.queryParam("context", "sentence").queryParam("count", "13")
.queryParam("cq", "textClass=Politik & corpus=WPD")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals("orth", node.at("/query/wrap/layer").asText());
@@ -323,20 +324,20 @@
node.at("/collection/operands/0/value").asText());
assertEquals("WPD", node.at("/collection/operands/1/value").asText());
- response = resource().path(API_VERSION).path("search")
+ response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("fields", "author, docSigle")
.queryParam("context", "sentence").queryParam("count", "13")
.queryParam("cq", "textClass=Politik & corpus=WPD")
.request()
- .get(ClientResponse.class);
+ .get();
// String version =
// LucenePackage.get().getImplementationVersion();;
// System.out.println("VERSION "+ version);
// System.out.println("RESPONSE "+ response);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- query = response.getEntity(String.class);
+ query = response.readEntity(String.class);
node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals("orth", node.at("/query/wrap/layer").asText());
@@ -347,13 +348,13 @@
@Test
public void testMetaFields () throws KustvaktException {
- ClientResponse response =
- resource().path(API_VERSION).path("/corpus/GOE/AGA/01784")
+ Response response =
+ target().path(API_VERSION).path("/corpus/GOE/AGA/01784")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String resp = response.getEntity(String.class);
+ String resp = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(resp);
// System.err.println(node.toString());
@@ -403,10 +404,10 @@
@Test
public void testSearchWithoutVersion () throws KustvaktException {
- ClientResponse response = resource().path("api").path("search")
+ Response response = target().path("api").path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.request()
- .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+ .accept(MediaType.APPLICATION_JSON).get();
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
assertEquals("/api/v1.0/search", location.getPath());
@@ -414,12 +415,12 @@
@Test
public void testSearchWrongVersion () throws KustvaktException {
- ClientResponse response = resource().path("api").path("v0.2")
+ Response response = target().path("api").path("v0.2")
.path("search").queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
- .accept(MediaType.APPLICATION_JSON)
.request()
- .get(ClientResponse.class);
+ .accept(MediaType.APPLICATION_JSON)
+ .get();
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
assertEquals("/api/v1.0/search", location.getPath());
@@ -427,46 +428,46 @@
@Test
public void testSearchWithIP () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Wasser").queryParam("ql", "poliqarp")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertTrue(node.at("/collection").isMissingNode());
}
@Test
public void testSearchWithAuthorizationHeader () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Wasser").queryParam("ql", "poliqarp")
.request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("test", "pwd"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertTrue(node.at("/collection").isMissingNode());
}
@Test
public void testSearchPublicMetadata () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("access-rewrite-disabled", "true")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertTrue(node.at("/matches/0/snippet").isMissingNode());
@@ -474,15 +475,15 @@
@Test
public void testSearchPublicMetadataWithCustomFields () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Sonne").queryParam("ql", "poliqarp")
.queryParam("fields", "author,title")
.queryParam("access-rewrite-disabled", "true")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertTrue(node.at("/matches/0/snippet").isMissingNode());
@@ -495,15 +496,15 @@
@Test
public void testSearchPublicMetadataWithNonPublicField () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "Sonne").queryParam("ql", "poliqarp")
.queryParam("fields", "author,title,snippet")
.queryParam("access-rewrite-disabled", "true")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .get();
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NON_PUBLIC_FIELD_IGNORED,
@@ -516,14 +517,14 @@
@Test
public void testSearchWithInvalidPage () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
.queryParam("page", "0")
.request()
- .get(ClientResponse.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ .get();
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
assertEquals("page must start from 1",node.at("/errors/0/1").asText());
@@ -534,14 +535,13 @@
searchKrill.getStatistics(null);
assertEquals(true, searchKrill.getIndex().isReaderOpen());
- MultivaluedMap<String, String> m = new MultivaluedMapImpl();
- m.add("token", "secret");
+ Form form = new Form();
+ form.param("token", "secret");
- ClientResponse response = resource().path(API_VERSION).path("index")
+ Response response = target().path(API_VERSION).path("index")
.path("close")
.request()
- .type(MediaType.APPLICATION_FORM_URLENCODED)
- .post(ClientResponse.class, m);
+ .post(Entity.form(form));
assertEquals(HttpStatus.OK_200, response.getStatus());
assertEquals(false, searchKrill.getIndex().isReaderOpen());
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchPipeTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchPipeTest.java
index 9922ce0..867a159 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchPipeTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchPipeTest.java
@@ -25,7 +25,9 @@
import org.mockserver.model.Header;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.config.LiteJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -111,16 +113,16 @@
"application/json; charset=utf-8"))
.withBody(pipeJson).withStatusCode(200));
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", glemmUri)
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
@@ -152,13 +154,13 @@
glemmUri = URLEncoder.encode(glemmUri, "utf-8");
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", glemmUri)
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
}
@@ -178,16 +180,16 @@
.withBody(pipeWithParamJson).withStatusCode(200));
String glemmUri2 = glemmUri + "?param=blah";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", glemmUri + "," + glemmUri2)
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(3, node.at("/query/wrap/key").size());
}
@@ -196,16 +198,16 @@
public void testSearchWithUnknownURL ()
throws IOException, KustvaktException {
String url =
- resource().getURI().toString() + API_VERSION + "/test/tralala";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ target().getUri().toString() + API_VERSION + "/test/tralala";
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", url)
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PIPE_FAILED, node.at("/warnings/0/0").asInt());
@@ -214,16 +216,16 @@
@Test
public void testSearchWithUnknownHost () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", "http://glemm")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PIPE_FAILED, node.at("/warnings/0/0").asInt());
@@ -238,14 +240,14 @@
String pipeUri = "http://localhost:"+port+"/non-json-pipe";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", pipeUri)
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ String entity = response.readEntity(String.class);
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -257,17 +259,17 @@
@Test
public void testSearchWithMultiplePipeWarnings () throws KustvaktException {
String url =
- resource().getURI().toString() + API_VERSION + "/test/tralala";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ target().getUri().toString() + API_VERSION + "/test/tralala";
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", url + "," + "http://glemm")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/warnings").size());
@@ -294,14 +296,14 @@
"application/json; charset=utf-8")));
String pipeUri = "http://localhost:"+port+"/invalid-response";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", pipeUri)
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ String entity = response.readEntity(String.class);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -320,14 +322,14 @@
.respond(response().withBody("blah").withStatusCode(200));
String pipeUri = "http://localhost:"+port+"/plain-text";
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", pipeUri)
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ String entity = response.readEntity(String.class);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -350,30 +352,30 @@
"application/json; charset=utf-8"))
.withBody(pipeJson).withStatusCode(200));
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", "http://unknown" + "," + glemmUri)
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
assertTrue(node.at("/warnings").isMissingNode());
- response = resource().path(API_VERSION).path("search")
+ response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", glemmUri + ",http://unknown")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- entity = response.getEntity(String.class);
+ entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PIPE_FAILED, node.at("/warnings/0/0").asInt());
}
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchTokenSnippetTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchTokenSnippetTest.java
index a091ecf..5602657 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchTokenSnippetTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchTokenSnippetTest.java
@@ -7,7 +7,9 @@
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.config.LiteJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -18,16 +20,16 @@
@Test
public void testSearchWithTokens () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("show-tokens", "true")
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertTrue(node.at("/matches/0/hasSnippet").asBoolean());
@@ -39,16 +41,16 @@
@Test
public void testSearchWithoutTokens () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("show-tokens", "false")
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertTrue(node.at("/matches/0/hasSnippet").asBoolean());
@@ -58,17 +60,17 @@
@Test
public void testSearchPublicMetadataWithTokens () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("access-rewrite-disabled", "true")
.queryParam("show-tokens", "true")
.queryParam("context", "sentence").queryParam("count", "13")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertFalse(node.at("/matches/0/hasSnippet").asBoolean());
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteStatisticControllerTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteStatisticControllerTest.java
index 99a05b4..2c7b726 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteStatisticControllerTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteStatisticControllerTest.java
@@ -5,14 +5,15 @@
import java.io.IOException;
+import javax.ws.rs.client.Entity;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
import de.ids_mannheim.korap.config.LiteJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -23,12 +24,12 @@
@Test
public void testStatisticsWithCq () throws KustvaktException{
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
assertEquals(
@@ -36,7 +37,7 @@
response.getHeaders().getFirst("X-Index-Revision")
);
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertEquals(2, node.at("/documents").asInt());
assertEquals(138180, node.at("/tokens").asInt());
@@ -48,15 +49,15 @@
@Test
public void testStatisticsWithCqAndCorpusQuery () throws KustvaktException{
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
.queryParam("corpusQuery", "textType=Autobiographie & corpusSigle=GOE")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertEquals(2, node.at("/documents").asInt());
assertEquals(138180, node.at("/tokens").asInt());
@@ -68,14 +69,14 @@
@Test
public void testStatisticsWithCorpusQuery () throws KustvaktException{
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("corpusQuery", "textType=Autobiographie & corpusSigle=GOE")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertEquals(9, node.at("/documents").asInt());
assertEquals(527662, node.at("/tokens").asInt());
@@ -90,27 +91,27 @@
@Test
public void testEmptyStatistics () throws KustvaktException{
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.queryParam("corpusQuery", "")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String query = response.getEntity(String.class);
+ String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertEquals(11, node.at("/documents").asInt());
assertEquals(665842, node.at("/tokens").asInt());
assertEquals(25074, node.at("/sentences").asInt());
assertEquals(772, node.at("/paragraphs").asInt());
- response = resource().path(API_VERSION)
+ response = target().path(API_VERSION)
.path("statistics")
.request()
- .method("GET", ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ .method("GET");
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- query = response.getEntity(String.class);
+ query = response.readEntity(String.class);
node = JsonUtils.readTree(query);
assertEquals(11, node.at("/documents").asInt());
assertEquals(665842, node.at("/tokens").asInt());
@@ -121,22 +122,22 @@
@Test
public void testGetStatisticsWithKoralQuery ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.request()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .post(ClientResponse.class,"{ \"collection\" : {\"@type\": "
+ .post(Entity.json("{ \"collection\" : {\"@type\": "
+ "\"koral:doc\", \"key\": \"availability\", \"match\": "
+ "\"match:eq\", \"type\": \"type:regex\", \"value\": "
- + "\"CC-BY.*\"} }");
+ + "\"CC-BY.*\"} }"));
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
assertEquals(
"Wes8Bd4h1OypPqbWF5njeQ==",
- response.getMetadata().getFirst("X-Index-Revision")
+ response.getHeaders().getFirst("X-Index-Revision")
);
JsonNode node = JsonUtils.readTree(ent);
@@ -149,15 +150,15 @@
@Test
public void testGetStatisticsWithEmptyCollection ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.request()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .post(ClientResponse.class,"{}");
+ .post(Entity.json("{}"));
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/errors/0/0").asInt(),
de.ids_mannheim.korap.util.StatusCodes.MISSING_COLLECTION);
@@ -168,15 +169,15 @@
@Test
public void testGetStatisticsWithIncorrectJson ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.request()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .post(ClientResponse.class,"{ \"collection\" : }");
+ .post(Entity.json("{ \"collection\" : }"));
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+ String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(StatusCodes.DESERIALIZATION_FAILED,
node.at("/errors/0/0").asInt());
@@ -187,13 +188,13 @@
@Test
public void testGetStatisticsWithoutKoralQuery ()
throws IOException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION)
+ Response response = target().path(API_VERSION)
.path("statistics")
.request()
- .post(ClientResponse.class);
+ .post(Entity.json(""));
- String ent = response.getEntity(String.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ String ent = response.readEntity(String.class);
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/SearchNetworkEndpointTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/SearchNetworkEndpointTest.java
index a4f9dc6..6377608 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/SearchNetworkEndpointTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/SearchNetworkEndpointTest.java
@@ -19,7 +19,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.config.LiteJerseyTest;
@@ -75,16 +76,16 @@
"application/json; charset=utf-8"))
.withBody(searchResult).withStatusCode(200));
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("engine", "network")
.request()
- .get(ClientResponse.class);
+ .get();
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ assertEquals(Status.OK.getStatusCode(),
response.getStatus());
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/matches").size());
@@ -95,17 +96,17 @@
public void testSearchWithUnknownURL ()
throws IOException, KustvaktException {
config.setNetworkEndpointURL("http://localhost:1040/search");
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("engine", "network")
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED,
node.at("/errors/0/0").asInt());
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
}
@@ -113,17 +114,17 @@
public void testSearchWithUnknownHost () throws KustvaktException {
config.setNetworkEndpointURL("http://search.com");
- ClientResponse response = resource().path(API_VERSION).path("search")
+ Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("engine", "network")
.request()
- .get(ClientResponse.class);
+ .get();
- String entity = response.getEntity(String.class);
+ String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED,
node.at("/errors/0/0").asInt());
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ assertEquals(Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
}
}