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
5e8f3839
Commit
5e8f3839
authored
Apr 26, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract code samples from docs
See gh-6313
parent
6de10ff7
Changes
27
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
902 additions
and
199 deletions
+902
-199
build.gradle
spring-boot-project/spring-boot-docs/build.gradle
+4
-0
spring-boot-features.adoc
...ing-boot-docs/src/docs/asciidoc/spring-boot-features.adoc
+45
-199
MyAutoConfiguration.java
...autoconfiguration/beanconditions/MyAutoConfiguration.java
+32
-0
SomeService.java
...creatingautoconfiguration/beanconditions/SomeService.java
+21
-0
MyAutoConfiguration.java
...utoconfiguration/classconditions/MyAutoConfiguration.java
+42
-0
SomeService.java
...reatingautoconfiguration/classconditions/SomeService.java
+21
-0
AcmeProperties.java
...ngautoconfiguration/configurationkeys/AcmeProperties.java
+54
-0
ConditionEvaluationReportTests.java
...gbootfeatures/testing/ConditionEvaluationReportTests.java
+38
-0
CustomizationConfiguration.java
...applications/restdocs/mvc/CustomizationConfiguration.java
+32
-0
ResultHandlerConfiguration.java
...applications/restdocs/mvc/ResultHandlerConfiguration.java
+32
-0
UserDocumentationTests.java
...ing/applications/restdocs/mvc/UserDocumentationTests.java
+52
-0
BatchConfiguration.java
...ures/testing/applications/slicing/BatchConfiguration.java
+28
-0
ExampleJdbcTests.java
...atures/testing/applications/slicing/ExampleJdbcTests.java
+27
-0
SampleApplication.java
...tures/testing/applications/slicing/SampleApplication.java
+28
-0
TestWebMvcConfigurer.java
...es/testing/applications/slicing/TestWebMvcConfigurer.java
+27
-0
WebConfiguration.java
...atures/testing/applications/slicing/WebConfiguration.java
+33
-0
SampleApplication.java
.../testing/applications/slicing/scan/SampleApplication.java
+28
-0
MyWebServiceClientTests.java
...ing/applications/webservices/MyWebServiceClientTests.java
+51
-0
Request.java
...ootfeatures/testing/applications/webservices/Request.java
+24
-0
Response.java
...otfeatures/testing/applications/webservices/Response.java
+33
-0
SomeWebService.java
...ures/testing/applications/webservices/SomeWebService.java
+36
-0
MyConfigFileTests.java
...s/springbootfeatures/testing/utils/MyConfigFileTests.java
+32
-0
MyEnvironmentTests.java
.../springbootfeatures/testing/utils/MyEnvironmentTests.java
+37
-0
MyTest.java
...ngbootfeatures/testing/utils/testresttemplate/MyTest.java
+36
-0
MyService.java
...k/boot/docs/springbootfeatures/webservices/MyService.java
+47
-0
MyWebServiceTemplateConfiguration.java
...atures/webservices/MyWebServiceTemplateConfiguration.java
+42
-0
package-info.java
...oot/docs/springbootfeatures/webservices/package-info.java
+20
-0
No files found.
spring-boot-project/spring-boot-docs/build.gradle
View file @
5e8f3839
...
...
@@ -97,6 +97,7 @@ dependencies {
implementation
(
"org.springframework:spring-webflux"
)
implementation
(
"org.springframework.amqp:spring-amqp"
)
implementation
(
"org.springframework.amqp:spring-rabbit"
)
implementation
(
"org.springframework.batch:spring-batch-core"
)
implementation
(
"org.springframework.data:spring-data-cassandra"
)
implementation
(
"org.springframework.data:spring-data-couchbase"
)
implementation
(
"org.springframework.data:spring-data-elasticsearch"
)
...
...
@@ -107,11 +108,14 @@ dependencies {
implementation
(
"org.springframework.data:spring-data-r2dbc"
)
implementation
(
"org.springframework.kafka:spring-kafka"
)
implementation
(
"org.springframework.kafka:spring-kafka-test"
)
implementation
(
"org.springframework.restdocs:spring-restdocs-mockmvc"
)
implementation
(
"org.springframework.restdocs:spring-restdocs-restassured"
)
implementation
(
"org.springframework.restdocs:spring-restdocs-webtestclient"
)
implementation
(
"org.springframework.security:spring-security-config"
)
implementation
(
"org.springframework.security:spring-security-oauth2-client"
)
implementation
(
"org.springframework.security:spring-security-web"
)
implementation
(
"org.springframework.ws:spring-ws-core"
)
implementation
(
"org.springframework.ws:spring-ws-test"
)
implementation
(
"org.junit.jupiter:junit-jupiter"
)
implementation
(
"org.yaml:snakeyaml"
)
...
...
spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc
View file @
5e8f3839
This diff is collapsed.
Click to expand it.
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/beanconditions/MyAutoConfiguration.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
creatingautoconfiguration
.
beanconditions
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
(
proxyBeanMethods
=
false
)
public
class
MyAutoConfiguration
{
@Bean
@ConditionalOnMissingBean
public
SomeService
someService
()
{
return
new
SomeService
();
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/beanconditions/SomeService.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
creatingautoconfiguration
.
beanconditions
;
public
class
SomeService
{
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/classconditions/MyAutoConfiguration.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
creatingautoconfiguration
.
classconditions
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
(
proxyBeanMethods
=
false
)
// Some conditions ...
public
class
MyAutoConfiguration
{
// Auto-configured beans ...
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
(
SomeService
.
class
)
public
static
class
SomeServiceConfiguration
{
@Bean
@ConditionalOnMissingBean
public
SomeService
someService
()
{
return
new
SomeService
();
}
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/classconditions/SomeService.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
creatingautoconfiguration
.
classconditions
;
class
SomeService
{
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/configurationkeys/AcmeProperties.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
creatingautoconfiguration
.
configurationkeys
;
import
java.time.Duration
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
@ConfigurationProperties
(
"acme"
)
public
class
AcmeProperties
{
/**
* Whether to check the location of acme resources.
*/
private
boolean
checkLocation
=
true
;
/**
* Timeout for establishing a connection to the acme server.
*/
private
Duration
loginTimeout
=
Duration
.
ofSeconds
(
3
);
// @fold:on // getters/setters ...
public
boolean
isCheckLocation
()
{
return
this
.
checkLocation
;
}
public
void
setCheckLocation
(
boolean
checkLocation
)
{
this
.
checkLocation
=
checkLocation
;
}
public
Duration
getLoginTimeout
()
{
return
this
.
loginTimeout
;
}
public
void
setLoginTimeout
(
Duration
loginTimeout
)
{
this
.
loginTimeout
=
loginTimeout
;
}
// @fold:off
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/ConditionEvaluationReportTests.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener
;
import
org.springframework.boot.logging.LogLevel
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
public
class
ConditionEvaluationReportTests
{
// start::code[]
@Test
void
autoConfigTest
()
{
ConditionEvaluationReportLoggingListener
initializer
=
new
ConditionEvaluationReportLoggingListener
(
LogLevel
.
INFO
);
new
ApplicationContextRunner
().
withInitializer
(
initializer
).
run
((
context
)
->
{
// Test something...
});
}
// end::code[]
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/restdocs/mvc/CustomizationConfiguration.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
restdocs
.
mvc
;
import
org.springframework.boot.test.autoconfigure.restdocs.RestDocsMockMvcConfigurationCustomizer
;
import
org.springframework.boot.test.context.TestConfiguration
;
import
org.springframework.restdocs.mockmvc.MockMvcRestDocumentationConfigurer
;
import
org.springframework.restdocs.templates.TemplateFormats
;
@TestConfiguration
public
class
CustomizationConfiguration
implements
RestDocsMockMvcConfigurationCustomizer
{
@Override
public
void
customize
(
MockMvcRestDocumentationConfigurer
configurer
)
{
configurer
.
snippets
().
withTemplateFormat
(
TemplateFormats
.
markdown
());
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/restdocs/mvc/ResultHandlerConfiguration.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
restdocs
.
mvc
;
import
org.springframework.boot.test.context.TestConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.restdocs.mockmvc.MockMvcRestDocumentation
;
import
org.springframework.restdocs.mockmvc.RestDocumentationResultHandler
;
@TestConfiguration
(
proxyBeanMethods
=
false
)
public
class
ResultHandlerConfiguration
{
@Bean
public
RestDocumentationResultHandler
restDocumentation
()
{
return
MockMvcRestDocumentation
.
document
(
"{method-name}"
);
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/restdocs/mvc/UserDocumentationTests.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
restdocs
.
mvc
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
;
import
org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
MockMvcRestDocumentation
.
document
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
@WebMvcTest
(
UserController
.
class
)
@AutoConfigureRestDocs
class
UserDocumentationTests
{
@Autowired
private
MockMvc
mvc
;
@Test
void
listUsers
()
throws
Exception
{
// @formatter:off
this
.
mvc
.
perform
(
get
(
"/users"
).
accept
(
MediaType
.
TEXT_PLAIN
))
.
andExpect
(
status
().
isOk
())
.
andDo
(
document
(
"list-users"
));
// @formatter:on
}
}
// @chomp:file
class
UserController
{
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/slicing/BatchConfiguration.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
slicing
;
import
org.springframework.batch.core.configuration.annotation.EnableBatchProcessing
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
(
proxyBeanMethods
=
false
)
@EnableBatchProcessing
public
class
BatchConfiguration
{
// ...
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/slicing/ExampleJdbcTests.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
slicing
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
import
org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration
;
import
org.springframework.boot.test.autoconfigure.jdbc.JdbcTest
;
@JdbcTest
@ImportAutoConfiguration
(
IntegrationAutoConfiguration
.
class
)
class
ExampleJdbcTests
{
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/slicing/SampleApplication.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
slicing
;
import
org.springframework.batch.core.configuration.annotation.EnableBatchProcessing
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
@EnableBatchProcessing
public
class
SampleApplication
{
// ...
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/slicing/TestWebMvcConfigurer.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
slicing
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
@Component
public
class
TestWebMvcConfigurer
implements
WebMvcConfigurer
{
// ...
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/slicing/WebConfiguration.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
slicing
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
@Configuration
public
class
WebConfiguration
{
@Bean
public
WebMvcConfigurer
testConfigurer
()
{
return
new
WebMvcConfigurer
()
{
// ...
};
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/slicing/scan/SampleApplication.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
slicing
.
scan
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.ComponentScan
;
@SpringBootApplication
@ComponentScan
({
"com.example.app"
,
"org.acme.another"
})
public
class
SampleApplication
{
// ...
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/webservices/MyWebServiceClientTests.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
webservices
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.webservices.client.WebServiceClientTest
;
import
org.springframework.ws.test.client.MockWebServiceServer
;
import
org.springframework.xml.transform.StringSource
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
springframework
.
ws
.
test
.
client
.
RequestMatchers
.
payload
;
import
static
org
.
springframework
.
ws
.
test
.
client
.
ResponseCreators
.
withPayload
;
@WebServiceClientTest
(
SomeWebService
.
class
)
class
MyWebServiceClientTests
{
@Autowired
private
MockWebServiceServer
server
;
@Autowired
private
SomeWebService
someWebService
;
@Test
void
mockServerCall
()
{
// @formatter:off
this
.
server
.
expect
(
payload
(
new
StringSource
(
"<request/>"
)))
.
andRespond
(
withPayload
(
new
StringSource
(
"<response><status>200</status></response>"
)));
assertThat
(
this
.
someWebService
.
test
())
.
extracting
(
Response:
:
getStatus
)
.
isEqualTo
(
200
);
// @formatter:on
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/webservices/Request.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
webservices
;
import
javax.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
(
name
=
"request"
)
class
Request
{
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/webservices/Response.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
webservices
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
(
name
=
"response"
)
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
class
Response
{
private
int
status
;
int
getStatus
()
{
return
this
.
status
;
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/applications/webservices/SomeWebService.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2020 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
applications
.
webservices
;
import
org.springframework.boot.webservices.client.WebServiceTemplateBuilder
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ws.client.core.WebServiceTemplate
;
@Service
public
class
SomeWebService
{
private
final
WebServiceTemplate
webServiceTemplate
;
public
SomeWebService
(
WebServiceTemplateBuilder
builder
)
{
this
.
webServiceTemplate
=
builder
.
build
();
}
public
Response
test
()
{
return
(
Response
)
this
.
webServiceTemplate
.
marshalSendAndReceive
(
"https://example.com"
,
new
Request
());
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/utils/MyConfigFileTests.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
utils
;
import
org.springframework.boot.test.context.ConfigDataApplicationContextInitializer
;
import
org.springframework.test.context.ContextConfiguration
;
@ContextConfiguration
(
classes
=
Config
.
class
,
initializers
=
ConfigDataApplicationContextInitializer
.
class
)
class
MyConfigFileTests
{
// ...
}
// @chomp:file
class
Config
{
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/utils/MyEnvironmentTests.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
utils
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.mock.env.MockEnvironment
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
class
MyEnvironmentTests
{
// start::code[]
@Test
void
testPropertySources
()
{
MockEnvironment
environment
=
new
MockEnvironment
();
TestPropertyValues
.
of
(
"org=Spring"
,
"name=Boot"
).
applyTo
(
environment
);
assertThat
(
environment
.
getProperty
(
"name"
)).
isEqualTo
(
"Boot"
);
}
// end::code[]
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/utils/testresttemplate/MyTest.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
testing
.
utils
.
testresttemplate
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.http.ResponseEntity
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
class
MyTest
{
private
TestRestTemplate
template
=
new
TestRestTemplate
();
@Test
void
testRequest
()
throws
Exception
{
ResponseEntity
<
String
>
headers
=
this
.
template
.
getForEntity
(
"https://myhost.example.com/example"
,
String
.
class
);
assertThat
(
headers
.
getHeaders
().
getLocation
()).
hasHost
(
"other.example.com"
);
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webservices/MyService.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
webservices
;
import
org.springframework.boot.webservices.client.WebServiceTemplateBuilder
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ws.client.core.WebServiceTemplate
;
import
org.springframework.ws.soap.client.core.SoapActionCallback
;
@Service
public
class
MyService
{
private
final
WebServiceTemplate
webServiceTemplate
;
public
MyService
(
WebServiceTemplateBuilder
webServiceTemplateBuilder
)
{
this
.
webServiceTemplate
=
webServiceTemplateBuilder
.
build
();
}
public
SomeResponse
someWsCall
(
SomeRequest
detailsReq
)
{
return
(
SomeResponse
)
this
.
webServiceTemplate
.
marshalSendAndReceive
(
detailsReq
,
new
SoapActionCallback
(
"https://ws.example.com/action"
));
}
}
// @chomp:file
class
SomeRequest
{
}
class
SomeResponse
{
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webservices/MyWebServiceTemplateConfiguration.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
springbootfeatures
.
webservices
;
import
java.time.Duration
;
import
org.springframework.boot.webservices.client.HttpWebServiceMessageSenderBuilder
;
import
org.springframework.boot.webservices.client.WebServiceTemplateBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.ws.client.core.WebServiceTemplate
;
import
org.springframework.ws.transport.WebServiceMessageSender
;
@Configuration
(
proxyBeanMethods
=
false
)
public
class
MyWebServiceTemplateConfiguration
{
@Bean
public
WebServiceTemplate
webServiceTemplate
(
WebServiceTemplateBuilder
builder
)
{
// @formatter:off
WebServiceMessageSender
sender
=
new
HttpWebServiceMessageSenderBuilder
()
.
setConnectTimeout
(
Duration
.
ofSeconds
(
5
))
.
setReadTimeout
(
Duration
.
ofSeconds
(
2
))
.
build
();
return
builder
.
messageSenders
(
sender
).
build
();
// @formatter:on
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webservices/package-info.java
0 → 100644
View file @
5e8f3839
/*
* Copyright 2012-2021 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
*
* https://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.
*/
/**
* Examples for the "Spring Boot Features - Web Services" section.
*/
package
org
.
springframework
.
boot
.
docs
.
springbootfeatures
.
webservices
;
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