@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2013 the original author or authors .
* Copyright 2002 - 2014 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -16,6 +16,8 @@
@@ -16,6 +16,8 @@
package org.springframework.web.util ;
import org.junit.Test ;
import java.io.ByteArrayInputStream ;
import java.io.ByteArrayOutputStream ;
import java.io.ObjectInputStream ;
@ -23,10 +25,12 @@ import java.io.ObjectOutputStream;
@@ -23,10 +25,12 @@ import java.io.ObjectOutputStream;
import java.net.URI ;
import java.net.URISyntaxException ;
import org.junit.Test ;
import static org.hamcrest.Matchers.* ;
import static org.junit.Assert.* ;
import static org.hamcrest.Matchers.equalTo ;
import static org.hamcrest.Matchers.instanceOf ;
import static org.hamcrest.Matchers.not ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertThat ;
import static org.springframework.web.util.UriComponentsBuilder.fromUriString ;
/ * *
* @author Arjen Poutsma
@ -84,22 +88,18 @@ public class UriComponentsTests {
@@ -84,22 +88,18 @@ public class UriComponentsTests {
@Test
public void port ( ) {
UriComponents uriComponents1 = UriComponentsBuilder . fromUriString (
"http://example.com:8080/bar" ) . build ( ) ;
UriComponents uriComponents2 = UriComponentsBuilder . fromUriString (
"http://example.com/bar" ) . port ( 8080 ) . build ( ) ;
UriComponents uriComponents3 = UriComponentsBuilder . fromUriString (
"http://example.com/bar" ) . port ( "{port}" ) . build ( ) . expand ( 8080 ) ;
UriComponents uriComponents4 = UriComponentsBuilder . fromUriString (
"http://example.com/bar" ) . port ( "808{digit}" ) . build ( ) . expand ( 0 ) ;
assertEquals ( 8080 , uriComponents1 . getPort ( ) ) ;
assertEquals ( "http://example.com:8080/bar" , uriComponents1 . toUriString ( ) ) ;
assertEquals ( 8080 , uriComponents2 . getPort ( ) ) ;
assertEquals ( "http://example.com:8080/bar" , uriComponents2 . toUriString ( ) ) ;
assertEquals ( 8080 , uriComponents3 . getPort ( ) ) ;
assertEquals ( "http://example.com:8080/bar" , uriComponents3 . toUriString ( ) ) ;
assertEquals ( 8080 , uriComponents4 . getPort ( ) ) ;
assertEquals ( "http://example.com:8080/bar" , uriComponents4 . toUriString ( ) ) ;
UriComponents uri1 = fromUriString ( "http://example.com:8080/bar" ) . build ( ) ;
UriComponents uri2 = fromUriString ( "http://example.com/bar" ) . port ( 8080 ) . build ( ) ;
UriComponents uri3 = fromUriString ( "http://example.com/bar" ) . port ( "{port}" ) . build ( ) . expand ( 8080 ) ;
UriComponents uri4 = fromUriString ( "http://example.com/bar" ) . port ( "808{digit}" ) . build ( ) . expand ( 0 ) ;
assertEquals ( 8080 , uri1 . getPort ( ) ) ;
assertEquals ( "http://example.com:8080/bar" , uri1 . toUriString ( ) ) ;
assertEquals ( 8080 , uri2 . getPort ( ) ) ;
assertEquals ( "http://example.com:8080/bar" , uri2 . toUriString ( ) ) ;
assertEquals ( 8080 , uri3 . getPort ( ) ) ;
assertEquals ( "http://example.com:8080/bar" , uri3 . toUriString ( ) ) ;
assertEquals ( 8080 , uri4 . getPort ( ) ) ;
assertEquals ( "http://example.com:8080/bar" , uri4 . toUriString ( ) ) ;
}
@Test ( expected = IllegalStateException . class )