Update Mivan.java, Author.java, and 22 more files...

develop
@Territory91 5 years ago
parent 0850c9f730
commit ba2f9e2b0c
  1. 23
      mivan/src/main/java/mivan/Mivan.java
  2. 15
      mivan/src/main/java/mivan/model/Author.java
  3. 9
      mivan/src/main/java/mivan/model/Book.java
  4. 89
      mivan/src/main/java/mivan/model/Item.java
  5. 52
      mivan/src/main/java/mivan/model/Person.java
  6. 5
      mivan/src/main/java/mivan/repository/AuthorRepositoryImpl.java
  7. 5
      mivan/src/main/java/mivan/repository/BookRepository.java
  8. 8
      mivan/src/main/java/mivan/repository/BookRepositoryImpl.java
  9. 6
      mivan/src/main/java/mivan/repository/ItemRepository.java
  10. 63
      mivan/src/main/java/mivan/repository/ItemRepositoryImpl.java
  11. 1
      mivan/src/main/java/mivan/repository/LoanRepository.java
  12. 3
      mivan/src/main/java/mivan/repository/LoanRepositoryImpl.java
  13. 5
      mivan/src/main/java/mivan/repository/Repository.java
  14. 9
      mivan/src/main/java/mivan/repository/StaffRepository.java
  15. 7
      mivan/src/main/java/mivan/repository/StaffRepositoryImpl.java
  16. 8
      mivan/src/main/java/mivan/repository/UserRepository.java
  17. 8
      mivan/src/main/java/mivan/repository/UserRepositoryImpl.java
  18. 12
      mivan/src/test/java/mivan/AuthorBookTest.java
  19. 10
      mivan/src/test/java/mivan/AuthorTest.java
  20. 12
      mivan/src/test/java/mivan/BookTest.java
  21. 72
      mivan/src/test/java/mivan/ItemTest.java
  22. 3
      mivan/src/test/java/mivan/LoanTest.java
  23. 4
      mivan/src/test/java/mivan/StaffTest.java

