Skip to content
Snippets Groups Projects
Commit 058ffd06 authored by Thorsten Vitt's avatar Thorsten Vitt
Browse files

Refactored common parts of the integration tests

parent 9eeb61be
No related branches found
No related tags found
No related merge requests found
package info.textgrid.services.aggregator;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import com.google.common.io.ByteStreams;
import com.google.common.io.NullOutputStream;
public abstract class AbstractIntegrationTest {
/**
* Creates a request in the form of a (not yet connected)
* {@link URLConnection}.
*
* @param request
* Path and query string (everything after the
* <code>aggregator/</code>
* @throws MalformedURLException
* @throws IOException
*/
protected URLConnection 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;
}
/**
* Reads the given connection's content (and throws it away).
*
* @param connection
* must be open.
* @return number of bytes read
* @throws IOException
*/
protected long readContents(final URLConnection connection) throws IOException {
final InputStream content = connection.getInputStream();
final long realLength = ByteStreams.copy(content,
new NullOutputStream());
return realLength;
}
}
\ No newline at end of file
package info.textgrid.services.aggregator;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.AuthFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.IoFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.MetadataParseFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ProtocolNotImplementedFault;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.MalformedURLException;
import java.net.URLConnection;
import javax.ws.rs.WebApplicationException;
import net.sf.saxon.s9api.SaxonApiException;
import org.junit.Assert;
import org.junit.Test;
import com.google.common.io.ByteStreams;
import com.google.common.io.NullOutputStream;
public class EpubIT {
public class EpubIT extends AbstractIntegrationTest {
@Test
public void testGet() throws ObjectNotFoundFault, MetadataParseFault,
IoFault, AuthFault, ProtocolNotImplementedFault, WebApplicationException, IOException, SaxonApiException {
public void testGet() throws MalformedURLException, IOException {
final URL url = new URL(System.getProperty("service.url")
+ "/epub/textgrid:jfst.0");
final URLConnection connection = url.openConnection();
connection.setConnectTimeout(360000);
final URLConnection connection = createRequest("/epub/textgrid:jfst.0");
connection.connect();
Assert.assertEquals("application/epub+zip", connection.getContentType());
// final int expectedLength = connection.getContentLength(); // -1 for
// now
final InputStream content = connection.getInputStream();
final long realLength = ByteStreams.copy(content,
new NullOutputStream());
final long realLength = readContents(connection);
Assert.assertTrue("Content empty", realLength > 0);
// Assert.assertEquals("Reported and delivered content lengths differ",
// expectedLength, realLength);
}
}
package info.textgrid.services.aggregator.html;
import info.textgrid.services.aggregator.AbstractIntegrationTest;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import junit.framework.Assert;
import org.junit.Test;
import com.google.common.io.ByteStreams;
import com.google.common.io.NullOutputStream;
public class HtmlIT {
public class HtmlIT extends AbstractIntegrationTest {
@Test
public void testGet() throws IOException {
final URL url = new URL(System.getProperty("service.url")
+ "/html/textgrid:jfst.0");
final URLConnection connection = url.openConnection();
connection.setConnectTimeout(360000);
final URLConnection connection = createRequest("/html/textgrid:jfst.0");
connection.connect();
Assert.assertEquals("text/html", connection.getContentType());
final InputStream content = connection.getInputStream();
final long realLength = ByteStreams.copy(content,
new NullOutputStream());
final long realLength = readContents(connection);
Assert.assertTrue("Content length > 0", realLength > 0);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment