Commit d1d9bbc6 by Antonio Rueda

Eliminadas operaciones y parámetros innecesarios al incluir Spring

Security
parent 085c5ef1
......@@ -49,7 +49,10 @@ public class ServicioReservas {
public ServicioReservas() {
}
public void nuevoHotel(@Valid Hotel hotel) {
public void nuevoHotel(Usuario direccion, @Valid Hotel hotel) {
if (!direccion.nombre().equals("direccion"))
throw new OperacionDeDireccion();
repositorioHoteles.guardar(hotel);
}
......@@ -60,9 +63,7 @@ public class ServicioReservas {
repositorioClientes.guardar(cliente);
}
/*
// Anular login (gestionado por Spring Security)
public Optional<Usuario> login(@Email String email, String clave) {
// Caso especial de login de la direccion
if (direccion.email().equals(email) && direccion.clave().equals(clave))
......@@ -70,7 +71,7 @@ public class ServicioReservas {
return repositorioClientes.buscar(email).filter(cliente -> cliente.clave().equals(clave));
}
*/
public Optional<Usuario> buscarUsuario(String email) {
if (email.equals(direccion.email()))
return Optional.of(direccion);
......
......@@ -51,9 +51,8 @@ public class TestServicioReservas {
var cliente = new Usuario("Pedro", "Jaén Jaén", "611203025", "pjaen@gmail.com", "miClAvE");
servicio.nuevoCliente(cliente);
assertThat(servicio.login("ppp@gmail.com", "miClAvE")).isEmpty();
assertThat(servicio.login("pjaen@gmail.com", "xyz")).isEmpty();
assertThat(servicio.login("pjaen@gmail.com", "miClAvE")).hasValueSatisfying(c -> c.email().equals(cliente.email()));
assertThat(servicio.buscarUsuario("ppp@gmail.com")).isEmpty();
assertThat(servicio.buscarUsuario("pjaen@gmail.com")).hasValueSatisfying(c -> c.email().equals(cliente.email()));
}
@Test
......@@ -61,11 +60,9 @@ public class TestServicioReservas {
void testBuscarHotel() {
var hotel1 = new Hotel("Gran Hotel Almería", "Almería", "Almería", "04001", 25, 50, 100, 180);
var hotel2 = new Hotel("Hotel Infanta Cristina", "Jaén", "Jaén", "23009", 30, 60, 120, 200);
var direccion = servicio.login("direccion@hotelxyz.es", "SeCrEtO").get();
servicio.nuevoHotel(direccion, hotel1);
servicio.nuevoHotel(direccion, hotel2);
servicio.nuevoHotel(hotel1);
servicio.nuevoHotel(hotel2);
List<Hotel> hoteles = servicio.buscarHotel("gran hotel", " almeria");
......@@ -80,11 +77,11 @@ public class TestServicioReservas {
var hotel2 = new Hotel("Hotel Espejo del Mar", "Almería", "Almería", "04001", 15, 35, 80, 110);
var hotel3 = new Hotel("Hotel Infanta Cristina", "Jaén", "Jaén", "23009", 30, 60, 120, 200);
var direccion = servicio.login("direccion@hotelxyz.es", "SeCrEtO").get();
var direccion = servicio.buscarUsuario("direccion@hotelxyz.es").get();
servicio.nuevoHotel(direccion, hotel1);
servicio.nuevoHotel(direccion, hotel2);
servicio.nuevoHotel(direccion, hotel3);
servicio.nuevoHotel(hotel1);
servicio.nuevoHotel(hotel2);
servicio.nuevoHotel(hotel3);
List<Hotel> hoteles = servicio.buscarHotelesDisponiblesPorLocalidad("almeria",
LocalDate.now().plusDays(7),
......@@ -99,13 +96,12 @@ public class TestServicioReservas {
@Test
@DirtiesContext
void testReservaHotel() {
var direccion = servicio.login("direccion@hotelxyz.es", "SeCrEtO").get();
servicio.nuevoHotel(direccion, new Hotel("Bed and Breakfast Almería", "Almería", "Almería", "04001", 2, 2, 60, 100));
servicio.nuevoHotel(new Hotel("Bed and Breakfast Almería", "Almería", "Almería", "04001", 2, 2, 60, 100));
servicio.nuevoCliente(new Usuario("Pedro", "Jaén Jaén", "611203025", "pjaen@gmail.com", "miClAvE"));
var hotel = servicio.buscarHotel("bed and breakfast", "almeria").get(0);
var cliente = servicio.login("pjaen@gmail.com", "miClAvE").get();
var cliente = servicio.buscarUsuario("pjaen@gmail.com").get();
var reserva = servicio.reserva(cliente, hotel, LocalDate.now().plusDays(7), LocalDate.now().plusDays(10), 0, 1);
......@@ -117,13 +113,12 @@ public class TestServicioReservas {
@Test
@DirtiesContext
void testReservaHotelSinDisponibilidad() {
var direccion = servicio.login("direccion@hotelxyz.es", "SeCrEtO").get();
servicio.nuevoHotel(direccion, new Hotel("Bed and Breakfast Almería", "Almería", "Almería", "04001", 2, 2, 60, 100));
servicio.nuevoHotel(new Hotel("Bed and Breakfast Almería", "Almería", "Almería", "04001", 2, 2, 60, 100));
servicio.nuevoCliente(new Usuario("Pedro", "Jaén Jaén", "611203025", "pjaen@gmail.com", "miClAvE"));
var hotel = servicio.buscarHotel("bed and breakfast", "almeria").get(0);
var cliente = servicio.login("pjaen@gmail.com", "miClAvE").get();
var cliente = servicio.buscarUsuario("pjaen@gmail.com").get();
// Reservar 2 habitaciones dobles
servicio.reserva(cliente, hotel, LocalDate.now().plusDays(7), LocalDate.now().plusDays(10), 0, 2);
......@@ -136,15 +131,14 @@ public class TestServicioReservas {
@Test
@DirtiesContext
void testReservaHotelesConcurrente() {
var direccion = servicio.login("direccion@hotelxyz.es", "SeCrEtO").get();
servicio.nuevoHotel(direccion, new Hotel("Bed and Breakfast Almería", "Almería", "Almería", "04001", 2, 2, 60, 100));
servicio.nuevoHotel(new Hotel("Bed and Breakfast Almería", "Almería", "Almería", "04001", 2, 2, 60, 100));
servicio.nuevoCliente(new Usuario("Pedro", "Jaén Jaén", "611203025", "pjaen@gmail.com", "miClAvE"));
servicio.nuevoCliente(new Usuario("Juan", "Granada Granada", "611213126", "jgranada@gmail.com", "miClAvE"));
var hotel = servicio.buscarHotel("bed and breakfast", "almeria").get(0);
var cliente1 = servicio.login("pjaen@gmail.com", "miClAvE").get();
var cliente2 = servicio.login("jgranada@gmail.com", "miClAvE").get();
var cliente1 = servicio.buscarUsuario("pjaen@gmail.com").get();
var cliente2 = servicio.buscarUsuario("jgranada@gmail.com").get();
// Reservar 2 habitaciones dobles
var th = new Thread(()-> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment