userdetails service responses
diff --git a/src/test/java/UserdataTest.java b/src/test/java/UserdataTest.java
index c3cc6b8..e5b598f 100644
--- a/src/test/java/UserdataTest.java
+++ b/src/test/java/UserdataTest.java
@@ -1,5 +1,6 @@
import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.dbException;
import de.ids_mannheim.korap.handlers.UserDetailsDao;
import de.ids_mannheim.korap.handlers.UserSettingsDao;
import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
@@ -47,7 +48,7 @@
}
@Test
- public void testDataGet() {
+ public void testDataGet() throws dbException {
User user = new KorAPUser();
user.setId(1);
UserDetailsDao dao = new UserDetailsDao(
diff --git a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
index c1e2cd1..2a685a8 100644
--- a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
+++ b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
@@ -10,6 +10,8 @@
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import java.io.UnsupportedEncodingException;
+import java.security.NoSuchAlgorithmException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
@@ -25,9 +27,9 @@
private static final String[] credentials = new String[] { "test1",
"testPass2015" };
- public static boolean setupUser() {
+ public static boolean setupAccount() {
boolean r = BeanConfiguration.hasContext();
- if (r) {
+ if (r && BeanConfiguration.getBeans().getUserDBHandler().size() == 0) {
EntityHandlerIface dao = BeanConfiguration.getBeans()
.getUserDBHandler();
Map m = new HashMap<>();
@@ -45,8 +47,37 @@
.createUserAccount(m, false);
}catch (KustvaktException e) {
// do nothing
- System.out.println("THE EXCEPTION...");
- e.printStackTrace();
+ Assert.assertNull("Test user could not be set up", true);
+ return false;
+ }
+ }
+ return r;
+ }
+
+ public static boolean setupSimpleAccount() {
+ boolean r = BeanConfiguration.hasContext();
+ if (r && BeanConfiguration.getBeans().getUserDBHandler().size() == 0) {
+ EntityHandlerIface dao = BeanConfiguration.getBeans()
+ .getUserDBHandler();
+ Map m = new HashMap<>();
+ m.put(Attributes.USERNAME, credentials[0]);
+
+ try {
+ String hash = BeanConfiguration.getBeans().getEncryption()
+ .produceSecureHash(credentials[1]);
+ m.put(Attributes.PASSWORD, hash);
+ }catch (NoSuchAlgorithmException | UnsupportedEncodingException | KustvaktException e) {
+
+ }
+ Assert.assertNotNull("userdatabase handler must not be null", dao);
+
+ try {
+ int i = dao.createAccount(User.UserFactory.toKorAPUser(m));
+ assert BeanConfiguration.getBeans().getUserDBHandler()
+ .getAccount(credentials[0]) != null;
+ assert i == 1;
+ }catch (KustvaktException e) {
+ // do nothing
Assert.assertNull("Test user could not be set up", true);
return false;
}
@@ -80,7 +111,18 @@
return r;
}
- public static boolean truncateAllUsers() {
+ public static void drop() {
+ if (BeanConfiguration.hasContext()) {
+ PersistenceClient cl = BeanConfiguration.getBeans()
+ .getPersistenceClient();
+ String sql = "drop database " + cl.getDatabase() + ";";
+ NamedParameterJdbcTemplate jdbc = (NamedParameterJdbcTemplate) cl
+ .getSource();
+ jdbc.update(sql, new HashMap<String, Object>());
+ }
+ }
+
+ public static boolean truncateAll() {
boolean r = BeanConfiguration.hasContext();
if (r) {
String sql = "SELECT Concat('TRUNCATE TABLE ', TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES";
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java
index 62beae8..4f27150 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java
@@ -4,6 +4,7 @@
import com.sun.jersey.api.client.ClientResponse;
import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.config.TestHelper;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
import de.ids_mannheim.korap.user.Attributes;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -27,7 +28,8 @@
}
@AfterClass
- public static void close() {
+ public static void close() throws KustvaktException {
+ BeanConfiguration.getBeans().getResourceProvider().deleteAll();
BeanConfiguration.closeApplication();
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java b/src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java
index f0865b6..e1dc167 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java
@@ -35,7 +35,7 @@
"de.ids_mannheim.korap.web.filter",
"de.ids_mannheim.korap.web.utils");
- TestHelper.setupUser();
+ TestHelper.setupAccount();
credentials = TestHelper.getUserCredentials();
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java b/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
index a804d69..4cf5ecb 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
@@ -39,7 +39,7 @@
info.setUrl("http://localhost:8080/api/v0.1");
info.setRedirect_uri("testwebsite/login");
- TestHelper.setupUser();
+ TestHelper.setupAccount();
user = TestHelper.getUser();
handler.registerClient(info, user);
}