Replace space indentation with tabs
Issue: SPR-10127
This commit is contained in:
committed by
Chris Beams
parent
1762157ad1
commit
2cf45bad86
@@ -245,8 +245,8 @@ public abstract class AbstractHttpRequestFactoryTestCase {
|
||||
@SuppressWarnings("serial")
|
||||
private static class EchoServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
echo(req, resp);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,69 +31,69 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public abstract class FreePortScanner {
|
||||
|
||||
private static final int MIN_SAFE_PORT = 1024;
|
||||
private static final int MIN_SAFE_PORT = 1024;
|
||||
|
||||
private static final int MAX_PORT = 65535;
|
||||
private static final int MAX_PORT = 65535;
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final Random random = new Random();
|
||||
|
||||
/**
|
||||
* Returns the number of a free port in the default range.
|
||||
*/
|
||||
public static int getFreePort() {
|
||||
return getFreePort(MIN_SAFE_PORT, MAX_PORT);
|
||||
}
|
||||
/**
|
||||
* Returns the number of a free port in the default range.
|
||||
*/
|
||||
public static int getFreePort() {
|
||||
return getFreePort(MIN_SAFE_PORT, MAX_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of a free port in the given range.
|
||||
*/
|
||||
public static int getFreePort(int minPort, int maxPort) {
|
||||
Assert.isTrue(minPort > 0, "'minPort' must be larger than 0");
|
||||
Assert.isTrue(maxPort > minPort, "'maxPort' must be larger than minPort");
|
||||
int portRange = maxPort - minPort;
|
||||
int candidatePort;
|
||||
int searchCounter = 0;
|
||||
do {
|
||||
if (++searchCounter > portRange) {
|
||||
throw new IllegalStateException(
|
||||
String.format("There were no ports available in the range %d to %d", minPort, maxPort));
|
||||
}
|
||||
candidatePort = getRandomPort(minPort, portRange);
|
||||
}
|
||||
while (!isPortAvailable(candidatePort));
|
||||
/**
|
||||
* Returns the number of a free port in the given range.
|
||||
*/
|
||||
public static int getFreePort(int minPort, int maxPort) {
|
||||
Assert.isTrue(minPort > 0, "'minPort' must be larger than 0");
|
||||
Assert.isTrue(maxPort > minPort, "'maxPort' must be larger than minPort");
|
||||
int portRange = maxPort - minPort;
|
||||
int candidatePort;
|
||||
int searchCounter = 0;
|
||||
do {
|
||||
if (++searchCounter > portRange) {
|
||||
throw new IllegalStateException(
|
||||
String.format("There were no ports available in the range %d to %d", minPort, maxPort));
|
||||
}
|
||||
candidatePort = getRandomPort(minPort, portRange);
|
||||
}
|
||||
while (!isPortAvailable(candidatePort));
|
||||
|
||||
return candidatePort;
|
||||
}
|
||||
return candidatePort;
|
||||
}
|
||||
|
||||
private static int getRandomPort(int minPort, int portRange) {
|
||||
return minPort + random.nextInt(portRange);
|
||||
}
|
||||
private static int getRandomPort(int minPort, int portRange) {
|
||||
return minPort + random.nextInt(portRange);
|
||||
}
|
||||
|
||||
private static boolean isPortAvailable(int port) {
|
||||
ServerSocket serverSocket;
|
||||
try {
|
||||
serverSocket = new ServerSocket();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Unable to create ServerSocket.", ex);
|
||||
}
|
||||
private static boolean isPortAvailable(int port) {
|
||||
ServerSocket serverSocket;
|
||||
try {
|
||||
serverSocket = new ServerSocket();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Unable to create ServerSocket.", ex);
|
||||
}
|
||||
|
||||
try {
|
||||
InetSocketAddress sa = new InetSocketAddress(port);
|
||||
serverSocket.bind(sa);
|
||||
return true;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
serverSocket.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
InetSocketAddress sa = new InetSocketAddress(port);
|
||||
serverSocket.bind(sa);
|
||||
return true;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
serverSocket.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -373,13 +373,13 @@ public class CommonsMultipartResolverTests {
|
||||
}
|
||||
List<FileItem> fileItems = new ArrayList<FileItem>();
|
||||
MockFileItem fileItem1 = new MockFileItem(
|
||||
"field1", "type1", empty ? "" : "field1.txt", empty ? "" : "text1");
|
||||
"field1", "type1", empty ? "" : "field1.txt", empty ? "" : "text1");
|
||||
MockFileItem fileItem1x = new MockFileItem(
|
||||
"field1", "type1", empty ? "" : "field1.txt", empty ? "" : "text1");
|
||||
"field1", "type1", empty ? "" : "field1.txt", empty ? "" : "text1");
|
||||
MockFileItem fileItem2 = new MockFileItem(
|
||||
"field2", "type2", empty ? "" : "C:/field2.txt", empty ? "" : "text2");
|
||||
"field2", "type2", empty ? "" : "C:/field2.txt", empty ? "" : "text2");
|
||||
MockFileItem fileItem2x = new MockFileItem(
|
||||
"field2x", "type2", empty ? "" : "C:\\field2x.txt", empty ? "" : "text2");
|
||||
"field2x", "type2", empty ? "" : "C:\\field2x.txt", empty ? "" : "text2");
|
||||
MockFileItem fileItem3 = new MockFileItem("field3", null, null, "value3");
|
||||
MockFileItem fileItem4 = new MockFileItem("field4", "text/html; charset=iso-8859-1", null, "value4");
|
||||
MockFileItem fileItem5 = new MockFileItem("field4", null, null, "value5");
|
||||
|
||||
@@ -38,11 +38,11 @@ public class UriComponentsBuilderTests {
|
||||
public void plain() throws URISyntaxException {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
|
||||
UriComponents result = builder.scheme("http").host("example.com").path("foo").queryParam("bar").fragment("baz").build();
|
||||
assertEquals("http", result.getScheme());
|
||||
assertEquals("example.com", result.getHost());
|
||||
assertEquals("foo", result.getPath());
|
||||
assertEquals("bar", result.getQuery());
|
||||
assertEquals("baz", result.getFragment());
|
||||
assertEquals("http", result.getScheme());
|
||||
assertEquals("example.com", result.getHost());
|
||||
assertEquals("foo", result.getPath());
|
||||
assertEquals("bar", result.getQuery());
|
||||
assertEquals("baz", result.getFragment());
|
||||
|
||||
URI expected = new URI("http://example.com/foo?bar#baz");
|
||||
assertEquals("Invalid result URI", expected, result.toUri());
|
||||
@@ -51,29 +51,29 @@ public class UriComponentsBuilderTests {
|
||||
@Test
|
||||
public void fromPath() throws URISyntaxException {
|
||||
UriComponents result = UriComponentsBuilder.fromPath("foo").queryParam("bar").fragment("baz").build();
|
||||
assertEquals("foo", result.getPath());
|
||||
assertEquals("bar", result.getQuery());
|
||||
assertEquals("baz", result.getFragment());
|
||||
assertEquals("foo", result.getPath());
|
||||
assertEquals("bar", result.getQuery());
|
||||
assertEquals("baz", result.getFragment());
|
||||
|
||||
URI expected = new URI("/foo?bar#baz");
|
||||
assertEquals("Invalid result URI", expected, result.toUri());
|
||||
|
||||
result = UriComponentsBuilder.fromPath("/foo").build();
|
||||
assertEquals("/foo", result.getPath());
|
||||
assertEquals("/foo", result.getPath());
|
||||
|
||||
expected = new URI("/foo");
|
||||
expected = new URI("/foo");
|
||||
assertEquals("Invalid result URI", expected, result.toUri());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromHierarchicalUri() throws URISyntaxException {
|
||||
URI uri = new URI("http://example.com/foo?bar#baz");
|
||||
UriComponents result = UriComponentsBuilder.fromUri(uri).build();
|
||||
assertEquals("http", result.getScheme());
|
||||
assertEquals("example.com", result.getHost());
|
||||
assertEquals("/foo", result.getPath());
|
||||
assertEquals("bar", result.getQuery());
|
||||
assertEquals("baz", result.getFragment());
|
||||
UriComponents result = UriComponentsBuilder.fromUri(uri).build();
|
||||
assertEquals("http", result.getScheme());
|
||||
assertEquals("example.com", result.getHost());
|
||||
assertEquals("/foo", result.getPath());
|
||||
assertEquals("bar", result.getQuery());
|
||||
assertEquals("baz", result.getFragment());
|
||||
|
||||
assertEquals("Invalid result URI", uri, result.toUri());
|
||||
}
|
||||
@@ -81,24 +81,24 @@ public class UriComponentsBuilderTests {
|
||||
@Test
|
||||
public void fromOpaqueUri() throws URISyntaxException {
|
||||
URI uri = new URI("mailto:foo@bar.com#baz");
|
||||
UriComponents result = UriComponentsBuilder.fromUri(uri).build();
|
||||
assertEquals("mailto", result.getScheme());
|
||||
assertEquals("foo@bar.com", result.getSchemeSpecificPart());
|
||||
assertEquals("baz", result.getFragment());
|
||||
UriComponents result = UriComponentsBuilder.fromUri(uri).build();
|
||||
assertEquals("mailto", result.getScheme());
|
||||
assertEquals("foo@bar.com", result.getSchemeSpecificPart());
|
||||
assertEquals("baz", result.getFragment());
|
||||
|
||||
assertEquals("Invalid result URI", uri, result.toUri());
|
||||
}
|
||||
|
||||
// SPR-9317
|
||||
|
||||
@Test
|
||||
public void fromUriEncodedQuery() throws URISyntaxException {
|
||||
URI uri = new URI("http://www.example.org/?param=aGVsbG9Xb3JsZA%3D%3D");
|
||||
String fromUri = UriComponentsBuilder.fromUri(uri).build().getQueryParams().get("param").get(0);
|
||||
String fromUriString = UriComponentsBuilder.fromUriString(uri.toString()).build().getQueryParams().get("param").get(0);
|
||||
@Test
|
||||
public void fromUriEncodedQuery() throws URISyntaxException {
|
||||
URI uri = new URI("http://www.example.org/?param=aGVsbG9Xb3JsZA%3D%3D");
|
||||
String fromUri = UriComponentsBuilder.fromUri(uri).build().getQueryParams().get("param").get(0);
|
||||
String fromUriString = UriComponentsBuilder.fromUriString(uri.toString()).build().getQueryParams().get("param").get(0);
|
||||
|
||||
assertEquals(fromUri, fromUriString);
|
||||
}
|
||||
assertEquals(fromUri, fromUriString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromUriString() {
|
||||
@@ -115,42 +115,42 @@ public class UriComponentsBuilderTests {
|
||||
result = UriComponentsBuilder.fromUriString(
|
||||
"http://arjen:foobar@java.sun.com:80/javase/6/docs/api/java/util/BitSet.html?foo=bar#and(java.util.BitSet)")
|
||||
.build();
|
||||
assertEquals("http", result.getScheme());
|
||||
assertEquals("arjen:foobar", result.getUserInfo());
|
||||
assertEquals("java.sun.com", result.getHost());
|
||||
assertEquals(80, result.getPort());
|
||||
assertEquals("/javase/6/docs/api/java/util/BitSet.html", result.getPath());
|
||||
assertEquals("foo=bar", result.getQuery());
|
||||
assertEquals("http", result.getScheme());
|
||||
assertEquals("arjen:foobar", result.getUserInfo());
|
||||
assertEquals("java.sun.com", result.getHost());
|
||||
assertEquals(80, result.getPort());
|
||||
assertEquals("/javase/6/docs/api/java/util/BitSet.html", result.getPath());
|
||||
assertEquals("foo=bar", result.getQuery());
|
||||
MultiValueMap<String, String> expectedQueryParams = new LinkedMultiValueMap<String, String>(1);
|
||||
expectedQueryParams.add("foo", "bar");
|
||||
assertEquals(expectedQueryParams, result.getQueryParams());
|
||||
assertEquals("and(java.util.BitSet)", result.getFragment());
|
||||
assertEquals("and(java.util.BitSet)", result.getFragment());
|
||||
|
||||
result = UriComponentsBuilder.fromUriString("mailto:java-net@java.sun.com#baz").build();
|
||||
assertEquals("mailto", result.getScheme());
|
||||
assertNull(result.getUserInfo());
|
||||
assertNull(result.getHost());
|
||||
assertEquals(-1, result.getPort());
|
||||
assertEquals("java-net@java.sun.com", result.getSchemeSpecificPart());
|
||||
assertNull(result.getPath());
|
||||
assertNull(result.getQuery());
|
||||
assertEquals("baz", result.getFragment());
|
||||
result = UriComponentsBuilder.fromUriString("mailto:java-net@java.sun.com#baz").build();
|
||||
assertEquals("mailto", result.getScheme());
|
||||
assertNull(result.getUserInfo());
|
||||
assertNull(result.getHost());
|
||||
assertEquals(-1, result.getPort());
|
||||
assertEquals("java-net@java.sun.com", result.getSchemeSpecificPart());
|
||||
assertNull(result.getPath());
|
||||
assertNull(result.getQuery());
|
||||
assertEquals("baz", result.getFragment());
|
||||
|
||||
result = UriComponentsBuilder.fromUriString("docs/guide/collections/designfaq.html#28").build();
|
||||
assertNull(result.getScheme());
|
||||
assertNull(result.getUserInfo());
|
||||
assertNull(result.getHost());
|
||||
assertEquals(-1, result.getPort());
|
||||
assertEquals("docs/guide/collections/designfaq.html", result.getPath());
|
||||
assertNull(result.getQuery());
|
||||
assertEquals("28", result.getFragment());
|
||||
result = UriComponentsBuilder.fromUriString("docs/guide/collections/designfaq.html#28").build();
|
||||
assertNull(result.getScheme());
|
||||
assertNull(result.getUserInfo());
|
||||
assertNull(result.getHost());
|
||||
assertEquals(-1, result.getPort());
|
||||
assertEquals("docs/guide/collections/designfaq.html", result.getPath());
|
||||
assertNull(result.getQuery());
|
||||
assertEquals("28", result.getFragment());
|
||||
}
|
||||
|
||||
// SPR-9832
|
||||
|
||||
@Test
|
||||
public void fromUriStringQueryParamWithReservedCharInValue() throws URISyntaxException {
|
||||
String uri = "http://www.google.com/ig/calculator?q=1USD=?EUR";
|
||||
String uri = "http://www.google.com/ig/calculator?q=1USD=?EUR";
|
||||
UriComponents result = UriComponentsBuilder.fromUriString(uri).build();
|
||||
|
||||
assertEquals("q=1USD=?EUR", result.getQuery());
|
||||
|
||||
@@ -26,25 +26,25 @@ import static org.junit.Assert.*;
|
||||
/** @author Arjen Poutsma */
|
||||
public class UriComponentsTests {
|
||||
|
||||
@Test
|
||||
public void encode() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromPath("/hotel list").build();
|
||||
UriComponents encoded = uriComponents.encode();
|
||||
assertEquals("/hotel%20list", encoded.getPath());
|
||||
}
|
||||
@Test
|
||||
public void encode() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromPath("/hotel list").build();
|
||||
UriComponents encoded = uriComponents.encode();
|
||||
assertEquals("/hotel%20list", encoded.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toUriEncoded() throws URISyntaxException {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/hotel list/Z\u00fcrich").build();
|
||||
UriComponents encoded = uriComponents.encode();
|
||||
assertEquals(new URI("http://example.com/hotel%20list/Z%C3%BCrich"), encoded.toUri());
|
||||
}
|
||||
@Test
|
||||
public void toUriEncoded() throws URISyntaxException {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/hotel list/Z\u00fcrich").build();
|
||||
UriComponents encoded = uriComponents.encode();
|
||||
assertEquals(new URI("http://example.com/hotel%20list/Z%C3%BCrich"), encoded.toUri());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toUriNotEncoded() throws URISyntaxException {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/hotel list/Z\u00fcrich").build();
|
||||
assertEquals(new URI("http://example.com/hotel%20list/Z\u00fcrich"), uriComponents.toUri());
|
||||
}
|
||||
@Test
|
||||
public void toUriNotEncoded() throws URISyntaxException {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/hotel list/Z\u00fcrich").build();
|
||||
assertEquals(new URI("http://example.com/hotel%20list/Z\u00fcrich"), uriComponents.toUri());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expand() {
|
||||
|
||||
@@ -53,15 +53,15 @@ public class UriTemplateTests {
|
||||
template.expand("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expandMap() throws Exception {
|
||||
Map<String, String> uriVariables = new HashMap<String, String>(2);
|
||||
uriVariables.put("booking", "42");
|
||||
uriVariables.put("hotel", "1");
|
||||
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
|
||||
URI result = template.expand(uriVariables);
|
||||
assertEquals("Invalid expanded template", new URI("http://example.com/hotels/1/bookings/42"), result);
|
||||
}
|
||||
@Test
|
||||
public void expandMap() throws Exception {
|
||||
Map<String, String> uriVariables = new HashMap<String, String>(2);
|
||||
uriVariables.put("booking", "42");
|
||||
uriVariables.put("hotel", "1");
|
||||
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
|
||||
URI result = template.expand(uriVariables);
|
||||
assertEquals("Invalid expanded template", new URI("http://example.com/hotels/1/bookings/42"), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expandMapDuplicateVariables() throws Exception {
|
||||
@@ -81,13 +81,13 @@ public class UriTemplateTests {
|
||||
assertEquals("Invalid expanded template", new URI("http://example.com/hotels/1/bookings/42"), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expandMapEncoded() throws Exception {
|
||||
Map<String, String> uriVariables = Collections.singletonMap("hotel", "Z\u00fcrich");
|
||||
UriTemplate template = new UriTemplate("http://example.com/hotel list/{hotel}");
|
||||
URI result = template.expand(uriVariables);
|
||||
assertEquals("Invalid expanded template", new URI("http://example.com/hotel%20list/Z%C3%BCrich"), result);
|
||||
}
|
||||
@Test
|
||||
public void expandMapEncoded() throws Exception {
|
||||
Map<String, String> uriVariables = Collections.singletonMap("hotel", "Z\u00fcrich");
|
||||
UriTemplate template = new UriTemplate("http://example.com/hotel list/{hotel}");
|
||||
URI result = template.expand(uriVariables);
|
||||
assertEquals("Invalid expanded template", new URI("http://example.com/hotel%20list/Z%C3%BCrich"), result);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void expandMapUnboundVariables() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user