/**
 * Copyright (C) 2014 Microsoft Corporation
 *
 * 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 com.microsoft.reef.webserver;

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

import org.mortbay.io.bio.StringEndPoint;
import org.mortbay.jetty.*;

import javax.servlet.ServletException;

import java.io.IOException;
import java.util.*;

public final class TestParsedHttpRequest {

  @Test
  public void testQueryMap() throws IOException, ServletException {

    final Request request = new Request(
        new HttpConnection(new LocalConnector(), new StringEndPoint(), new Server()));

    request.setUri(new HttpURI("http://localhost.com/get#test?a=10&b=20&a=30"));
    request.setQueryString("a=10&b=20&a=30");

    final ParsedHttpRequest parsedRequest = new ParsedHttpRequest(request);

    final Map<String, List<String>> queryMap = new LinkedHashMap<String, List<String>>(2) {{
      put("a", Arrays.asList("10", "30"));
      put("b", Arrays.asList("20"));
    }};

    Assert.assertEquals(queryMap, parsedRequest.getQueryMap());
  }
}

@@ -664,21 +664,70 @@
 .junit.A
-ssert
+fter;%0Aimport org.junit.Assert;%0Aimport org.junit.Before
 ;%0Aimport
@@ -853,16 +853,50 @@
 ception;
+%0Aimport javax.servlet.http.Cookie;
 %0A%0Aimport
@@ -988,13 +988,86 @@
 %0A%0A  
-@Test
+private Request request;%0A  private ParsedHttpRequest parsedRequest;%0A%0A  @Before
 %0A  p
@@ -1081,19 +1081,12 @@
 oid 
-testQueryMa
+setU
 p() 
@@ -1133,22 +1133,13 @@
     
-final Request 
+this.
 requ
@@ -1245,24 +1245,29 @@
 r()));%0A%0A    
+this.
 request.setU
@@ -1335,16 +1335,21 @@
 ));%0A    
+this.
 request.
@@ -1386,37 +1386,64 @@
 %22);%0A
-%0A
     
-final ParsedHttpRequest 
+this.request.setContentType(%22text/json%22);%0A%0A    this.
 pars
@@ -1476,16 +1476,21 @@
 Request(
+this.
 request)
@@ -1495,55 +1495,84 @@
 t);%0A
-%0A    final Map%3CString, List%3CString%3E%3E queryMap =
+  %7D%0A%0A  @Test%0A  public void testQueryMap() %7B%0A    Assert.assertEquals(%0A       
  new
@@ -1612,14 +1612,17 @@
 g%3E%3E(
-2
 ) %7B%7B%0A
+    
     
@@ -1662,24 +1662,28 @@
 0%22));%0A      
+   
+ 
 put(%22b%22, Arr
@@ -1709,47 +1709,219 @@
     
-%7D%7D;%0A%0A    Assert.assertEquals(queryMap, 
+    %7D%7D,%0A        this.parsedRequest.getQueryMap());%0A  %7D%0A%0A  @Test%0A  public void testHeaders() %7B%0A    Assert.assertEquals(%0A        new HashMap%3CString, String%3E() %7B%7B put(%22Content-Type%22, %22text/json%22); %7D%7D,%0A        this.
 pars
@@ -1929,31 +1929,30 @@
 dRequest.get
-QueryMap
+Headers
 ());%0A  %7D%0A%7D%0A

add testHeaders() unit test; created setUp() section