Removed TestHelper
Change-Id: Ie167cb271c32e3a9381ad85c6e9dc4b3a779c868
diff --git a/full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java b/full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java
index e06d9f7..6c2834b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java
@@ -89,9 +89,4 @@
authenticationManager.getUserData(user, UserSettingProcessor.class);
}
-
- @Override
- public void initMethod () throws KustvaktException {
- helper().setupAccount();
- }
}
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
index 2268d87..0de7e58 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java
@@ -34,13 +34,10 @@
assertNotNull("Application context must not be null!", this.context);
jlog.debug("running one-time before init for class "
+ this.getClass().getSimpleName() + " ...");
- BeansFactory.setKustvaktContext(getContext());
+// BeansFactory.setKustvaktContext(getContext());
assertNotNull(BeansFactory.getKustvaktContext());
- initMethod();
}
- public abstract void initMethod () throws KustvaktException;
-
public void close () {
BeansFactory.closeApplication();
}
@@ -80,16 +77,16 @@
}
}
- protected ContextHolder getContext () {
- return helper().getContext();
- }
-
- protected TestHelper helper () {
- try {
- return TestHelper.newInstance(this.context);
- }
- catch (Exception e) {
- return null;
- }
- }
+// 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/config/TestHelper.java b/full/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
deleted file mode 100644
index efe2fd8..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
+++ /dev/null
@@ -1,325 +0,0 @@
-package de.ids_mannheim.korap.config;
-
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.File;
-import java.io.IOException;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.dbcp2.BasicDataSource;
-import org.flywaydb.core.Flyway;
-import org.joda.time.DateTime;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.jdbc.core.RowCallbackHandler;
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
-import org.springframework.jdbc.datasource.SingleConnectionDataSource;
-
-import de.ids_mannheim.korap.authentication.KustvaktAuthenticationManager;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.handlers.JDBCClient;
-import de.ids_mannheim.korap.interfaces.EntityHandlerIface;
-import de.ids_mannheim.korap.interfaces.KustvaktBaseDaoInterface;
-import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.utils.TimeUtils;
-
-/**
- * creates a test user that can be used to access protected functions
- *
- * @author hanl
- * @date 16/10/2015
- */
-public class TestHelper {
-
- private static Logger jlog = LoggerFactory.getLogger(TestHelper.class);
- private static final Map<String, Object> data = new HashMap<>();
- static {
- data.put(Attributes.ID, 3); // 2);
- data.put(Attributes.USERNAME, "testUser1"); // bodmer funktioniert noch nicht
- data.put(Attributes.PASSWORD, "testPass2015");
- data.put(Attributes.FIRSTNAME, "test");
- data.put(Attributes.LASTNAME, "user");
- data.put(Attributes.EMAIL, "test@ids-mannheim.de");
- data.put(Attributes.ADDRESS, "Mannheim");
- data.put(Attributes.DEFAULT_FOUNDRY_LEMMA, "test_l");
- data.put(Attributes.DEFAULT_FOUNDRY_POS, "test_p");
- data.put(Attributes.DEFAULT_FOUNDRY_CONSTITUENT, "test_const");
- }
-
- private ContextHolder beansHolder;
-
- public static TestHelper newInstance (ApplicationContext ctx)
- throws Exception {
- TestHelper b = new TestHelper();
- b.beansHolder = new ContextHolder(ctx) {};
- return b;
- }
-
-
- public <T> T getBean (Class<T> type) {
- return this.beansHolder.getBean(type);
- }
-
-
- public ContextHolder getContext () {
- return this.beansHolder;
- }
-
-
- public <T> T getBean (String name) {
- return (T) this.beansHolder.getBean(name);
- }
-
-
- public TestHelper setupAccount () throws KustvaktException {
- KustvaktBaseDaoInterface dao = getBean(ContextHolder.KUSTVAKT_USERDB);
-
- KustvaktAuthenticationManager manager = getBean(ContextHolder.KUSTVAKT_AUTHENTICATION_MANAGER);
-// manager.createUserAccount(KustvaktConfiguration.KUSTVAKT_USER, false);
- try {
- User user = getUser();
- jlog.debug("found user, skipping setup ...");
- if (!user.getUsername().equals(data.get(Attributes.USERNAME))){
- return this;
- }
- }
- catch (RuntimeException e) {
- // do nothing and continue
- }
-
- Map m = getUserCredentials();
- assertNotNull("userdatabase handler must not be null", dao);
-
-// try {
-// manager.createUserAccount(m, false);
-// }
-// catch (KustvaktException e) {
-// throw new RuntimeException(e);
-// /*// do nothing
-// jlog.error("Error: {}", e.string());
-// assertNotNull("Test user could not be set up", null);*/
-// }
- assertNotEquals(0, dao.size());
- return this;
- }
-
- // EM
- @Deprecated
-// public TestHelper setupSimpleAccount (String username, String password) {
-// KustvaktBaseDaoInterface dao = getBean(ContextHolder.KUSTVAKT_USERDB);
-// EntityHandlerIface edao = (EntityHandlerIface) dao;
-// try {
-// edao.getAccount(username);
-// }
-// catch (EmptyResultException e) {
-// // do nothing
-// }
-// catch (KustvaktException ex) {
-// assertNull("Test user could not be set up", true);
-// }
-//
-// Map m = new HashMap<>();
-// m.put(Attributes.USERNAME, username);
-//
-// try {
-// String hash = ((EncryptionIface) getBean(ContextHolder.KUSTVAKT_ENCRYPTION))
-// .secureHash(password);
-// m.put(Attributes.PASSWORD, hash);
-// }
-// catch (NoSuchAlgorithmException | UnsupportedEncodingException
-// | KustvaktException e) {
-// // do nohting
-// assertNotNull("Exception thrown", null);
-// }
-// assertNotNull("userdatabase handler must not be null", dao);
-//
-// try {
-//
-// int i = edao.createAccount(User.UserFactory.toKorAPUser(m));
-// assert BeansFactory.getKustvaktContext().getUserDBHandler()
-// .getAccount((String) data.get(Attributes.USERNAME)) != null;
-// assertEquals(1, i);
-// }
-// catch (KustvaktException e) {
-// // do nothing
-// assertNull("Test user could not be set up", true);
-// }
-// return this;
-// }
-
-
- public User getUser () {
- try {
- return ((EntityHandlerIface) getBean(ContextHolder.KUSTVAKT_USERDB))
- .getAccount((String) data.get(Attributes.USERNAME));
- }
- catch (KustvaktException e) {
- // do nothing
- }
- throw new RuntimeException("User could not be retrieved!");
- }
-
-
- public TestHelper dropUser (String ... usernames) throws KustvaktException {
- if (usernames == null || usernames.length == 0) {
- KustvaktBaseDaoInterface dao = getBean(ContextHolder.KUSTVAKT_USERDB);
- dao.truncate();
- }
- for (String name : Arrays.asList(usernames)) {
- if (remove(name))
- break;
- }
- return this;
- }
-
-
- private boolean remove (String username) throws KustvaktException {
- EntityHandlerIface dao = getBean(ContextHolder.KUSTVAKT_USERDB);
- User us = dao.getAccount(username);
- dao.deleteAccount(us.getId());
- return true;
- }
-
-
- public TestHelper truncateAll () {
- String sql = "SELECT Concat('TRUNCATE TABLE ', TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES";
- final Set<String> queries = new HashSet<>();
- PersistenceClient cl = getBean(ContextHolder.KUSTVAKT_POLICIES);
- NamedParameterJdbcTemplate source = (NamedParameterJdbcTemplate) cl
- .getSource();
-
- source.query(sql, new RowCallbackHandler() {
- @Override
- public void processRow (ResultSet rs) throws SQLException {
- queries.add(rs.getString(1));
-
- }
- });
-// System.out.println(queries);
- for (String query : queries)
- source.update(query, new HashMap<String, Object>());
- return this;
- }
-
-
- public static Map<String, Object> getUserCredentials () {
- return new HashMap<>(data);
- }
-
- public void close () {
- BeansFactory.closeApplication();
- }
-
-
- private TestHelper () {
-
- }
-
- // EM: use Spring XML config
- @Deprecated
- private static PersistenceClient mysql_db () throws IOException {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setDriverClassName("com.mysql.jdbc.Driver");
- dataSource.setUrl("jdbc:mysql://localhost:3306/kustvakt_test");
- dataSource.setUsername("mhanl");
- dataSource.setPassword("password");
- JDBCClient client = new JDBCClient(dataSource);
- client.setDatabase("mariadb");
-
- Flyway fl = new Flyway();
- fl.setDataSource(dataSource);
- fl.setLocations("db.mysql");
- fl.migrate();
-
- return client;
- }
-
- // EM: use Spring XML config
- @Deprecated
- protected static PersistenceClient sqlite_db (boolean memory)
- throws InterruptedException {
- SingleConnectionDataSource dataSource = new SingleConnectionDataSource();
- dataSource.setDriverClassName("org.sqlite.JDBC");
- DateTime t = TimeUtils.getNow();
- //String name = testclass != null ? testclass.getSimpleName() + "_" : "";
-
- if (memory)
- dataSource.setUrl("jdbc:sqlite::memory:");
- else {
- File tmp = new File("tmp");
- if (!tmp.exists())
- tmp.mkdirs();
- dataSource.setUrl("jdbc:sqlite:tmp/sqlite_" + t.getMillis()
- + ".sqlite");
- }
- dataSource.setSuppressClose(true);
-
- Flyway fl = new Flyway();
- fl.setDataSource(dataSource);
- fl.setLocations("db.sqlite");
- fl.migrate();
-
- JDBCClient client = new JDBCClient(dataSource);
- client.setDatabase("sqlite");
- return client;
- }
-
- // EM: use Spring XML config
- @Deprecated
- public static PersistenceClient sqlite_db_norm (boolean memory) {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setDriverClassName("org.sqlite.JDBC");
- dataSource.setMaxTotal(1);
- dataSource.setInitialSize(1);
- dataSource.setMaxIdle(1);
- dataSource.addConnectionProperty("lazy-init", "true");
- DateTime t = TimeUtils.getNow();
- if (memory)
- dataSource.setUrl("jdbc:sqlite::memory:");
- else {
- File tmp = new File("tmp");
- if (!tmp.exists())
- tmp.mkdirs();
- dataSource.setUrl("jdbc:sqlite:tmp/sqlite_" + t.toString());
- }
-
- Flyway fl = new Flyway();
- fl.setDataSource(dataSource);
- fl.setLocations("db.sqlite");
- fl.migrate();
-
- JDBCClient client = new JDBCClient(dataSource);
- client.setDatabase("sqlite");
- return client;
- }
-
- // EM: use Spring XML config
- @Deprecated
- public static PersistenceClient h2_emb () throws SQLException {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setUrl("jdbc:h2:mem:");
- dataSource.getConnection().nativeSQL("SET MODE MySQL;");
- dataSource.getConnection().commit();
- dataSource.setUsername("sa");
- dataSource.setPassword("");
- dataSource.setDriverClassName("org.h2.Driver");
-
- Flyway fl = new Flyway();
- fl.setDataSource(dataSource);
- fl.setLocations("db.mysql");
- fl.migrate();
- JDBCClient client = new JDBCClient(dataSource);
- client.setDatabase("h2");
- return client;
- }
-
- }
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/DemoUserTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/DemoUserTest.java
deleted file mode 100644
index bae08c3..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/misc/DemoUserTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package de.ids_mannheim.korap.misc;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import com.sun.jersey.api.client.ClientResponse;
-
-import de.ids_mannheim.korap.config.BeansFactory;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.web.FastJerseyTest;
-
-/**
- * EM: DemoUser is not saved in the new DB
- *
- * @author hanl
- * @date 04/02/2016
- */
-@Deprecated
-@Ignore
-public class DemoUserTest extends FastJerseyTest {
-
- @Override
- public void initMethod () throws KustvaktException {
- helper().setupAccount();
- BeansFactory.setKustvaktContext(helper().getContext());
- }
-
-
- @Test
- public void testDemoCollectionGet () {
- // ClientResponse response = resource().path(getVersion())
- // .path("collection").path("i");
- }
-
-
- @Test
- public void testDemoUserInfoGet () {
-
- }
-
-
- @Test
- public void testDemoUserDetailsGet () {
-
- }
-
-
- @Test
- public void testDemoUserSettingsGet () {
-
- }
-
-
- @Test
- public void testSearch () {
- ClientResponse response = resource().path(getAPIVersion())
- .path("search").queryParam("q", "[base=Wort]")
- .queryParam("ql", "poliqarp").get(ClientResponse.class);
-
-// System.out.println("_____________________________");
-// System.out.println(response);
-// System.out.println("entity " + response.getEntity(String.class));
- }
-
-}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/FilterTest.java b/full/src/test/java/de/ids_mannheim/korap/web/FilterTest.java
deleted file mode 100644
index 9c80de5..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/web/FilterTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package de.ids_mannheim.korap.web;
-
-import static org.junit.Assert.assertEquals;
-
-import org.eclipse.jetty.server.Response;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.UniformInterfaceException;
-
-import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.config.TestHelper;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-
-/** EM: fix tests. new DB does not save users.
- * @author hanl
- * @date 08/02/2016
- */
-@Ignore
-public class FilterTest extends FastJerseyTest {
-
- @Test
- public void testTestUserAuth () throws UniformInterfaceException, ClientHandlerException,
- KustvaktException {
-
- ClientResponse resp = resource()
- .path("user/info")
- .header(Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- (String) TestHelper.getUserCredentials().get(Attributes.USERNAME),
- (String) TestHelper.getUserCredentials().get(Attributes.PASSWORD)))
- .get(ClientResponse.class);
- assert resp.getStatus() == Response.SC_OK;
- }
-
-
- @Test
- @Ignore
- public void testDemoAuth () {
- ClientResponse resp = resource()
- .path("user/info").get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(), resp.getStatus());
- }
-
-
- @Test
- public void testUnauthorizedAuth () throws UniformInterfaceException,
- ClientHandlerException, KustvaktException {
-
- ClientResponse resp = resource()
- .path("user/info")
- .header(Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- "kustvakt", "kustvakt2015"))
- .get(ClientResponse.class);
- String entity = resp.getEntity(String.class);
-// System.out.println(entity);
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(), resp.getStatus());
- }
-
-
- @Override
- public void initMethod () throws KustvaktException {
-// helper().setupAccount();
- }
-}
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 9997c10..d5f4aeb 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
@@ -6,7 +6,6 @@
import static org.junit.Assert.assertNotNull;
import org.joda.time.DateTime;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -15,10 +14,8 @@
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.config.TestHelper;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.TimeUtils;
import de.ids_mannheim.korap.web.FastJerseyTest;
@@ -33,25 +30,6 @@
private static String[] credentials;
- @BeforeClass
- public static void configure () throws Exception {
- credentials = new String[2];
- credentials[0] = (String) TestHelper.getUserCredentials().get(Attributes.USERNAME);
- credentials[1] = (String) TestHelper.getUserCredentials().get(Attributes.PASSWORD);
- }
-
-
- @Override
- public void initMethod () throws KustvaktException {
- helper().setupAccount();
- }
-
-
- @Test
- public void testBasicHttp () {
- User user = helper().getUser();
- }
-
@Test
public void testSessionToken() throws KustvaktException {
String auth = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
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 cd35e86..198a1cb 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
@@ -29,12 +29,6 @@
@Ignore
public class QuerySerializationControllerTest extends FastJerseyTest {
- @Override
- public void initMethod () throws KustvaktException {
- // helper().runBootInterfaces();
- }
-
-
@Test
public void testQuerySerializationFilteredPublic ()
throws KustvaktException {
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 67b0916..3e38c9a 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
@@ -25,11 +25,6 @@
@Ignore
public class ResourceInfoControllerTest extends FastJerseyTest {
- @Override
- public void initMethod () throws KustvaktException {
- // helper().runBootInterfaces();
- }
-
@Test
public void testGetPublicVirtualCollectionInfo () throws KustvaktException {
ClientResponse response = resource().path(getAPIVersion())
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 cc25d21..9d9e2c3 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
@@ -6,7 +6,6 @@
import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import java.net.URI;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
@@ -15,7 +14,6 @@
import javax.ws.rs.core.MultivaluedMap;
import org.apache.commons.collections.map.LinkedMap;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,7 +29,6 @@
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.config.TestHelper;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -52,18 +49,6 @@
FullConfiguration config;
private static String[] credentials;
- @Override
- public void initMethod() throws KustvaktException {
- helper().setupAccount();
- }
-
- @BeforeClass
- public static void setup() throws Exception {
- credentials = new String[2];
- credentials[0] = (String) TestHelper.getUserCredentials().get(Attributes.USERNAME);
- credentials[1] = (String) TestHelper.getUserCredentials().get(Attributes.PASSWORD);
- }
-
@Test
public void loginHTTP() throws KustvaktException {
String enc = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(credentials[0], credentials[1]);
@@ -203,7 +188,6 @@
assertNotNull(node);
assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
assertEquals("UserDetails", node.at("/errors/0/2").asText());
- helper().dropUser("userservicetest");
}
@Test