package com.wizzardo.http;

import com.wizzardo.tools.http.ConnectionMethod;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;

/**
 * Created by wizzardo on 16.04.15.
 */
public class RestHandlerTest extends ServerTest {

    @Test
    public void test_allowPostAndPut() throws IOException {
        handler = new UrlHandler()
                .append("/rest", new RestHandler()
                        .post(
                                (request, response) -> response.setBody("post")
                        )
                        .put(
                                (request, response) -> response.setBody("put")
                        ))
        ;

        Assert.assertEquals("post", makeRequest("/rest").post().asString());
        Assert.assertEquals("put", makeRequest("/rest").method(ConnectionMethod.PUT).execute().asString());
        Assert.assertEquals(405, makeRequest("/rest").get().getResponseCode());
        Assert.assertEquals("POST, PUT", makeRequest("/rest").get().header("Allow"));
    }

}

@@ -1041,10 +1041,1278 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void test_allowGetAndDelete() throws IOException %7B%0A        handler = new UrlHandler()%0A                .append(%22/rest%22, new RestHandler()%0A                        .get(%0A                                (request, response) -%3E response.setBody(%22get%22)%0A                        )%0A                        .delete(%0A                                (request, response) -%3E response.setBody(%22delete%22)%0A                        ))%0A        ;%0A%0A        Assert.assertEquals(%22get%22, makeRequest(%22/rest%22).get().asString());%0A        Assert.assertEquals(%22delete%22, makeRequest(%22/rest%22).method(ConnectionMethod.DELETE).execute().asString());%0A        Assert.assertEquals(405, makeRequest(%22/rest%22).post().getResponseCode());%0A        Assert.assertEquals(%22GET, DELETE%22, makeRequest(%22/rest%22).post().header(%22Allow%22));%0A    %7D%0A%0A    @Test%0A    public void test_allowNothing() throws IOException %7B%0A        handler = new UrlHandler()%0A                .append(%22/rest%22, new RestHandler().get(null))%0A        ;%0A%0A        Assert.assertEquals(405, makeRequest(%22/rest%22).get().getResponseCode());%0A        Assert.assertEquals(null, makeRequest(%22/rest%22).get().header(%22Allow%22));%0A%0A        Assert.assertEquals(405, makeRequest(%22/rest%22).method(ConnectionMethod.HEAD).execute().getResponseCode());%0A    %7D%0A%0A
 %7D%0A

improve tests