JAVA-3090: updating README.md for spring-reactive
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
package com.baeldung;
|
||||
|
||||
import com.baeldung.reactive.actuator.Spring5ReactiveApplication;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.reactive.security.SpringSecurity5Application;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = SpringSecurity5Application.class)
|
||||
@SpringBootTest(classes = Spring5ReactiveApplication.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
@Test
|
||||
|
||||
-92
@@ -1,92 +0,0 @@
|
||||
package com.baeldung.reactive.functional;
|
||||
|
||||
import com.baeldung.webflux.Employee;
|
||||
import com.baeldung.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;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = EmployeeSpringFunctionalApplication.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class EmployeeSpringFunctionalIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private EmployeeFunctionalConfig config;
|
||||
|
||||
@MockBean
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@Test
|
||||
public void givenEmployeeId_whenGetEmployeeById_thenCorrectEmployee() {
|
||||
WebTestClient client = WebTestClient
|
||||
.bindToRouterFunction(config.getEmployeeByIdRoute())
|
||||
.build();
|
||||
|
||||
Employee employee = new Employee("1", "Employee 1");
|
||||
|
||||
given(employeeRepository.findEmployeeById("1")).willReturn(Mono.just(employee));
|
||||
|
||||
client.get()
|
||||
.uri("/employees/1")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(Employee.class)
|
||||
.isEqualTo(employee);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetAllEmployees_thenCorrectEmployees() {
|
||||
WebTestClient client = WebTestClient
|
||||
.bindToRouterFunction(config.getAllEmployeesRoute())
|
||||
.build();
|
||||
|
||||
List<Employee> employees = Arrays.asList(
|
||||
new Employee("1", "Employee 1"),
|
||||
new Employee("2", "Employee 2"));
|
||||
|
||||
Flux<Employee> employeeFlux = Flux.fromIterable(employees);
|
||||
given(employeeRepository.findAllEmployees()).willReturn(employeeFlux);
|
||||
|
||||
client.get()
|
||||
.uri("/employees")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBodyList(Employee.class)
|
||||
.isEqualTo(employees);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUpdateEmployee_thenEmployeeUpdated() {
|
||||
WebTestClient client = WebTestClient
|
||||
.bindToRouterFunction(config.updateEmployeeRoute())
|
||||
.build();
|
||||
|
||||
Employee employee = new Employee("1", "Employee 1 Updated");
|
||||
|
||||
client.post()
|
||||
.uri("/employees/update")
|
||||
.body(Mono.just(employee), Employee.class)
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk();
|
||||
|
||||
verify(employeeRepository).updateEmployee(employee);
|
||||
}
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
package com.baeldung.reactive.webflux;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import com.baeldung.webflux.EmployeeSpringApplication;
|
||||
import com.baeldung.webflux.Employee;
|
||||
import com.baeldung.webflux.EmployeeRepository;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes=EmployeeSpringApplication.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class EmployeeControllerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient testClient;
|
||||
|
||||
@MockBean
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@Test
|
||||
public void givenEmployeeId_whenGetEmployeeById_thenCorrectEmployee() {
|
||||
|
||||
Employee employee = new Employee("1", "Employee 1 Name");
|
||||
|
||||
given(employeeRepository.findEmployeeById("1")).willReturn(Mono.just(employee));
|
||||
testClient.get()
|
||||
.uri("/employees/1")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(Employee.class)
|
||||
.isEqualTo(employee);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetAllEmployees_thenCorrectEmployees() {
|
||||
|
||||
List<Employee> employeeList = new ArrayList<>();
|
||||
|
||||
Employee employee1 = new Employee("1", "Employee 1 Name");
|
||||
Employee employee2 = new Employee("2", "Employee 2 Name");
|
||||
Employee employee3 = new Employee("3", "Employee 3 Name");
|
||||
|
||||
employeeList.add(employee1);
|
||||
employeeList.add(employee2);
|
||||
employeeList.add(employee3);
|
||||
|
||||
Flux<Employee> employeeFlux = Flux.fromIterable(employeeList);
|
||||
|
||||
given(employeeRepository.findAllEmployees()).willReturn(employeeFlux);
|
||||
testClient.get()
|
||||
.uri("/employees")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBodyList(Employee.class)
|
||||
.hasSize(3)
|
||||
.isEqualTo(employeeList);
|
||||
}
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
package com.baeldung.security;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import com.baeldung.reactive.security.SpringSecurity5Application;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = SpringSecurity5Application.class)
|
||||
public class SecurityIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
|
||||
private WebTestClient rest;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.rest = WebTestClient.bindToApplicationContext(this.context).configureClient().build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNoCredentials_thenRedirectToLogin() {
|
||||
this.rest.get().uri("/").exchange().expectStatus().is3xxRedirection();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@WithMockUser
|
||||
public void whenHasCredentials_thenSeesGreeting() {
|
||||
this.rest.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("Hello, user");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user