diff --git a/spring-boot-testing/pom.xml b/spring-boot-testing/pom.xml index 2a498e54c5..dd40789604 100644 --- a/spring-boot-testing/pom.xml +++ b/spring-boot-testing/pom.xml @@ -23,6 +23,10 @@ org.springframework.boot spring-boot-starter-tomcat + + org.springframework.boot + spring-boot-starter-security + org.springframework.boot spring-boot-starter-test @@ -43,6 +47,13 @@ ${spock.version} test + + + io.rest-assured + rest-assured + test + + @@ -99,13 +110,23 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IntegrationTest.java + + + + - autoconfiguration + integration @@ -118,13 +139,8 @@ test - - **/*LiveTest.java - **/*IntegrationTest.java - **/*IntTest.java - - **/AutoconfigurationTest.java + **/*IntegrationTest.java @@ -142,7 +158,7 @@ - org.baeldung.boot.Application + com.baeldung.boot.Application 2.2.4 1.2-groovy-2.4 diff --git a/spring-boot-testing/src/main/java/com/baeldung/boot/SecurityConfig.java b/spring-boot-testing/src/main/java/com/baeldung/boot/SecurityConfig.java new file mode 100644 index 0000000000..61e86d01c5 --- /dev/null +++ b/spring-boot-testing/src/main/java/com/baeldung/boot/SecurityConfig.java @@ -0,0 +1,32 @@ +//package com.baeldung.boot; +// +//import org.springframework.context.annotation.Configuration; +//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +//import org.springframework.security.config.annotation.web.builders.HttpSecurity; +//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +// +// +//@Configuration +//@EnableWebSecurity +//public class SecurityConfig extends WebSecurityConfigurerAdapter { +// +// @Override +// protected void configure(AuthenticationManagerBuilder auth) throws Exception { +// auth.inMemoryAuthentication() +// .withUser("john") +// .password("{noop}123") +// .roles("USER"); +// } +// +// @Override +// protected void configure(HttpSecurity http) throws Exception { +// http.authorizeRequests() +// .antMatchers("/hello") +// .permitAll() +// .anyRequest() +// .authenticated() +// .and() +// .httpBasic(); +// } +//} \ No newline at end of file diff --git a/spring-boot-testing/src/main/java/com/baeldung/boot/controller/rest/HomeController.java b/spring-boot-testing/src/main/java/com/baeldung/boot/controller/rest/HomeController.java new file mode 100644 index 0000000000..595c34254b --- /dev/null +++ b/spring-boot-testing/src/main/java/com/baeldung/boot/controller/rest/HomeController.java @@ -0,0 +1,14 @@ +package com.baeldung.boot.controller.rest; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HomeController { + + @GetMapping("/") + public String salutation() { + return "Welcome !"; + } + +} \ No newline at end of file diff --git a/spring-boot-testing/src/main/resources/application.properties b/spring-boot-testing/src/main/resources/application.properties new file mode 100644 index 0000000000..e378aacdd5 --- /dev/null +++ b/spring-boot-testing/src/main/resources/application.properties @@ -0,0 +1,4 @@ + +# security +spring.security.user.name=john +spring.security.user.password=123 \ No newline at end of file diff --git a/spring-boot-testing/src/test/groovy/com/baeldung/boot/LoadContextTest.groovy b/spring-boot-testing/src/test/groovy/com/baeldung/boot/LoadContextIntegrationTest.groovy similarity index 91% rename from spring-boot-testing/src/test/groovy/com/baeldung/boot/LoadContextTest.groovy rename to spring-boot-testing/src/test/groovy/com/baeldung/boot/LoadContextIntegrationTest.groovy index 85b0a4b89b..8bfc86685c 100644 --- a/spring-boot-testing/src/test/groovy/com/baeldung/boot/LoadContextTest.groovy +++ b/spring-boot-testing/src/test/groovy/com/baeldung/boot/LoadContextIntegrationTest.groovy @@ -10,7 +10,7 @@ import spock.lang.Title @Title("Application Specification") @Narrative("Specification which beans are expected") @SpringBootTest -class LoadContextTest extends Specification { +class LoadContextIntegrationTest extends Specification { @Autowired(required = false) private WebController webController diff --git a/spring-boot-testing/src/test/groovy/com/baeldung/boot/WebControllerTest.groovy b/spring-boot-testing/src/test/groovy/com/baeldung/boot/WebControllerIntegrationTest.groovy similarity index 94% rename from spring-boot-testing/src/test/groovy/com/baeldung/boot/WebControllerTest.groovy rename to spring-boot-testing/src/test/groovy/com/baeldung/boot/WebControllerIntegrationTest.groovy index 119992acc3..17c60376ed 100644 --- a/spring-boot-testing/src/test/groovy/com/baeldung/boot/WebControllerTest.groovy +++ b/spring-boot-testing/src/test/groovy/com/baeldung/boot/WebControllerIntegrationTest.groovy @@ -12,9 +12,9 @@ import spock.lang.Title @Title("WebController Specification") @Narrative("The Specification of the behaviour of the WebController. It can greet a person, change the name and reset it to 'world'") -@AutoConfigureMockMvc -@WebMvcTest -class WebControllerTest extends Specification { +@AutoConfigureMockMvc(secure=false) +@WebMvcTest() +class WebControllerIntegrationTest extends Specification { @Autowired private MockMvc mvc diff --git a/spring-boot-testing/src/test/groovy/com/baeldung/boot/WebControllerTest.groovy alias b/spring-boot-testing/src/test/groovy/com/baeldung/boot/WebControllerTest.groovy alias new file mode 100644 index 0000000000..f2fc2f48e2 Binary files /dev/null and b/spring-boot-testing/src/test/groovy/com/baeldung/boot/WebControllerTest.groovy alias differ