KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > mail > javamail > ConfigurableMimeFileTypeMapTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.mail.javamail;
18
19 import java.io.File JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.springframework.core.io.ClassPathResource;
24 import org.springframework.core.io.Resource;
25
26 /**
27  * @author Rob Harrop
28  * @author Juergen Hoeller
29  */

30 public class ConfigurableMimeFileTypeMapTests extends TestCase {
31
32     public void testAgainstDefaultConfiguration() throws Exception JavaDoc {
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 JavaDoc {
45         ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
46         assertEquals("Invalid content type for HTM", "text/html", ftm.getContentType(new File JavaDoc("/tmp/foobar.HTM")));
47     }
48
49     public void testWithAdditionalMappings() throws Exception JavaDoc {
50         ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
51         ftm.setMappings(new String JavaDoc[] {"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 JavaDoc {
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