Corregido el funcionamiento del test de ControladorRESTTEST

parent 2134592e
...@@ -98,6 +98,23 @@ public class Usuario { ...@@ -98,6 +98,23 @@ public class Usuario {
this.sistemaCarPooling = sis; this.sistemaCarPooling = sis;
} }
public Usuario(String nombre, String apellidos, Date FNac, String DNI, int telefono, String email,
String claveAcceso, Rol rol) {
this.nombre = nombre;
this.apellidos = apellidos;
this.FNac = FNac;
this.DNI = DNI;
this.telefono = telefono;
this.email = email;
this.claveAcceso = claveAcceso;
this.puntuacion = new ArrayList<>();
this.rol = rol;
this.viajesOfertados = new ArrayList<>();
this.solicitudesPendientes = new ArrayList<>();
this.historicoSolicitudes = new ArrayList<>();
this.puntuacionMedia = 0;
}
public void setSistemaCarPooling(SistemaCarPooling sis){ this.sistemaCarPooling = sis;} public void setSistemaCarPooling(SistemaCarPooling sis){ this.sistemaCarPooling = sis;}
public String getNombre() { public String getNombre() {
......
...@@ -8,14 +8,14 @@ import java.util.Date; ...@@ -8,14 +8,14 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
public record DTOUsuario (String nombre, String apellidos, Date FNac, String DNI, int telefono, String email, String claveAcceso, Usuario.Rol rol, double puntuacionMedia, List<Solicitud> solicitudesPendientes, List<Solicitud> historicoSolicitudes, SistemaCarPooling sistemaCarPooling){ public record DTOUsuario (String nombre, String apellidos, Date FNac, String DNI, int telefono, String email, String claveAcceso, Usuario.Rol rol){
public DTOUsuario(Usuario usuario) { public DTOUsuario(Usuario usuario) {
this(usuario.getNombre(), usuario.getApellidos(), usuario.getFNac(), usuario.getDNI(), usuario.getTelefono(), usuario.getEmail(), usuario.getClaveAcceso(), usuario.getRol(), usuario.getPuntuacionMedia(), usuario.getSolicitudesPendientes(), usuario.getHistoricoSolicitudes(), usuario.getSistemaCarPooling()); this(usuario.getNombre(), usuario.getApellidos(), usuario.getFNac(), usuario.getDNI(), usuario.getTelefono(), usuario.getEmail(), usuario.getClaveAcceso(), usuario.getRol());
} }
public Usuario altaUsuario(){ public Usuario altaUsuario(){
return new Usuario(nombre, apellidos, FNac, DNI, telefono, email, claveAcceso, rol, sistemaCarPooling); return new Usuario(nombre, apellidos, FNac, DNI, telefono, email, claveAcceso, rol);
} }
@Override @Override
...@@ -23,12 +23,12 @@ public record DTOUsuario (String nombre, String apellidos, Date FNac, String DNI ...@@ -23,12 +23,12 @@ public record DTOUsuario (String nombre, String apellidos, Date FNac, String DNI
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
DTOUsuario that = (DTOUsuario) o; DTOUsuario that = (DTOUsuario) o;
return telefono == that.telefono && Double.compare(that.puntuacionMedia, puntuacionMedia) == 0 && Objects.equals(nombre, that.nombre) && Objects.equals(apellidos, that.apellidos) && Objects.equals(FNac, that.FNac) && Objects.equals(DNI, that.DNI) && Objects.equals(email, that.email) && Objects.equals(claveAcceso, that.claveAcceso) && rol == that.rol && Objects.equals(solicitudesPendientes, that.solicitudesPendientes) && Objects.equals(historicoSolicitudes, that.historicoSolicitudes) && Objects.equals(sistemaCarPooling, that.sistemaCarPooling); return telefono == that.telefono && Objects.equals(nombre, that.nombre) && Objects.equals(apellidos, that.apellidos) && Objects.equals(FNac, that.FNac) && Objects.equals(DNI, that.DNI) && Objects.equals(email, that.email) && Objects.equals(claveAcceso, that.claveAcceso) && rol == that.rol;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(nombre, apellidos, FNac, DNI, telefono, email, claveAcceso, rol, puntuacionMedia, solicitudesPendientes); return Objects.hash(nombre, apellidos, FNac, DNI, telefono, email, claveAcceso, rol);
} }
@Override @Override
...@@ -42,8 +42,6 @@ public record DTOUsuario (String nombre, String apellidos, Date FNac, String DNI ...@@ -42,8 +42,6 @@ public record DTOUsuario (String nombre, String apellidos, Date FNac, String DNI
", email='" + email + '\'' + ", email='" + email + '\'' +
", claveAcceso='" + claveAcceso + '\'' + ", claveAcceso='" + claveAcceso + '\'' +
", rol=" + rol + ", rol=" + rol +
", puntuacionMedia=" + puntuacionMedia +
", solicitudesPendientes=" + solicitudesPendientes +
'}'; '}';
} }
} }
...@@ -47,11 +47,8 @@ public class ControladorRESTTEST { ...@@ -47,11 +47,8 @@ public class ControladorRESTTEST {
} }
@Test @Test
public void altaUsuario(){ public void altaUsuario(){
List<Solicitud> solicitudList = new ArrayList<>();
List<Solicitud> historico = new ArrayList<>();
SistemaCarPooling sis = new SistemaCarPooling();
Date fecha = new Date(2000, 12, 1); Date fecha = new Date(2000, 12, 1);
DTOUsuario usuario = new DTOUsuario("Fernando", "Alonso Díaz",fecha, "11995667D", 988674533, "hola@gmail.com", "1234", Usuario.Rol.CONDUCTOR, 0, solicitudList, historico, sis); DTOUsuario usuario = new DTOUsuario("Fernando", "Alonso Diaz",fecha, "78162640S", 670988953, "hola@gmail.com", "1234", Usuario.Rol.CONDUCTOR);
ResponseEntity<DTOUsuario> respuesta = restTemplate.postForEntity ResponseEntity<DTOUsuario> respuesta = restTemplate.postForEntity
( (
"/usuarios", usuario, DTOUsuario.class "/usuarios", usuario, DTOUsuario.class
......
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