package org.pac4j.saml.util;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.net.URI;
import java.net.URISyntaxException;

import org.junit.Test;


/**
 * Unit test for class {@link UriUtils}.
 * 
 * @author jkacer
 */
public class UriUtilsTest {

    @Test
    public void twoNullUrisMustEqual() {
        assertTrue(UriUtils.urisEqualAfterPortNormalization(null, null));
    }
    
    @Test
    public void nullUriAndNonNullUriMustNotEqual() throws URISyntaxException {
        final URI uri = new URI("http://somewhere/something");
        assertFalse(UriUtils.urisEqualAfterPortNormalization(uri, null));
        assertFalse(UriUtils.urisEqualAfterPortNormalization(null, uri));
    }
    
    @Test
    public void uriMustEqualItself() throws URISyntaxException {
        final URI uri = new URI("http://somewhere/something");
        assertTrue(UriUtils.urisEqualAfterPortNormalization(uri, uri));
    }
    
    @Test
    public void twoSameUrisMustEqual() throws URISyntaxException {
        final URI uri1 = new URI("http://somewhere/something");
        final URI uri2 = new URI("http://somewhere/something");
        assertTrue(UriUtils.urisEqualAfterPortNormalization(uri1, uri2));
        assertTrue(UriUtils.urisEqualAfterPortNormalization(uri2, uri1));
    }
    
    @Test
    public void twoDifferntUrisMustNotEqual() throws URISyntaxException {
        final URI uri1 = new URI("http://somewhere/something1");
        final URI uri2 = new URI("http://somewhere/something2");
        assertFalse(UriUtils.urisEqualAfterPortNormalization(uri1, uri2));
        assertFalse(UriUtils.urisEqualAfterPortNormalization(uri2, uri1));
    }
    
    @Test
    public void sameUrisWithImplicitAndExplicitHttpPortMustEqual() throws URISyntaxException {
        final URI uri1 = new URI("http://somewhere:80/something");
        final URI uri2 = new URI("http://somewhere/something");
        assertTrue(UriUtils.urisEqualAfterPortNormalization(uri1, uri2));
        assertTrue(UriUtils.urisEqualAfterPortNormalization(uri2, uri1));
    }

    @Test
    public void sameUrisWithImplicitAndExplicitHttpsPortMustEqual() throws URISyntaxException {
        final URI uri1 = new URI("https://somewhere:443/something");
        final URI uri2 = new URI("https://somewhere/something");
        assertTrue(UriUtils.urisEqualAfterPortNormalization(uri1, uri2));
        assertTrue(UriUtils.urisEqualAfterPortNormalization(uri2, uri1));
    }
    
    @Test
    public void differentUrisWithImplicitAndExplicitHttpPortMustNotEqual() throws URISyntaxException {
        final URI uri1 = new URI("http://somewhere:80/something1");
        final URI uri2 = new URI("http://somewhere/something2");
        assertFalse(UriUtils.urisEqualAfterPortNormalization(uri1, uri2));
        assertFalse(UriUtils.urisEqualAfterPortNormalization(uri2, uri1));
    }

    @Test
    public void differentUrisWithImplicitAndExplicitHttpsPortMustNotEqual() throws URISyntaxException {
        final URI uri1 = new URI("https://somewhere:443/something1");
        final URI uri2 = new URI("https://somewhere/something2");
        assertFalse(UriUtils.urisEqualAfterPortNormalization(uri1, uri2));
        assertFalse(UriUtils.urisEqualAfterPortNormalization(uri2, uri1));
    }
    
}

@@ -1,8 +1,619 @@
+/*%0D%0A  Copyright 2012 -2015 pac4j organization%0D%0A   Licensed under the Apache License, Version 2.0 (the %22License%22);%0D%0A   you may not use this file except in compliance with the License.%0D%0A   You may obtain a copy of the License at%0D%0A       http://www.apache.org/licenses/LICENSE-2.0%0D%0A   Unless required by applicable law or agreed to in writing, software%0D%0A   distributed under the License is distributed on an %22AS IS%22 BASIS,%0D%0A   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0D%0A   See the License for the specific language governing permissions and%0D%0A   limitations under the License.%0D%0A */%0D%0A 
 package 
@@ -887,16 +887,33 @@
 jkacer%0D%0A
+ * @since 1.8.0%0D%0A
  */%0D%0Apub

Update UriUtilsTest.java