Package org.sentinel.servers.http.protocol

Source Code of org.sentinel.servers.http.protocol.HTTPHeadersTest

package org.sentinel.servers.http.protocol;

import org.sentinel.servers.http.protocol.NoSuchHTTPHeaderException;
import org.sentinel.servers.http.protocol.HTTPHeaders;
import org.sentinel.servers.http.protocol.HTTPHeader;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.junit.Assert.*;
import org.junit.Test;

public class HTTPHeadersTest
{
   
    public HTTPHeadersTest()
    {
    }

    @Test
    public void testGet()
    {
        try {
            HTTPHeaders headers = new HTTPHeaders();
            headers.add(new HTTPHeader("key", "value"));
            assertEquals("value", headers.get("key").getValue());
        }
        catch(NoSuchHTTPHeaderException ex) {
            fail(ex.getMessage());
        }
    }

    @Test
    public void testGetNonExistantHeader()
    {
        try {
            HTTPHeaders headers = new HTTPHeaders();
            assertEquals("value", headers.get("key").getValue());
            fail("Should of failed before this point.");
        }
        catch(NoSuchHTTPHeaderException ex) {
            // good
        }
    }

    @Test
    public void testAddOrReplace()
    {
        try {
            HTTPHeaders headers = new HTTPHeaders();
            headers.addOrReplace(new HTTPHeader("key", "value"));
            assertEquals("value", headers.get("key").getValue());
           
            headers.addOrReplace(new HTTPHeader("key", "value2"));
            assertEquals("value2", headers.get("key").getValue());
        }
        catch(NoSuchHTTPHeaderException ex) {
            fail(ex.getMessage());
        }
    }
   
}
TOP

Related Classes of org.sentinel.servers.http.protocol.HTTPHeadersTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.