#BAEL-2862: update test case

This commit is contained in:
h_sharifi 2023-01-02 14:12:00 +03:30
parent 9b206922fd
commit 32763ab63d
1 changed files with 6 additions and 24 deletions

View File

@ -1,23 +1,19 @@
package com.baeldung.web.controller; package com.baeldung.web.controller;
import static org.hamcrest.MatcherAssert.assertThat; import com.baeldung.web.log.app.Application;
import static org.hamcrest.Matchers.equalTo; import com.baeldung.web.log.data.TaxiRide;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Configuration; import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner; 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 static org.hamcrest.MatcherAssert.assertThat;
import com.baeldung.web.log.data.TaxiRide; import static org.hamcrest.Matchers.equalTo;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = { Application.class, TaxiFareControllerIntegrationTest.SecurityConfig.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(classes = { Application.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TaxiFareControllerIntegrationTest { public class TaxiFareControllerIntegrationTest {
@LocalServerPort @LocalServerPort
@ -25,8 +21,6 @@ public class TaxiFareControllerIntegrationTest {
@Test @Test
public void givenRequest_whenFetchTaxiFareRateCard_thanOK() { public void givenRequest_whenFetchTaxiFareRateCard_thanOK() {
System.out.println(port);
String URL = "http://localhost:" + port + "/spring-rest"; String URL = "http://localhost:" + port + "/spring-rest";
TestRestTemplate testRestTemplate = new TestRestTemplate(); TestRestTemplate testRestTemplate = new TestRestTemplate();
TaxiRide taxiRide = new TaxiRide(true, 10l); TaxiRide taxiRide = new TaxiRide(true, 10l);
@ -37,16 +31,4 @@ public class TaxiFareControllerIntegrationTest {
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();
}
}
} }