Package com.vtence.molecule.middlewares

Source Code of com.vtence.molecule.middlewares.ServerHeaderTest

package com.vtence.molecule.middlewares;

import com.vtence.molecule.Application;
import com.vtence.molecule.Request;
import com.vtence.molecule.Response;
import com.vtence.molecule.support.MockRequest;
import com.vtence.molecule.support.MockResponse;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

public class ServerHeaderTest {

    String serverName = "server/version";
    ServerHeader serverHeader = new ServerHeader(serverName);

    MockRequest request = new MockRequest();
    MockResponse response = new MockResponse();

    @Test public void
    setsServerHeader() throws Exception {
        serverHeader.connectTo(write(serverName));
        serverHeader.handle(request, response);
        assertServer(serverName);
    }

    private Application write(final String text) {
        return new Application() {
            public void handle(Request request, Response response) throws Exception {
                response.body(text);
            }
        };
    }

    private void assertServer(String server) {
        assertThat("server header", response.text(), equalTo(server));
    }
}
TOP

Related Classes of com.vtence.molecule.middlewares.ServerHeaderTest

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.