Commit Graph

21 Commits

Author SHA1 Message Date
Phillip Webb
d442bfbeff Polish 2023-04-10 16:22:11 -07:00
Phillip Webb
7f5785182d Switch @SpringBootTest to UseMainMethod.NEVER by default
See gh-22405
2022-09-15 12:37:26 -07:00
Phillip Webb
41e0bbf4bb Add SpringBootTest.useMainMethod support
Add a new `useMainMethod` attribute to `SpringBootTest` which can be
used to determine how the test should run. The three available options
are:

	- `ALWAYS`
	- `NEVER`
	- `WHEN_AVAILABLE`

The default is `WHEN_AVAILABLE` which will attempt to launch the test
using the `main` method if there is one.

The `SpringBootContextLoader` has been updated to use the new
`SpringApplicationHook` interface when the main method is being used.

Closes gh-22405
2022-09-14 22:37:37 -07:00
Vedran Pavic
95e0d6c0f7 Update smoke tests to avoid conflicts with NAME environment variable
This commit updates several smoke tests in order to avoid conflicts
with NAME environment variable that is present in WSL and causes
project build to fail. Previous attempt to fix this in 7da42d71 was
incomplete.

See gh-31267
2022-06-08 11:34:19 +01:00
Andy Wilkinson
f6d24dc1a8 Fix typos
See gh-30773
2022-05-03 14:09:37 +01:00
Andy Wilkinson
8f1b8622ba Ensure that webEnvironment=NONE creates non-web context
Previously, if spring.main.web-application-type was configured in
application.properties to servlet or reactive, setting
webEnvironment=NONE on @SpringBootTest would not work correctly and
a servlet or reactive web application context would be created
based on the value of spring.main.web-application-type.

This commit updates the test context bootstapper to set
spring.main.web-application-type to none when webEnvironment has been
set to none. This is done in the merged context configuration's
property source properties which are applied to the environment in a
high-precedence test property source that will override configuration
in application.properties.

Closes gh-29695
2022-04-14 14:44:30 +01:00
Andy Wilkinson
4bcb7e2f77 Prevent ActiveProfilesTests from binding to 8080
Due to gh-29695, smoketest.profile.ActiveProfilesTests starts a web
server bound to the default port (8080) despite the test setting
`webEnvironment` to `NONE`.

This commit works around the problem by running the tests with
server.port set to zero.

Closes gh-30086
2022-03-07 14:55:00 +00:00
Phillip Webb
3f7bf7d34f Modify SpringApplication Environment rather than setting it
Update `SpringBootContextLoader` so that when possible the
`SpringApplication` remains in control of creating the `Environment`
instance.

Prior to this commit, we would always create the `Environment` in the
`SpringBootContextLoader` and then call `setEnvironment` on the
`SpringApplication`. This meant that the `ApplicationEnvironment`
classes were not used and that `isCustomEnvironment` was set to `true`
so no conversion was applied.

With the updated code, an `ApplicationListener` is used to mutate the
`Environment` instance and add the required test property sources.

Fixes gh-29169
2022-01-14 13:47:22 -08:00
Phillip Webb
eb6b48fff0 Use side-effect free environment with tests rather than converting
Refine the logic introduced in 64270eca to use a side-effect free
Environment implementation rather than converting the Environment early.

Early conversion can cause condition evaluation issues if
`src/test/resources/application.properties` files are bound to the
`SpringApplication`. Specifically the `spring.main.web-application-type`
property can change the `Environment` type which must happen before
conditions are evaluated.

Fixes gh-29169
2022-01-12 14:21:52 -08:00
Madhura Bhave
64270eca51 Convert environment used by SpringBootTestContextLoader
This commit aligns `SpringBootTest`s to also use `ApplicationEnvironment`
instead of `StandardEnvironment`. This prevents the side-effect of active
profiles from `@ActiveProfiles` from being added to the environment when
doGetActiveProfiles is called. In this case, calling `addActiveProfiles()`
in the environment post processor would result in `@ActiveProfiles` being
added to the environment first, resulting in the wrong order.

The additional call to `setActiveProfiles()` is also not necessary when using
ApplicationEnvironment because that call was put in place to prevent the side-effect
which `ApplicationEnvironment` does not have.

Fixes gh-28530
2021-11-17 16:40:53 -08:00
Andy Wilkinson
788a42d694 Merge branch '2.3.x' into 2.4.x
See gh-25076
2021-02-02 15:12:27 +00:00
Andy Wilkinson
67479b6380 Add junit-platform-launcher dependency by convention
Closes gh-25074
2021-02-02 13:03:21 +00:00
Phillip Webb
257608a3a3 Merge branch '2.3.x' into 2.4.x
Closes gh-25076
2021-02-01 16:03:43 -08:00
Phillip Webb
939b5dfc26 Add junit-platform-launcher dependency
Update `build.gradle` files to ensure that `junit-platform-launcher` is
a `testRuntimeOnly` dependency. This ensures that tests can be run from
Eclipse.

Closes gh-25074
2021-02-01 15:31:28 -08:00
Phillip Webb
3352024b1c Provide ConfigFileApplicationListener replacement
Deprecate `ConfigFileApplicationListener` and provide a replacement
mechanism that supports arbitrary config data imports.

This commit updates the following areas:

- Extract `EnvironmentPostProcessor` invocation logic from the
  `ConfigFileApplicationListener` to new dedicated listener. Also
  providing support for `Log` injection.

- Extract `RandomPropertySource` adding logic from the
  `ConfigFileApplicationListener` to a dedicated class.

- Migrate to the recently introduced `DefaultPropertiesPropertySource`
  class when moving the defaultProperties `PropertySource`

- Replace processing logic with a phased approach to ensure that
  profile enablement happens in a distinct phase and that profiles
  can no longer be activated on an ad-hoc basis.

- Provide a more predictable and logical import order for processing
  `application.properties` and `application.yml` files.

- Add support for a `spring.config.import` property which can be used
  to import additional config data. Also provide a pluggable API
  allowing third-parties to resolve and load locations themselves.

- Add `spring.config.activate.on-profile` support which replaces the
  existing `spring.profiles` property.

- Add `spring.config.activate.on-cloud-platform` support which allows
  a config data document to be active only on a given cloud platform.

- Support a `spring.config.use-legacy-processing` property allowing the
  previous processing logic to be used.

Closes gh-22497

Co-authored-by: Madhura Bhave <mbhave@vmware.com>
2020-07-22 21:02:32 -07:00
Phillip Webb
e0013454b5 Use parentheses when declaring dependencies
Update all dependencies declarations to use the form `scope(reference)`
rather than `scope reference`.

Prior to this commit we declared dependencies without parentheses unless
we were forced to add them due to an `exclude`.
2020-01-22 16:02:38 -08:00
Phillip Webb
0209cd3e4c Polish quote form used in Gradle scripts
Replace Gradle single quote strings with the double quote form
whenever possible. The change helps to being consistency to the
dependencies section where mostly single quotes were used, but
occasionally double quotes were required due to `${}` references.
2020-01-22 15:49:52 -08:00
Andy Wilkinson
ce99db1902 Port the build to Gradle
Closes gh-19609
Closes gh-19608
2020-01-10 14:15:35 +00:00
Stephane Nicoll
4d21efcc0a Remove outdated comment in smoke tests
Closes gh-17741
2019-08-01 10:36:08 +02:00
Phillip Webb
c3816bfe7b Polish output capture names 2019-07-15 00:24:18 +01:00
Madhura Bhave
d9466f5659 Move smoke tests under spring-boot-test
See gh-17393
2019-07-02 15:55:58 -07:00