tika-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattm...@apache.org
Subject svn commit: r1306147 - in /tika/trunk/tika-server: ./ src/test/java/org/apache/tika/server/
Date Wed, 28 Mar 2012 04:05:11 GMT
Author: mattmann
Date: Wed Mar 28 04:05:10 2012
New Revision: 1306147

URL: http://svn.apache.org/viewvc?rev=1306147&view=rev
Log:
- TIKA-593: improvement: use CXF client for test harnesses, remove all extraneous pom.xml
dependencies and remove dep on commons-httpclient

Modified:
    tika/trunk/tika-server/pom.xml
    tika/trunk/tika-server/src/test/java/org/apache/tika/server/CXFTestBase.java
    tika/trunk/tika-server/src/test/java/org/apache/tika/server/MetadataResourceTest.java
    tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaResourceTest.java
    tika/trunk/tika-server/src/test/java/org/apache/tika/server/UnpackerResourceTest.java

Modified: tika/trunk/tika-server/pom.xml
URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/pom.xml?rev=1306147&r1=1306146&r2=1306147&view=diff
==============================================================================
--- tika/trunk/tika-server/pom.xml (original)
+++ tika/trunk/tika-server/pom.xml Wed Mar 28 04:05:10 2012
@@ -70,32 +70,6 @@
 		   <version>2.5.2</version>
 		</dependency>   	
         <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-jdk14</artifactId>
-            <version>1.6.1</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-httpclient</groupId>
-            <artifactId>commons-httpclient</artifactId>
-            <version>3.1</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>commons-logging</groupId>
-            <artifactId>commons-logging</artifactId>
-            <version>1.1.1</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-codec</groupId>
-            <artifactId>commons-codec</artifactId>
-            <version>1.3</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-collections</groupId>
-            <artifactId>commons-collections</artifactId>
-            <version>3.2.1</version>
-        </dependency>
-        <dependency>
             <groupId>commons-cli</groupId>
             <artifactId>commons-cli</artifactId>
             <version>1.2</version>
@@ -105,12 +79,6 @@
             <artifactId>commons-lang</artifactId>
             <version>2.5</version>
         </dependency>
-	    <dependency>
-	       <groupId>javax.servlet</groupId>
-	       <artifactId>servlet-api</artifactId>
-	       <version>2.4</version>
-	       <scope>provided</scope>
-	    </dependency>        
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>

Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/CXFTestBase.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/CXFTestBase.java?rev=1306147&r1=1306146&r2=1306147&view=diff
==============================================================================
--- tika/trunk/tika-server/src/test/java/org/apache/tika/server/CXFTestBase.java (original)
+++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/CXFTestBase.java Wed Mar 28
04:05:10 2012
@@ -17,176 +17,21 @@
 
 package org.apache.tika.server;
 
-import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.ws.rs.core.HttpHeaders;
-
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
-import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
-import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.commons.compress.utils.IOUtils;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
 import org.apache.cxf.io.CachedOutputStream;
