Simplified JerseyTest in lite version.
Change-Id: I1401bca7add1d79245bfd18d38e580ad8b822ffe
diff --git a/core/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyBaseTest.java b/core/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyBaseTest.java
deleted file mode 100644
index 0c45d7b..0000000
--- a/core/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyBaseTest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-package de.ids_mannheim.korap.web.service;
-
-import java.net.URI;
-
-import javax.ws.rs.core.UriBuilder;
-
-import org.junit.After;
-import org.junit.BeforeClass;
-import org.springframework.web.context.ContextLoaderListener;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.core.DefaultResourceConfig;
-import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
-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 de.ids_mannheim.korap.config.BeanConfigBaseTest;
-
-/**
- * @author hanl
- * @date 29/07/2015
- */
-public abstract class FastJerseyBaseTest extends BeanConfigBaseTest {
-
- private final static String API_VERSION = "v0.1";
-
- private static DefaultResourceConfig resourceConfig =
- new DefaultResourceConfig();
-
- private static TestContainerFactory testContainerFactory;
-
- protected static TestContainer testContainer;
-
- protected static Client client;
-
- protected static int PORT = 8089; // FB, was: 9000;
- protected static int PORT_IT = 1;
- protected static String containerURI = "http://localhost/";
-
-
-// public static void addClass (Class<?> resourceClass) {
-// resourceConfig.getClasses().add(resourceClass);
-// }
-//
-// public static void addSingleton (Object resourceSingleton) {
-// resourceConfig.getSingletons().add(resourceSingleton);
-// }
-
-
- public String getAPIVersion () {
- return API_VERSION;
- }
-
-
-// public static <T> void addProviderForContext (Class<T> contextClass,
-// T contextObject) {
-// addSingleton(new SingletonTypeInjectableProvider<Context, T>(
-// contextClass, contextObject) {});
-// }
-
-
-// public static void addRequestFilter (Object filter) {
-// resourceConfig.getContainerRequestFilters().add(filter);
-// }
-//
-//
-// public static void addResponseFilter (Object filter) {
-// resourceConfig.getContainerResponseFilters().add(filter);
-// }
-
-
- public static void setTestContainerFactory (
- TestContainerFactory newTestContainerFactory) {
- testContainerFactory = newTestContainerFactory;
- }
-
-
- @BeforeClass
- public static void cleanStaticVariables () {
- resourceConfig = new DefaultResourceConfig();
- }
-
-
- protected static void initServer (int port, String[] classPackages) {
- AppDescriptor ad;
- if (classPackages == null)
- ad = new LowLevelAppDescriptor.Builder(resourceConfig).build();
- else
- ad = new WebAppDescriptor.Builder(classPackages)
- .servletClass(SpringServlet.class)
- .contextListenerClass(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(), ad);
- client = testContainer.getClient();
- if (client == null) {
- client = Client.create(ad.getClientConfig());
- }
- }
-
- @After
- public void stopServer () {
-
- testContainer.stop();
- testContainer = null;
- client = null;
- }
-
-
- public Client client () {
- return client;
- }
-
-
- public URI getBaseUri () {
- return testContainer.getBaseUri();
- }
-
-
- public WebResource resource () {
- return client.resource(getBaseUri());
- }
-
-
-
-}
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
index aa7657a..3ac9366 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/FastJerseyTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/FastJerseyTest.java
@@ -1,20 +1,119 @@
package de.ids_mannheim.korap.web;
+import java.net.URI;
import java.util.concurrent.ThreadLocalRandom;
-import org.junit.Before;
+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 com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.core.DefaultResourceConfig;
+import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
+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 de.ids_mannheim.korap.config.BeanConfigBaseTest;
import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.TestHelper;
-import de.ids_mannheim.korap.web.service.FastJerseyBaseTest;
-public abstract class FastJerseyTest extends FastJerseyBaseTest {
+public abstract class FastJerseyTest extends BeanConfigBaseTest{
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" };
+ private final static String API_VERSION = "v0.1";
+
+ private static DefaultResourceConfig resourceConfig =
+ new DefaultResourceConfig();
+
+ private static TestContainerFactory testContainerFactory;
+
+ protected static TestContainer testContainer;
+
+ protected static 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 DefaultResourceConfig();
+ }
+
+
+ protected static void initServer (int port, String[] classPackages) {
+ AppDescriptor ad;
+ if (classPackages == null)
+ ad = new LowLevelAppDescriptor.Builder(resourceConfig).build();
+ else
+ ad = new WebAppDescriptor.Builder(classPackages)
+ .servletClass(SpringServlet.class)
+ .contextListenerClass(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(), ad);
+ client = testContainer.getClient();
+ if (client == null) {
+ client = Client.create(ad.getClientConfig());
+ }
+ }
+
+ @After
+ public void stopServer () {
+
+ testContainer.stop();
+ testContainer = null;
+ client = null;
+ }
+
+
+ public Client client () {
+ return client;
+ }
+
+
+ public URI getBaseUri () {
+ return testContainer.getBaseUri();
+ }
+
+
+ public WebResource resource () {
+ return client.resource(getBaseUri());
+ }
+
protected TestHelper helper () {
try {
return TestHelper.newInstance(this.context);
diff --git a/lite/src/main/resources/test-config.xml b/lite/src/main/resources/test-config.xml
deleted file mode 100644
index b219666..0000000
--- a/lite/src/main/resources/test-config.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:util="http://www.springframework.org/schema/util"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns="http://www.springframework.org/schema/beans"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-4.0.xsd
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util-4.0.xsd">
-
-
- <context:component-scan base-package="de.ids_mannheim.korap" />
- <context:annotation-config />
-
- <bean id="properties"
- class="org.springframework.beans.factory.config.PropertiesFactoryBean">
- <property name="ignoreResourceNotFound" value="true"/>
- <property name="locations">
- <array>
- <value>classpath:kustvakt-lite.conf</value>
- <value>file:./kustvakt-lite.conf</value>
- </array>
- </property>
- </bean>
-
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="properties">
- <ref bean="properties"/>
- </property>
- </bean>
-
- <bean id="kustvakt_auditing"
- class="de.ids_mannheim.korap.interfaces.defaults.DefaultAuditing">
- </bean>
-
- <bean id="kustvakt_response"
- class="de.ids_mannheim.korap.web.CoreResponseHandler">
- <constructor-arg index="0" name="iface" ref="kustvakt_auditing"/>
- </bean>
-
- <bean id="kustvakt_config"
- class="de.ids_mannheim.korap.config.KustvaktConfiguration">
- <constructor-arg index="0" name="properties" ref="properties"/>
- </bean>
-
- <bean name="kustvakt_encryption"
- class="de.ids_mannheim.korap.interfaces.defaults.DefaultEncryption">
- </bean>
-
- <bean id="kustvakt_rewrite" class="de.ids_mannheim.korap.resource.rewrite.RewriteHandler">
- <constructor-arg ref="kustvakt_config" />
- </bean>
-
- <bean id="search_krill"
- class="de.ids_mannheim.korap.web.SearchKrill">
- <constructor-arg value="${krill.indexDir}"/>
- </bean>
-
-</beans>
\ No newline at end of file
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyLightTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyLightTest.java
deleted file mode 100644
index 81ae635..0000000
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyLightTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package de.ids_mannheim.korap.web.service;
-
-import org.junit.Before;
-
-import de.ids_mannheim.korap.config.ContextHolder;
-
-public abstract class FastJerseyLightTest extends FastJerseyBaseTest {
-
- private static String[] classPackages =
- new String[] { "de.ids_mannheim.korap.web.service.light" };
-
-
- 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) {
- initServer(PORT, classPackages);
- startServer();
- }
- }
-
- @Override
- protected ContextHolder getContext () {
- return new ContextHolder(this.context) {};
- }
-}
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LightServiceTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LightServiceTest.java
index 39213a7..3b694af 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LightServiceTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LightServiceTest.java
@@ -4,11 +4,21 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
+import java.util.concurrent.ThreadLocalRandom;
+
import org.apache.lucene.LucenePackage;
import org.junit.Test;
+import org.springframework.web.context.ContextLoaderListener;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
+import com.sun.jersey.test.framework.AppDescriptor;
+import com.sun.jersey.test.framework.JerseyTest;
+import com.sun.jersey.test.framework.WebAppDescriptor;
+import com.sun.jersey.test.framework.spi.container.TestContainerException;
+import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
+import com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
@@ -18,17 +28,36 @@
* Created by hanl on 29.04.16.
*
* @author margaretha
- * @date 10/10/2017
+ * @date 17/01/2017
*
* Recent changes:
- * - updated the service paths and methods of query serialization tests
- * - added statistic service test
+ * - removed test configuration using FastJerseyLightTest
*/
-public class LightServiceTest extends FastJerseyLightTest {
+public class LightServiceTest extends JerseyTest{
+
+ public static final String classPackage = "de.ids_mannheim.korap.web.service.light";
@Override
- public void initMethod () throws KustvaktException {}
+ protected TestContainerFactory getTestContainerFactory ()
+ throws TestContainerException {
+ return new GrizzlyWebTestContainerFactory();
+ }
+ @Override
+ protected AppDescriptor configure () {
+ return new WebAppDescriptor.Builder(classPackage)
+ .servletClass(SpringServlet.class)
+ .contextListenerClass(ContextLoaderListener.class)
+ .contextParam("contextConfigLocation",
+ "classpath:light-config.xml")
+ .build();
+ }
+
+ @Override
+ protected int getPort (int defaultPort) {
+ return ThreadLocalRandom.current().nextInt(5000, 8000 + 1);
+ }
+
@Test
public void testStatistics () throws KustvaktException{
ClientResponse response = resource()