TIKA-87: MimeTypes should allow modification of MIME types
[tika.git] / src / test / java / org / apache / tika / mime / MediaTypeTest.java
blobe613830a0ec907d74fb3518a07326435355dfbd2
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.apache.tika.mime;
19 import java.util.HashMap;
20 import java.util.Map;
22 import junit.framework.TestCase;
24 public class MediaTypeTest extends TestCase {
26 public void testBasics() {
27 assertEquals(
28 "application/octet-stream",
29 new MediaType("application", "octet-stream").toString());
31 assertEquals(
32 "text/plain",
33 new MediaType("text", "plain").toString());
35 Map<String, String> parameters = new HashMap<String, String>();
36 assertEquals(
37 "text/plain",
38 new MediaType("text", "plain", parameters).toString());
40 parameters.put("charset", "UTF-8");
41 assertEquals(
42 "text/plain; charset=UTF-8",
43 new MediaType("text", "plain", parameters).toString());
45 parameters.put("x-eol-style", "crlf");
46 assertEquals(
47 "text/plain; charset=UTF-8; x-eol-style=crlf",
48 new MediaType("text", "plain", parameters).toString());
51 public void testLowerCase() {
52 assertEquals(
53 "text/plain",
54 new MediaType("TEXT", "PLAIN").toString());
55 assertEquals(
56 "text/plain",
57 new MediaType("Text", "Plain").toString());
59 Map<String, String> parameters = new HashMap<String, String>();
60 assertEquals(
61 "text/plain",
62 new MediaType("text", "PLAIN", parameters).toString());
64 parameters.put("CHARSET", "UTF-8");
65 assertEquals(
66 "text/plain; charset=UTF-8",
67 new MediaType("TEXT", "plain", parameters).toString());
69 parameters.put("X-Eol-Style", "crlf");
70 assertEquals(
71 "text/plain; charset=UTF-8; x-eol-style=crlf",
72 new MediaType("TeXt", "PlAiN", parameters).toString());
75 public void testTrim() {
76 assertEquals(
77 "text/plain",
78 new MediaType(" text ", " plain ").toString());
79 assertEquals(
80 "text/plain",
81 new MediaType("\ttext", "plain\t").toString());
83 Map<String, String> parameters = new HashMap<String, String>();
84 assertEquals(
85 "text/plain",
86 new MediaType("text\r\n", " \tplain", parameters).toString());
88 parameters.put(" charset", "UTF-8");
89 assertEquals(
90 "text/plain; charset=UTF-8",
91 new MediaType("\n\ntext", "plain \r", parameters).toString());
93 parameters.put("\r\n\tx-eol-style \t", "crlf");
94 assertEquals(
95 "text/plain; charset=UTF-8; x-eol-style=crlf",
96 new MediaType(" text", "\tplain ", parameters).toString());
99 public void testQuote() {
100 Map<String, String> parameters = new HashMap<String, String>();
101 parameters.put("a", " value with spaces ");
102 parameters.put("b", "text/plain");
103 parameters.put("c", "()<>@,;:\\\"/[]?=");
104 assertEquals(
105 "text/plain; a=\" value with spaces \"; b=\"text\\/plain\""
106 + "; c=\"\\(\\)\\<\\>\\@\\,\\;\\:\\\\\\\"\\/\\[\\]\\?\\=\"",
107 new MediaType("text", "plain", parameters).toString());