KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > junit > TestContentType


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

15 package org.apache.tapestry.junit;
16
17 import org.apache.tapestry.util.ContentType;
18
19 /**
20  * Test the functionality of {@link org.apache.tapestry.util.ContentType}
21  *
22  * @author Mindbridge
23  * @since 3.0
24  */

25
26 public class TestContentType extends TapestryTestCase
27 {
28
29     public void testParsing1() throws Exception JavaDoc
30     {
31         ContentType contentType = new ContentType("text/html;charset=utf-8");
32
33         assertEquals("The base type of the ContentType is invalid", "text", contentType
34                 .getBaseType());
35
36         assertEquals("The html type of the ContentType is invalid", "html", contentType
37                 .getSubType());
38
39         assertEquals("The mime type of the ContentType is invalid", "text/html", contentType
40                 .getMimeType());
41
42         String JavaDoc[] parameterNames = contentType.getParameterNames();
43         assertEquals(
44                 "The number of parameter names of the ContentType is invalid",
45                 1,
46                 parameterNames.length);
47
48         assertEquals(
49                 "The parameter names of the ContentType are invalid",
50                 "charset",
51                 parameterNames[0]);
52
53         String JavaDoc charset = contentType.getParameter("charset");
54         assertEquals("The charset parameter of the ContentType is invalid", "utf-8", charset);
55
56         String JavaDoc nonexistant = contentType.getParameter("nonexistant");
57         assertTrue(
58                 "ContentType does not return null for a non-existant parameter",
59                 nonexistant == null);
60     }
61
62     public void testParsing2() throws Exception JavaDoc
63     {
64         ContentType contentType = new ContentType("text/html");
65
66         assertEquals("The base type of the ContentType is invalid", "text", contentType
67                 .getBaseType());
68
69         assertEquals("The html type of the ContentType is invalid", "html", contentType
70                 .getSubType());
71
72         assertEquals("The mime type of the ContentType is invalid", "text/html", contentType
73                 .getMimeType());
74
75         String JavaDoc[] parameterNames = contentType.getParameterNames();
76         assertEquals(
77                 "The number of parameter names of the ContentType is invalid",
78                 0,
79                 parameterNames.length);
80
81         String JavaDoc charset = contentType.getParameter("charset");
82         assertTrue("The charset parameter of the ContentType is invalid", charset == null);
83     }
84
85     public void testUnparsing1() throws Exception JavaDoc
86     {
87         ContentType contentType = new ContentType();
88
89         contentType.setBaseType("text");
90         contentType.setSubType("html");
91         contentType.setParameter("charset", "utf-8");
92
93         assertEquals(
94                 "ContentType does not generate a valid String representation",
95                 "text/html;charset=utf-8",
96                 contentType.unparse());
97     }
98
99     public void testUnparsing2() throws Exception JavaDoc
100     {
101         ContentType contentType = new ContentType();
102
103         contentType.setBaseType("text");
104         contentType.setSubType("html");
105
106         assertEquals(
107                 "ContentType does not generate a valid String representation",
108                 "text/html",
109                 contentType.unparse());
110     }
111
112 }
113
Popular Tags