Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
576d5dd5
Commit
576d5dd5
authored
Dec 28, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
ad3b767b
25bd0e04
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
130 additions
and
3 deletions
+130
-3
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+2
-2
SpringBootContextLoader.java
...gframework/boot/test/context/SpringBootContextLoader.java
+17
-1
SpringBootTestCustomPortTests.java
...work/boot/test/context/SpringBootTestCustomPortTests.java
+53
-0
SpringBootTestWebEnvironmentRandomPortCustomPortTests.java
...pringBootTestWebEnvironmentRandomPortCustomPortTests.java
+58
-0
No files found.
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
576d5dd5
...
...
@@ -1806,11 +1806,11 @@ Spring decides not to handle it. Most of the time this will not happen (unless y
the default MVC configuration) because Spring will always be able to handle requests
through the `DispatcherServlet`.
By default, resources are mapped on `/**` but you can tune that via
By default, resources are mapped on `+/**+` but you can tune that via
`spring.mvc.static-path-pattern`. For instance, relocating all resources to `/resources/**`
can be achieved as follows:
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
----
spring.mvc.static-path-pattern=/resources/**
----
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java
View file @
576d5dd5
...
...
@@ -21,10 +21,12 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.test.mock.web.SpringBootMockServletContext
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.boot.web.support.ServletContextApplicationContextInitializer
;
...
...
@@ -34,6 +36,9 @@ import org.springframework.context.ConfigurableApplicationContext;
import
org.springframework.core.SpringVersion
;
import
org.springframework.core.annotation.AnnotatedElementUtils
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.MutablePropertySources
;
import
org.springframework.core.env.PropertySourcesPropertyResolver
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
org.springframework.test.context.ContextConfigurationAttributes
;
...
...
@@ -65,6 +70,7 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
* @author Dave Syer
* @author Phillip Webb
* @author Andy Wilkinson
* @author Stephane Nicoll
* @see SpringBootTest
*/
public
class
SpringBootContextLoader
extends
AbstractContextLoader
{
...
...
@@ -143,7 +149,7 @@ public class SpringBootContextLoader extends AbstractContextLoader {
// JMX bean names will clash if the same bean is used in multiple contexts
disableJmx
(
properties
);
properties
.
addAll
(
Arrays
.
asList
(
config
.
getPropertySourceProperties
()));
if
(!
isEmbeddedWebEnvironment
(
config
))
{
if
(!
isEmbeddedWebEnvironment
(
config
)
&&
!
hasCustomServerPort
(
properties
)
)
{
properties
.
add
(
"server.port=-1"
);
}
return
properties
.
toArray
(
new
String
[
properties
.
size
()]);
...
...
@@ -153,6 +159,16 @@ public class SpringBootContextLoader extends AbstractContextLoader {
properties
.
add
(
"spring.jmx.enabled=false"
);
}
private
boolean
hasCustomServerPort
(
List
<
String
>
properties
)
{
Map
<
String
,
Object
>
props
=
TestPropertySourceUtils
.
convertInlinedPropertiesToMap
(
properties
.
toArray
(
new
String
[
properties
.
size
()]));
MutablePropertySources
sources
=
new
MutablePropertySources
();
sources
.
addFirst
(
new
MapPropertySource
(
"inline"
,
props
));
RelaxedPropertyResolver
resolver
=
new
RelaxedPropertyResolver
(
new
PropertySourcesPropertyResolver
(
sources
),
"server."
);
return
resolver
.
containsProperty
(
"port"
);
}
private
List
<
ApplicationContextInitializer
<?>>
getInitializers
(
MergedContextConfiguration
config
,
SpringApplication
application
)
{
List
<
ApplicationContextInitializer
<?>>
initializers
=
new
ArrayList
<
ApplicationContextInitializer
<?>>();
...
...
spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestCustomPortTests.java
0 → 100644
View file @
576d5dd5
/*
* 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
.
test
.
context
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.Environment
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Test for {@link SpringBootTest} with a custom inline server.port in a non-embedded
* web environment.
*
* @author Stephane Nicoll
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
properties
=
"server.port=12345"
)
public
class
SpringBootTestCustomPortTests
{
@Autowired
private
Environment
environment
;
@Test
public
void
validatePortIsNotOverwritten
()
{
String
port
=
this
.
environment
.
getProperty
(
"server.port"
);
assertThat
(
port
).
isEqualTo
(
"12345"
);
}
@Configuration
protected
static
class
Config
{
}
}
spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java
0 → 100644
View file @
576d5dd5
/*
* 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
.
test
.
context
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.AbstractSpringBootTestEmbeddedWebEnvironmentTests.AbstractConfig
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.Environment
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Test for {@link SpringBootTest} with a custom inline server.port in an embedded web
* environment.
*
* @author Stephane Nicoll
*/
@RunWith
(
SpringRunner
.
class
)
@DirtiesContext
@SpringBootTest
(
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"server.port=12345"
})
public
class
SpringBootTestWebEnvironmentRandomPortCustomPortTests
{
@Autowired
private
Environment
environment
;
@Test
public
void
validatePortIsNotOverwritten
()
{
String
port
=
this
.
environment
.
getProperty
(
"server.port"
);
assertThat
(
port
).
isEqualTo
(
"0"
);
}
@Configuration
@EnableWebMvc
protected
static
class
Config
extends
AbstractConfig
{
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment