Commit f6a32a1d authored by Anand Shah's avatar Anand Shah Committed by Stephane Nicoll

Add `@LocalServerPort`

Closes gh-5262
parent a3a38c6b
...@@ -34,7 +34,6 @@ import org.junit.Test; ...@@ -34,7 +34,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.EndpointMvcIntegrationTests.Application; import org.springframework.boot.actuate.autoconfigure.EndpointMvcIntegrationTests.Application;
import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping; import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping;
...@@ -48,6 +47,7 @@ import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration; ...@@ -48,6 +47,7 @@ import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -78,7 +78,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -78,7 +78,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DirtiesContext @DirtiesContext
public class EndpointMvcIntegrationTests { public class EndpointMvcIntegrationTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
@Autowired @Autowired
......
...@@ -21,9 +21,9 @@ import java.util.Arrays; ...@@ -21,9 +21,9 @@ import java.util.Arrays;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication; import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication;
import org.springframework.boot.actuate.endpoint.mvc.HalBrowserMvcEndpointServerContextPathIntegrationTests.SpringBootHypermediaApplication; import org.springframework.boot.actuate.endpoint.mvc.HalBrowserMvcEndpointServerContextPathIntegrationTests.SpringBootHypermediaApplication;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -57,7 +57,7 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; ...@@ -57,7 +57,7 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
@DirtiesContext @DirtiesContext
public class HalBrowserMvcEndpointServerContextPathIntegrationTests { public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
@Test @Test
......
...@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati ...@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomFilterContextPathTests.Application; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomFilterContextPathTests.Application;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -62,7 +63,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -62,7 +63,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WebAppConfiguration @WebAppConfiguration
public class JerseyAutoConfigurationCustomFilterContextPathTests { public class JerseyAutoConfigurationCustomFilterContextPathTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private RestTemplate restTemplate = new TestRestTemplate(); private RestTemplate restTemplate = new TestRestTemplate();
......
...@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati ...@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomFilterPathTests.Application; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomFilterPathTests.Application;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -61,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -61,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WebAppConfiguration @WebAppConfiguration
public class JerseyAutoConfigurationCustomFilterPathTests { public class JerseyAutoConfigurationCustomFilterPathTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private RestTemplate restTemplate = new TestRestTemplate(); private RestTemplate restTemplate = new TestRestTemplate();
......
...@@ -30,13 +30,13 @@ import org.glassfish.jersey.server.ResourceConfig; ...@@ -30,13 +30,13 @@ import org.glassfish.jersey.server.ResourceConfig;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObjectMapperProviderTests.Application; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObjectMapperProviderTests.Application;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -62,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -62,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WebAppConfiguration @WebAppConfiguration
public class JerseyAutoConfigurationCustomObjectMapperProviderTests { public class JerseyAutoConfigurationCustomObjectMapperProviderTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private RestTemplate restTemplate = new TestRestTemplate(); private RestTemplate restTemplate = new TestRestTemplate();
......
...@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati ...@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletContextPathTests.Application; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletContextPathTests.Application;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -61,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -61,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WebAppConfiguration @WebAppConfiguration
public class JerseyAutoConfigurationCustomServletContextPathTests { public class JerseyAutoConfigurationCustomServletContextPathTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private RestTemplate restTemplate = new TestRestTemplate(); private RestTemplate restTemplate = new TestRestTemplate();
......
...@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati ...@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletPathTests.Application; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletPathTests.Application;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -61,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -61,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WebAppConfiguration @WebAppConfiguration
public class JerseyAutoConfigurationCustomServletPathTests { public class JerseyAutoConfigurationCustomServletPathTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private RestTemplate restTemplate = new TestRestTemplate(); private RestTemplate restTemplate = new TestRestTemplate();
......
...@@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati ...@@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefaultFilterPathTests.Application; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefaultFilterPathTests.Application;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -60,7 +61,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -60,7 +61,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WebAppConfiguration @WebAppConfiguration
public class JerseyAutoConfigurationDefaultFilterPathTests { public class JerseyAutoConfigurationDefaultFilterPathTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private RestTemplate restTemplate = new TestRestTemplate(); private RestTemplate restTemplate = new TestRestTemplate();
......
...@@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati ...@@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefaultServletPathTests.Application; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefaultServletPathTests.Application;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -60,7 +61,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -60,7 +61,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WebAppConfiguration @WebAppConfiguration
public class JerseyAutoConfigurationDefaultServletPathTests { public class JerseyAutoConfigurationDefaultServletPathTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private RestTemplate restTemplate = new TestRestTemplate(); private RestTemplate restTemplate = new TestRestTemplate();
......
...@@ -30,13 +30,13 @@ import org.glassfish.jersey.server.ResourceConfig; ...@@ -30,13 +30,13 @@ import org.glassfish.jersey.server.ResourceConfig;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObjectMapperProviderTests.Application; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObjectMapperProviderTests.Application;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -62,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -62,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WebAppConfiguration @WebAppConfiguration
public class JerseyAutoConfigurationObjectMapperProviderTests { public class JerseyAutoConfigurationObjectMapperProviderTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private RestTemplate restTemplate = new TestRestTemplate(); private RestTemplate restTemplate = new TestRestTemplate();
......
...@@ -33,6 +33,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationServ ...@@ -33,6 +33,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationServ
import org.springframework.boot.autoconfigure.test.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.test.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
...@@ -62,7 +63,7 @@ public class JerseyAutoConfigurationServletContainerTests { ...@@ -62,7 +63,7 @@ public class JerseyAutoConfigurationServletContainerTests {
@ClassRule @ClassRule
public static OutputCapture output = new OutputCapture(); public static OutputCapture output = new OutputCapture();
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
@Test @Test
......
...@@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati ...@@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletPathTests.Application; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletPathTests.Application;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
...@@ -60,7 +61,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -60,7 +61,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WebAppConfiguration @WebAppConfiguration
public class JerseyAutoConfigurationWithoutApplicationPathTests { public class JerseyAutoConfigurationWithoutApplicationPathTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private RestTemplate restTemplate = new TestRestTemplate(); private RestTemplate restTemplate = new TestRestTemplate();
......
...@@ -24,7 +24,6 @@ import org.junit.Test; ...@@ -24,7 +24,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServicesRefreshTokenTests.Application; import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServicesRefreshTokenTests.Application;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
...@@ -32,6 +31,7 @@ import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoCo ...@@ -32,6 +31,7 @@ import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoCo
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest; import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -71,7 +71,7 @@ public class UserInfoTokenServicesRefreshTokenTests { ...@@ -71,7 +71,7 @@ public class UserInfoTokenServicesRefreshTokenTests {
@Rule @Rule
public ExpectedException expected = ExpectedException.none(); public ExpectedException expected = ExpectedException.none();
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private UserInfoTokenServices services; private UserInfoTokenServices services;
......
...@@ -19,9 +19,9 @@ package org.springframework.boot.autoconfigure.web; ...@@ -19,9 +19,9 @@ package org.springframework.boot.autoconfigure.web;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.web.RemappedErrorViewIntegrationTests.TestConfiguration; import org.springframework.boot.autoconfigure.web.RemappedErrorViewIntegrationTests.TestConfiguration;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
...@@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DirtiesContext @DirtiesContext
public class RemappedErrorViewIntegrationTests { public class RemappedErrorViewIntegrationTests {
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
private RestTemplate template = new TestRestTemplate(); private RestTemplate template = new TestRestTemplate();
......
...@@ -23,6 +23,7 @@ import org.junit.runner.RunWith; ...@@ -23,6 +23,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.test.SpringApplicationIntegrationTestTests.Config; import org.springframework.boot.test.SpringApplicationIntegrationTestTests.Config;
...@@ -54,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -54,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@IntegrationTest({ "server.port=0", "value=123" }) @IntegrationTest({ "server.port=0", "value=123" })
public class SpringApplicationIntegrationTestTests { public class SpringApplicationIntegrationTestTests {
@Value("${local.server.port}") @LocalServerPort
private int port = 0; private int port = 0;
@Value("${value}") @Value("${value}")
......
...@@ -23,6 +23,7 @@ import org.junit.runner.RunWith; ...@@ -23,6 +23,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.bind.LocalServerPort;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.test.SpringApplicationWebIntegrationTestTests.Config; import org.springframework.boot.test.SpringApplicationWebIntegrationTestTests.Config;
...@@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WebIntegrationTest({ "server.port=0", "value=123" }) @WebIntegrationTest({ "server.port=0", "value=123" })
public class SpringApplicationWebIntegrationTestTests { public class SpringApplicationWebIntegrationTestTests {
@Value("${local.server.port}") @LocalServerPort
private int port = 0; private int port = 0;
@Value("${value}") @Value("${value}")
......
/*
* Copyright 2012-2016 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.bind;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.springframework.beans.factory.annotation.Value;
/**
* Meta annotation for replacement of property local.server.port. Can be used instead of
* <code>@Value("${local.server.port}")</code>
*
* @author Anand Shah
*/
@Value("${local.server.port}")
@Retention(RetentionPolicy.RUNTIME)
public @interface LocalServerPort {
}
/*
* Copyright 2012-2016 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.bind;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.bind.PropertySourcesBindingTests.TestConfig;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link LocalServerPort} annotation based injection of local.server.port
* property.
*
* @author Anand Shah
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = TestConfig.class)
public class LocalServerPortTests {
private ConfigurableApplicationContext context;
@Value("${local.server.port:}")
private String localServerPortFromValue;
@LocalServerPort
private String localServerPortFromAnnotation;
@Test
public void testLocalServerPortAnnotation() {
SpringApplication application = new SpringApplication(LocalServerPortTests.class);
application.setWebEnvironment(true);
this.context = application.run();
assertThat(this.localServerPortFromAnnotation).isNotNull().isNotEmpty()
.isEqualTo(this.localServerPortFromValue).isEqualTo(
this.context.getEnvironment().getProperty("local.server.port"));
}
@Bean
public JettyEmbeddedServletContainerFactory container() {
return new JettyEmbeddedServletContainerFactory(8081);
}
}
...@@ -2,3 +2,4 @@ foo=spam ...@@ -2,3 +2,4 @@ foo=spam
bar=some bar=some
spam=bucket spam=bucket
the-name=name the-name=name
local.server.port=8081
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment