From 98f22e6bb42e41e32103c02920180aec06112bd6 Mon Sep 17 00:00:00 2001
From: Thorsten Vitt <thorsten.vitt@uni-wuerzburg.de>
Date: Mon, 27 May 2013 11:32:14 +0000
Subject: [PATCH] Unified integration tests

git-svn-id: https://develop.sub.uni-goettingen.de/repos/textgrid/trunk/services/aggregator@14081 7c539038-3410-0410-b1ec-0f2a7bf1c452
---
 .../aggregator/AbstractIntegrationTest.java   |  6 +++--
 .../textgrid/services/aggregator/PdfIT.java   | 23 +++++++++++++++++++
 .../textgrid/services/aggregator/TestPDF.java | 20 ----------------
 .../services/aggregator/html/HtmlIT.java      |  8 +++----
 4 files changed, 31 insertions(+), 26 deletions(-)
 create mode 100644 src/test/java/info/textgrid/services/aggregator/PdfIT.java
 delete mode 100644 src/test/java/info/textgrid/services/aggregator/TestPDF.java

diff --git a/src/test/java/info/textgrid/services/aggregator/AbstractIntegrationTest.java b/src/test/java/info/textgrid/services/aggregator/AbstractIntegrationTest.java
index f86baaf..ffc5715 100644
--- a/src/test/java/info/textgrid/services/aggregator/AbstractIntegrationTest.java
+++ b/src/test/java/info/textgrid/services/aggregator/AbstractIntegrationTest.java
@@ -2,6 +2,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
@@ -21,12 +22,13 @@ public abstract class AbstractIntegrationTest {
 	 * @throws MalformedURLException
 	 * @throws IOException
 	 */
-	protected URLConnection createRequest(final String request) throws MalformedURLException,
+	protected HttpURLConnection createRequest(final String request)
+			throws MalformedURLException,
 			IOException {
 				final URL url = new URL(System.getProperty("service.url") + request);
 				final URLConnection connection = url.openConnection();
 				connection.setConnectTimeout(360000);
-				return connection;
+		return (HttpURLConnection) connection;
 			}
 
 	/**
diff --git a/src/test/java/info/textgrid/services/aggregator/PdfIT.java b/src/test/java/info/textgrid/services/aggregator/PdfIT.java
new file mode 100644
index 0000000..dcaf3de
--- /dev/null
+++ b/src/test/java/info/textgrid/services/aggregator/PdfIT.java
@@ -0,0 +1,23 @@
+package info.textgrid.services.aggregator;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+public class PdfIT extends AbstractIntegrationTest {
+
+	@Test
+	public void testGet() throws MalformedURLException, IOException {
+		final HttpURLConnection connection = createRequest("/pdf/textgrid:jfss.0");
+		connection.connect();
+		Assert.assertEquals(200, connection.getResponseCode());
+		Assert.assertEquals("application/pdf", connection.getContentType());
+		Assert.assertTrue("Response should be non-null",
+				readContents(connection) > 0);
+	}
+
+}
diff --git a/src/test/java/info/textgrid/services/aggregator/TestPDF.java b/src/test/java/info/textgrid/services/aggregator/TestPDF.java
deleted file mode 100644
index 77ed884..0000000
--- a/src/test/java/info/textgrid/services/aggregator/TestPDF.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package info.textgrid.services.aggregator;
-
-import info.textgrid.services.aggregator.pdf.PDF;
-
-import java.net.URI;
-
-import javax.ws.rs.core.Response;
-
-import junit.framework.Assert;
-
-public class TestPDF {
-
-	// @Test FIXME
-	public void testGet() {
-		final PDF pdf = new PDF(TextGridRepProvider.getInstance());
-		final Response response = pdf.get(URI.create("textgrid:jfss.0"), null);
-		Assert.assertEquals(200, response.getStatus());
-	}
-
-}
diff --git a/src/test/java/info/textgrid/services/aggregator/html/HtmlIT.java b/src/test/java/info/textgrid/services/aggregator/html/HtmlIT.java
index af594c2..712473c 100644
--- a/src/test/java/info/textgrid/services/aggregator/html/HtmlIT.java
+++ b/src/test/java/info/textgrid/services/aggregator/html/HtmlIT.java
@@ -3,7 +3,7 @@
 import info.textgrid.services.aggregator.AbstractIntegrationTest;
 
 import java.io.IOException;
-import java.net.URLConnection;
+import java.net.HttpURLConnection;
 
 import junit.framework.Assert;
 
@@ -14,11 +14,11 @@ public class HtmlIT extends AbstractIntegrationTest {
 
 	@Test
 	public void testGet() throws IOException {
-		final URLConnection connection = createRequest("/html/textgrid:jfst.0");
+		final HttpURLConnection connection = createRequest("/html/textgrid:jfst.0");
 		connection.connect();
+		Assert.assertEquals(200, connection.getResponseCode());
 		Assert.assertEquals("text/html", connection.getContentType());
-		final long realLength = readContents(connection);
-		Assert.assertTrue("Content length > 0", realLength > 0);
+		Assert.assertTrue("Content length > 0", readContents(connection) > 0);
 	}
 
 
-- 
GitLab