@ -1,36 +1,13 @@
package mivan; package mivan;
import java.io.Console;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import mivan.model.User;
import mivan.repository.UserRepository;
import mivan.repository.UserRepositoryImpl;
@SpringBootApplication @SpringBootApplication
public class Mivan { public class Mivan {
public static void main(String[] args) { public static void main(String[] args) {
String firstName = "Paolo";
String lastName = "Verdi";
String city = "Milano";
String username = "p.verdi1";
String email = "p.verdi1@campus.unimib.it";
String password = "pverdipassword";
User user = new User(firstName, lastName, city, username, email, password);
UserRepository userRepository = new UserRepositoryImpl();
userRepository.addUser(user);
int size = userRepository.getSize();
System.out.print(size);
SpringApplication.run(Mivan.class, args); SpringApplication.run(Mivan.class, args);
} }

@ -21,20 +21,22 @@ public class Author implements Serializable {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true) @Column(name = "id", unique = true)
private long id; private long id;
@Column(name = "name", nullable=false) @Column(name = "name", nullable = false)
private String name; private String name;
@ManyToMany(mappedBy="authors") @ManyToMany(mappedBy = "authors")
private List<Book> books; private List<Book> books;
public Author() {} public Author() {
}
public Author(String name) { public Author(String name) {
super(); super();
this.name = name; this.name = name;
this.books = new ArrayList <Book>(); this.books = new ArrayList<Book>();
} }
public long getId() { public long getId() {
@ -67,8 +69,7 @@ public class Author implements Serializable {
public void removeBook(Book book) { public void removeBook(Book book) {
if (this.books.contains(book)) if (this.books.contains(book))
this.books.remove(book); this.books.remove(book);
book.removeAuthor(this); book.removeAuthor(this);
} }
} }

@ -20,20 +20,17 @@ public class Book implements Serializable {
private static final long serialVersionUID = 19L; private static final long serialVersionUID = 19L;
@Id @Id
@Column(name = "isbn", nullable=false, unique=true) @Column(name = "isbn", nullable = false, unique = true)
private long isbn; private long isbn;
@Column(name = "title", nullable=false) @Column(name = "title", nullable = false)
private String title; private String title;
@OneToOne @OneToOne
private Book prequel; private Book prequel;
@ManyToMany @ManyToMany
@JoinTable( @JoinTable(name = "book_has_author", joinColumns = @JoinColumn(name = "isbn", referencedColumnName = "isbn"), inverseJoinColumns = @JoinColumn(name = "id", referencedColumnName = "id"))
name = "book_has_author",
joinColumns=@JoinColumn(name="isbn", referencedColumnName="isbn"),
inverseJoinColumns=@JoinColumn(name="id", referencedColumnName="id") )
private List<Author> authors; private List<Author> authors;
public Book() { public Book() {

@ -13,49 +13,50 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
@Entity @Entity
@Table(name="item") @Table(name = "item")
public class Item implements Serializable{ public class Item implements Serializable {
private static final long serialVersionUID = 1993L; private static final long serialVersionUID = 1993L;
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true) @Column(name = "id", unique = true)
private long id; private long id;
@ManyToOne(fetch=FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="isbn") @JoinColumn(name = "isbn")
private Book book; private Book book;
@ManyToOne(fetch=FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="location") @JoinColumn(name = "location")
private Location location; private Location location;
public Item () {} public Item() {
public Item(Book book, Location location){ }
super();
this.book = book; public Item(Book book, Location location) {
this.location = location; super();
} this.book = book;
this.location = location;
public long getId() { }
return this.id;
} public long getId() {
return this.id;
public Book getBook(){ }
return this.book;
} public Book getBook() {
return this.book;
public void setBook(Book book){ }
this.book = book;
} public void setBook(Book book) {
this.book = book;
public Location getLocation() { }
return this.location;
} public Location getLocation() {
return this.location;
public void setLocation(Location location) { }
this.location = location;
} public void setLocation(Location location) {
this.location = location;
}
} }

@ -7,26 +7,24 @@ import javax.persistence.*;
@MappedSuperclass @MappedSuperclass
public class Person implements Serializable { public class Person implements Serializable {
private static final long serialVersionUID = -5124436115031696628L; private static final long serialVersionUID = -5124436115031696628L;
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true) @Column(name = "id", unique = true)
private long id; private long id;
@Column(name = "firstName", nullable=false) @Column(name = "firstName", nullable = false)
private String firstName; private String firstName;
@Column(name = "lastName", nullable=false) @Column(name = "lastName", nullable = false)
private String lastName; private String lastName;
@Column(name = "city") @Column(name = "city")
private String city; private String city;
public Person() {
public Person() {} }
public Person(String firstName, String lastName, String city) { public Person(String firstName, String lastName, String city) {
super(); super();
@ -36,28 +34,28 @@ public class Person implements Serializable {
} }
public long getId() { public long getId() {
return id; return id;
} }
public void setId(int id) { public void setId(int id) {
this.id = id; this.id = id;
} }
public String getFirstName() { public String getFirstName() {
return firstName; return firstName;
} }
public void setFirstName(String firstName) { public void setFirstName(String firstName) {
this.firstName = firstName; this.firstName = firstName;
} }
public String getLastName() { public String getLastName() {
return lastName; return lastName;
} }
public void setLastName(String lastName) { public void setLastName(String lastName) {
this.lastName = lastName; this.lastName = lastName;
} }
public String getCity() { public String getCity() {
return city; return city;
@ -72,6 +70,4 @@ public class Person implements Serializable {
return "Person [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", city=" + city + "]"; return "Person [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", city=" + city + "]";
} }
} }

@ -89,8 +89,8 @@ public class AuthorRepositoryImpl implements AuthorRepository {
Author author = null; Author author = null;
try { try {
author = (Author) entityManager.createQuery("FROM Author u WHERE lower(u.name) = '" + name.toLowerCase() + "'") author = (Author) entityManager
.getSingleResult(); .createQuery("FROM Author u WHERE lower(u.name) = '" + name.toLowerCase() + "'").getSingleResult();
entityManager.close(); entityManager.close();
} catch (Exception ex) { } catch (Exception ex) {
@ -152,5 +152,4 @@ public class AuthorRepositoryImpl implements AuthorRepository {
} }
} }
} }

@ -2,9 +2,9 @@ package mivan.repository;
import mivan.model.Book; import mivan.model.Book;
public interface BookRepository extends Repository<Book, Long>{ public interface BookRepository extends Repository<Book, Long> {
//public Optional<AddressUser> findUserAddressById(Long id); // public Optional<AddressUser> findUserAddressById(Long id);
public void deleteBookById(Long isbn); public void deleteBookById(Long isbn);
@ -20,4 +20,3 @@ public interface BookRepository extends Repository<Book, Long>{
public int getSize(); public int getSize();
} }

@ -14,7 +14,7 @@ public class BookRepositoryImpl implements BookRepository {
private EntityManagerFactory entityManagerFactory; private EntityManagerFactory entityManagerFactory;
public BookRepositoryImpl(){ public BookRepositoryImpl() {
this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan"); this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan");
} }
@ -51,7 +51,7 @@ public class BookRepositoryImpl implements BookRepository {
} }
@Override @Override
public void addBook(Book book) { public void addBook(Book book) {
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); final EntityManager entityManager = this.entityManagerFactory.createEntityManager();
try { try {
if (!entityManager.getTransaction().isActive()) { if (!entityManager.getTransaction().isActive()) {
@ -117,8 +117,6 @@ public class BookRepositoryImpl implements BookRepository {
return size; return size;
} }
@Override @Override
public void addAuthor(Long isbn, Long id) { public void addAuthor(Long isbn, Long id) {
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); final EntityManager entityManager = this.entityManagerFactory.createEntityManager();
@ -157,6 +155,4 @@ public class BookRepositoryImpl implements BookRepository {
} }
} }
} }

@ -4,10 +4,10 @@ import mivan.model.Item;
public interface ItemRepository extends Repository<Item, Long> { public interface ItemRepository extends Repository<Item, Long> {
public void deleteItemById(Long id); public void deleteItemById(Long id);
public void addItem(Item item); public void addItem(Item item);
public int getSize(); public int getSize();
} }

@ -1,4 +1,5 @@
package mivan.repository; package mivan.repository;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -9,30 +10,31 @@ import javax.persistence.Persistence;
import mivan.model.Item; import mivan.model.Item;
public class ItemRepositoryImpl implements ItemRepository { public class ItemRepositoryImpl implements ItemRepository {
private EntityManagerFactory entityManagerFactory; private EntityManagerFactory entityManagerFactory;
public ItemRepositoryImpl() {
this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan");
}
public ItemRepositoryImpl() { @Override
this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan"); public Optional<Item> findById(Long id) {
} final EntityManager entityManager = this.entityManagerFactory.createEntityManager();
@Override Item item = entityManager.find(Item.class, id);
public Optional<Item> findById(Long id) { entityManager.close();
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); return Optional.ofNullable(item);
Item item = entityManager.find(Item.class, id); }
entityManager.close();
return Optional.ofNullable(item);
}
@Override @Override
public Iterable<Item> findAll() { public Iterable<Item> findAll() {
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); final EntityManager entityManager = this.entityManagerFactory.createEntityManager();
List<Item> items = entityManager.createQuery("FROM Item", Item.class).getResultList(); List<Item> items = entityManager.createQuery("FROM Item", Item.class).getResultList();
entityManager.close(); entityManager.close();
return items; return items;
} }
@Override @Override
public void deleteItemById(Long id) { public void deleteItemById(Long id) {
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); final EntityManager entityManager = this.entityManagerFactory.createEntityManager();
try { try {
if (!entityManager.getTransaction().isActive()) { if (!entityManager.getTransaction().isActive()) {
entityManager.getTransaction().begin(); entityManager.getTransaction().begin();
@ -44,11 +46,11 @@ public class ItemRepositoryImpl implements ItemRepository {
} catch (Exception ex) { } catch (Exception ex) {
entityManager.getTransaction().rollback(); entityManager.getTransaction().rollback();
} }
} }
@Override @Override
public void addItem(Item item) { public void addItem(Item item) {
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); final EntityManager entityManager = this.entityManagerFactory.createEntityManager();
try { try {
if (!entityManager.getTransaction().isActive()) { if (!entityManager.getTransaction().isActive()) {
entityManager.getTransaction().begin(); entityManager.getTransaction().begin();
@ -61,11 +63,11 @@ public class ItemRepositoryImpl implements ItemRepository {
entityManager.getTransaction().rollback(); entityManager.getTransaction().rollback();
} }
} }
@Override @Override
public int getSize() { public int getSize() {
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); final EntityManager entityManager = this.entityManagerFactory.createEntityManager();
int size = 0; int size = 0;
try { try {
size = entityManager.createQuery("FROM Item").getResultList().size(); size = entityManager.createQuery("FROM Item").getResultList().size();
@ -75,7 +77,6 @@ public class ItemRepositoryImpl implements ItemRepository {
size = 0; size = 0;
} }
return size; return size;
} }
} }

@ -1,6 +1,5 @@
package mivan.repository; package mivan.repository;
import mivan.model.Loan; import mivan.model.Loan;
public interface LoanRepository extends Repository<Loan, Long> { public interface LoanRepository extends Repository<Loan, Long> {

@ -9,7 +9,7 @@ import javax.persistence.Persistence;
import mivan.model.Loan; import mivan.model.Loan;
public class LoanRepositoryImpl implements LoanRepository{ public class LoanRepositoryImpl implements LoanRepository {
private EntityManagerFactory entityManagerFactory; private EntityManagerFactory entityManagerFactory;
@ -81,7 +81,6 @@ public class LoanRepositoryImpl implements LoanRepository{
} }
} }
@Override @Override
public int getSize() { public int getSize() {
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); final EntityManager entityManager = this.entityManagerFactory.createEntityManager();

@ -3,6 +3,7 @@ package mivan.repository;
import java.util.Optional; import java.util.Optional;
public interface Repository<T, ID> { public interface Repository<T, ID> {
Optional<T> findById(ID id); Optional<T> findById(ID id);
Iterable<T> findAll();
Iterable<T> findAll();
} }

@ -3,19 +3,18 @@ package mivan.repository;
import mivan.model.Location; import mivan.model.Location;
import mivan.model.Staff; import mivan.model.Staff;
public interface StaffRepository extends Repository<Staff, Long> {
public interface StaffRepository extends Repository<Staff, Long>{
public void deleteStaffById(Long id); public void deleteStaffById(Long id);
public void addStaff(Staff user); public void addStaff(Staff user);
public void updateStaff(Long id, String firstname, String lastname, String city, String idka, String ruolo, Location location); public void updateStaff(Long id, String firstname, String lastname, String city, String idka, String ruolo,
Location location);
public Staff searchStaffByidka(String idka); public Staff searchStaffByidka(String idka);
//public List<Staff> searchStaffByRole(String role); // public List<Staff> searchStaffByRole(String role);
public int getSize(); public int getSize();
} }

@ -10,7 +10,7 @@ import javax.persistence.Persistence;
import mivan.model.Location; import mivan.model.Location;
import mivan.model.Staff; import mivan.model.Staff;
public class StaffRepositoryImpl implements StaffRepository{ public class StaffRepositoryImpl implements StaffRepository {
private EntityManagerFactory entityManagerFactory; private EntityManagerFactory entityManagerFactory;
@ -26,7 +26,6 @@ public class StaffRepositoryImpl implements StaffRepository{
return Optional.ofNullable(staff); return Optional.ofNullable(staff);
} }
@Override @Override
public Iterable<Staff> findAll() { public Iterable<Staff> findAll() {
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); final EntityManager entityManager = this.entityManagerFactory.createEntityManager();
@ -64,8 +63,8 @@ public class StaffRepositoryImpl implements StaffRepository{
} }
} }
public void updateStaff(Long id, String firstname, String lastname, String city, String idka, String ruolo,
public void updateStaff(Long id, String firstname, String lastname, String city,String idka,String ruolo,Location location) { Location location) {
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); final EntityManager entityManager = this.entityManagerFactory.createEntityManager();
try { try {
if (!entityManager.getTransaction().isActive()) { if (!entityManager.getTransaction().isActive()) {

@ -2,20 +2,20 @@ package mivan.repository;
import mivan.model.User; import mivan.model.User;
public interface UserRepository extends Repository<User, Long>{ public interface UserRepository extends Repository<User, Long> {
//public Optional<AddressUser> findUserAddressById(Long id); // public Optional<AddressUser> findUserAddressById(Long id);
public void deleteUserById(Long id); public void deleteUserById(Long id);
public void addUser(User user); public void addUser(User user);
public void updateUser(Long id, String firstname, String lastname, String city,String username, String email, String password); public void updateUser(Long id, String firstname, String lastname, String city, String username, String email,
String password);
public User searchUserByName(String username); public User searchUserByName(String username);
public User searchUserByEmail(String email); public User searchUserByEmail(String email);
public int getSize(); public int getSize();
} }

@ -7,7 +7,6 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence; import javax.persistence.Persistence;
import mivan.model.User; import mivan.model.User;
public class UserRepositoryImpl implements UserRepository { public class UserRepositoryImpl implements UserRepository {
@ -64,8 +63,8 @@ public class UserRepositoryImpl implements UserRepository {
} }
} }
public void updateUser(Long id, String firstname, String lastname, String city, String username, String email,
public void updateUser(Long id, String firstname, String lastname, String city,String username, String email, String password) { String password) {
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); final EntityManager entityManager = this.entityManagerFactory.createEntityManager();
try { try {
if (!entityManager.getTransaction().isActive()) { if (!entityManager.getTransaction().isActive()) {
@ -91,7 +90,8 @@ public class UserRepositoryImpl implements UserRepository {
User user = null; User user = null;
try { try {
user = (User) entityManager.createQuery("FROM User u WHERE lower(u.username) = '" + username.toLowerCase() + "'") user = (User) entityManager
.createQuery("FROM User u WHERE lower(u.username) = '" + username.toLowerCase() + "'")
.getSingleResult(); .getSingleResult();
entityManager.close(); entityManager.close();

@ -1,15 +1,8 @@
package mivan; package mivan;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Optional;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import mivan.model.Author;
import mivan.repository.AuthorRepository; import mivan.repository.AuthorRepository;
import mivan.repository.AuthorRepositoryImpl; import mivan.repository.AuthorRepositoryImpl;
import mivan.repository.BookRepository; import mivan.repository.BookRepository;
@ -22,9 +15,4 @@ public class AuthorBookTest {
private BookRepository bookRepository = new BookRepositoryImpl(); private BookRepository bookRepository = new BookRepositoryImpl();
} }

@ -18,12 +18,10 @@ public class AuthorTest {
private AuthorRepository authorRepository = new AuthorRepositoryImpl(); private AuthorRepository authorRepository = new AuthorRepositoryImpl();
@Test @Test
@Order(1) @Order(1)
void testAddAuthor() { void testAddAuthor() {
String name = "Ivan"; String name = "Ivan";
Author author = new Author(name); Author author = new Author(name);
@ -32,7 +30,6 @@ public class AuthorTest {
int size = authorRepository.getSize(); int size = authorRepository.getSize();
assertEquals(size, 1); assertEquals(size, 1);
} }
@ -46,11 +43,13 @@ public class AuthorTest {
authorRepository.addAuthor(author); authorRepository.addAuthor(author);
String updatedName ="Javoso"; String updatedName = "Javoso";
authorRepository.updateAuthor(author.getId(), updatedName); authorRepository.updateAuthor(author.getId(), updatedName);
Optional<Author> updated_author = authorRepository.findById(author.getId()); Optional<Author> updated_author = authorRepository.findById(author.getId());
updated_author.ifPresent(a -> {assertEquals(a.getName(), updatedName);}); updated_author.ifPresent(a -> {
assertEquals(a.getName(), updatedName);
});
} }
@ -74,5 +73,4 @@ public class AuthorTest {
assertEquals(end_size, size); assertEquals(end_size, size);
} }
} }

@ -5,23 +5,17 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Optional; import java.util.Optional;
import javax.validation.constraints.AssertTrue;
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import mivan.model.Author;
import mivan.model.Book; import mivan.model.Book;
import mivan.model.User;
import mivan.repository.BookRepository; import mivan.repository.BookRepository;
import mivan.repository.BookRepositoryImpl; import mivan.repository.BookRepositoryImpl;
public class BookTest { public class BookTest {
private BookRepository bookRepository = new BookRepositoryImpl(); private BookRepository bookRepository = new BookRepositoryImpl();
@Test @Test
@Order(1) @Order(1)
void testAddBook() { void testAddBook() {
@ -36,14 +30,13 @@ public class BookTest {
int size = bookRepository.getSize(); int size = bookRepository.getSize();
assertEquals(size, 1); assertEquals(size, 1);
} }
@Test @Test
@Order(2) @Order(2)
void testUpdateBook(){ void testUpdateBook() {
long isbn = 12348; long isbn = 12348;
String title = "odissea"; String title = "odissea";
Book prequel = null; Book prequel = null;
@ -61,7 +54,6 @@ public class BookTest {
} }
@Test @Test
@Order(3) @Order(3)
void testDeleteBook() { void testDeleteBook() {
@ -82,7 +74,7 @@ public class BookTest {
bookRepository.deleteBookById(ID); bookRepository.deleteBookById(ID);
int size = bookRepository.getSize(); int size = bookRepository.getSize();
assertEquals(start_size,size); assertEquals(start_size, size);
} }
} }

@ -12,47 +12,43 @@ import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import mivan.model.Book; import mivan.model.Book;
import mivan.model.Item; import mivan.model.Item;
import mivan.model.Location; import mivan.model.Location;
import mivan.repository.BookRepository;
import mivan.repository.ItemRepository; import mivan.repository.ItemRepository;
import mivan.repository.ItemRepositoryImpl; import mivan.repository.ItemRepositoryImpl;
@TestMethodOrder(OrderAnnotation.class) @TestMethodOrder(OrderAnnotation.class)
public class ItemTest { public class ItemTest {
private ItemRepository itemRepository = new ItemRepositoryImpl(); private ItemRepository itemRepository = new ItemRepositoryImpl();
@Test
@Test @Order(1)
@Order(1) void testAddItem() {
void testAddItem() { Book book = null;
Book book = null; Location location = null;
Location location = null; Item item = new Item(book, location);
Item item = new Item(book, location); itemRepository.addItem(item);
itemRepository.addItem(item); int size = itemRepository.getSize();
int size = itemRepository.getSize(); assertEquals(1, size);
assertEquals(1, size); }
}
@Test
@Order(2)
@Test void testRemoveItem() {
@Order(2) int startSize = itemRepository.getSize();
void testRemoveItem() { Book book = null;
int startSize = itemRepository.getSize(); Location location = null;
Book book = null; Item item = new Item(book, location);
Location location = null; itemRepository.addItem(item);
Item item = new Item(book, location); int size = itemRepository.getSize();
itemRepository.addItem(item); assertEquals(startSize + 1, size);
int size = itemRepository.getSize();
assertEquals(startSize + 1, size); Optional<Item> optItem2 = itemRepository.findById(item.getId());
Optional<Item> optItem2 = itemRepository.findById(item.getId()); Item item2 = optItem2.get();
long ID = item2.getId();
Item item2 = optItem2.get(); itemRepository.deleteItemById(ID);
long ID = item2.getId();
itemRepository.deleteItemById(ID); int finalSize = itemRepository.getSize();
assertEquals(startSize, finalSize);
int finalSize = itemRepository.getSize();
assertEquals(startSize, finalSize); }
}
} }

@ -59,7 +59,7 @@ public class LoanTest {
String update_state = "returned"; String update_state = "returned";
loanRepository.updateLoan(0L,update_state); loanRepository.updateLoan(0L, update_state);
Optional<Loan> opt_loan = loanRepository.findById(0L); Optional<Loan> opt_loan = loanRepository.findById(0L);
@ -90,7 +90,6 @@ public class LoanTest {
Loan book2 = opt_loan2.get(); Loan book2 = opt_loan2.get();
long ID = book2.getId(); long ID = book2.getId();
loanRepository.deleteLoanById(ID); loanRepository.deleteLoanById(ID);
int size = loanRepository.getSize(); int size = loanRepository.getSize();

@ -46,8 +46,6 @@ public class StaffTest {
int newsize = staffRepository.getSize(); int newsize = staffRepository.getSize();
assertEquals(newsize, size + 1); assertEquals(newsize, size + 1);
Iterable<Staff> sad2 = staffRepository.findAll();
} }
@Test @Test
@ -97,7 +95,7 @@ public class StaffTest {
String newlastname = "test_update_staff_newlastname"; String newlastname = "test_update_staff_newlastname";
String newcity = "test_update_staff_newcity"; String newcity = "test_update_staff_newcity";
String newidka = "test_update_staff_newidka"; String newidka = "test_update_staff_newidka";
String newruolo = "test_update_staff_newrole"; String newruolo = "test_update_staff_newrole";
staffRepository.updateStaff(id, newfirstname, newlastname, newcity, newidka, newruolo, newlocation); staffRepository.updateStaff(id, newfirstname, newlastname, newcity, newidka, newruolo, newlocation);

Loading…
Cancel
Save