package be.ephec.nsjc.jws.model.test;

import be.ephec.nsjc.jws.model.Header;
import be.ephec.nsjc.jws.model.Response;
import be.ephec.nsjc.jws.model.ResponseCode;

import java.util.HashMap;

import static org.junit.Assert.*;


public class ResponseTest {

    private static Response res;

    @org.junit.Before
    public void setUp() {
        // Init a response with HTTPCode OK, 1 header and "Hello world" as html body

        Header headerContentType = new Header("Content-Type", "text/html; charset=UTF-8");

        HashMap<String, String> headers = new HashMap<String, String>();
        headers.put(headerContentType.getLabel(), headerContentType.getValue());

        res = new Response(ResponseCode.OK, headers, "<!DOCTYPE html>\r\n<html>\r\n\t<body>\r\n\t\tHello world !\r\n\t</body></html>");
    }

    @org.junit.Test
    public void addHeader() throws Exception {
    }

    @org.junit.Test
    public void delHeader() throws Exception {
        Header headerContentType = new Header("Content-Type", "text/html; charset=UTF-8");
        Header headerContentLength = new Header("Content-Length", "50");

        // Remove a header label that's not in the response
        assertFalse(res.hasHeader(headerContentLength.getLabel()));
        assertEquals(null, res.delHeader(headerContentLength.getLabel()));
        assertFalse(res.hasHeader(headerContentLength.getLabel()));

        // Remove a header label that's in the response
        assertTrue(res.hasHeader(headerContentType.getLabel()));
        assertEquals(headerContentType, res.delHeader(headerContentType.getLabel()));
        assertFalse(res.hasHeader(headerContentType.getLabel()));

    }

    @org.junit.Test
    public void delHeade1r() throws Exception {
        Header headerContentTypePlain = new Header("Content-Type", "text/html; charset=UTF-8");
        Header headerContentTypeHTML = new Header("Content-Type", "text/plain; charset=UTF-8");

        // Remove a header that's not in the response
        assertFalse(res.hasHeader(headerContentTypePlain));
        assertEquals(null, res.delHeader(headerContentTypePlain));
        assertFalse(res.hasHeader(headerContentTypePlain));

        // Remove a header that's in the response
        assertTrue(res.hasHeader(headerContentTypeHTML));
        assertEquals(headerContentTypeHTML, res.delHeader(headerContentTypeHTML));
        assertFalse(res.hasHeader(headerContentTypeHTML));
    }

    @org.junit.Test
    public void hasHeader() throws Exception {
        Header headerContentType = new Header("Content-Type", "text/html; charset=UTF-8");
        Header headerContentLength = new Header("Content-Length", "50");

        assertFalse(res.hasHeader(headerContentLength.getLabel()));
        assertTrue(res.hasHeader(headerContentType.getLabel()));
    }

    @org.junit.Test
    public void hasHeader1() throws Exception {
        Header headerContentTypePlain = new Header("Content-Type", "text/html; charset=UTF-8");
        Header headerContentTypeHTML = new Header("Content-Type", "text/plain; charset=UTF-8");

        assertFalse(res.hasHeader(headerContentTypePlain));
        assertTrue(res.hasHeader(headerContentTypeHTML));

    }

    @org.junit.Test
    public void testToString() throws Exception {
        String[] expected = {
                "HTTP1.1 200 ok",
                "Content-Type: text/html; charset=UTF-8",
                "",
                "<!DOCTYPE html>",
                "<html>",
                "    <body>",
                "        Hello World !",
                "    </body>",
                "</html>"
        };


        assertEquals(String.join("\r\n", expected).replaceAll("    ", "\t"), res.toString());
    }
}
@@ -790,16 +790,20 @@
 t%3C/body%3E
+%5Cr%5Cn
 %3C/html%3E%22
@@ -801,24 +801,24 @@
 n%3C/html%3E%22);%0A
-
     %7D%0A%0A    @
@@ -1804,36 +1804,37 @@
 nt-Type%22, %22text/
-html
+plain
 ; charset=UTF-8%22
@@ -1900,37 +1900,36 @@
 nt-Type%22, %22text/
-plain
+html
 ; charset=UTF-8%22
@@ -2936,36 +2936,37 @@
 nt-Type%22, %22text/
-html
+plain
 ; charset=UTF-8%22
@@ -3032,37 +3032,36 @@
 nt-Type%22, %22text/
-plain
+html
 ; charset=UTF-8%22
@@ -3055,33 +3055,32 @@
 harset=UTF-8%22);%0A
-%0A
         assertFa
@@ -3322,10 +3322,10 @@
 200 
-ok
+OK
 %22,%0A 
@@ -3527,9 +3527,9 @@
 llo 
-W
+w
 orld

correct test