Home » Open-JDK-6.b17-src » javax » activation » [javadoc | source]

    1   /**
    2    *
    3    * Copyright 2003-2004 The Apache Software Foundation
    4    *
    5    *  Licensed under the Apache License, Version 2.0 (the "License");
    6    *  you may not use this file except in compliance with the License.
    7    *  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   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.
   16    */
   17   
   18   package javax.activation;
   19   
   20   import java.util.Enumeration;
   21   
   22   import junit.framework.TestCase;
   23   
   24   
   25   /**
   26    *
   27    * @version $Rev: 123433 $ $Date: 2004-12-27 09:29:47 -0800 (Mon, 27 Dec 2004) $
   28    */
   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               // ok
   95   		}
   96   	}
   97   
   98   	public void testMissingValueParameterList() {
   99   		try {
  100   			parameterList.parse("; name=;name2=value");
  101               fail("Expected MimeTypeParseException");
  102           } catch (MimeTypeParseException e) {
  103               // ok
  104   		}
  105   	}
  106   
  107   	public void testNoNameParameterList() {
  108   		try {
  109   			parameterList.parse("; = value");
  110               fail("Expected MimeTypeParseException");
  111           } catch (MimeTypeParseException e) {
  112               // ok
  113   		}
  114   	}
  115   
  116   	public void testUnterminatedQuotedString() {
  117   		try {
  118   			parameterList.parse("; = \"value");
  119               fail("Expected MimeTypeParseException");
  120           } catch (MimeTypeParseException e) {
  121               // ok
  122   		}
  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                   // ok
  133               }
  134           }
  135   	}
  136   }
  137   

Home » Open-JDK-6.b17-src » javax » activation » [javadoc | source]