package org.dstadler.commoncrawl.oldindex;

import static org.junit.Assert.assertTrue;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.dstadler.commoncrawl.Utils;
import org.dstadler.commoncrawl.oldindex.ProcessAndDownload;
import org.junit.Test;


public class ProcessAndDownloadTest {

    @Test
    public void testOffer() throws Exception {
    	File tempDir = File.createTempFile("ProcessAndDownloadTest", ".dir");
    	assertTrue(tempDir.delete());
    	File prevDir = Utils.DOWNLOAD_DIR;
    	Utils.DOWNLOAD_DIR = tempDir;
    	
        File destFile = new File(tempDir, "11.123.196.205_e99ca2lsdqfg_2sf4659mhyqd2dy_Word+Study+Handout.doc");
        try {
	        File file = File.createTempFile("ProcessAndDownloadTest", ".tmp");
	        try {
	            assertTrue(file.delete());
	            
	            try (BlockProcessor process = new ProcessAndDownload(file, false)) {
	                byte[] block = FileUtils.readFileToByteArray(new File("src/test/data/block1.bin"));
	                
	                process.offer(block, 0);
	            } // the implicit close() will wait for the queue to be empty...
	
	            // need to do this outside the block to let process.close() join the Thread
	            assertTrue(file.exists());
	            assertTrue(file.length() > 0);
	            
				assertTrue("Should have resulting file, but did not find it at " + destFile, destFile.exists());
	        } finally {
	            assertTrue(file.delete());
	        }
        } finally {
        	FileUtils.deleteDirectory(tempDir);
        	Utils.DOWNLOAD_DIR = prevDir;
        }
    }
}

@@ -549,21 +549,16 @@
 empDir;%0A
-    %09
 %0A       
@@ -612,19 +612,19 @@
 205_
-e99ca2lsdqf
+iraz4x2bg0x
 g_2s
@@ -645,15 +645,15 @@
 Word
-+
+_
 Study
-+
+_
 Hand
@@ -808,30 +808,17 @@
 ete());%0A
-%09            
 %0A
+
 %09       
@@ -996,26 +996,9 @@
 ));%0A
-%09                
 %0A
+
 %09   
@@ -1117,10 +1117,9 @@
 ...%0A
-%09
 %0A
+
 %09   
@@ -1287,29 +1287,16 @@
 ) %3E 0);%0A
-%09            
 %0A%09%09%09%09ass

Fix unit test