package com.atexpose;

import com.atexpose.dispatcher.IDispatcher;
import com.atexpose.dispatcherfactories.WebServerBuilder;
import io.schinzel.basicutils.Sandman;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.junit.After;
import org.junit.Test;

import java.io.IOException;

import static org.assertj.core.api.Assertions.*;


/**
 * Tests different set ups of the web server.
 *
 * @author Schinzel
 */

public class WebServerCustomTest {
    private AtExpose mAtExpose;


    @After
    public void after() {
        mAtExpose.shutdown();
        //Snooze required to get tests to work on Travis
        Sandman.snoozeMillis(10);
    }


    @Test
    public void requestPage_PageDoesNotExist_404() throws IOException {
        IDispatcher webServer = WebServerBuilder.create()
                //Set dir where html and other files resides
                .webServerDir("testfiles")
                //Set custom 404 page
                .fileName404Page("WebServerCustomTest_404Page.html")
                //Build web server
                .build();
        mAtExpose = AtExpose.create()
                //Start web server
                .start(webServer);
        String result = Jsoup
                .connect("http://127.0.0.1:5555/noSuchFile.html")
                .method(Connection.Method.GET)
                .ignoreHttpErrors(true)
                .execute()
                .body();
        assertThat(result).contains("Custom 404. File not found");

    }

}

@@ -705,17 +705,32 @@
 NotExist
-_
+Custom404_Custom
 404() th
@@ -1488,18 +1488,788 @@
 ound%22);%0A
-%0A
     %7D%0A%0A
+%0A    @Test%0A    public void requestPage_PageDoesNotExistNotCustom404_Default404() throws IOException %7B%0A        IDispatcher webServer = WebServerBuilder.create()%0A                //Set dir where html and other files resides%0A                .webServerDir(%22testfiles%22)%0A                //Build web server%0A                .build();%0A        mAtExpose = AtExpose.create()%0A                //Start web server%0A                .start(webServer);%0A        String result = Jsoup%0A                .connect(%22http://127.0.0.1:5555/noSuchFile.html%22)%0A                .method(Connection.Method.GET)%0A                .ignoreHttpErrors(true)%0A                .execute()%0A                .body();%0A        assertThat(result).contains(%22%3Chtml%3E%3Cbody%3E%3Ccenter%3EFile not found%3C/center%3E%3Cbody%3E%3C/html%3E%22);%0A    %7D%0A
 %7D%0A

Test added