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
;
22 import junit
.framework
.TestCase
;
24 public class MediaTypeTest
extends TestCase
{
26 public void testBasics() {
28 "application/octet-stream",
29 new MediaType("application", "octet-stream").toString());
33 new MediaType("text", "plain").toString());
35 Map
<String
, String
> parameters
= new HashMap
<String
, String
>();
38 new MediaType("text", "plain", parameters
).toString());
40 parameters
.put("charset", "UTF-8");
42 "text/plain; charset=UTF-8",
43 new MediaType("text", "plain", parameters
).toString());
45 parameters
.put("x-eol-style", "crlf");
47 "text/plain; charset=UTF-8; x-eol-style=crlf",
48 new MediaType("text", "plain", parameters
).toString());
51 public void testLowerCase() {
54 new MediaType("TEXT", "PLAIN").toString());
57 new MediaType("Text", "Plain").toString());
59 Map
<String
, String
> parameters
= new HashMap
<String
, String
>();
62 new MediaType("text", "PLAIN", parameters
).toString());
64 parameters
.put("CHARSET", "UTF-8");
66 "text/plain; charset=UTF-8",
67 new MediaType("TEXT", "plain", parameters
).toString());
69 parameters
.put("X-Eol-Style", "crlf");
71 "text/plain; charset=UTF-8; x-eol-style=crlf",
72 new MediaType("TeXt", "PlAiN", parameters
).toString());
75 public void testTrim() {
78 new MediaType(" text ", " plain ").toString());
81 new MediaType("\ttext", "plain\t").toString());
83 Map
<String
, String
> parameters
= new HashMap
<String
, String
>();
86 new MediaType("text\r\n", " \tplain", parameters
).toString());
88 parameters
.put(" charset", "UTF-8");
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");
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", "()<>@,;:\\\"/[]?=");
105 "text/plain; a=\" value with spaces \"; b=\"text\\/plain\""
106 + "; c=\"\\(\\)\\<\\>\\@\\,\\;\\:\\\\\\\"\\/\\[\\]\\?\\=\"",
107 new MediaType("text", "plain", parameters
).toString());