package com.atexpose.dispatcher.channels.webchannel.redirect;

import org.junit.Assert;
import org.junit.Test;

import java.net.URI;

public class RedirectsTest {
    @Test
    public void shouldAndGetRedirect() throws Exception {
        Redirects redirects = Redirects.getBuilder()
                .setHttpsRedirect()
                .addHostRedirect("example.com", "www.example.com")
                .addHostRedirect("www.example.com", "www.schinzel.io")
                .addFileRedirect("a/b/c/source.html", "q/r/s/dest.html")
                .build();
        URI uri = new URI("http://example.com/a/b/c/source.html?k1=ŹźŻż&k2=سش&k3=ДЂ");
        Assert.assertTrue(redirects.shouldRedirect(uri));
        Assert.assertEquals("https://www.schinzel.io/q/r/s/dest.html?k1=ŹźŻż&k2=سش&k3=ДЂ", redirects.getNewLocation(uri).toString());
    }


    @Test
    public void shouldRedirect_noRedirect() throws Exception {
        Redirects redirects = Redirects.getBuilder()
                .setHttpsRedirect()
                .addHostRedirect("example.com", "www.example.com")
                .addHostRedirect("www.example.com", "www.schinzel.io")
                .addFileRedirect("a/b/c/source.html", "q/r/s/dest.html")
                .build();
        URI uri = new URI("https://www.google.com");
        Assert.assertFalse(redirects.shouldRedirect(uri));
    }

}
@@ -192,22 +192,16 @@
 ould
-AndGet
 Redirect
 () t
@@ -188,32 +188,49 @@
 d shouldRedirect
+AndGetNewLocation
 () throws Except
@@ -1296,24 +1296,24 @@
 ogle.com%22);%0A
-
         Asse
@@ -1366,9 +1366,1421 @@
 %0A    %7D%0A%0A
+%0A    @Test%0A    public void shouldRedirectAndGetNewLocation_failWhale() throws Exception %7B%0A        Redirects redirects = Redirects.getBuilder()%0A                .setHttpsRedirect()%0A                .setFailWhaleRedirect(%22bapp.html%22)%0A                .addHostRedirect(%22example.com%22, %22www.example.com%22)%0A                .addHostRedirect(%22www.example.com%22, %22www.schinzel.io%22)%0A                .addFileRedirect(%22a/b/c/source.html%22, %22q/r/s/dest.html%22)%0A                .build();%0A        URI uri = new URI(%22https://www.schinzel.io%22);%0A        //The only redirect clause that hits is the fail whale.%0A        Assert.assertTrue(redirects.shouldRedirect(uri));%0A        Assert.assertEquals(%22https://www.schinzel.io/bapp.html%22, redirects.getNewLocation(uri).toString());%0A    %7D%0A%0A%0A    @Test%0A    public void getNewLocation_failWhale_multipleRedirectsHits() throws Exception %7B%0A        Redirects redirects = Redirects.getBuilder()%0A                .setFailWhaleRedirect(%22bapp.html%22)%0A                .addHostRedirect(%22example.com%22, %22www.example.com%22)%0A                .addHostRedirect(%22www.example.com%22, %22www.schinzel.io%22)%0A                .addFileRedirect(%22a/b/c/source.html%22, %22q/r/s/dest.html%22)%0A                .setHttpsRedirect()%0A                .build();%0A        URI uri = new URI(%22http://example.com/a/b/c/source.html%22);%0A        Assert.assertEquals(%22https://www.schinzel.io/bapp.html%22, redirects.getNewLocation(uri).toString());%0A    %7D%0A%0A
 %7D

Test added