Sistemati alcuni test

develop
@Territory91 5 years ago
parent add01c655f
commit aed390be8c
  1. 71
      mivan/src/main/java/mivan/model/User.java
  2. 48
      mivan/src/test/java/mivan/LocationTest.java
  3. 59
      mivan/src/test/java/mivan/StaffTest.java
  4. 48
      mivan/src/test/java/mivan/UserTest.java

@ -1,6 +1,5 @@
package mivan.model; package mivan.model;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
@ -11,80 +10,56 @@ public class User extends Person {
private static final long serialVersionUID = -5124436115031696628L; private static final long serialVersionUID = -5124436115031696628L;
@Column(name = "username", nullable=false,unique=true) @Column(name = "username", nullable = false, unique = true)
private String username; private String username;
@Column(name = "email", nullable=false,unique=true) @Column(name = "email", nullable = false, unique = true)
private String email; private String email;
@Column(name = "password", nullable=false) @Column(name = "password", nullable = false)
private String password; private String password;
protected User() { protected User() {
} }
public User(String firstName, String lastName, String city, String username, String email, String password) {
super(firstName, lastName, city);
public User(String firstName, String lastName, String city,String username, String email, String password) {
super(firstName,lastName,city);
this.username = username; this.username = username;
this.email = email; this.email = email;
this.password = password; this.password = password;
} }
public String getUsername() { public String getUsername() {
return username; return username;
} }
public void setUsername(String username) { public void setUsername(String username) {
this.username = username; this.username = username;
} }
public String getEmail() { public String getEmail() {
return email; return email;
} }
public void setEmail(String email) { public void setEmail(String email) {
this.email = email; this.email = email;
} }
public String getPassword() { public String getPassword() {
return password; return password;
} }
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
public static long getSerialversionuid() { public static long getSerialversionuid() {
return serialVersionUID; return serialVersionUID;
} }
@Override @Override
public String toString() { public String toString() {
return "User [username=" + username + ", email=" + email + ", password=" + password + "]"; return "User [username=" + username + ", email=" + email + ", password=" + password + "]";
} }
} }

