/*
 * Javalin - https://javalin.io
 * Copyright 2017 David Åse
 * Licensed under Apache 2.0: https://github.com/tipsy/javalin/blob/master/LICENSE
 *
 */

package io.javalin;

import java.io.IOException;

import org.junit.Test;

import io.javalin.util.SimpleHttpClient;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

/**
 * Created by enchanting on 03.08.17.
 */
public class TestIgnoreTrailingSlashes {

    @Test()
    public void dontIgnoreTrailingSlashes() throws IOException {

        String endpointResponse = "Hello, slash!";
        String endpoint = "/hello";
        int port = 7787;
        SimpleHttpClient simpleHttpClient = new SimpleHttpClient();
        Javalin app = Javalin.create()
            .port(port)
            .dontIgnoreTrailingSlashes()
            .start();

        app.get(endpoint, ctx -> ctx.result(endpointResponse));
        assertThat(simpleHttpClient.http_GET("http://localhost:" + port + endpoint).getBody(), is(endpointResponse));
        assertThat(simpleHttpClient.http_GET("http://localhost:" + port + endpoint + "/").getBody(), not(endpointResponse));

        app.stop();
    }

    @Test()
    public void ignoreTrailingSlashes() throws IOException {

        String endpointResponse = "Hello, slash!";
        String endpoint = "/hello";
        int port = 7787;
        SimpleHttpClient simpleHttpClient = new SimpleHttpClient();
        Javalin app = Javalin.create()
            .port(port)
            .start();

        app.get(endpoint, ctx -> ctx.result(endpointResponse));
        assertThat(simpleHttpClient.http_GET("http://localhost:" + port + endpoint).getBody(), is(endpointResponse));
        assertThat(simpleHttpClient.http_GET("http://localhost:" + port + endpoint + "/").getBody(), is(endpointResponse));

        app.stop();
    }
}

@@ -443,261 +443,151 @@
     
-@Test()%0A    public void dontIgnoreTrailingSlashes() throws IOException %7B%0A%0A        String endpointResponse = %22Hello, slash!%22;%0A        String endpoint = %22/hello%22;%0A        int port = 7787;%0A        SimpleHttpClient simpleHttpClient = new SimpleHttpClient();
+private SimpleHttpClient simpleHttpClient = new SimpleHttpClient();%0A%0A    @Test%0A    public void dontIgnoreTrailingSlashes() throws IOException %7B
 %0A   
@@ -626,32 +626,8 @@
 e()%0A
-            .port(port)%0A
     
@@ -675,34 +675,32 @@
         .start()
-;%0A
 %0A        app.get
@@ -692,32 +692,33 @@
         
-app
+    
 .get(
-endpoint
+%22/hello%22
 , ctx -%3E
@@ -729,32 +729,31 @@
 .result(
-endpointResponse
+%22Hello, slash!%22
 ));%0A    
@@ -815,59 +815,50 @@
 ost:
-%22 + port + endpoint).getBody(), is(endpointResponse
+7000/hello%22).getBody(), is(%22Hello, slash!%22
 ));%0A
@@ -924,71 +924,51 @@
 ost:
-%22 + port + endpoint + %22/%22).getBody(), not(endpointResponse
+7000/hello/%22).getBody(), is(%22Not found%22
 ));%0A
-%0A
     
@@ -999,18 +999,16 @@
    @Test
-()
 %0A    pub
@@ -1064,189 +1064,8 @@
 on %7B
-%0A%0A        String endpointResponse = %22Hello, slash!%22;%0A        String endpoint = %22/hello%22;%0A        int port = 7787;%0A        SimpleHttpClient simpleHttpClient = new SimpleHttpClient();
 %0A   
@@ -1074,33 +1074,32 @@
    Javalin app =
- 
 Javalin.create()
@@ -1116,17 +1116,14 @@
    .
-port(po
+sta
 rt
+(
 )%0A  
@@ -1137,42 +1137,20 @@
    .
-start();%0A%0A        app.get(endpoint
+get(%22/hello%22
 , ct
@@ -1165,32 +1165,31 @@
 .result(
-endpointResponse
+%22Hello, slash!%22
 ));%0A    
@@ -1251,59 +1251,50 @@
 ost:
-%22 + port + endpoint).getBody(), is(endpointResponse
+7000/hello%22).getBody(), is(%22Hello, slash!%22
 ));%0A
@@ -1360,31 +1360,18 @@
 ost:
-%22 + port + endpoint + %22
+7000/hello
 /%22).
@@ -1388,29 +1388,27 @@
  is(
-endpointResponse
+%22Hello, slash!%22
 ));%0A
-%0A
     
@@ -1429,10 +1429,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Simplify trailing-slash test