refactoring; test inits
diff --git a/src/test/.DS_Store b/src/test/.DS_Store
index c7f4961..b5e4a6e 100644
--- a/src/test/.DS_Store
+++ b/src/test/.DS_Store
Binary files differ
diff --git a/src/test/java/.DS_Store b/src/test/java/.DS_Store
index 9462fb8..f388377 100644
--- a/src/test/java/.DS_Store
+++ b/src/test/java/.DS_Store
Binary files differ
diff --git a/src/test/java/CollectionQueryBuilderTest.java b/src/test/java/CollectionQueryBuilderTest.java
index de9a089..aeb753f 100644
--- a/src/test/java/CollectionQueryBuilderTest.java
+++ b/src/test/java/CollectionQueryBuilderTest.java
@@ -13,67 +13,76 @@
public void testsimpleAdd() {
CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "WPD");
- // System.out.println(b.toJSON());
+
+ JsonNode node = JsonUtils.readTree(b.toJSON());
+
+ assert node != null;
+ assert node.at("/collection/@type").asText().equals("koral:doc");
+ assert node.at("/collection/key").asText().equals("corpusID");
+
}
@Test
- public void testSimpleConjunctive() {
+ public void testSimpleConjunction() {
CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "WPD").and()
.addSegment("textClass", CollectionQueryBuilder3.EQ.EQUAL,
"freizeit");
- // System.out.println(b.toJSON());
+ JsonNode node = JsonUtils.readTree(b.toJSON());
+
+ assert node != null;
+ assert node.at("/collection/@type").asText().equals("koral:docGroup");
+ assert node.at("/collection/operation").asText()
+ .equals("operation:and");
+ assert node.at("/collection/operands/0/key").asText()
+ .equals("corpusID");
+ assert node.at("/collection/operands/1/key").asText()
+ .equals("textClass");
}
@Test
- public void testSimpleDisjunctive() {
+ public void testSimpleDisjunction() {
CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
- b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "WPD").and()
+ b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "WPD").or()
.addSegment("textClass", CollectionQueryBuilder3.EQ.EQUAL,
"freizeit");
- // System.out.println(b.toJSON());
+ JsonNode node = JsonUtils.readTree(b.toJSON());
+
+ assert node != null;
+ assert node.at("/collection/operation").asText().equals("operation:or");
+ assert node.at("/collection/operands/0/key").asText()
+ .equals("corpusID");
+ assert node.at("/collection/operands/1/key").asText()
+ .equals("textClass");
}
@Test
public void testComplexSubQuery() {
-
CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
- b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "ADF").and()
+ b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "ADF").or()
.addSub("textClass=freizeit & corpusID=WPD");
- // System.out.println(b.toJSON());
- }
- @Test // basically joining two or more resource queries
- public void testAddResourceQueryAfter() {
- CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
- b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "ADF").and()
- .addSub("textClass=freizeit & corpusID=WPD");
- // System.out.println(b.toJSON());
+ JsonNode node = JsonUtils.readTree(b.toJSON());
- // join.addSegment("textClass", "politik");
- }
+ assert node != null;
+ assert node.at("/collection/operation").asText().equals("operation:or");
+ assert node.at("/collection/operands/0/key").asText()
+ .equals("corpusID");
+ assert node.at("/collection/operands/1/@type").asText()
+ .equals("koral:docGroup");
- @Test // basically joining two or more resource queries
- public void testAddResourceQueryBefore() {
- CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
- b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "ADF").and()
- .addSub("textClass!=freizeit & corpusID=WPD");
-
- // CollectionQueryBuilder3 join = new CollectionQueryBuilder3();
- // join.addRaw(b.toJSON());
- // join.addSegment("textClass", "politik");
- // System.out.println("JOINED " + join.toJSON());
}
@Test
- public void test1() {
+ public void testAddResourceQueryAfter() {
CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "ADF").or()
.addSub("textClass=freizeit & corpusID=WPD");
CollectionQueryBuilder3 c = new CollectionQueryBuilder3();
c.setBaseQuery(b.toJSON());
- c.addSub("textClass=wissenschaft");
+ c.addSegment("textClass", CollectionQueryBuilder3.EQ.EQUAL,
+ "wissenschaft");
JsonNode node = JsonUtils.readTree(c.toJSON());
@@ -84,4 +93,26 @@
.equals("wissenschaft");
}
+ @Test
+ public void testAddComplexResourceQueryAfter() {
+ CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
+ b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "ADF").or()
+ .addSub("textClass=freizeit & corpusID=WPD");
+
+ CollectionQueryBuilder3 c = new CollectionQueryBuilder3();
+ c.setBaseQuery(b.toJSON());
+ c.addSub("(textClass=politik & corpusID=AZPS)");
+
+ JsonNode node = JsonUtils.readTree(c.toJSON());
+
+ assert node != null;
+ assert node.at("/collection/operands/2/@type").asText()
+ .equals("koral:docGroup");
+ assert node.at("/collection/operands/2/operands/0/value").asText()
+ .equals("politik");
+ assert node.at("/collection/operands/2/operands/1/value").asText()
+ .equals("AZPS");
+
+ }
+
}
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() {
+
+ }
}