1 16 17 package org.springframework.mail.javamail; 18 19 import java.io.File ; 20 21 import junit.framework.TestCase; 22 23 import org.springframework.core.io.ClassPathResource; 24 import org.springframework.core.io.Resource; 25 26 30 public class ConfigurableMimeFileTypeMapTests extends TestCase { 31 32 public void testAgainstDefaultConfiguration() throws Exception { 33 ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap(); 34 ftm.afterPropertiesSet(); 35 36 assertEquals("Invalid content type for HTM", "text/html", ftm.getContentType("foobar.HTM")); 37 assertEquals("Invalid content type for html", "text/html", ftm.getContentType("foobar.html")); 38 assertEquals("Invalid content type for c++", "text/plain", ftm.getContentType("foobar.c++")); 39 assertEquals("Invalid content type for svf", "image/vnd.svf", ftm.getContentType("foobar.svf")); 40 assertEquals("Invalid content type for dsf", "image/x-mgx-dsf", ftm.getContentType("foobar.dsf")); 41 assertEquals("Invalid default content type", "application/octet-stream", ftm.getContentType("foobar.foo")); 42 } 43 44 public void testAgainstDefaultConfigurationWithFilePath() throws Exception { 45 ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap(); 46 assertEquals("Invalid content type for HTM", "text/html", ftm.getContentType(new File ("/tmp/foobar.HTM"))); 47 } 48 49 public void testWithAdditionalMappings() throws Exception { 50 ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap(); 51 ftm.setMappings(new String [] {"foo/bar HTM foo", "foo/cpp c++"}); 52 ftm.afterPropertiesSet(); 53 54 assertEquals("Invalid content type for HTM - override didn't work", "foo/bar", ftm.getContentType("foobar.HTM")); 55 assertEquals("Invalid content type for c++ - override didn't work", "foo/cpp", ftm.getContentType("foobar.c++")); 56 assertEquals("Invalid content type for foo - new mapping didn't work", "foo/bar", ftm.getContentType("bar.foo")); 57 } 58 59 public void testWithCustomMappingLocation() throws Exception { 60 Resource resource = new ClassPathResource("test.mime.types", getClass()); 61 62 ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap(); 63 ftm.setMappingLocation(resource); 64 ftm.afterPropertiesSet(); 65 66 assertEquals("Invalid content type for foo", "text/foo", ftm.getContentType("foobar.foo")); 67 assertEquals("Invalid content type for bar", "text/bar", ftm.getContentType("foobar.bar")); 68 assertEquals("Invalid content type for fimg", "image/foo", ftm.getContentType("foobar.fimg")); 69 assertEquals("Invalid content type for bimg", "image/bar", ftm.getContentType("foobar.bimg")); 70 } 71 72 } 73 | Popular Tags |