1 15 package org.apache.tapestry.junit; 16 17 import org.apache.tapestry.util.ContentType; 18 19 25 26 public class TestContentType extends TapestryTestCase 27 { 28 29 public void testParsing1() throws Exception 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 [] 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 charset = contentType.getParameter("charset"); 54 assertEquals("The charset parameter of the ContentType is invalid", "utf-8", charset); 55 56 String 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 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 [] parameterNames = contentType.getParameterNames(); 76 assertEquals( 77 "The number of parameter names of the ContentType is invalid", 78 0, 79 parameterNames.length); 80 81 String charset = contentType.getParameter("charset"); 82 assertTrue("The charset parameter of the ContentType is invalid", charset == null); 83 } 84 85 public void testUnparsing1() throws Exception 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 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 |