Removed old tests.
Change-Id: Ia4d709e8663e9c113ca02cf8c8260e85d58bac7d
diff --git a/full/Changes b/full/Changes
index 7648ee3..92c154e 100644
--- a/full/Changes
+++ b/full/Changes
@@ -2,6 +2,7 @@
- Removed auditing (#611)
- Removed old database configurations (#612)
+- Removed old tests
# version 0.70.1
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java b/full/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java
deleted file mode 100644
index 3b308b0..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package de.ids_mannheim.korap.config;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.junit.runner.RunWith;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.model.InitializationError;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import net.jcip.annotations.NotThreadSafe;
-
-/**
- * @author hanl
- * @date 09/03/2016
- */
-@NotThreadSafe
-@RunWith(BeanConfigTest.SpringExtendedSetupListener.class)
-@ContextConfiguration("classpath:test-config.xml")
-@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
-public abstract class BeanConfigTest {
-
- private static Logger jlog = LogManager.getLogger(BeanConfigTest.class);
- @Autowired
- protected ApplicationContext context;
-
- public void init () throws Exception {
- assertNotNull("Application context must not be null!", this.context);
- jlog.debug("running one-time before init for class "
- + this.getClass().getSimpleName() + " ...");
-// BeansFactory.setKustvaktContext(getContext());
- assertNotNull(BeansFactory.getKustvaktContext());
- }
-
- public void close () {
- BeansFactory.closeApplication();
- }
-
- public static class SpringExtendedSetupListener
- extends SpringJUnit4ClassRunner {
-
- private BeanConfigTest instanceSetupListener;
-
-
- public SpringExtendedSetupListener (Class<?> clazz)
- throws InitializationError {
- super(clazz);
- }
-
-
- @Override
- protected Object createTest () throws Exception {
- Object test = super.createTest();
- // Note that JUnit4 will call this createTest() multiple times for each
- // test method, so we need to ensure to call "beforeClassSetup" only once.
- if (test instanceof BeanConfigTest
- && instanceSetupListener == null) {
- instanceSetupListener = (BeanConfigTest) test;
- instanceSetupListener.init();
- }
- return test;
- }
-
-
- @Override
- public void run (RunNotifier notifier) {
- super.run(notifier);
- if (instanceSetupListener != null) {
- instanceSetupListener.close();
- }
- }
- }
-
-// protected ContextHolder getContext () {
-// return helper().getContext();
-// }
-//
-// protected TestHelper helper () {
-// try {
-// return TestHelper.newInstance(this.context);
-// }
-// catch (Exception e) {
-// return null;
-// }
-// }
-}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/FastJerseyTest.java b/full/src/test/java/de/ids_mannheim/korap/web/FastJerseyTest.java
deleted file mode 100644
index ae9a2ef..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/web/FastJerseyTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package de.ids_mannheim.korap.web;
-
-import java.net.URI;
-import java.util.concurrent.ThreadLocalRandom;
-
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.UriBuilder;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.springframework.web.context.ContextLoaderListener;
-
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import org.glassfish.jersey.server.ResourceConfig;
-import org.glassfish.jersey.servlet.ServletContainer;
-import org.glassfish.jersey.test.DeploymentContext;
-import org.glassfish.jersey.test.ServletDeploymentContext;
-import org.glassfish.jersey.test.spi.TestContainer;
-import org.glassfish.jersey.test.spi.TestContainerFactory;
-import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory;
-import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory;
-
-import de.ids_mannheim.korap.config.BeanConfigTest;
-
-public abstract class FastJerseyTest extends BeanConfigTest{
-
- private static String[] classPackages =
- new String[] { "de.ids_mannheim.korap.web.service.full",
- "de.ids_mannheim.korap.web.filter",
- "de.ids_mannheim.korap.web.utils" };
-
- public final static String API_VERSION = "v0.1";
-
- private static ResourceConfig resourceConfig =
- new ResourceConfig();
-
- private static TestContainerFactory testContainerFactory;
-
- protected static TestContainer testContainer;
-
- protected static javax.ws.rs.client.Client client;
-
- protected static int PORT = 8089; // FB, was: 9000;
- protected static int PORT_IT = 1;
- protected static String containerURI = "http://localhost/";
-
- public String getAPIVersion () {
- return API_VERSION;
- }
-
- public static void setTestContainerFactory (
- TestContainerFactory newTestContainerFactory) {
- testContainerFactory = newTestContainerFactory;
- }
-
-
- @BeforeClass
- public static void cleanStaticVariables () {
- resourceConfig = new ResourceConfig();
- }
-
-
- protected static void initServer (int port, String[] classPackages) {
- DeploymentContext dc;
- if (classPackages == null)
- dc = DeploymentContext.builder(resourceConfig).build();
- else
- dc = ServletDeploymentContext
- .forServlet(new ServletContainer(resourceConfig.packages(classPackages)))
- .addListener(ContextLoaderListener.class)
- .contextParam("contextConfigLocation", "classpath:test-config.xml")
- .build();
-
- TestContainerFactory tcf = testContainerFactory;
- if (tcf == null) {
- if (classPackages == null)
- tcf = new GrizzlyTestContainerFactory();
- else
- tcf = new GrizzlyWebTestContainerFactory();
- }
-
- testContainer = tcf.create(
- UriBuilder.fromUri(containerURI).port(port).build(), dc);
- client = testContainer.getClientConfig().getClient();
- if (client == null) {
- client = ClientBuilder.newClient(testContainer.getClientConfig());
- }
- }
-
- @After
- public void stopServer () {
-
- testContainer.stop();
- testContainer = null;
- client = null;
- }
-
-
- public Client client () {
- return client;
- }
-
-
- public URI getBaseUri () {
- return testContainer.getBaseUri();
- }
-
-
- public WebTarget target () {
- return client.target(getBaseUri());
- }
-
-// protected TestHelper helper () {
-// try {
-// return TestHelper.newInstance(this.context);
-// }
-// catch (Exception e) {
-// return null;
-// }
-// }
-//
-//
-// @Override
-// protected ContextHolder getContext () {
-// return helper().getContext();
-// }
-
-
- public static void startServer () {
- try {
- if (testContainer != null) {
- testContainer.start();
- }
- }
- catch (Exception e) {
- initServer(PORT + PORT_IT++, classPackages);
- startServer();
- }
- }
-
-
- @Before
- public void startServerBeforeFirstTestRun () {
- if (testContainer == null) {
- int port = ThreadLocalRandom.current().nextInt(5000, 8000 + 1);
- initServer(port, classPackages);
- startServer();
- }
- }
-
-}
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
deleted file mode 100644
index 8ebe6a6..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/AuthenticationControllerTest.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package de.ids_mannheim.korap.web.controller;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.joda.time.DateTime;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import com.fasterxml.jackson.databind.JsonNode;
-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;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.utils.TimeUtils;
-import de.ids_mannheim.korap.web.FastJerseyTest;
-
-/**
- * EM: fix tests. New DB does not save users.
- * @author hanl
- * @date 24/09/2015
- */
-@Ignore
-public class AuthenticationControllerTest extends FastJerseyTest {
-
- private static String[] credentials;
-
- @Test
- public void testSessionToken() throws KustvaktException {
- String auth = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- credentials[0], credentials[1]);
- Response response = target().path("auth")
- .path("sessionToken")
- .request()
- .header(Attributes.AUTHORIZATION, auth)
- .get();
- assertEquals(Status.OK.getStatusCode(),
- response.getStatus());
- String en = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(en);
- assertNotNull(node);
-
- String token = node.path("token").asText();
- String token_type = node.path("token_type").asText();
- String expiration = node.path("expires").asText();
- DateTime ex = TimeUtils.getTime(expiration);
- assertNotEquals("", token);
- assertNotEquals("", token_type);
- assertFalse(TimeUtils.isExpired(ex.getMillis()));
-
- response = target().path("user")
- .path("info")
- .request()
- .header(Attributes.AUTHORIZATION, token_type + " "+ token)
- .get();
- en = response.readEntity(String.class);
-
- assertEquals(Status.OK.getStatusCode(),
- response.getStatus());
-
- response = target().path("auth")
- .path("logout")
- .request()
- .header(Attributes.AUTHORIZATION, token_type + " "+ token)
- .get();
-
- assertEquals(Status.OK.getStatusCode(),
- response.getStatus());
- }
-
- @Test
- public void testSessionTokenExpire() throws KustvaktException {
- String auth = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- credentials[0], credentials[1]);
- Response response = target().path("auth")
- .path("sessionToken")
- .request()
- .header(Attributes.AUTHORIZATION, auth)
- .get();
- assertEquals(Status.OK.getStatusCode(),
- response.getStatus());
- String en = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(en);
- assertNotNull(node);
-
- String token = node.path("token").asText();
- String token_type = node.path("token_type").asText();
- String expiration = node.path("expires").asText();
- DateTime ex = TimeUtils.getTime(expiration);
- assertNotEquals("", token);
- assertNotEquals("", token_type);
-
- while (true) {
- if (TimeUtils.isExpired(ex.getMillis()))
- break;
- }
- response = target().path("user")
- .path("info")
- .request()
- .header(Attributes.AUTHORIZATION, token_type + " "+ token)
- .get();
- en = response.readEntity(String.class);
- node = JsonUtils.readTree(en);
- assertNotNull(node);
-
- assertEquals(StatusCodes.BAD_CREDENTIALS, node.at("/errors/0/0").asInt());
- assertEquals(Status.UNAUTHORIZED.getStatusCode(),
- response.getStatus());
- }
-
-
-// @Test
-// public void testBlockingFilterFail() {
-//
-// }
-//
-//
-// @Test
-// public void testBasicLogout () {
-//
-// }
-//
-//
-// @Test
-// public void testSessionTokenLogin () {
-//
-// }
-//
-//
-// @Test
-// public void testSessionTokenLogout () {
-//
-// }
-//
-//
-// @Test
-// public void testOpenIDLogin () {
-//
-// }
-//
-//
-// @Test
-// public void testOpenIDLogout () {
-//
-// }
-//
-//
-// // -- are these even right? auth - authorization
-// @Test
-// public void testOAuth2Login () {
-//
-// }
-//
-//
-// @Test
-// public void testOAuth2Logout () {
-//
-// }
-
- //todo: test basicauth via secure connection
-
-}
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 87fd5bd..23c7257 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
@@ -13,24 +13,24 @@
import java.util.Iterator;
import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.junit.Ignore;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.web.FastJerseyTest;
// EM: The API is disabled
@Ignore
-public class QuerySerializationControllerTest extends FastJerseyTest {
+public class QuerySerializationControllerTest extends SpringJerseyTest {
@Test
public void testQuerySerializationFilteredPublic ()
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 53a9957..7e9fba6 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,19 +5,19 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.junit.Ignore;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
-import javax.ws.rs.core.Response;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.web.FastJerseyTest;
/**
* @author hanl, margaretha
@@ -25,11 +25,11 @@
* EM: FIX ME: Database restructure
*/
@Ignore
-public class ResourceInfoControllerTest extends FastJerseyTest {
+public class ResourceInfoControllerTest extends SpringJerseyTest {
@Test
public void testGetPublicVirtualCollectionInfo () throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("collection")
.request()
.get();
@@ -45,7 +45,7 @@
@Test
public void testGetVirtualCollectionInfoWithAuthentication ()
throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("collection")
.request()
.header(Attributes.AUTHORIZATION,
@@ -65,7 +65,7 @@
@Test
public void testGetVirtualCollectionInfoById () throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("collection").path("GOE-VC")
.request()
.get();
@@ -83,7 +83,7 @@
@Test
public void testGetVirtualCollectionInfoByIdUnauthorized ()
throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("collection").path("WPD15-VC")
.request()
.get();
@@ -101,7 +101,7 @@
@Test
public void testGetPublicCorporaInfo () throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("corpus")
.request()
.get();
@@ -117,7 +117,7 @@
@Test
public void testGetCorpusInfoById () throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("corpus").path("WPD13")
.request()
.get();
@@ -135,7 +135,7 @@
@Test
public void testGetCorpusInfoById2 () throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("corpus").path("GOE")
.request()
.get();
@@ -151,7 +151,7 @@
@Test
public void testGetPublicFoundriesInfo () throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("foundry")
.request()
.get();
@@ -167,7 +167,7 @@
@Test
public void testGetFoundryInfoById () throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("foundry").path("tt")
.request()
.get();
@@ -183,7 +183,7 @@
@Test
public void testGetUnexistingCorpusInfo () throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("corpus").path("ZUW19")
.request()
.get();
@@ -205,7 +205,7 @@
// exception instead?
@Test
public void testGetUnauthorizedCorpusInfo () throws KustvaktException {
- Response response = target().path(getAPIVersion())
+ Response response = target().path(API_VERSION)
.path("corpus").path("BRZ10")
.request()
.get();
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
deleted file mode 100644
index 1259041..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/ShibbolethUserControllerTest.java
+++ /dev/null
@@ -1,357 +0,0 @@
-package de.ids_mannheim.korap.web.controller;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.text.ParseException;
-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;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.nimbusds.jose.JOSEException;
-import com.nimbusds.jwt.SignedJWT;
-import javax.ws.rs.core.Response;
-
-import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.config.BeansFactory;
-import de.ids_mannheim.korap.config.FullConfiguration;
-import de.ids_mannheim.korap.config.JWTSigner;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.utils.TimeUtils;
-import de.ids_mannheim.korap.web.FastJerseyTest;
-
-/** EM: To do: not implemented in the new DB yet
- * @author hanl
- * @date 21/03/2015
- */
-
-// todo: do benchmarks for simple request to check access_token check and user
-// retrieval!
-@Ignore
-public class ShibbolethUserControllerTest extends FastJerseyTest {
-
- @Autowired
- FullConfiguration config;
- private static String[] credentials;
-
- @Test
- public void loginHTTP() throws KustvaktException {
- String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- Response response = target().path("user").path("info")
- .request()
- .header(Attributes.AUTHORIZATION, enc).get();
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
- }
-
- // EM: This test require VPN / IDS Intranet
- @Test
- @Ignore
- public void loginJWT() throws KustvaktException{
- String en = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- /* lauffähige Version von Hanl: */
- Response response = target().path("auth").path("apiToken")
- .request()
- .header(Attributes.AUTHORIZATION, en).get();
- /**/
- /*
- * 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();
- *
- */
-
-// 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());
- }
-
- // EM: cannot do test with LDAP
- @Test
- @Ignore
- public void loginJWTExpired() throws InterruptedException, KustvaktException, ParseException, JOSEException {
-
- assertTrue(BeansFactory.getKustvaktContext().getConfiguration().getTokenTTL() < 10);
-
- String en = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- Response response = target().path("auth").path("apiToken")
- .request()
- .header(Attributes.AUTHORIZATION, en).get();
-
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
- assertNotNull(node);
- String token = node.path("token").asText();
-
- JWTSigner sign = new JWTSigner(BeansFactory.getKustvaktContext().getConfiguration().getSharedSecret(),
- config.getIssuer(), -1);
- //BeansFactory.getKustvaktContext().getConfiguration().getIssuer(), -1);
- SignedJWT jwt = sign.verifyToken(token);
-
- while (true) {
- if (TimeUtils.isExpired(jwt.getJWTClaimsSet().getExpirationTime().getTime()))
- break;
- }
-
- response = target().path("user").path("info")
- .request()
- .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]);
- Response response = target().path("user").path("details")
- .request()
- .header(Attributes.AUTHORIZATION, enc).get();
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
- }
-
- @Test
- public void testGetUserDetailsEmbeddedPointer() throws KustvaktException {
- String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- Map m = new LinkedMap();
- m.put("test", "[100, \"error message\", true, \"another message\"]");
-
- Response response = target().path("user").path("details")
- .request()
- .header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
- .post(Entity.json(m));
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- response = target().path("user").path("details").queryParam("pointer", "test")
- .request()
- .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);
- }
-
- @Test
- public void testUpdateUserDetailsMerge() throws KustvaktException{
- String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- Map m = new LinkedMap();
- m.put("test", "test value 1");
-
- Response response = target().path("user").path("details")
- .request()
- .header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
- .post(Entity.json(m));
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- response = target().path("user").path("details")
- .request()
- .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());
- assertEquals("user", node.at("/lastName").asText());
- assertEquals("test@ids-mannheim.de", node.at("/email").asText());
- }
-
- @Test
- public void testGetUserDetailsPointer() throws KustvaktException {
- String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- Response response = target().path("user").path("details")
- .queryParam("pointer", "email")
- .request()
- .header(Attributes.AUTHORIZATION, enc).get();
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String ent = response.readEntity(String.class);
- assertEquals("test@ids-mannheim.de", ent);
- }
-
- @Test
- public void testGetUserDetailsNonExistent() throws KustvaktException {
-// helper().setupSimpleAccount("userservicetest", "servicepass");
-
- String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("userservicetest", "servicepass");
- Response response = target().path("user").path("details")
- .request()
- .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());
- assertEquals("UserDetails", node.at("/errors/0/2").asText());
- }
-
- @Test
- public void testGetUserSettings() throws KustvaktException {
- String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- Response response = target().path("user").path("settings")
- .request()
- .header(Attributes.AUTHORIZATION, enc).get();
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
- }
-
- @Test
- public void testUpdateUserDetailsJson() throws KustvaktException{
- String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- Map m = new LinkedMap();
- m.put("firstName", "newName");
- m.put("lastName", "newLastName");
- m.put("email", "newtest@ids-mannheim.de");
-
- Response response = target().path("user").path("details")
- .request()
- .header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
- .post(Entity.json(m));
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- response = target().path("user").path("details")
- .request()
- .header(Attributes.AUTHORIZATION, enc)
- .get();
-
- 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());
- assertEquals("newtest@ids-mannheim.de", node.path("email").asText());
- assertEquals("Mannheim", node.path("address").asText());
-
- m = new LinkedMap();
- m.put("firstName", "test");
- m.put("lastName", "user");
- m.put("email", "test@ids-mannheim.de");
-
- response = target().path("user").path("details")
- .request()
- .header(Attributes.AUTHORIZATION, enc)
- .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]);
- Form m = new Form();
- m.param("queryLanguage", "poliqarp_test");
- m.param("pageLength", "200");
-
- Response response = target().path("user").path("settings")
- .request()
- .header(Attributes.AUTHORIZATION, enc).header("Content-Type", "application/x-www-form-urlencodeBase64d")
- .get();
-
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- JsonNode map = JsonUtils.readTree(response.readEntity(String.class));
- assertNotNull(map);
-
- assertNotEquals(m.asMap().getFirst("queryLanguage"), map.get("queryLanguage"));
- assertNotEquals(m.asMap().get("pageLength"), Integer.valueOf((String) m.asMap().getFirst("pageLength")));
-
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- response = target().path("user").path("settings")
- .request()
- .header(Attributes.AUTHORIZATION, enc)
- .header("Content-Type", "application/x-www-form-urlencodeBase64d")
- .post(Entity.form(m));
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- response = target().path("user").path("settings")
- .request()
- .header(Attributes.AUTHORIZATION, enc)
- .header("Content-Type", "application/x-www-form-urlencodeBase64d").get();
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- map = JsonUtils.readTree(response.readEntity(String.class));
- assertNotNull(map);
-
- assertEquals(map.get("queryLanguage"), m.asMap().getFirst("queryLanguage"));
- int p1 = map.path("pageLength").asInt();
- int p2 = Integer.valueOf((String) m.asMap().getFirst("pageLength"));
- assertEquals(p1, p2);
- }
-
- @Test
- public void testUpdateUserSettingsJson() throws IOException, KustvaktException {
- String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
- Map m = new HashMap<>();
- m.put("queryLanguage", "poliqarp_test");
- m.put("pageLength", "200");
- m.put("setting_1", "value_1");
-
- Response response = target().path("user").path("settings")
- .request()
- .header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
- .get();
-
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- 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(Status.OK.getStatusCode(), response.getStatus());
-
- response = target().path("user").path("settings")
- .request()
- .header(Attributes.AUTHORIZATION, enc)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .post(Entity.json(m));
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- response = target().path("user").path("settings")
- .request()
- .header(Attributes.AUTHORIZATION, enc)
- .get();
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- map = JsonUtils.readTree(response.readEntity(String.class));
- assertNotNull(map);
-
- assertEquals(map.path("queryLanguage").asText(), m.get("queryLanguage"));
- int p1 = map.path("pageLength").asInt();
- int p2 = Integer.valueOf((String) m.get("pageLength"));
- assertEquals(p1, p2);
- }
-
- @Test
- public void testLoginFailedLockAccount() {
-
- }
-
- @Test
- public void delete() {
-
- }
-
-}