// Copyright 2014, Kevin Ko <kevin@faveset.com>

package com.faveset.khttp;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.nio.ByteBuffer;

@RunWith(JUnit4.class)
public class RequestHeaderHandlerTest {
    @Test
    public void testSimple() throws InvalidRequestException {
        ByteBuffer buf = Helper.makeByteBuffer("hello: world\n");
        HandlerState state = new HandlerState();

        RequestHeaderHandler handler = new RequestHeaderHandler();
        assertFalse(handler.handleState(null, buf, state));

        assertEquals(1, state.getRequestBuilder().getHeader("hello").size());
        assertEquals("world", state.getRequestBuilder().getHeaderFirst("hello"));

        buf.clear();
        buf.put(Helper.makeByteBuffer("foo: bar\r\n"));
        buf.flip();
        assertFalse(handler.handleState(null, buf, state));
        assertEquals(1, state.getRequestBuilder().getHeader("foo").size());
        assertEquals("bar", state.getRequestBuilder().getHeaderFirst("foo"));

        buf.clear();
        buf.put(Helper.makeByteBuffer("\n"));
        buf.flip();
        assertTrue(handler.handleState(null, buf, state));
    }
}

@@ -1195,24 +1195,1005 @@
 t(%22foo%22));%0A%0A
+        buf.clear();%0A        buf.put(Helper.makeByteBuffer(%22%5Cn%22));%0A        buf.flip();%0A        assertTrue(handler.handleState(null, buf, state));%0A    %7D%0A%0A    // TODO: test partial.%0A%0A    @Test%0A    public void testContinuation() throws InvalidRequestException %7B%0A        ByteBuffer buf = Helper.makeByteBuffer(%22hello: world%5Cn%22);%0A        HandlerState state = new HandlerState();%0A%0A        RequestHeaderHandler handler = new RequestHeaderHandler();%0A        assertFalse(handler.handleState(null, buf, state));%0A%0A        assertEquals(1, state.getRequestBuilder().getHeader(%22hello%22).size());%0A        assertEquals(%22world%22, state.getRequestBuilder().getHeaderFirst(%22hello%22));%0A%0A        buf.clear();%0A        buf.put(Helper.makeByteBuffer(%22 hi?%5Cn%22));%0A        buf.flip();%0A        assertFalse(handler.handleState(null, buf, state));%0A%0A        assertEquals(1, state.getRequestBuilder().getHeader(%22hello%22).size());%0A        assertEquals(%22world hi?%22, state.getRequestBuilder().getHeaderFirst(%22hello%22));%0A%0A
         buf.

Add continuation test.