@ -28,8 +28,8 @@ public class LocationTest {
@Order(1) @Order(1)
void testAddLocation() { void testAddLocation() {
String lname = "Library bria 2"; String lname = "test_add_location_name";
String ladress = "via chissa dove2"; String ladress = "test_add_location_adress";
Location location = new Location(lname, ladress); Location location = new Location(lname, ladress);
int size = locationRepository.getSize(); int size = locationRepository.getSize();
@ -46,18 +46,18 @@ public class LocationTest {
void testUpdateLocation() { void testUpdateLocation() {
// creo nuovo menìmbro dello staff // creo nuovo menìmbro dello staff
String firstname = "Ivan"; String firstname1 = "test_update_location_name1";
String lastname = "Donati"; String lastname1 = "test_update_location_lastname1";
String city = "Milano"; String city1 = "test_update_location_city1";
String idka = "lihwelhqluchwlir8"; String idka1 = "test_update_location_idka1";
String ruolo = "frontoffice"; String ruolo1 = "test_update_location_role1";
Staff newstaff1 = new Staff(firstname, lastname, city, idka, ruolo); Staff newstaff1 = new Staff(firstname1, lastname1, city1, idka1, ruolo1);
String firstname2 = "Rossi"; String firstname2 = "test_update_location_name2";
String lastname2 = "Donati"; String lastname2 = "test_update_location_lastname2";
String city2 = "Milano"; String city2 = "test_update_location_city2";
String idka2 = "lihwelhsfgdghhwlir8"; String idka2 = "test_update_location_idka2";
String ruolo2 = "manager"; String ruolo2 = "test_update_location_role2";
Staff newstaff2 = new Staff(firstname2, lastname2, city2, idka2, ruolo2); Staff newstaff2 = new Staff(firstname2, lastname2, city2, idka2, ruolo2);
staffRepository.addStaff(newstaff1); staffRepository.addStaff(newstaff1);
@ -68,8 +68,8 @@ public class LocationTest {
staffs.add(newstaff2); staffs.add(newstaff2);
// creo una locazione // creo una locazione
String lname = "Library cosa 2"; String lname = "test_update_location_name";
String ladress = "via chissa dove"; String ladress = "test_update_location_adress";
Location newlocation = new Location(lname, ladress); Location newlocation = new Location(lname, ladress);
locationRepository.addLocation(newlocation); locationRepository.addLocation(newlocation);
@ -77,16 +77,16 @@ public class LocationTest {
long id = editLocation.getId(); long id = editLocation.getId();
// nuovi dati per modificare i vecchi // nuovi dati per modificare i vecchi
String newlName = "Library bria 5"; String newlname = "test_update_location_newname";
String newlAdress = "via prossima stella"; String newladress = "test_update_location_newadress";
// aggungo i membri dello staff / modifico i dati della location // aggungo i membri dello staff / modifico i dati della location
locationRepository.updateLocation(id, newlName, newlAdress, staffs); locationRepository.updateLocation(id, newlname, newladress, staffs);
Optional<Location> location = locationRepository.findById(id); Optional<Location> location = locationRepository.findById(id);
location.ifPresent(a -> { location.ifPresent(a -> {
assertEquals(a.getName(), newlName); assertEquals(a.getName(), newlname);
assertEquals(a.getAdress(), newlAdress); assertEquals(a.getAdress(), newladress);
assertEquals(a.getStaffs(), staffs); assertEquals(a.getStaffs(), staffs);
}); });
} }
@ -95,8 +95,8 @@ public class LocationTest {
@Order(3) @Order(3)
void testDeleteLocation() { void testDeleteLocation() {
String lname = "Library bria 9"; String lname = "test_delete_location_name";
String ladress = "via chissa dove9"; String ladress = "test_delete_location_adress";
Location location = new Location(lname, ladress); Location location = new Location(lname, ladress);
locationRepository.addLocation(location); locationRepository.addLocation(location);
@ -110,7 +110,7 @@ public class LocationTest {
int newsize = locationRepository.getSize(); int newsize = locationRepository.getSize();
assertEquals(newsize, size -1); assertEquals(newsize, size - 1);
} }
} }

@ -26,14 +26,14 @@ public class StaffTest {
@Order(1) @Order(1)
void testAddStaff() { void testAddStaff() {
String firstname = "Ivan"; String firstname = "test_add_staff_name";
String lastname = "Donati"; String lastname = "test_add_staff_lastname";
String city = "Milano"; String city = "test_add_staff_city";
String idka = "lihwelhqluchwlir8"; String idka = "test_add_staff_idka";
String ruolo = "frontoffice"; String ruolo = "test_add_staff_role";
String lname = "Library bria 2"; String lname = "test_add_staff_loc_name";
String ladress = "via chissa dove"; String ladress = "test_add_staff_loc_adress";
Location location = new Location(lname, ladress); Location location = new Location(lname, ladress);
locationRepository.addLocation(location); locationRepository.addLocation(location);
@ -55,13 +55,13 @@ public class StaffTest {
void testUpdateStaff() { void testUpdateStaff() {
// creo una locazione // creo una locazione
String lname = "Library cosa 2"; String lname = "test_update_staff_loc_name";
String ladress = "via chissa dove"; String ladress = "test_update_staff_loc_adress";
Location location = new Location(lname, ladress); Location location = new Location(lname, ladress);
// creo una seconda locazione // creo una seconda locazione
String newlName = "Library destra 5"; String newlName = "test_update_staff_loc_newname";
String newlAdress = "via prossima stella"; String newlAdress = "test_update_staff_loc_newname";
Location newlocation = new Location(newlName, newlAdress); Location newlocation = new Location(newlName, newlAdress);
int losize = locationRepository.getSize(); int losize = locationRepository.getSize();
@ -74,11 +74,12 @@ public class StaffTest {
assertEquals(newlosize, losize + 2); // ci sono 2 locazioni aggunte assertEquals(newlosize, losize + 2); // ci sono 2 locazioni aggunte
// creo un membro dello staff // creo un membro dello staff
String firstname = "Maccio"; String firstname = "test_update_staff_name";
String lastname = "Donati"; String lastname = "test_update_staff_lastname";
String city = "Milano"; String city = "test_update_staff_city";
String idka = "lihwelhqluchwlir8"; String idka = "test_update_staff_idka";
String ruolo = "frontoffice"; String ruolo = "test_update_staff_role";
Staff newstaff = new Staff(firstname, lastname, city, idka, ruolo); Staff newstaff = new Staff(firstname, lastname, city, idka, ruolo);
int size = staffRepository.getSize(); int size = staffRepository.getSize();
@ -92,11 +93,11 @@ public class StaffTest {
Staff editStaff = staffRepository.searchStaffByidka(idka); Staff editStaff = staffRepository.searchStaffByidka(idka);
long id = editStaff.getId(); long id = editStaff.getId();
String newfirstname = "Ivans"; String newfirstname = "test_update_staff_newname";
String newlastname = "Donatis"; String newlastname = "test_update_staff_newlastname";
String newcity = "Milanos"; String newcity = "test_update_staff_newcity";
String newidka = "lihwelhkluchwlir5"; String newidka = "test_update_staff_newidka";
String newruolo = "spazzino"; String newruolo = "test_update_staff_newrole";
staffRepository.updateStaff(id, newfirstname, newlastname, newcity, newidka, newruolo, newlocation); staffRepository.updateStaff(id, newfirstname, newlastname, newcity, newidka, newruolo, newlocation);
@ -117,14 +118,14 @@ public class StaffTest {
@Order(3) @Order(3)
void testDeleteStaff() { void testDeleteStaff() {
String firstname = "John"; String firstname = "test_delete_staff_name";
String lastname = "Donati"; String lastname = "test_delete_staff_lastname";
String city = "Milano"; String city = "test_delete_staff_city";
String idka = "lihwelhsfghhwlir8"; String idka = "test_delete_staff_idka";
String ruolo = "manager"; String ruolo = "test_delete_staff_role";
String lname = "Library siniz 2"; String lname = "test_delete_staff_loc_name";
String ladress = "via sassa dove"; String ladress = "test_delete_staff_loc_adress";
Location location = new Location(lname, ladress); Location location = new Location(lname, ladress);
locationRepository.addLocation(location); locationRepository.addLocation(location);

@ -23,12 +23,12 @@ class UserTest {
@Order(1) @Order(1)
void testAddUser() { void testAddUser() {
String firstname = "Ivan"; String firstname = "test_add_user_name";
String lastname = "Donati"; String lastname = "test_add_user_lastname";
String city = "Milano"; String city = "test_add_user_city";
String username = "p.donati"; String username = "test_add_user_username";
String email = "p.donati@campus.unimib.it"; String email = "test_add_user_email";
String password = "pdonatipassword"; String password = "test_add_user_password";
User user = new User(firstname, lastname, city, username, email, password); User user = new User(firstname, lastname, city, username, email, password);
int size = userRepository.getSize(); int size = userRepository.getSize();
@ -44,12 +44,12 @@ class UserTest {
@Order(2) @Order(2)
void testUpdateCompany() { void testUpdateCompany() {
String firstname = "Simone"; String firstname = "test_update_user_name";
String lastname = "Donati"; String lastname = "test_update_user_lastname";
String city = "Milano"; String city = "test_update_user_city";
String username = "i.donati"; String username = "test_update_user_username";
String email = "i.donati@campus.unimib.it"; String email = "test_update_user_email";
String password = "passwordsicura"; String password = "test_update_user_password";
User newuser = new User(firstname, lastname, city, username, email, password); User newuser = new User(firstname, lastname, city, username, email, password);
@ -59,12 +59,12 @@ class UserTest {
long id = editUser.getId(); long id = editUser.getId();
String newfirstname = "Ivans"; String newfirstname = "test_update_user_newname";
String newlastname = "Donatis"; String newlastname = "test_update_user_newlastname";
String newcity = "Milanos"; String newcity = "test_update_user_newcity";
String newusername = "asd.donati1s"; String newusername = "test_update_user_newusername";
String newemail = "asd.donati@campus.unimib.com"; String newemail = "test_update_user_newemail";
String newpassword = "newpdonatipassword"; String newpassword = "test_update_user_newpassword";
userRepository.updateUser(id, newfirstname, newlastname, newcity, newusername, newemail, newpassword); userRepository.updateUser(id, newfirstname, newlastname, newcity, newusername, newemail, newpassword);
@ -84,12 +84,12 @@ class UserTest {
@Order(3) @Order(3)
void testDeleteUser() { void testDeleteUser() {
String firstname = "Rossi"; String firstname = "test_delete_user_name";
String lastname = "Donati"; String lastname = "test_delete_user_lastname";
String city = "Milano"; String city = "test_delete_user_city";
String username = "r.donati"; String username = "test_delete_user_username";
String email = "r.donati@campus.unimib.it"; String email = "test_delete_user_email";
String password = "rdonatipassword"; String password = "test_delete_user_password";
User newuser = new User(firstname, lastname, city, username, email, password); User newuser = new User(firstname, lastname, city, username, email, password);

Loading…
Cancel
Save