refactoring; test inits
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/AuthServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/AuthServiceTest.java
index 2a4486e..10d5855 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/AuthServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/AuthServiceTest.java
@@ -4,5 +4,10 @@
* @author hanl
* @date 24/09/2015
*/
-public class AuthServiceTest {
+public class AuthServiceTest extends FastJerseyTest {
+
+ //todo: test basicauth via secure connection
+
+
+
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyTest.java b/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyTest.java
index f3a0a04..b77e4be 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyTest.java
@@ -5,10 +5,10 @@
import com.sun.jersey.api.core.DefaultResourceConfig;
import com.sun.jersey.spi.inject.SingletonTypeInjectableProvider;
import com.sun.jersey.test.framework.AppDescriptor;
-import com.sun.jersey.test.framework.LowLevelAppDescriptor;
+import com.sun.jersey.test.framework.WebAppDescriptor;
import com.sun.jersey.test.framework.spi.container.TestContainer;
import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
-import com.sun.jersey.test.framework.spi.container.grizzly.GrizzlyTestContainerFactory;
+import com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -68,11 +68,14 @@
}
public static void initServer() {
- AppDescriptor ad = new LowLevelAppDescriptor.Builder(resourceConfig)
- .build();
+
+ // AppDescriptor ad = new LowLevelAppDescriptor.Builder(resourceConfig)
+ // .build();
+ AppDescriptor ad = new WebAppDescriptor.Builder().build();
+
TestContainerFactory tcf = testContainerFactory;
if (tcf == null) {
- tcf = new GrizzlyTestContainerFactory();
+ tcf = new GrizzlyWebTestContainerFactory();
}
testContainer = tcf
.create(UriBuilder.fromUri("http://localhost/").port(9998)
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java b/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
index 88ad2bf..101da58 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
@@ -4,6 +4,7 @@
import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor;
import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.web.service.light.LightService;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -74,7 +75,7 @@
.queryParam("q", "[base=Haus & surface=Hauses]")
.queryParam("ql", "poliqarp").queryParam("cutOff", "true")
.queryParam("page", "1").get(ClientResponse.class);
- System.out.println("RESPONSE " + response);
+ System.out.println("RESPONSE " + response.getEntity(String.class));
}
}
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 19bb99e..4cd0ed5 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
@@ -1,8 +1,32 @@
package de.ids_mannheim.korap.web.service;
+import com.sun.jersey.api.client.ClientResponse;
+import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
/**
* @author hanl
* @date 23/09/2015
*/
-public class OAuth2EndpointTest {
+public class OAuth2EndpointTest extends FastJerseyTest {
+
+ @BeforeClass
+ public static void configure() {
+ BeanConfiguration.loadClasspathContext();
+ addClass(OAuthService.class);
+ // todo: change korap user personal data!
+ String header = BasicHttpAuth.encode("test", "test1");
+ }
+
+ @Test
+ public void testAuthorizeClient() {
+ ClientResponse response = resource().path(API_VERSION).path("oauth2")
+ .path("register")
+ .queryParam("redirect_url", "korap.ids-mannheim.de/redirect")
+ .header("Host", "korap.ids-mannheim.de")
+ .post(ClientResponse.class);
+ }
+
}
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 eadced8..7e982f7 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
@@ -4,10 +4,11 @@
import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.config.ClientInfo;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.ext.config.BeanHelperExtension;
-import de.ids_mannheim.korap.ext.security.oauth2.OAuth2Handler;
+import de.ids_mannheim.korap.handlers.OAuth2Handler;
import de.ids_mannheim.korap.interfaces.EncryptionIface;
-import de.ids_mannheim.korap.user.*;
+import de.ids_mannheim.korap.user.KorAPUser;
+import de.ids_mannheim.korap.user.TokenContext;
+import de.ids_mannheim.korap.user.User;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -18,19 +19,17 @@
* @date 13/05/2015
*/
-//works
public class OAuth2HandlerTest {
private static ClientInfo info;
private static OAuth2Handler handler;
private static EncryptionIface crypto;
- private static final String SCOPE = "search preferences queries account";
+ private static final String SCOPES = "search preferences queries account";
private static final KorAPUser user = User.UserFactory.getUser("test_user");
@BeforeClass
public static void setup() throws KustvaktException {
BeanConfiguration.loadClasspathContext("classpath-config.xml");
- BeanConfiguration.setCustomBeansHolder(new BeanHelperExtension());
handler = new OAuth2Handler(
BeanConfiguration.getBeans().getPersistenceClient());
crypto = BeanConfiguration.getBeans().getEncryption();
@@ -58,7 +57,7 @@
String auth_code = crypto.createToken();
AuthCodeInfo codeInfo = new AuthCodeInfo(info.getClient_id(),
auth_code);
- codeInfo.setScopes(SCOPE);
+ codeInfo.setScopes(SCOPES);
handler.authorize(codeInfo, user);
codeInfo = handler.getAuthorization(auth_code);
@@ -71,11 +70,12 @@
String auth_code = crypto.createToken();
AuthCodeInfo codeInfo = new AuthCodeInfo(info.getClient_id(),
auth_code);
- codeInfo.setScopes(SCOPE);
+ codeInfo.setScopes(SCOPES);
handler.authorize(codeInfo, user);
String t = crypto.createToken();
- handler.addToken(codeInfo.getCode(), t, 7200);
+ String refresh = crypto.createToken();
+ handler.addToken(codeInfo.getCode(), t, refresh, 7200);
TokenContext ctx = handler.getContext(t);
Assert.assertNotNull("context is null", ctx);
@@ -85,7 +85,16 @@
}
@Test
+ public void testTokenEndpointRedirect() {
+
+ }
+
+ @Test
public void testStoreAccessCodeViaAuthCodeThrowsNoException() {
+ String auth_code = crypto.createToken();
+ AuthCodeInfo codeInfo = new AuthCodeInfo(info.getClient_id(),
+ auth_code);
+ codeInfo.setScopes(SCOPES);
}
@@ -98,4 +107,15 @@
public void testAccessTokenbyUserDeleteCascade() {
}
+
+ @Test
+ public void testRefreshToken() {
+
+ }
+
+ // fixme: exception thrown?!
+ @Test
+ public void testAccessTokenExpired() {
+
+ }
}