-import org.apache.tika.io.CloseShieldInputStream;
-
-import au.com.bytecode.opencsv.CSVReader;
 import junit.framework.TestCase;
 
 public class CXFTestBase extends TestCase {
 
-	protected Map<String, String> putAndGetMet(String address,
-			InputStream content) throws Exception {
-		Map<String, String> met = new HashMap<String, String>();
-		PutMethod put = new PutMethod(address);
-		put.setRequestBody(content);
-		HttpClient httpClient = new HttpClient();
-		InputStreamReader reader = null;
-
-		try {
-			httpClient.executeMethod(put);
-			CSVReader csvReader = new CSVReader(new InputStreamReader(
-					put.getResponseBodyAsStream()));
-
-			String[] nextLine;
-			while ((nextLine = csvReader.readNext()) != null) {
-				met.put(nextLine[0], nextLine[1]);
-			}
-
-		} finally {
-			put.releaseConnection();
-		}
-
-		return met;
-	}
-
-	protected String getAndReturnResp(String address) throws HttpException,
-			IOException {
-		String resp = null;
-		GetMethod get = new GetMethod(address);
-		HttpClient httpClient = new HttpClient();
-		InputStreamReader reader = null;
-
-		try {
-			httpClient.executeMethod(get);
-			resp = get.getResponseBodyAsString();
-		} finally {
-			get.releaseConnection();
-		}
-
-		return resp;
-	}
-
-	protected void putAndCheckStatus(String address, InputStream content,
-			int expectedStatus) throws Exception {
-		putAndCheckStatus(address, null, content, expectedStatus);
-	}
-	
-	protected void putAndCheckStatus(String address, String contentType, InputStream content,
-			int expectedStatus) throws Exception {
-		PutMethod put = new PutMethod(address);
-		put.setRequestBody(content);
-		if(contentType != null) 
-			put.setRequestHeader(HttpHeaders.CONTENT_TYPE, contentType);
-		HttpClient httpClient = new HttpClient();
-		try {
-			int result = httpClient.executeMethod(put);
-			assertEquals(expectedStatus, result);
-		} finally {
-			put.releaseConnection();
-		}
-	}
-
-	protected String putAndGetString(String address, InputStream content)
-			throws Exception {
-		String resp = null;
-		PutMethod put = new PutMethod(address);
-		put.setRequestBody(content);
-		HttpClient httpClient = new HttpClient();
-		InputStreamReader reader = null;
-
-		try {
-			httpClient.executeMethod(put);
-			resp = put.getResponseBodyAsString();
-		} finally {
-			put.releaseConnection();
-		}
-
-		return resp;
-	}
-
-	protected Map<String,String> putAndGetMapData(String address,
-			InputStream content, boolean zip) throws Exception {
-		PutMethod put = new PutMethod(address);
-		put.setRequestBody(content);
-		HttpClient httpClient = new HttpClient();
-        Map<String,String> data = new HashMap<String, String>();
-		
-		try {
-			httpClient.executeMethod(put);
-			data = readArchive(zip ? 
-					new ZipArchiveInputStream(put.getResponseBodyAsStream()):
-						new TarArchiveInputStream(put.getResponseBodyAsStream()));
-		} finally {
-			put.releaseConnection();
-		}
-
-		return data;
-	}
-	
-	protected String putAndGetArchiveText(String address,
-			InputStream content, boolean zip) throws Exception {
-		PutMethod put = new PutMethod(address);
-		put.setRequestBody(content);
-		HttpClient httpClient = new HttpClient();
-        String archiveText = null;
-		
-		try {
-			httpClient.executeMethod(put);
-			archiveText = readArchiveText(zip ? 
-					new ZipArchiveInputStream(put.getResponseBodyAsStream()):
-						new TarArchiveInputStream(put.getResponseBodyAsStream()));
-		} finally {
-			//put.releaseConnection();
-		}
-
-		return archiveText;
-	}	
-
-	protected void getAndCompare(String address, String expectedValue,
-			String acceptType, String expectedContentType, int expectedStatus)
-			throws Exception {
-		GetMethod get = new GetMethod(address);
-		get.setRequestHeader("Accept", acceptType);
-		get.setRequestHeader("Accept-Language", "da;q=0.8,en");
-		HttpClient httpClient = new HttpClient();
-		try {
-			int result = httpClient.executeMethod(get);
-			assertEquals(expectedStatus, result);
-			String content = getStringFromInputStream(get
-					.getResponseBodyAsStream());
-			assertEquals("Expected value is wrong", expectedValue, content);
-			if (expectedContentType != null) {
-				Header ct = get.getResponseHeader("Content-Type");
-				assertEquals("Wrong type of response", expectedContentType,
-						ct.getValue());
-			}
-		} finally {
-			get.releaseConnection();
-		}
-	}
-
 	protected String getStringFromInputStream(InputStream in) throws Exception {
 		CachedOutputStream bos = new CachedOutputStream();
 		IOUtils.copy(in, bos);
@@ -195,48 +40,27 @@ public class CXFTestBase extends TestCas
 		return bos.getOut().toString();
 	}
 
-	protected InputStream cloneInputStream(InputStream is) throws IOException {
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		// Fake code simulating the copy
-		// You can generally do better with nio if you need...
-		// And please, unlike me, do something about the Exceptions :D
-		byte[] buffer = new byte[1024];
-		int len;
-		while ((len = is.read(buffer)) > -1) {
-			baos.write(buffer, 0, len);
-		}
-		baos.flush();
-		return new ByteArrayInputStream(baos.toByteArray());
-
-	}
-	
-
 	protected Map<String, String> readArchive(ArchiveInputStream zip)
 			throws IOException {
 		Map<String, String> data = new HashMap<String, String>();
 
 		while (true) {
 			ArchiveEntry entry = zip.getNextEntry();
-
 			if (entry == null) {
 				break;
 			}
-
+			
 			ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
 			IOUtils.copy(zip, bos);
-
 			data.put(entry.getName(), DigestUtils.md5Hex(bos.toByteArray()));
 		}
 
 		return data;
 	}
 
-	protected String readArchiveText(ArchiveInputStream zip)
-			throws IOException {
+	protected String readArchiveText(ArchiveInputStream zip) throws IOException {
 		while (true) {
 			ArchiveEntry entry = zip.getNextEntry();
-
 			if (entry == null) {
 				break;
 			}
@@ -246,13 +70,10 @@ public class CXFTestBase extends TestCas
 			}
 
 			ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
 			IOUtils.copy(zip, bos);
-
 			return bos.toString("UTF-8");
 		}
 
 		return null;
-	}	
-
+	}
 }

Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/MetadataResourceTest.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/MetadataResourceTest.java?rev=1306147&r1=1306146&r2=1306147&view=diff
==============================================================================
--- tika/trunk/tika-server/src/test/java/org/apache/tika/server/MetadataResourceTest.java
(original)
+++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/MetadataResourceTest.java
Wed Mar 28 04:05:10 2012
@@ -17,18 +17,30 @@
 
 package org.apache.tika.server;
 
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.HashMap;
 import java.util.Map;
 
