[JAVA-8148] Code clean up

This commit is contained in:
Haroon Khan 2022-04-28 17:20:37 +01:00
parent 003d00daa9
commit 39f17dd3d1
6 changed files with 80 additions and 91 deletions

View File

@ -12,6 +12,4 @@ public class Employee {
private String id;
private String name;
// standard getters and setters
}

View File

@ -26,13 +26,11 @@ public class EmployeeWebSecurityConfig {
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
http.csrf()
.disable()
http
.csrf().disable()
.authorizeExchange()
.pathMatchers(HttpMethod.POST, "/employees/update")
.hasRole("ADMIN")
.pathMatchers("/**")
.permitAll()
.pathMatchers(HttpMethod.POST, "/employees/update").hasRole("ADMIN")
.pathMatchers("/**").permitAll()
.and()
.httpBasic();
return http.build();

View File

@ -64,11 +64,10 @@ public class EmployeeFunctionalConfig {
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
http.csrf()
.disable()
http
.csrf().disable()
.authorizeExchange()
.anyExchange()
.permitAll();
.anyExchange().permitAll();
return http.build();
}
}

View File

@ -22,7 +22,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT, classes= EmployeeSpringApplication.class)
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = EmployeeSpringApplication.class)
public class EmployeeControllerIntegrationTest {
@Autowired
@ -64,7 +64,7 @@ public class EmployeeControllerIntegrationTest {
}
@Test
@WithMockUser(username = "admin", roles = {"ADMIN"})
@WithMockUser(username = "admin", roles = { "ADMIN" })
public void givenValidUser_whenUpdateEmployee_thenEmployeeUpdated() {
Employee employee = new Employee("10", "Employee 10 Updated");

View File

@ -2,10 +2,8 @@ package com.baeldung.reactive.webflux.functional;
import com.baeldung.reactive.webflux.Employee;
import com.baeldung.reactive.webflux.EmployeeRepository;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
@ -19,10 +17,10 @@ import java.util.List;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = EmployeeSpringFunctionalApplication.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = EmployeeSpringFunctionalApplication.class)
public class EmployeeSpringFunctionalIntegrationTest {
@Autowired
@ -44,10 +42,8 @@ public class EmployeeSpringFunctionalIntegrationTest {
client.get()
.uri("/employees/1")
.exchange()
.expectStatus()
.isOk()
.expectBody(Employee.class)
.isEqualTo(employee);
.expectStatus().isOk()
.expectBody(Employee.class).isEqualTo(employee);
}
@Test
@ -58,7 +54,8 @@ public class EmployeeSpringFunctionalIntegrationTest {
List<Employee> employees = Arrays.asList(
new Employee("1", "Employee 1"),
new Employee("2", "Employee 2"));
new Employee("2", "Employee 2")
);
Flux<Employee> employeeFlux = Flux.fromIterable(employees);
given(employeeRepository.findAllEmployees()).willReturn(employeeFlux);
@ -66,10 +63,8 @@ public class EmployeeSpringFunctionalIntegrationTest {
client.get()
.uri("/employees")
.exchange()
.expectStatus()
.isOk()
.expectBodyList(Employee.class)
.isEqualTo(employees);
.expectStatus().isOk()
.expectBodyList(Employee.class).isEqualTo(employees);
}
@Test
@ -84,8 +79,7 @@ public class EmployeeSpringFunctionalIntegrationTest {
.uri("/employees/update")
.body(Mono.just(employee), Employee.class)
.exchange()
.expectStatus()
.isOk();
.expectStatus().isOk();
verify(employeeRepository).updateEmployee(employee);
}