/* Copyright 2011 Florian Schulz

Licensed 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 de.hanbei.httpserver.request;

import de.hanbei.httpserver.common.Cookie;
import de.hanbei.httpserver.common.Header;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class HeaderTest {

    private Header header;

    @Before
    public void setUp() throws Exception {
        this.header = new Header();
        this.header.addParameter("Accept", new Header.Parameter("text/xml"));
        this.header.addParameter("Accept", new Header.Parameter("text/html", 0.1));

        this.header.addParameter("Accept-Language", new Header.Parameter("en", 0.1));
        this.header
                .addParameter("Accept-Language", new Header.Parameter("en-us", 0.5));

        this.header.addParameter("Accept-Encoding", new Header.Parameter("gzip"));
        this.header.addParameter("Accept-Encoding", new Header.Parameter("deflate"));

        this.header.addParameter("Accept-Charset", "ISO-8859-1");
        this.header.addParameter("Accept-Charset", "utf-8", 0.7);
        this.header.addParameter("Accept-Charset", "*", 0.7);

    }

    @Test
    public void testToString() {
        assertEquals(""
                + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n"
                + "Accept: text/xml,text/html;q=0.1\n"
                + "Accept-Language: en;q=0.1,en-us;q=0.5\n"
                + "Accept-Encoding: gzip,deflate\n"
                , header.toString());
    }

    @Test
    public void testToStringWithCookie() {
        this.header.addCookie(new Cookie("test", "test"));
        this.header.addCookie(new Cookie("test2", "test2"));
        assertEquals(""
                + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n"
                + "Accept: text/xml,text/html;q=0.1\n"
                + "Accept-Language: en;q=0.1,en-us;q=0.5\n"
                + "Accept-Encoding: gzip,deflate\n"
                + "Cookie: test=test; test2=test2", header.toString());
    }
}

@@ -720,24 +720,100 @@
 unit.Test;%0A%0A
+import java.util.Arrays;%0A%0Aimport static org.junit.Assert.assertArrayEquals;%0A
 import stati
@@ -1716,38 +1716,32 @@
 7);%0A%0A    %7D%0A%0A
-    
+%09
 @Test%0A
-    
+%09
 public void 
@@ -1761,50 +1761,40 @@
 ) %7B%0A
-        assertEquals(%22%22%0A                + 
+%09%09String%5B%5D expectedLines = %7B%0A%09%09%09
 %22Acc
@@ -1840,238 +1840,284 @@
 =0.7
-%5Cn%22%0A                + %22Accept: text/xml,text/html;q=0.1%5Cn%22%0A                + %22Accept-Language: en;q=0.1,en-us;q=0.5%5Cn%22%0A                + %22Accept-Encoding: gzip,deflate%5Cn%22%0A                , header.toString());%0A    %7D%0A%0A    
+%22,%0A%09%09%09%22Accept-Encoding: gzip,deflate%22,%0A%09%09%09%22Accept-Language: en;q=0.1,en-us;q=0.5%22,%0A%09%09%09%22Accept: text/xml,text/html;q=0.1%22%0A%09%09%7D;%0A%09%09String%5B%5D actualLines = this.header.toString().split(%22%5Cn%22);%0A%09%09Arrays.sort(actualLines);%0A%09%09assertArrayEquals(expectedLines, actualLines);%0A%09%7D%0A%0A%09
 @Test%0A
-    
+%09
 publ
@@ -2151,24 +2151,18 @@
 kie() %7B%0A
-        
+%09%09
 this.hea
@@ -2200,32 +2200,26 @@
 , %22test%22));%0A
-        
+%09%09
 this.header.
@@ -2263,50 +2263,40 @@
 ));%0A
-        assertEquals(%22%22%0A                + 
+%09%09String%5B%5D expectedLines = %7B%0A%09%09%09
 %22Acc
@@ -2342,255 +2342,310 @@
 =0.7
-%5Cn%22%0A                + %22Accept: text/xml,text/html;q=0.1%5Cn%22%0A                + %22Accept-Language: en;q=0.1,en-us;q=0.5%5Cn%22%0A                + %22Accept-Encoding: gzip,deflate%5Cn%22%0A                + %22Cookie: test=test; test2=test2%22, header.toString());%0A    
+%22,%0A%09%09%09%22Accept-Encoding: gzip,deflate%22,%0A%09%09%09%22Accept-Language: en;q=0.1,en-us;q=0.5%22,%0A%09%09%09%22Accept: text/xml,text/html;q=0.1%22,%0A%09%09%09%22Cookie: test=test; test2=test2%22%0A%09%09%7D;%0A%09%09String%5B%5D actualLines = this.header.toString().split(%22%5Cn%22);%0A%09%09Arrays.sort(actualLines);%0A%09%09assertArrayEquals(expectedLines, actualLines);%0A%09
 %7D%0A%7D%0A

Fix failing test