diff --git a/spring-boot-runtime/pom.xml b/spring-boot-runtime/pom.xml index f5c98f0fde..772fd20d9e 100644 --- a/spring-boot-runtime/pom.xml +++ b/spring-boot-runtime/pom.xml @@ -63,6 +63,10 @@ spring-boot-admin-starter-client ${spring-boot-admin-starter-client.version} + + org.springframework.security + spring-security-test + com.h2database diff --git a/spring-boot-runtime/src/test/java/com/baeldung/web/controller/TaxiFareControllerIntegrationTest.java b/spring-boot-runtime/src/test/java/com/baeldung/web/controller/TaxiFareControllerIntegrationTest.java index 602971635b..97d669d3fa 100644 --- a/spring-boot-runtime/src/test/java/com/baeldung/web/controller/TaxiFareControllerIntegrationTest.java +++ b/spring-boot-runtime/src/test/java/com/baeldung/web/controller/TaxiFareControllerIntegrationTest.java @@ -7,14 +7,17 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.context.annotation.Configuration; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import com.baeldung.web.log.app.Application; import com.baeldung.web.log.data.TaxiRide; @RunWith(SpringRunner.class) -@SpringBootTest(classes = { Application.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = { Application.class, TaxiFareControllerIntegrationTest.SecurityConfig.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class TaxiFareControllerIntegrationTest { @LocalServerPort @@ -23,6 +26,7 @@ public class TaxiFareControllerIntegrationTest { @Test public void givenRequest_whenFetchTaxiFareRateCard_thanOK() { + System.out.println(port); String URL = "http://localhost:" + port + "/spring-rest"; TestRestTemplate testRestTemplate = new TestRestTemplate(); TaxiRide taxiRide = new TaxiRide(true, 10l); @@ -30,6 +34,19 @@ public class TaxiFareControllerIntegrationTest { URL + "/taxifare/calculate/", taxiRide, String.class); - //assertThat(fare, equalTo("200")); + assertThat(fare, equalTo("200")); + } + + @Configuration + static class SecurityConfig extends WebSecurityConfigurerAdapter { + @Override + protected void configure(HttpSecurity http) throws Exception { + System.out.println("security being set"); + http + .authorizeRequests() + .anyRequest().permitAll() + .and() + .csrf().disable(); + } } } \ No newline at end of file