1 17 18 package javax.activation; 19 20 import java.util.Enumeration; 21 22 import junit.framework.TestCase; 23 24 25 29 public class MimeTypeParameterListTest extends TestCase { 30 private MimeTypeParameterList parameterList; 31 32 protected void setUp() throws Exception { 33 super.setUp(); 34 parameterList = new MimeTypeParameterList(); 35 } 36 37 public void testEmptyParameterList() { 38 assertEquals(0, parameterList.size()); 39 assertTrue(parameterList.isEmpty()); 40 } 41 42 public void testSimpleParameterList() throws MimeTypeParseException { 43 parameterList.parse(";name=value"); 44 assertEquals(1, parameterList.size()); 45 assertFalse(parameterList.isEmpty()); 46 Enumeration e = parameterList.getNames(); 47 assertTrue(e.hasMoreElements()); 48 assertEquals("name", e.nextElement()); 49 assertFalse(e.hasMoreElements()); 50 assertEquals("value", parameterList.get("name")); 51 } 52 53 public void testQuotedValue() throws MimeTypeParseException { 54 parameterList.parse(";name=\"val()ue\""); 55 assertEquals(1, parameterList.size()); 56 assertEquals("val()ue", parameterList.get("name")); 57 } 58 59 public void testWhiteSpacesParameterList() throws MimeTypeParseException { 60 parameterList.parse("; name= value"); 61 assertEquals(1, parameterList.size()); 62 assertEquals("name", parameterList.getNames().nextElement()); 63 assertEquals("value", parameterList.get("name")); 64 } 65 66 public void testLongParameterList() throws MimeTypeParseException { 67 parameterList.parse(";name1=value1; name2 = value2; name3=value3;name4 = value4"); 68 assertEquals(4, parameterList.size()); 69 assertEquals("value1", parameterList.get("name1")); 70 assertEquals("value2", parameterList.get("name2")); 71 assertEquals("value3", parameterList.get("name3")); 72 assertEquals("value4", parameterList.get("name4")); 73 } 74 75 public void testCaseInsensitivity() throws MimeTypeParseException { 76 parameterList.parse(";name1=value; NAME2=VALUE; NaMe3=VaLuE"); 77 assertEquals(3, parameterList.size()); 78 assertEquals("value", parameterList.get("name1")); 79 assertEquals("VALUE", parameterList.get("name2")); 80 assertEquals("VaLuE", parameterList.get("name3")); 81 assertEquals("value", parameterList.get("NAME1")); 82 assertEquals("value", parameterList.get("NaMe1")); 83 parameterList.remove("NAME1"); 84 assertNull(parameterList.get("name1")); 85 parameterList.remove("name3"); 86 assertEquals("; name2=VALUE", parameterList.toString()); 87 } 88 89 public void testNoValueParameterList() { 90 try { 91 parameterList.parse("; name="); 92 fail("Expected MimeTypeParseException"); 93 } catch (MimeTypeParseException e) { 94 } 96 } 97 98 public void testMissingValueParameterList() { 99 try { 100 parameterList.parse("; name=;name2=value"); 101 fail("Expected MimeTypeParseException"); 102 } catch (MimeTypeParseException e) { 103 } 105 } 106 107 public void testNoNameParameterList() { 108 try { 109 parameterList.parse("; = value"); 110 fail("Expected MimeTypeParseException"); 111 } catch (MimeTypeParseException e) { 112 } 114 } 115 116 public void testUnterminatedQuotedString() { 117 try { 118 parameterList.parse("; = \"value"); 119 fail("Expected MimeTypeParseException"); 120 } catch (MimeTypeParseException e) { 121 } 123 } 124 125 public void testSpecialInAttribute() { 126 String specials = "()<>@,;:\\\"/[]?= \t"; 127 for (int i=0; i < specials.length(); i++) { 128 try { 129 parameterList.parse(";na"+specials.charAt(i)+"me=value"); 130 fail("Expected MimeTypeParseException for special: " + specials.charAt(i)); 131 } catch (MimeTypeParseException e) { 132 } 134 } 135 } 136 } 137 138 | Popular Tags |