+import javax.ws.rs.core.Response;
+
 import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSBindingFactory;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.junit.Test;
 
+import au.com.bytecode.opencsv.CSVReader;
+
 public class MetadataResourceTest extends CXFTestBase {
 	private static final String META_PATH = "/meta";
 
+	private static final String endPoint = "http://localhost:"
+			+ TikaServerCli.DEFAULT_PORT;
+
 	private Server server;
 
 	/*
@@ -42,7 +54,7 @@ public class MetadataResourceTest extend
 		sf.setResourceClasses(MetadataResource.class);
 		sf.setResourceProvider(MetadataResource.class,
 				new SingletonResourceProvider(new MetadataResource()));
-		sf.setAddress("http://localhost:" + TikaServerCli.DEFAULT_PORT + "/");
+		sf.setAddress(endPoint + "/");
 		BindingFactoryManager manager = sf.getBus().getExtension(
 				BindingFactoryManager.class);
 		JAXRSBindingFactory factory = new JAXRSBindingFactory();
@@ -51,7 +63,6 @@ public class MetadataResourceTest extend
 				factory);
 		server = sf.create();
 	}
-	
 
 	/*
 	 * (non-Javadoc)
@@ -63,19 +74,30 @@ public class MetadataResourceTest extend
 		server.stop();
 		server.destroy();
 	}
-	
 
 	@Test
 	public void testSimpleWord() throws Exception {
-		Map<String, String> metadata = putAndGetMet("http://localhost:"
-				+ TikaServerCli.DEFAULT_PORT + META_PATH+ "/" + TikaResourceTest.TEST_DOC,
-				ClassLoader
+		Response response = WebClient
+				.create(endPoint + META_PATH)
+				.type("application/msword")
+				.accept("text/csv")
+				.put(ClassLoader
 						.getSystemResourceAsStream(TikaResourceTest.TEST_DOC));
-		System.out.println(metadata);
+
+		Reader reader = new InputStreamReader(
+				(InputStream) response.getEntity());
+
+		CSVReader csvReader = new CSVReader(reader);
+
+		Map<String, String> metadata = new HashMap<String, String>();
+
+		String[] nextLine;
+		while ((nextLine = csvReader.readNext()) != null) {
+			metadata.put(nextLine[0], nextLine[1]);
+		}
 
 		assertNotNull(metadata.get("Author"));
 		assertEquals("Maxim Valyanskiy", metadata.get("Author"));
 	}
 
-
 }

Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaResourceTest.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaResourceTest.java?rev=1306147&r1=1306146&r2=1306147&view=diff
==============================================================================
--- tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaResourceTest.java (original)
+++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaResourceTest.java Wed
Mar 28 04:05:10 2012
@@ -17,24 +17,25 @@
 
 package org.apache.tika.server;
 
-import java.io.IOException;
-import org.apache.commons.httpclient.HttpException;
+import java.io.InputStream;
+
+import javax.ws.rs.core.Response;
 import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSBindingFactory;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.junit.Test;
 
 public class TikaResourceTest extends CXFTestBase {
-	private static final String TIKA_PATH = "tika";
+	private static final String TIKA_PATH = "/tika";
 	public static final String TEST_DOC = "test.doc";
 	public static final String TEST_XLSX = "16637.xlsx";
 	private static final int UNPROCESSEABLE = 422;
-	private static final String service = "http://localhost:"
-			+ TikaServerCli.DEFAULT_PORT + "/";
 	private static final String endPoint = "http://localhost:"
-			+ TikaServerCli.DEFAULT_PORT + "/" + TIKA_PATH;
+			+ TikaServerCli.DEFAULT_PORT;
+	private static final String WADL_MEDIA_TYPE = "application/vnd.sun.wadl+xml";
 
 	private Server server;
 
@@ -49,7 +50,7 @@ public class TikaResourceTest extends CX
 		sf.setResourceClasses(TikaResource.class);
 		sf.setResourceProvider(TikaResource.class,
 				new SingletonResourceProvider(new TikaResource()));
-		sf.setAddress(service);
+		sf.setAddress(endPoint + "/");
 		BindingFactoryManager manager = sf.getBus().getExtension(
 				BindingFactoryManager.class);
 		JAXRSBindingFactory factory = new JAXRSBindingFactory();
@@ -58,7 +59,6 @@ public class TikaResourceTest extends CX
 				factory);
 		server = sf.create();
 	}
-	
 
 	/*
 	 * (non-Javadoc)
@@ -70,34 +70,43 @@ public class TikaResourceTest extends CX
 		server.stop();
 		server.destroy();
 	}
-	
 
 	@Test
 	public void testHelloWorld() throws Exception {
-		getAndCompare(endPoint, TikaResource.GREETING, "text/plain",
-				"text/plain", 200);
+		Response response = WebClient.create(endPoint + TIKA_PATH)
+				.type("text/plain").accept("text/plain").get();
+		assertEquals(TikaResource.GREETING,
+				getStringFromInputStream((InputStream) response.getEntity()));
 	}
 
 	@Test
 	public void testSimpleWord() throws Exception {
-		String responseMsg = putAndGetString(endPoint,
-				ClassLoader
-						.getSystemResourceAsStream(TikaResourceTest.TEST_DOC));
-
+		Response response = WebClient.create(endPoint + TIKA_PATH)
+				.type("application/msword")
+				.accept("text/plain")
+				.put(ClassLoader.getSystemResourceAsStream(TEST_DOC));
+		String responseMsg = getStringFromInputStream((InputStream) response
+				.getEntity());
 		assertTrue(responseMsg.contains("test"));
 	}
 
 	@Test
-	public void testApplicationWadl() throws HttpException, IOException {
-		String serviceWadl = endPoint + "/application.wadl";
-		String resp = getAndReturnResp(serviceWadl);
+	public void testApplicationWadl() throws Exception {
+		Response response = WebClient
+				.create(endPoint + TIKA_PATH + "/application.wadl")
+				.accept("text/plain").get();
+		String resp = getStringFromInputStream((InputStream) response
+				.getEntity());
 		assertTrue(resp.length() > 0);
 	}
 
 	@Test
 	public void testPasswordXLS() throws Exception {
-		putAndCheckStatus(endPoint,
-				ClassLoader.getSystemResourceAsStream("password.xls"),
-				UNPROCESSEABLE);
+		Response response = WebClient.create(endPoint + TIKA_PATH)
+				.type("application/vnd.ms-excel")
+				.accept("text/plain")
+				.put(ClassLoader.getSystemResourceAsStream("password.xls"));
+
+		assertEquals(UNPROCESSEABLE, response.getStatus());
 	}
 }

Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/UnpackerResourceTest.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/UnpackerResourceTest.java?rev=1306147&r1=1306146&r2=1306147&view=diff
==============================================================================
--- tika/trunk/tika-server/src/test/java/org/apache/tika/server/UnpackerResourceTest.java
(original)
+++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/UnpackerResourceTest.java
Wed Mar 28 04:05:10 2012
@@ -17,16 +17,22 @@
 
 package org.apache.tika.server;
 
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSBindingFactory;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.junit.Test;
 
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import javax.ws.rs.core.Response;
 
 public class UnpackerResourceTest extends CXFTestBase {
 	private static final String UNPACKER_PATH = "/unpacker";
@@ -55,7 +61,9 @@ public class UnpackerResourceTest extend
 	private static final String DOCX_EXE2_MD5 = "2485435c7c22d35f2de9b4c98c0c2e1a";
 	private static final String DOCX_EXE2_NAME = "Setup.exe";
 	private static final String XSL_IMAGE2_MD5 = "8969288f4245120e7c3870287cce0ff3";
-
+	private static final String APPLICATION_MSWORD = "application/msword";
+	private static final String APPLICATION_XML = "application/xml";
+	private static final String CONTENT_TYPE = "Content-type";
 
 	private Server server;
 
@@ -74,7 +82,7 @@ public class UnpackerResourceTest extend
 		sf.setResourceClasses(UnpackerResource.class);
 		sf.setResourceProvider(UnpackerResource.class,
 				new SingletonResourceProvider(new UnpackerResource()));
-		sf.setAddress(endPoint+"/");
+		sf.setAddress(endPoint + "/");
 		BindingFactoryManager manager = sf.getBus().getExtension(
 				BindingFactoryManager.class);
 		JAXRSBindingFactory factory = new JAXRSBindingFactory();
@@ -97,9 +105,14 @@ public class UnpackerResourceTest extend
 
 	@Test
 	public void testDocWAV() throws Exception {
-		Map<String, String> data = putAndGetMapData(endPoint + UNPACKER_PATH + 
-				"/" + TEST_DOC_WAV,
-				ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV), true);
+		Response response = WebClient.create(endPoint + UNPACKER_PATH)
+				.type(APPLICATION_MSWORD).accept("application/zip")
+				.put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV));
+
+		ArchiveInputStream zip = new ZipArchiveInputStream(
+				(InputStream) response.getEntity());
+
+		Map<String, String> data = readArchive(zip);
 		assertEquals(WAV1_MD5, data.get(WAV1_NAME));
 		assertEquals(WAV2_MD5, data.get(WAV2_NAME));
 		assertFalse(data.containsKey(UnpackerResource.TEXT_FILENAME));
@@ -107,9 +120,14 @@ public class UnpackerResourceTest extend
 
 	@Test
 	public void testDocWAVText() throws Exception {
-		Map<String, String> data = putAndGetMapData(endPoint + ALL_PATH + 
-				"/" + TEST_DOC_WAV,
-				ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV), true);
+		Response response = WebClient.create(endPoint + ALL_PATH)
+				.type(APPLICATION_MSWORD).accept("application/zip")
+				.put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV));
+
+		ArchiveInputStream zip = new ZipArchiveInputStream(
+				(InputStream) response.getEntity());
+
+		Map<String, String> data = readArchive(zip);
 		assertEquals(WAV1_MD5, data.get(WAV1_NAME));
 		assertEquals(WAV2_MD5, data.get(WAV2_NAME));
 		assertTrue(data.containsKey(UnpackerResource.TEXT_FILENAME));
@@ -117,70 +135,106 @@ public class UnpackerResourceTest extend
 
 	@Test
 	public void testDocPicture() throws Exception {
-		Map<String, String> data = putAndGetMapData(endPoint + UNPACKER_PATH + 
-				"/" + TEST_DOC_WAV,
-				ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV), true);
+		Response response = WebClient.create(endPoint + UNPACKER_PATH)
+				.type(APPLICATION_MSWORD).accept("application/zip")
+				.put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV));
+
+		ZipArchiveInputStream zip = new ZipArchiveInputStream(
+				(InputStream) response.getEntity());
+		Map<String, String> data = readArchive(zip);
+
 		assertEquals(JPG_MD5, data.get(JPG_NAME));
 	}
 
 	@Test
 	public void testDocPictureNoOle() throws Exception {
-		Map<String, String> data = putAndGetMapData(endPoint + UNPACKER_PATH + 
-				"/2pic.doc",
-				ClassLoader.getSystemResourceAsStream("2pic.doc"), true);
+		Response response = WebClient.create(endPoint + UNPACKER_PATH)
+				.type(APPLICATION_MSWORD).accept("application/zip")
+				.put(ClassLoader.getSystemResourceAsStream("2pic.doc"));
+
+		ZipArchiveInputStream zip = new ZipArchiveInputStream(
+				(InputStream) response.getEntity());
+
+		Map<String, String> data = readArchive(zip);
 		assertEquals(JPG2_MD5, data.get(JPG2_NAME));
 	}
 
 	@Test
 	public void testImageDOCX() throws Exception {
-		Map<String, String> data = putAndGetMapData(endPoint + UNPACKER_PATH + 
-				"/" + TEST_DOCX_IMAGE,
-				ClassLoader.getSystemResourceAsStream(TEST_DOCX_IMAGE), true);
+		Response response = WebClient.create(endPoint + UNPACKER_PATH)
+		.accept("application/zip").put(
+				ClassLoader.getSystemResourceAsStream(TEST_DOCX_IMAGE));
+
+		ZipArchiveInputStream zip = new ZipArchiveInputStream(
+				(InputStream) response.getEntity());
+
+		Map<String, String> data = readArchive(zip);
 		assertEquals(DOCX_IMAGE1_MD5, data.get(DOCX_IMAGE1_NAME));
 		assertEquals(DOCX_IMAGE2_MD5, data.get(DOCX_IMAGE2_NAME));
 	}
 
-	//FIXME: Disabled for now, pending TIKA-593 @Test
+	//FIXME: Disabled until TIKA-593 is done @Test
 	public void Xtest415() throws Exception {
-		putAndCheckStatus(endPoint + UNPACKER_PATH + "/" + TEST_DOC_WAV,
-				"xxx/xxx", ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV), 415);
+		Response response = WebClient.create(endPoint + UNPACKER_PATH)
+				.type("xxx/xxx").accept("application/zip")
+				.put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV));
+
+		assertEquals(415, response.getStatus());
 	}
 
 	@Test
 	public void testExeDOCX() throws Exception {
 		String TEST_DOCX_EXE = "2exe.docx";
-		Map<String, String> data = putAndGetMapData(endPoint + UNPACKER_PATH 
-				+ "/" + TEST_DOCX_EXE,
-				ClassLoader.getSystemResourceAsStream(TEST_DOCX_EXE), true);
+		Response response = WebClient.create(endPoint + UNPACKER_PATH)
+				.accept("application/zip")
+				.put(ClassLoader.getSystemResourceAsStream(TEST_DOCX_EXE));
+
+		ZipArchiveInputStream zip = new ZipArchiveInputStream(
+				(InputStream) response.getEntity());
+
+		Map<String, String> data = readArchive(zip);
+
 		assertEquals(DOCX_EXE1_MD5, data.get(DOCX_EXE1_NAME));
 		assertEquals(DOCX_EXE2_MD5, data.get(DOCX_EXE2_NAME));
 	}
 
 	@Test
 	public void testImageXSL() throws Exception {
-		Map<String, String> data = putAndGetMapData(endPoint + UNPACKER_PATH + "/" 
-				+ "pic.xls",
-				ClassLoader.getSystemResourceAsStream("pic.xls"), true);
+		Response response = WebClient.create(endPoint + UNPACKER_PATH)
+				.accept("application/zip")
+				.put(ClassLoader.getSystemResourceAsStream("pic.xls"));
+
+		ZipArchiveInputStream zip = new ZipArchiveInputStream(
+				(InputStream) response.getEntity());
+
+		Map<String, String> data = readArchive(zip);
 		assertEquals(XSL_IMAGE1_MD5, data.get("0.jpg"));
 		assertEquals(XSL_IMAGE2_MD5, data.get("1.jpg"));
 	}
 
-	//FIXME: Disabled for now @Test
-	public void XtestTarDocPicture() throws Exception {
-		Map<String, String> data = putAndGetMapData(endPoint + UNPACKER_PATH + "/" + 
-				TEST_DOC_WAV,
-				ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV), false);
+	@Test
+	public void testTarDocPicture() throws Exception {
+		Response response = WebClient.create(endPoint + UNPACKER_PATH)
+				.type(APPLICATION_MSWORD).accept("application/x-tar")
+				.put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV));
+
+		Map<String, String> data = readArchive(new TarArchiveInputStream(
+				(InputStream) response.getEntity()));
+
 		assertEquals(JPG_MD5, data.get(JPG_NAME));
 	}
 
-	//FIXME: Disabled for now @Test
-	public void XtestText() throws Exception {
-		String responseMsg = putAndGetArchiveText(endPoint + UNPACKER_PATH + "/" + 
-				"test.doc",
-				ClassLoader.getSystemResourceAsStream("test.doc"), true);
+	@Test
+	public void testText() throws Exception {
+		Response response = WebClient.create(endPoint + ALL_PATH)
+				.header(CONTENT_TYPE, APPLICATION_XML)
+				.accept("application/zip")
+				.put(ClassLoader.getSystemResourceAsStream("test.doc"));
+
+		String responseMsg = readArchiveText(new ZipArchiveInputStream(
+				(InputStream) response.getEntity()));
 		assertNotNull(responseMsg);
 		assertTrue(responseMsg.contains("test"));
 	}
 
-
 }



Mime
View raw message