/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.apache.tomcat.util.http;

import org.junit.Assert;
import org.junit.Test;

public class TestMimeHeaders {

    public static final String HEADER_NAME_LC_STRING = "test";
    public static final String HEADER_NAME_UC_STRING = "TEST";
    public static final String HEADER_NAME_MIXED_STRING = "tEsT";

    @Test
    public void testSetValueStringIgnoresCase01() {
        MimeHeaders mh = new MimeHeaders();

        mh.setValue(HEADER_NAME_LC_STRING).setString(HEADER_NAME_LC_STRING);
        mh.setValue(HEADER_NAME_UC_STRING).setString(HEADER_NAME_UC_STRING);

        Assert.assertEquals(HEADER_NAME_UC_STRING, mh.getValue(HEADER_NAME_UC_STRING).toString());
        Assert.assertEquals(HEADER_NAME_UC_STRING, mh.getValue(HEADER_NAME_LC_STRING).toString());
        Assert.assertEquals(HEADER_NAME_UC_STRING, mh.getValue(HEADER_NAME_MIXED_STRING).toString());
    }

    @Test
    public void testSetValueStringIgnoresCase02() {
        MimeHeaders mh = new MimeHeaders();

        mh.setValue(HEADER_NAME_UC_STRING).setString(HEADER_NAME_UC_STRING);
        mh.setValue(HEADER_NAME_LC_STRING).setString(HEADER_NAME_LC_STRING);

        Assert.assertEquals(HEADER_NAME_LC_STRING, mh.getValue(HEADER_NAME_LC_STRING).toString());
        Assert.assertEquals(HEADER_NAME_LC_STRING, mh.getValue(HEADER_NAME_UC_STRING).toString());
        Assert.assertEquals(HEADER_NAME_LC_STRING, mh.getValue(HEADER_NAME_MIXED_STRING).toString());
    }

    @Test
    public void testSetValueStringIgnoresCase03() {
        MimeHeaders mh = new MimeHeaders();

        mh.setValue(HEADER_NAME_UC_STRING).setString(HEADER_NAME_UC_STRING);
        mh.setValue(HEADER_NAME_MIXED_STRING).setString(HEADER_NAME_MIXED_STRING);

        Assert.assertEquals(HEADER_NAME_MIXED_STRING, mh.getValue(HEADER_NAME_LC_STRING).toString());
        Assert.assertEquals(HEADER_NAME_MIXED_STRING, mh.getValue(HEADER_NAME_UC_STRING).toString());
        Assert.assertEquals(HEADER_NAME_MIXED_STRING, mh.getValue(HEADER_NAME_MIXED_STRING).toString());
    }

}

@@ -845,16 +845,95 @@
 .http;%0A%0A
+import java.util.Enumeration;%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 import o
@@ -1196,16 +1196,178 @@
  %22tEsT%22;
+%0A    public static final String HEADER_NAME_A = %22aaa%22;%0A    public static final String HEADER_NAME_B = %22bbb%22;%0A    public static final String HEADER_NAME_C = %22ccc%22;
 %0A%0A    @T
@@ -3082,10 +3082,1185 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testNamesEnumerator() %7B%0A        MimeHeaders mh = new MimeHeaders();%0A%0A        mh.setValue(HEADER_NAME_A);%0A        mh.setValue(HEADER_NAME_B);%0A        mh.setValue(HEADER_NAME_C);%0A%0A        Set%3CString%3E expected = new HashSet%3C%3E();%0A        expected.add(HEADER_NAME_A);%0A        expected.add(HEADER_NAME_B);%0A        expected.add(HEADER_NAME_C);%0A%0A        Enumeration%3CString%3E names = mh.names();%0A        while (names.hasMoreElements()) %7B%0A            Assert.assertTrue(expected.remove(names.nextElement()));%0A        %7D%0A        Assert.assertFalse(names.hasMoreElements());%0A    %7D%0A%0A    @Test%0A    public void testNamesEnumeratorWithNull() %7B%0A        MimeHeaders mh = new MimeHeaders();%0A%0A        mh.setValue(HEADER_NAME_A);%0A        mh.setValue(null);%0A        mh.setValue(HEADER_NAME_C);%0A%0A        Set%3CString%3E expected = new HashSet%3C%3E();%0A        expected.add(HEADER_NAME_A);%0A        expected.add(null);%0A        expected.add(HEADER_NAME_C);%0A%0A        Enumeration%3CString%3E names = mh.names();%0A        while (names.hasMoreElements()) %7B%0A            Assert.assertTrue(expected.remove(names.nextElement()));%0A        %7D%0A        Assert.assertFalse(names.hasMoreElements());%0A    %7D%0A
 %7D%0A

Add a test for enumerating headers names when one is null