package de.uni_siegen.wineme.come_in.thumbnailer.test;

import java.io.File;

import de.uni_siegen.wineme.come_in.thumbnailer.util.mime.MimeTypeDetector;

public class MimeDetectionTest extends MyTestCase {
	private MimeTypeDetector mimeType;
	private File parent;

	public void setUp()
	{
		mimeType = new MimeTypeDetector();
		parent = new File(MyTestSuite.TESTFILES_DIR + "wrong_extension");
	}
	
	public void testImageFiles()
	{
		// Images
		assertMime("image/jpeg", "test2-jpg.bmp");
		assertMime("image/png", "test2-png.jpg");
		assertMime("image/bmp", "test2-bmp.png");
	}
	public void testTextFiles()
	{
		// Text
		assertMime("text/rtf", "test2-rtf.pdf");
		assertMime("application/pdf", "test2-pdf.ps");
	}
	
	public void testOpenOfficeFiles()
	{
		assertMime("application/vnd.oasis.opendocument.presentation", "test2-odp.pps");
	}
	
	public void testOpenOfficeFiles2()
	{
		assertMime("application/vnd.oasis.opendocument.spreadsheet", "test2-ods.xls");
	}

	public void testOpenOfficeFiles3()
	{
		assertMime("application/vnd.oasis.opendocument.text", "test2-odt.sxw");
	}

	public void testOpenOfficeFiles4()
	{
		assertMime("application/vnd.oasis.opendocument.text", "test2-odt.doc");
	}

	public void testOffice2007Files()
	{
		assertMime("application/vnd.openxmlformats-officedocument.wordprocessingml", "test2-docx.doc");
	}

	public void testOffice2007Files2()
	{
		assertMime("application/vnd.openxmlformats-officedocument.presentationml", "test2-pptx.ppt");
	}

	public void testOffice2007Files3()
	{
		assertMime("application/vnd.openxmlformats-officedocument.spreadsheetml", "test2-xlsx.ods");
	}

	public void testOffice2007Files4()
	{
		assertMime("application/vnd.openxmlformats-officedocument.spreadsheetml", "test2-xlsx.ppt");
	}

	public void testOfficeFiles()
	{
		assertMime("application/vnd.ms-powerpoint", "test2-ppt.odp");
	}

	public void testOfficeFiles2()
	{
		assertMime("application/vnd.ms-word", "test2-doc.ott");
	}

	public void testOfficeFiles3()
	{
		assertMime("application/vnd.ms-excel", "test2-xls.odp");
	}
	
	public void testScratch()
	{
		assertEquals("Standard extension of scratch was wrongly returned", "sb", mimeType.getStandardExtensionForMimeType("application/x-mit-scratch"));
		assertTrue("doesExtensionMatchMimeType of Scratch didn't return true", mimeType.doesExtensionMatchMimeType("sb", "application/x-mit-scratch"));
		assertMime("application/x-mit-scratch", "test2-sb.sbx");
	}
	
	public void assertMime(String expectedMime, String filename)
	{
		String mime = mimeType.getMimeType(new File(parent, filename));
		if (!expectedMime.equalsIgnoreCase(mime))
			fail("File " + filename + ": Mime is not equal: expected \"" + expectedMime + "\", but was \"" + mime + "\".");
	}
}

@@ -259,16 +259,103 @@
 arent;%0A%0A
+%09public MimeDetectionTest()%0A%09%7B%0A%09%09new MimeTypeDetector(); // Initialize beforehand%0A%09%7D%0A%09%0A
 %09public 
@@ -501,35 +501,356 @@
 test
-ImageFiles()%0A%09%7B%0A%09%09// Images
+GetExtensionFor()%0A%09%7B%0A%09%09assertEquals(%22odt%22, mimeType.getStandardExtensionForMimeType(%22application/vnd.oasis.opendocument.text%22));%0A%09%09assertTrue(mimeType.doesExtensionMatchMimeType(%22odt%22, %22application/vnd.oasis.opendocument.text%22));%0A%09%7D%0A%09%0A%09public void testImageFiles()%0A%09%7B%0A%09%09assertMime(%22image/png%22, %22test2-png.jpg%22);%0A%09%7D%0A%09public void testImageFiles2()%0A%09%7B
 %0A%09%09a
@@ -896,50 +896,43 @@
 );%0A%09
-%09assertMime(%22image/png%22, %22test2-png.jpg%22);
+%7D%0A%09public void testImageFiles3()%0A%09%7B
 %0A%09%09a
@@ -1011,18 +1011,8 @@
 %0A%09%7B%0A
-%09%09// Text%0A
 %09%09as
@@ -1050,16 +1050,54 @@
 .pdf%22);%0A
+%09%7D%0A%09%0A%09public void testTextFiles2()%0A%09%7B%0A
 %09%09assert

Add Test: Extension