diff --git a/.gitignore b/.gitignore index df19b1b..0c01375 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ *.bib~ *.pdf + + +mivan/target +mivan/bin diff --git a/mivan/.editorconfig b/mivan/.editorconfig new file mode 100644 index 0000000..2eccc8b --- /dev/null +++ b/mivan/.editorconfig @@ -0,0 +1,14 @@ +# http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true +end_of_line = lf +charset = utf-8 + +[*.{yml,yaml,json}] +insert_final_newline = false diff --git a/multibook/.gitignore b/mivan/.gitignore similarity index 100% rename from multibook/.gitignore rename to mivan/.gitignore diff --git a/multibook/.mvn/wrapper/MavenWrapperDownloader.java b/mivan/.mvn/wrapper/MavenWrapperDownloader.java similarity index 97% rename from multibook/.mvn/wrapper/MavenWrapperDownloader.java rename to mivan/.mvn/wrapper/MavenWrapperDownloader.java index e76d1f3..2281075 100644 --- a/multibook/.mvn/wrapper/MavenWrapperDownloader.java +++ b/mivan/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-present the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import java.util.Properties; public class MavenWrapperDownloader { - private static final String WRAPPER_VERSION = "0.5.6"; + private static final String WRAPPER_VERSION = "0.5.5"; /** * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */ diff --git a/multibook/.mvn/wrapper/maven-wrapper.jar b/mivan/.mvn/wrapper/maven-wrapper.jar similarity index 91% rename from multibook/.mvn/wrapper/maven-wrapper.jar rename to mivan/.mvn/wrapper/maven-wrapper.jar index 2cc7d4a..0d5e649 100644 Binary files a/multibook/.mvn/wrapper/maven-wrapper.jar and b/mivan/.mvn/wrapper/maven-wrapper.jar differ diff --git a/multibook/.mvn/wrapper/maven-wrapper.properties b/mivan/.mvn/wrapper/maven-wrapper.properties similarity index 58% rename from multibook/.mvn/wrapper/maven-wrapper.properties rename to mivan/.mvn/wrapper/maven-wrapper.properties index 642d572..7d59a01 100644 --- a/multibook/.mvn/wrapper/maven-wrapper.properties +++ b/mivan/.mvn/wrapper/maven-wrapper.properties @@ -1,2 +1,2 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar diff --git a/multibook/mvnw b/mivan/mvnw similarity index 98% rename from multibook/mvnw rename to mivan/mvnw index a16b543..21d3ee8 100755 --- a/multibook/mvnw +++ b/mivan/mvnw @@ -19,7 +19,7 @@ # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- -# Maven Start Up Batch script +# Maven2 Start Up Batch script # # Required ENV vars: # ------------------ @@ -212,9 +212,9 @@ else echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." fi if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" fi while IFS="=" read key value; do case "$key" in (wrapperUrl) jarUrl="$value"; break ;; @@ -246,7 +246,7 @@ else else curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f fi - + else if [ "$MVNW_VERBOSE" = true ]; then echo "Falling back to using Java to download" diff --git a/multibook/mvnw.cmd b/mivan/mvnw.cmd similarity index 97% rename from multibook/mvnw.cmd rename to mivan/mvnw.cmd index c8d4337..84d60ab 100644 --- a/multibook/mvnw.cmd +++ b/mivan/mvnw.cmd @@ -18,7 +18,7 @@ @REM ---------------------------------------------------------------------------- @REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script +@REM Maven2 Start Up Batch script @REM @REM Required ENV vars: @REM JAVA_HOME - location of a JDK home dir @@ -26,7 +26,7 @@ @REM Optional ENV vars @REM M2_HOME - location of maven2's installed home dir @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven @REM e.g. to debug Maven itself, use @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @@ -120,7 +120,7 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B @@ -134,7 +134,7 @@ if exist %WRAPPER_JAR% ( ) ) else ( if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" ) if "%MVNW_VERBOSE%" == "true" ( echo Couldn't find %WRAPPER_JAR%, downloading it ... diff --git a/multibook/pom.xml b/mivan/pom.xml similarity index 56% rename from multibook/pom.xml rename to mivan/pom.xml index 4160597..4b75c2b 100644 --- a/multibook/pom.xml +++ b/mivan/pom.xml @@ -1,35 +1,43 @@ - 4.0.0 org.springframework.boot spring-boot-starter-parent - 2.2.2.RELEASE - + 2.2.1.RELEASE + - com.unimib.disco.mivan - multibook + mivan 0.0.1-SNAPSHOT - multibook - Project for book loan + mivan + Spring MVC and Hibernate project + UTF-8 + UTF-8 1.8 org.springframework.boot - spring-boot-starter-data-jpa + spring-boot-starter-thymeleaf - org.springframework.boot - spring-boot-devtools - runtime - true + spring-boot-starter-web + + org.hibernate + hibernate-core + + + org.hibernate + hibernate-entitymanager + + com.h2database h2 @@ -53,6 +61,10 @@ org.springframework.boot spring-boot-maven-plugin + + true + ${project.artifactId} + diff --git a/mivan/src/main/java/mivan/Mivan.java b/mivan/src/main/java/mivan/Mivan.java new file mode 100644 index 0000000..f8b851a --- /dev/null +++ b/mivan/src/main/java/mivan/Mivan.java @@ -0,0 +1,37 @@ +package mivan; + +import java.io.Console; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import mivan.model.User; +import mivan.repository.UserRepository; +import mivan.repository.UserRepositoryImpl; + +@SpringBootApplication +public class Mivan { + + 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); + } + +} diff --git a/mivan/src/main/java/mivan/model/Author.java b/mivan/src/main/java/mivan/model/Author.java new file mode 100644 index 0000000..3df1f6d --- /dev/null +++ b/mivan/src/main/java/mivan/model/Author.java @@ -0,0 +1,74 @@ +package mivan.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "author") +public class Author implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", unique = true) + private long id; + + @Column(name = "name", nullable=false) + + private String name; + + @ManyToMany(mappedBy="authors") + private List books; + + public Author() {} + public Author(String name) { + super(); + this.name = name; + this.books = new ArrayList (); + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getBooks() { + return this.books; + } + + public void addBook(Book book) { + if (!this.books.contains(book)) { + this.books.add(book); + book.addAuthor(this); + } + } + + public void removeBook(Book book) { + if (this.books.contains(book)) + this.books.remove(book); + book.removeAuthor(this); + } + + +} diff --git a/mivan/src/main/java/mivan/model/Book.java b/mivan/src/main/java/mivan/model/Book.java new file mode 100644 index 0000000..0c00668 --- /dev/null +++ b/mivan/src/main/java/mivan/model/Book.java @@ -0,0 +1,93 @@ +package mivan.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinTable; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "book") +public class Book implements Serializable { + + private static final long serialVersionUID = 19L; + + @Id + @Column(name = "isbn", nullable=false, unique=true) + private long isbn; + + @Column(name = "title", nullable=false) + private String title; + + @OneToOne + private Book prequel; + + @ManyToMany + @JoinTable( + name = "book_has_author", + joinColumns=@JoinColumn(name="isbn", referencedColumnName="isbn"), + inverseJoinColumns=@JoinColumn(name="id", referencedColumnName="id") ) + private List authors; + + public Book() { + } + + public Book(long isbn, String title, Book prequel) { + this.isbn = isbn; + this.title = title; + this.prequel = prequel; + this.authors = new ArrayList(); + } + + public long getIsbn() { + return isbn; + } + + public String getTitle() { + return title; + } + + public Book getPrequel() { + return prequel; + } + + public void setIsbn(long isbn) { + this.isbn = isbn; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setPrequel(Book prequel) { + this.prequel = prequel; + } + + public List getAuthors() { + return this.authors; + } + + public void addAuthor(Author author) { + + if (!this.authors.contains(author)) { + this.authors.add(author); + author.addBook(this); + } + } + + public void removeAuthor(Author author) { + if (this.authors.contains(author)) { + this.authors.remove(author); + author.removeBook(this); + } + + } + +} diff --git a/mivan/src/main/java/mivan/model/Location.java b/mivan/src/main/java/mivan/model/Location.java new file mode 100644 index 0000000..58246d9 --- /dev/null +++ b/mivan/src/main/java/mivan/model/Location.java @@ -0,0 +1,83 @@ +package mivan.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "location") +public class Location implements Serializable { + + private static final long serialVersionUID = -5124436115031696628L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", unique = true) + private Long id; + + @Column(name = "name", nullable = false, unique = true) + private String name; + + @Column(name = "adress", nullable = false) + private String adress; + + @OneToMany(mappedBy = "location") + private List staffs; + + protected Location() { + } + + public Location(String name, String adress) { + this.name = name; + this.adress = adress; + this.staffs = new ArrayList(); + } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getAdress() { + return adress; + } + + public List getStaffs() { + return staffs; + } + + public void setId(Long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setAdress(String adress) { + this.adress = adress; + } + + public void setStaffs(List staffs) { + this.staffs = staffs; + } + + public void addStaff(Staff staff) { + this.staffs.add(staff); + if (staff.getLocation() != this) { + staff.setLocation(this); + } + } + +} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Person.java b/mivan/src/main/java/mivan/model/Person.java similarity index 70% rename from multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Person.java rename to mivan/src/main/java/mivan/model/Person.java index 7dd3068..9c9d46a 100644 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Person.java +++ b/mivan/src/main/java/mivan/model/Person.java @@ -1,15 +1,19 @@ -package com.unimib.disco.mivan.multibook.model; +package mivan.model; +import java.io.Serializable; import javax.persistence.*; @MappedSuperclass -public class Person { +public class Person implements Serializable { + private static final long serialVersionUID = -5124436115031696628L; + + @Id - @Column(name = "id", nullable=false) - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", unique = true) private long id; @Column(name = "firstName", nullable=false) @@ -63,6 +67,11 @@ public class Person { this.city = city; } + @Override + public String toString() { + return "Person [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", city=" + city + "]"; + } + } diff --git a/mivan/src/main/java/mivan/model/Staff.java b/mivan/src/main/java/mivan/model/Staff.java new file mode 100644 index 0000000..cbec79c --- /dev/null +++ b/mivan/src/main/java/mivan/model/Staff.java @@ -0,0 +1,71 @@ +package mivan.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "staff") +public class Staff extends Person { + + private static final long serialVersionUID = -5124436115031696628L; + + @Column(name = "idka", nullable = false, unique = true) + private String idka; + + @Column(name = "ruolo", nullable = false) + private String ruolo; + + @ManyToOne + @JoinColumn(name = "location_id", referencedColumnName = "id") + private Location location; + + public Staff() { + super(); + // TODO Auto-generated constructor stub + } + + public Staff(String firstName, String lastName, String city, String idka, String ruolo, Location location) { + super(firstName, lastName, city); + this.idka = idka; + this.ruolo = ruolo; + setLocation(location); + } + + public Staff(String firstName, String lastName, String city, String idka, String ruolo) { + super(firstName, lastName, city); + this.idka = idka; + this.ruolo = ruolo; + + } + + public String getIdka() { + return idka; + } + + public String getRuolo() { + return ruolo; + } + + public Location getLocation() { + return location; + } + + public void setIdka(String idka) { + this.idka = idka; + } + + public void setRuolo(String ruolo) { + this.ruolo = ruolo; + } + + public void setLocation(Location location) { + this.location = location; + if (!location.getStaffs().contains(this)) { + location.getStaffs().add(this); + } + } + +} diff --git a/mivan/src/main/java/mivan/model/User.java b/mivan/src/main/java/mivan/model/User.java new file mode 100644 index 0000000..3b4bdec --- /dev/null +++ b/mivan/src/main/java/mivan/model/User.java @@ -0,0 +1,90 @@ +package mivan.model; + + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Entity +@Table(name = "user") +public class User extends Person { + + private static final long serialVersionUID = -5124436115031696628L; + + @Column(name = "username", nullable=false,unique=true) + private String username; + + @Column(name = "email", nullable=false,unique=true) + private String email; + + @Column(name = "password", nullable=false) + private String password; + + + protected User() { + } + + + +public User(String firstName, String lastName, String city,String username, String email, String password) { + super(firstName,lastName,city); + this.username = username; + this.email = email; + this.password = password; +} + + + +public String getUsername() { + return username; +} + + + +public void setUsername(String username) { + this.username = username; +} + + + +public String getEmail() { + return email; +} + + + +public void setEmail(String email) { + this.email = email; +} + + + +public String getPassword() { + return password; +} + + + +public void setPassword(String password) { + this.password = password; +} + + + +public static long getSerialversionuid() { + return serialVersionUID; +} + + + +@Override +public String toString() { + return "User [username=" + username + ", email=" + email + ", password=" + password + "]"; +} + + + + + + +} diff --git a/mivan/src/main/java/mivan/repository/AuthorRepository.java b/mivan/src/main/java/mivan/repository/AuthorRepository.java new file mode 100644 index 0000000..b5fc0d2 --- /dev/null +++ b/mivan/src/main/java/mivan/repository/AuthorRepository.java @@ -0,0 +1,20 @@ +package mivan.repository; + +import mivan.model.Author; + +public interface AuthorRepository extends Repository { + + public void deleteAuthorById(Long id); + + public void addAuthor(Author author); + + public void updateAuthor(Long id, String name); + + public Author searchAuthorByName(String name); + + public void addBook(Long isbn, Long id); + + public void removeBook(Long isbn, Long id); + + public int getSize(); +} diff --git a/mivan/src/main/java/mivan/repository/AuthorRepositoryImpl.java b/mivan/src/main/java/mivan/repository/AuthorRepositoryImpl.java new file mode 100644 index 0000000..ea0d85b --- /dev/null +++ b/mivan/src/main/java/mivan/repository/AuthorRepositoryImpl.java @@ -0,0 +1,156 @@ +package mivan.repository; + +import java.util.List; +import java.util.Optional; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import mivan.model.Author; +import mivan.model.Book; + +public class AuthorRepositoryImpl implements AuthorRepository { + + private EntityManagerFactory entityManagerFactory; + + public AuthorRepositoryImpl() { + this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan"); + } + + @Override + public Optional findById(Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + Author author = entityManager.find(Author.class, id); + entityManager.close(); + return Optional.ofNullable(author); + } + + @Override + public Iterable findAll() { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + List author = entityManager.createQuery("FROM Author", Author.class).getResultList(); + entityManager.close(); + return author; + } + + @Override + public void deleteAuthorById(Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Author author = entityManager.find(Author.class, id); + entityManager.remove(author); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + @Override + public void addAuthor(Author author) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + entityManager.persist(author); + entityManager.getTransaction().commit(); + entityManager.close(); + + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + @Override + public void updateAuthor(Long id, String name) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Author author = entityManager.find(Author.class, id); + author.setName(name); + entityManager.persist(author); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + @Override + public Author searchAuthorByName(String name) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + + Author author = null; + try { + author = (Author) entityManager.createQuery("FROM Author u WHERE lower(u.name) = '" + name.toLowerCase() + "'") + .getSingleResult(); + + entityManager.close(); + } catch (Exception ex) { + author = null; + } + + return author; + } + + @Override + public int getSize() { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + int size = 0; + try { + size = entityManager.createQuery("FROM Author").getResultList().size(); + + entityManager.close(); + } catch (Exception ex) { + size = 0; + } + return size; + } + + @Override + public void addBook(Long isbn, Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Book book = entityManager.find(Book.class, isbn); + Author author = entityManager.find(Author.class, id); + book.addAuthor(author); + entityManager.persist(book); + entityManager.persist(author); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + @Override + public void removeBook(Long isbn, Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Book book = entityManager.find(Book.class, isbn); + Author author = entityManager.find(Author.class, id); + book.removeAuthor(author); + entityManager.persist(book); + entityManager.persist(author); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + +} diff --git a/mivan/src/main/java/mivan/repository/BookRepository.java b/mivan/src/main/java/mivan/repository/BookRepository.java new file mode 100644 index 0000000..ba772ae --- /dev/null +++ b/mivan/src/main/java/mivan/repository/BookRepository.java @@ -0,0 +1,23 @@ +package mivan.repository; + +import mivan.model.Book; + +public interface BookRepository extends Repository{ + + //public Optional findUserAddressById(Long id); + + public void deleteBookById(Long isbn); + + public void addBook(Book book); + + public void updateBook(Long isbn, String title, Book prequel); + + public Book searchBookByTitle(String title); + + public void addAuthor(Long isbn, Long id); + + public void removeAuthor(Long isbn, Long id); + + public int getSize(); +} + diff --git a/mivan/src/main/java/mivan/repository/BookRepositoryImpl.java b/mivan/src/main/java/mivan/repository/BookRepositoryImpl.java new file mode 100644 index 0000000..4c0006e --- /dev/null +++ b/mivan/src/main/java/mivan/repository/BookRepositoryImpl.java @@ -0,0 +1,162 @@ +package mivan.repository; + +import java.util.List; +import java.util.Optional; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import mivan.model.Author; +import mivan.model.Book; + +public class BookRepositoryImpl implements BookRepository { + + private EntityManagerFactory entityManagerFactory; + + public BookRepositoryImpl(){ + this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan"); + } + + @Override + public Optional findById(Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + Book book = entityManager.find(Book.class, id); + entityManager.close(); + return Optional.ofNullable(book); + } + + @Override + public Iterable findAll() { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + List book = entityManager.createQuery("FROM Book", Book.class).getResultList(); + entityManager.close(); + return book; + } + + @Override + public void deleteBookById(Long isbn) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Book book = entityManager.find(Book.class, isbn); + entityManager.remove(book); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + @Override + public void addBook(Book book) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + entityManager.persist(book); + entityManager.getTransaction().commit(); + entityManager.close(); + + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + @Override + public void updateBook(Long isbn, String title, Book prequel) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Book book = entityManager.find(Book.class, isbn); + book.setTitle(title); + entityManager.persist(book); + if (prequel != null) { + book.setPrequel(prequel); + } + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + @Override + public Book searchBookByTitle(String title) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + + Book book = null; + try { + book = (Book) entityManager.createQuery("FROM Book u WHERE lower(u.title) = '" + title.toLowerCase() + "'") + .getSingleResult(); + + entityManager.close(); + } catch (Exception ex) { + book = null; + } + + return book; + } + + @Override + public int getSize() { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + int size = 0; + try { + size = entityManager.createQuery("FROM Book").getResultList().size(); + + entityManager.close(); + } catch (Exception ex) { + size = 0; + } + return size; + } + + + + @Override + public void addAuthor(Long isbn, Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Book book = entityManager.find(Book.class, isbn); + Author author = entityManager.find(Author.class, id); + book.addAuthor(author); + entityManager.persist(book); + entityManager.persist(author); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + @Override + public void removeAuthor(Long isbn, Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Book book = entityManager.find(Book.class, isbn); + Author author = entityManager.find(Author.class, id); + book.removeAuthor(author); + entityManager.persist(book); + entityManager.persist(author); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + + +} diff --git a/mivan/src/main/java/mivan/repository/LocationRepository.java b/mivan/src/main/java/mivan/repository/LocationRepository.java new file mode 100644 index 0000000..2980213 --- /dev/null +++ b/mivan/src/main/java/mivan/repository/LocationRepository.java @@ -0,0 +1,20 @@ +package mivan.repository; + +import java.util.List; + +import mivan.model.Location; +import mivan.model.Staff; + +public interface LocationRepository extends Repository { + + public void deleteLocationById(Long id); + + public void addLocation(Location user); + + public void updateLocation(Long id, String name, String adress, List staffs); + + public Location searchLocationByName(String name); + + public int getSize(); + +} diff --git a/mivan/src/main/java/mivan/repository/LocationRepositoryImpl.java b/mivan/src/main/java/mivan/repository/LocationRepositoryImpl.java new file mode 100644 index 0000000..a60cadc --- /dev/null +++ b/mivan/src/main/java/mivan/repository/LocationRepositoryImpl.java @@ -0,0 +1,114 @@ +package mivan.repository; + +import java.util.List; +import java.util.Optional; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import mivan.model.Location; +import mivan.model.Staff; + +public class LocationRepositoryImpl implements LocationRepository { + + private EntityManagerFactory entityManagerFactory; + + public LocationRepositoryImpl() { + this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan"); + } + + @Override + public Optional findById(Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + Location location = entityManager.find(Location.class, id); + entityManager.close(); + return Optional.ofNullable(location); + } + + @Override + public Iterable findAll() { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + List location = entityManager.createQuery("FROM Location", Location.class).getResultList(); + entityManager.close(); + return location; + } + + public void deleteLocationById(Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Location location = entityManager.find(Location.class, id); + entityManager.remove(location); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + public void addLocation(Location location) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + entityManager.persist(location); + entityManager.getTransaction().commit(); + entityManager.close(); + + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + public void updateLocation(Long id, String name, String adress, List staffs) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Location location = entityManager.find(Location.class, id); + location.setName(name); + location.setAdress(adress); + location.setStaffs(staffs); + entityManager.persist(location); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + public Location searchLocationByName(String name) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + + Location location = null; + try { + location = (Location) entityManager + .createQuery("FROM Location u WHERE lower(u.name) = '" + name.toLowerCase() + "'") + .getSingleResult(); + + entityManager.close(); + } catch (Exception ex) { + location = null; + } + + return location; + } + + public int getSize() { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + int size = 0; + try { + size = entityManager.createQuery("FROM Location").getResultList().size(); + + entityManager.close(); + } catch (Exception ex) { + size = 0; + } + return size; + } +} diff --git a/mivan/src/main/java/mivan/repository/Repository.java b/mivan/src/main/java/mivan/repository/Repository.java new file mode 100644 index 0000000..8c14a0f --- /dev/null +++ b/mivan/src/main/java/mivan/repository/Repository.java @@ -0,0 +1,8 @@ +package mivan.repository; + +import java.util.Optional; + +public interface Repository { + Optional findById(ID id); + Iterable findAll(); +} diff --git a/mivan/src/main/java/mivan/repository/StaffRepository.java b/mivan/src/main/java/mivan/repository/StaffRepository.java new file mode 100644 index 0000000..651b5c6 --- /dev/null +++ b/mivan/src/main/java/mivan/repository/StaffRepository.java @@ -0,0 +1,21 @@ +package mivan.repository; + +import mivan.model.Location; +import mivan.model.Staff; + + +public interface StaffRepository extends Repository{ + + public void deleteStaffById(Long id); + + public void addStaff(Staff user); + + public void updateStaff(Long id, String firstname, String lastname, String city, String idka, String ruolo, Location location); + + public Staff searchStaffByidka(String idka); + + //public List searchStaffByRole(String role); + + + public int getSize(); +} diff --git a/mivan/src/main/java/mivan/repository/StaffRepositoryImpl.java b/mivan/src/main/java/mivan/repository/StaffRepositoryImpl.java new file mode 100644 index 0000000..ae8df0c --- /dev/null +++ b/mivan/src/main/java/mivan/repository/StaffRepositoryImpl.java @@ -0,0 +1,118 @@ +package mivan.repository; + +import java.util.List; +import java.util.Optional; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import mivan.model.Location; +import mivan.model.Staff; + +public class StaffRepositoryImpl implements StaffRepository{ + + private EntityManagerFactory entityManagerFactory; + + public StaffRepositoryImpl() { + this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan"); + } + + @Override + public Optional findById(Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + Staff staff = entityManager.find(Staff.class, id); + entityManager.close(); + return Optional.ofNullable(staff); + } + + + @Override + public Iterable findAll() { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + List staffs = entityManager.createQuery("FROM Staff", Staff.class).getResultList(); + entityManager.close(); + return staffs; + } + + public void deleteStaffById(Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Staff staff = entityManager.find(Staff.class, id); + entityManager.remove(staff); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + public void addStaff(Staff staff) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + entityManager.persist(staff); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + + public void updateStaff(Long id, String firstname, String lastname, String city,String idka,String ruolo,Location location) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + Staff staff = entityManager.find(Staff.class, id); + staff.setFirstName(firstname); + staff.setLastName(lastname); + staff.setCity(city); + staff.setIdka(idka); + staff.setRuolo(ruolo); + staff.setLocation(location); + + entityManager.persist(staff); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + public Staff searchStaffByidka(String idka) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + + Staff staff = null; + try { + staff = (Staff) entityManager.createQuery("FROM Staff u WHERE lower(u.idka) = '" + idka.toLowerCase() + "'") + .getSingleResult(); + + entityManager.close(); + } catch (Exception ex) { + staff = null; + } + + return staff; + } + + public int getSize() { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + int size = 0; + try { + size = entityManager.createQuery("FROM Staff").getResultList().size(); + + entityManager.close(); + } catch (Exception ex) { + size = 0; + } + return size; + } +} diff --git a/mivan/src/main/java/mivan/repository/UserRepository.java b/mivan/src/main/java/mivan/repository/UserRepository.java new file mode 100644 index 0000000..f040321 --- /dev/null +++ b/mivan/src/main/java/mivan/repository/UserRepository.java @@ -0,0 +1,21 @@ +package mivan.repository; + +import mivan.model.User; + +public interface UserRepository extends Repository{ + + //public Optional findUserAddressById(Long id); + + public void deleteUserById(Long id); + + public void addUser(User user); + + public void updateUser(Long id, String firstname, String lastname, String city,String username, String email, String password); + + public User searchUserByName(String username); + + public User searchUserByEmail(String email); + + + public int getSize(); +} diff --git a/mivan/src/main/java/mivan/repository/UserRepositoryImpl.java b/mivan/src/main/java/mivan/repository/UserRepositoryImpl.java new file mode 100644 index 0000000..6ce5cd8 --- /dev/null +++ b/mivan/src/main/java/mivan/repository/UserRepositoryImpl.java @@ -0,0 +1,133 @@ +package mivan.repository; + +import java.util.List; +import java.util.Optional; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + + +import mivan.model.User; + +public class UserRepositoryImpl implements UserRepository { + + private EntityManagerFactory entityManagerFactory; + + public UserRepositoryImpl() { + this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan"); + } + + @Override + public Optional findById(Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + User user = entityManager.find(User.class, id); + entityManager.close(); + return Optional.ofNullable(user); + } + + @Override + public Iterable findAll() { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + List users = entityManager.createQuery("FROM User", User.class).getResultList(); + entityManager.close(); + return users; + } + + public void deleteUserById(Long id) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + User user = entityManager.find(User.class, id); + entityManager.remove(user); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + public void addUser(User user) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + entityManager.persist(user); + entityManager.getTransaction().commit(); + entityManager.close(); + + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + + public void updateUser(Long id, String firstname, String lastname, String city,String username, String email, String password) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + User user = entityManager.find(User.class, id); + user.setFirstName(firstname); + user.setLastName(lastname); + user.setCity(city); + user.setUsername(username); + user.setEmail(email); + user.setPassword(password); + entityManager.persist(user); + entityManager.getTransaction().commit(); + entityManager.close(); + } catch (Exception ex) { + entityManager.getTransaction().rollback(); + } + } + + public User searchUserByName(String username) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + + User user = null; + try { + user = (User) entityManager.createQuery("FROM User u WHERE lower(u.username) = '" + username.toLowerCase() + "'") + .getSingleResult(); + + entityManager.close(); + } catch (Exception ex) { + user = null; + } + + return user; + } + + public User searchUserByEmail(String email) { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + + User user = null; + try { + user = (User) entityManager.createQuery("FROM User u WHERE lower(u.email) = '" + email.toLowerCase() + "'") + .getSingleResult(); + + entityManager.close(); + } catch (Exception ex) { + user = null; + } + + return user; + } + + public int getSize() { + final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); + int size = 0; + try { + size = entityManager.createQuery("FROM User").getResultList().size(); + + entityManager.close(); + } catch (Exception ex) { + size = 0; + } + return size; + } +} diff --git a/mivan/src/main/resources/META-INF/persistence.xml b/mivan/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..fec0853 --- /dev/null +++ b/mivan/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,27 @@ + + + org.hibernate.jpa.HibernatePersistenceProvider + + + + + + + + + + + + + + + diff --git a/mivan/src/main/resources/application.properties b/mivan/src/main/resources/application.properties new file mode 100644 index 0000000..a860a0d --- /dev/null +++ b/mivan/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.application.name=Mivan +spring.datasource.url=jdbc:h2:file:./data/demo \ No newline at end of file diff --git a/mivan/src/test/java/mivan/AuthorBookTest.java b/mivan/src/test/java/mivan/AuthorBookTest.java new file mode 100644 index 0000000..3500557 --- /dev/null +++ b/mivan/src/test/java/mivan/AuthorBookTest.java @@ -0,0 +1,30 @@ +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.MethodOrderer.OrderAnnotation; + +import mivan.model.Author; +import mivan.repository.AuthorRepository; +import mivan.repository.AuthorRepositoryImpl; +import mivan.repository.BookRepository; +import mivan.repository.BookRepositoryImpl; + +@TestMethodOrder(OrderAnnotation.class) +public class AuthorBookTest { + + private AuthorRepository authorRepository = new AuthorRepositoryImpl(); + + private BookRepository bookRepository = new BookRepositoryImpl(); + + + + + + +} diff --git a/mivan/src/test/java/mivan/AuthorTest.java b/mivan/src/test/java/mivan/AuthorTest.java new file mode 100644 index 0000000..59002f2 --- /dev/null +++ b/mivan/src/test/java/mivan/AuthorTest.java @@ -0,0 +1,78 @@ +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.MethodOrderer.OrderAnnotation; + +import mivan.model.Author; +import mivan.repository.AuthorRepository; +import mivan.repository.AuthorRepositoryImpl; + +@TestMethodOrder(OrderAnnotation.class) +public class AuthorTest { + + private AuthorRepository authorRepository = new AuthorRepositoryImpl(); + + + @Test + @Order(1) + void testAddAuthor() { + + + String name = "Ivan"; + + Author author = new Author(name); + + authorRepository.addAuthor(author); + + int size = authorRepository.getSize(); + + + assertEquals(size, 1); + } + + @Test + @Order(2) + void testUpdateAuthor() { + + String name = "Ivan"; + + Author author = new Author(name); + + authorRepository.addAuthor(author); + + String updatedName ="Javoso"; + + authorRepository.updateAuthor(author.getId(), updatedName); + Optional updated_author = authorRepository.findById(author.getId()); + updated_author.ifPresent(a -> {assertEquals(a.getName(), updatedName);}); + + } + + @Test + @Order(3) + void testDeleteUser() { + int size = authorRepository.getSize(); + String name = "gollum"; + + Author author = new Author(name); + + authorRepository.addAuthor(author); + + Author editAuthor = authorRepository.searchAuthorByName(name); + + long ID = editAuthor.getId(); + + authorRepository.deleteAuthorById(ID); + + int end_size = authorRepository.getSize(); + assertEquals(end_size, size); + } + + +} diff --git a/mivan/src/test/java/mivan/BookTest.java b/mivan/src/test/java/mivan/BookTest.java new file mode 100644 index 0000000..9ff3abe --- /dev/null +++ b/mivan/src/test/java/mivan/BookTest.java @@ -0,0 +1,88 @@ +package mivan; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Optional; + +import javax.validation.constraints.AssertTrue; + +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; + +import mivan.model.Author; +import mivan.model.Book; +import mivan.model.User; +import mivan.repository.BookRepository; +import mivan.repository.BookRepositoryImpl; + +public class BookTest { + + + private BookRepository bookRepository = new BookRepositoryImpl(); + + + @Test + @Order(1) + void testAddBook() { + + long isbn = 1234; + String title = "illiade"; + Book prequel = null; + + Book book = new Book(isbn, title, prequel); + + bookRepository.addBook(book); + + int size = bookRepository.getSize(); + + + assertEquals(size, 1); + + } + + @Test + @Order(2) + void testUpdateBook(){ + long isbn = 12348; + String title = "odissea"; + Book prequel = null; + + Book book = new Book(isbn, title, prequel); + + bookRepository.addBook(book); + String update_title = "eneide"; + bookRepository.updateBook(isbn, update_title, prequel); + + Optional opt_book2 = bookRepository.findById(isbn); + + Book book2 = opt_book2.get(); + assertTrue(update_title.equals(book2.getTitle())); + + } + + + @Test + @Order(3) + void testDeleteBook() { + int start_size = bookRepository.getSize(); + long isbn = 12345; + String title = "illiade"; + Book prequel = null; + + Book book = new Book(isbn, title, prequel); + + bookRepository.addBook(book); + + Optional opt_book2 = bookRepository.findById(isbn); + + Book book2 = opt_book2.get(); + long ID = book2.getIsbn(); + + bookRepository.deleteBookById(ID); + + int size = bookRepository.getSize(); + assertEquals(start_size,size); + } + +} diff --git a/mivan/src/test/java/mivan/LocationTest.java b/mivan/src/test/java/mivan/LocationTest.java new file mode 100644 index 0000000..4202fa8 --- /dev/null +++ b/mivan/src/test/java/mivan/LocationTest.java @@ -0,0 +1,116 @@ +package mivan; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.ArrayList; +import java.util.List; +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.MethodOrderer.OrderAnnotation; + +import mivan.model.Location; +import mivan.model.Staff; +import mivan.repository.LocationRepository; +import mivan.repository.LocationRepositoryImpl; +import mivan.repository.StaffRepository; +import mivan.repository.StaffRepositoryImpl; + +@TestMethodOrder(OrderAnnotation.class) +public class LocationTest { + + private StaffRepository staffRepository = new StaffRepositoryImpl(); + private LocationRepository locationRepository = new LocationRepositoryImpl(); + + @Test + @Order(1) + void testAddLocation() { + + String lname = "Library bria 2"; + String ladress = "via chissa dove2"; + Location location = new Location(lname, ladress); + + int size = locationRepository.getSize(); + + locationRepository.addLocation(location); + + int newsize = locationRepository.getSize(); + + assertEquals(newsize, size + 1); + } + + @Test + @Order(2) + void testUpdateLocation() { + + // creo nuovo menìmbro dello staff + String firstname = "Ivan"; + String lastname = "Donati"; + String city = "Milano"; + String idka = "lihwelhqluchwlir8"; + String ruolo = "frontoffice"; + Staff newstaff1 = new Staff(firstname, lastname, city, idka, ruolo); + + String firstname2 = "Rossi"; + String lastname2 = "Donati"; + String city2 = "Milano"; + String idka2 = "lihwelhsfgdghhwlir8"; + String ruolo2 = "manager"; + Staff newstaff2 = new Staff(firstname2, lastname2, city2, idka2, ruolo2); + + staffRepository.addStaff(newstaff1); + staffRepository.addStaff(newstaff2); + + List staffs = new ArrayList(); + staffs.add(newstaff1); + staffs.add(newstaff2); + + // creo una locazione + String lname = "Library cosa 2"; + String ladress = "via chissa dove"; + Location newlocation = new Location(lname, ladress); + locationRepository.addLocation(newlocation); + + Location editLocation = locationRepository.searchLocationByName(lname); + + long id = editLocation.getId(); + // nuovi dati per modificare i vecchi + String newlName = "Library bria 5"; + String newlAdress = "via prossima stella"; + + // aggungo i membri dello staff / modifico i dati della location + locationRepository.updateLocation(id, newlName, newlAdress, staffs); + + Optional location = locationRepository.findById(id); + location.ifPresent(a -> { + assertEquals(a.getName(), newlName); + assertEquals(a.getAdress(), newlAdress); + assertEquals(a.getStaffs(), staffs); + }); + } + + @Test + @Order(3) + void testDeleteLocation() { + + String lname = "Library bria 9"; + String ladress = "via chissa dove9"; + Location location = new Location(lname, ladress); + locationRepository.addLocation(location); + + Location removeLocation = locationRepository.searchLocationByName(lname); + + long ID = removeLocation.getId(); + + int size = locationRepository.getSize(); + + locationRepository.deleteLocationById(ID); + + int newsize = locationRepository.getSize(); + + assertEquals(newsize, size -1); + } + +} diff --git a/mivan/src/test/java/mivan/StaffTest.java b/mivan/src/test/java/mivan/StaffTest.java new file mode 100644 index 0000000..5920453 --- /dev/null +++ b/mivan/src/test/java/mivan/StaffTest.java @@ -0,0 +1,146 @@ +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.MethodOrderer.OrderAnnotation; + +import mivan.model.Location; +import mivan.model.Staff; +import mivan.repository.LocationRepository; +import mivan.repository.LocationRepositoryImpl; +import mivan.repository.StaffRepository; +import mivan.repository.StaffRepositoryImpl; + +@TestMethodOrder(OrderAnnotation.class) +public class StaffTest { + + private StaffRepository staffRepository = new StaffRepositoryImpl(); + private LocationRepository locationRepository = new LocationRepositoryImpl(); + + @Test + @Order(1) + void testAddStaff() { + + String firstname = "Ivan"; + String lastname = "Donati"; + String city = "Milano"; + String idka = "lihwelhqluchwlir8"; + String ruolo = "frontoffice"; + + String lname = "Library bria 2"; + String ladress = "via chissa dove"; + Location location = new Location(lname, ladress); + locationRepository.addLocation(location); + + Staff newstaff = new Staff(firstname, lastname, city, idka, ruolo, location); + + int size = staffRepository.getSize(); + + staffRepository.addStaff(newstaff); + + int newsize = staffRepository.getSize(); + + assertEquals(newsize, size + 1); + + Iterable sad2 = staffRepository.findAll(); + } + + @Test + @Order(2) + void testUpdateStaff() { + + // creo una locazione + String lname = "Library cosa 2"; + String ladress = "via chissa dove"; + Location location = new Location(lname, ladress); + + // creo una seconda locazione + String newlName = "Library destra 5"; + String newlAdress = "via prossima stella"; + Location newlocation = new Location(newlName, newlAdress); + + int losize = locationRepository.getSize(); + + locationRepository.addLocation(location); + locationRepository.addLocation(newlocation); + + int newlosize = locationRepository.getSize(); + + assertEquals(newlosize, losize + 2); // ci sono 2 locazioni aggunte + + // creo un membro dello staff + String firstname = "Maccio"; + String lastname = "Donati"; + String city = "Milano"; + String idka = "lihwelhqluchwlir8"; + String ruolo = "frontoffice"; + Staff newstaff = new Staff(firstname, lastname, city, idka, ruolo); + + int size = staffRepository.getSize(); + + staffRepository.addStaff(newstaff); + + int newsize = staffRepository.getSize(); + + assertEquals(newsize, size + 1); // c'è 1 nuovo membro dello staff + + Staff editStaff = staffRepository.searchStaffByidka(idka); + + long id = editStaff.getId(); + String newfirstname = "Ivans"; + String newlastname = "Donatis"; + String newcity = "Milanos"; + String newidka = "lihwelhkluchwlir5"; + String newruolo = "spazzino"; + + staffRepository.updateStaff(id, newfirstname, newlastname, newcity, newidka, newruolo, newlocation); + + Optional staff = staffRepository.findById(id); + staff.ifPresent(a -> { + assertEquals(a.getFirstName(), newfirstname); + assertEquals(a.getLastName(), newlastname); + assertEquals(a.getCity(), newcity); + assertEquals(a.getIdka(), newidka); + assertEquals(a.getRuolo(), newruolo); + assertEquals(a.getLocation().getName(), newlName); + assertEquals(a.getLocation().getAdress(), newlAdress); + + }); + } + + @Test + @Order(3) + void testDeleteStaff() { + + String firstname = "John"; + String lastname = "Donati"; + String city = "Milano"; + String idka = "lihwelhsfghhwlir8"; + String ruolo = "manager"; + + String lname = "Library siniz 2"; + String ladress = "via sassa dove"; + Location location = new Location(lname, ladress); + locationRepository.addLocation(location); + + Staff newstaff = new Staff(firstname, lastname, city, idka, ruolo, location); + + staffRepository.addStaff(newstaff); + + Staff editStaff = staffRepository.searchStaffByidka(idka); + + long ID = editStaff.getId(); + + staffRepository.deleteStaffById(ID); + ; + + int size = staffRepository.getSize(); + assertEquals(size, 0); + } + +} diff --git a/mivan/src/test/java/mivan/UserTest.java b/mivan/src/test/java/mivan/UserTest.java new file mode 100644 index 0000000..d7efa13 --- /dev/null +++ b/mivan/src/test/java/mivan/UserTest.java @@ -0,0 +1,109 @@ +package mivan; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Optional; + +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; + +import mivan.model.User; +import mivan.repository.UserRepository; +import mivan.repository.UserRepositoryImpl; + +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +@TestMethodOrder(OrderAnnotation.class) +class UserTest { + + private UserRepository userRepository = new UserRepositoryImpl(); + + @Test + @Order(1) + void testAddUser() { + + String firstname = "Ivan"; + String lastname = "Donati"; + String city = "Milano"; + String username = "p.donati"; + String email = "p.donati@campus.unimib.it"; + String password = "pdonatipassword"; + User user = new User(firstname, lastname, city, username, email, password); + + int size = userRepository.getSize(); + + userRepository.addUser(user); + + int newsize = userRepository.getSize(); + + assertEquals(newsize, size + 1); + } + + @Test + @Order(2) + void testUpdateCompany() { + + String firstname = "Simone"; + String lastname = "Donati"; + String city = "Milano"; + String username = "i.donati"; + String email = "i.donati@campus.unimib.it"; + String password = "passwordsicura"; + + User newuser = new User(firstname, lastname, city, username, email, password); + + userRepository.addUser(newuser); + + User editUser = userRepository.searchUserByName(username); + + long id = editUser.getId(); + + String newfirstname = "Ivans"; + String newlastname = "Donatis"; + String newcity = "Milanos"; + String newusername = "asd.donati1s"; + String newemail = "asd.donati@campus.unimib.com"; + String newpassword = "newpdonatipassword"; + + userRepository.updateUser(id, newfirstname, newlastname, newcity, newusername, newemail, newpassword); + + Optional user = userRepository.findById(id); + user.ifPresent(a -> { + assertEquals(a.getFirstName(), newfirstname); + assertEquals(a.getLastName(), newlastname); + assertEquals(a.getCity(), newcity); + assertEquals(a.getUsername(), newusername); + assertEquals(a.getEmail(), newemail); + assertEquals(a.getPassword(), newpassword); + + }); + } + + @Test + @Order(3) + void testDeleteUser() { + + String firstname = "Rossi"; + String lastname = "Donati"; + String city = "Milano"; + String username = "r.donati"; + String email = "r.donati@campus.unimib.it"; + String password = "rdonatipassword"; + + User newuser = new User(firstname, lastname, city, username, email, password); + + userRepository.addUser(newuser); + + User editUser = userRepository.searchUserByName(username); + + long ID = editUser.getId(); + + int size = userRepository.getSize(); + + userRepository.deleteUserById(ID); + + int newsize = userRepository.getSize(); + assertEquals(newsize, size - 1); + } +} diff --git a/multibook/database.mv.db b/multibook/database.mv.db deleted file mode 100644 index c151f91..0000000 Binary files a/multibook/database.mv.db and /dev/null differ diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/MultibookApplication.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/MultibookApplication.java deleted file mode 100644 index 34fb121..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/MultibookApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.unimib.disco.mivan.multibook; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class MultibookApplication { - - public static void main(String[] args) { - SpringApplication.run(MultibookApplication.class, args); - } - -} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/controller/UserController.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/controller/UserController.java deleted file mode 100644 index b6cb4d1..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/controller/UserController.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.unimib.disco.mivan.multibook.controller; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.unimib.disco.mivan.multibook.model.User; -import com.unimib.disco.mivan.multibook.repository.UserRepository; - -public class UserController { - - @Autowired - UserRepository userRepository; - - - public void createUser(String firstName, String lastName, String city,String username, String email, String password) { - - User user = new User(firstName, lastName, city,username,email,password); - - userRepository.save(user); - - - - - } -} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Author.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Author.java deleted file mode 100644 index 25010b9..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Author.java +++ /dev/null @@ -1,55 +0,0 @@ -/*package com.unimib.disco.mivan.multibook.model; - -import java.util.List; - -import javax.persistence.*; - -public class Author { - - - @Id - @Column(name = "id", nullable=false) - @GeneratedValue(strategy = GenerationType.AUTO) - private long id; - - @Column(name = "firstName", nullable=false) - private String artName; - - @ManyToMany - List publications; - - public Author() { - // TODO Auto-generated constructor stub - } - - public Author(String artName, List publications) { - super(); - this.artName = artName; - this.publications = publications; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getArtName() { - return artName; - } - - public void setArtName(String artName) { - this.artName = artName; - } - - public List getPublications() { - return publications; - } - - public void setPublications(List publications) { - this.publications = publications; - } - -}*/ diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Book.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Book.java deleted file mode 100644 index af7820e..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Book.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.unimib.disco.mivan.multibook.model; - -import java.util.List; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToMany; -import javax.persistence.OneToOne; - -@Entity -public class Book { - - @Id - @Column(name = "isbn", nullable=false) - private int isbn; - - @Column(name = "titolo", nullable=false) - private String titolo; - - @OneToOne - private Book prequel; - /* - @ManyToMany - List authors; - */ - - public Book() { - // TODO Auto-generated constructor stub - } - - public Book(int isbn, String titolo, Book prequel/*, List authors*/) { - super(); - this.isbn = isbn; - this.titolo = titolo; - this.prequel = prequel; - //this.authors = authors; - } - - public int getIsbn() { - return isbn; - } - - public void setIsbn(int isbn) { - this.isbn = isbn; - } - - public String getTitolo() { - return titolo; - } - - public void setTitolo(String titolo) { - this.titolo = titolo; - } - - public Book getPrequel() { - return prequel; - } - - public void setPrequel(Book prequel) { - this.prequel = prequel; - } - - - - - -} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Item.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Item.java deleted file mode 100644 index e020d43..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Item.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.unimib.disco.mivan.multibook.model; - -import javax.persistence.Column; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.ManyToOne; - -public class Item{ - - - @Id - @Column(name = "id", nullable=false) - @GeneratedValue(strategy = GenerationType.AUTO) - private int id; - - @ManyToOne - private Location location; - - @ManyToOne - private Book libro; - - - public Item() { - // TODO Auto-generated constructor stub - } - - - public Item(Book libro,Location location) { - this.libro = libro; - this.location=location; - // TODO Auto-generated constructor stub - } - - - public int getId() { - return id; - } - - - public void setId(int id) { - this.id = id; - } - - - public Location getLocation() { - return location; - } - - - public void setLocation(Location location) { - this.location = location; - } - - - public Book getLibro() { - return libro; - } - - - public void setLibro(Book libro) { - this.libro = libro; - } - -} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Loan.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Loan.java deleted file mode 100644 index daa82e3..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Loan.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.unimib.disco.mivan.multibook.model; - -import java.util.Date; - -import javax.persistence.Column; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - -public class Loan { - - @Id - @Column(name = "id", nullable=false) - @GeneratedValue(strategy = GenerationType.AUTO) - private int id; - - - @ManyToOne - private Item item; - - @ManyToOne - private Staff staff; - - @ManyToOne - private User user; - - @Column(name = "start") - @Temporal(TemporalType.TIMESTAMP) - Date start; - - @Column(name = "end") - @Temporal(TemporalType.TIMESTAMP) - Date end; - - public Loan() { - // TODO Auto-generated constructor stub - } - - public Loan(int id, Item item, Staff staff, User user, Date start, Date end) { - super(); - this.item = item; - this.staff = staff; - this.user = user; - this.start = start; - this.end = end; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public Item getItem() { - return item; - } - - public void setItem(Item item) { - this.item = item; - } - - public Staff getStaff() { - return staff; - } - - public void setStaff(Staff staff) { - this.staff = staff; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - - public Date getStart() { - return start; - } - - public void setStart(Date start) { - this.start = start; - } - - public Date getEnd() { - return end; - } - - public void setEnd(Date end) { - this.end = end; - } - - - -} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Location.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Location.java deleted file mode 100644 index 4c6cd8c..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Location.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.unimib.disco.mivan.multibook.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class Location { - - @Id - @Column(name = "id", nullable=false) - @GeneratedValue(strategy = GenerationType.AUTO) - private long id; - - @Column(name = "name", nullable=false) - private String name; - - @Column(name = "address", nullable=false) - private String address; - - @Column(name = "city", nullable=false) - private String city; - - public Location() { - // TODO Auto-generated constructor stub - } - - public Location(String name, String address, String city) { - super(); - this.name = name; - this.address = address; - this.city = city; - } -} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Staff.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Staff.java deleted file mode 100644 index e35f3b2..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/Staff.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.unimib.disco.mivan.multibook.model; - -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ManyToOne; - -@Entity -public class Staff extends User { - - @ManyToOne(fetch = FetchType.LAZY) - private Location library; - - - public Staff() { - // TODO Auto-generated constructor stub - } - - public Staff(String firstName, String lastName, String city, String username, String email, - String password, Location library) { - super(firstName, lastName, city, username, email, password); - this.library=library; - - // TODO Auto-generated constructor stub - } - -} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/User.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/User.java deleted file mode 100644 index 3a46bcc..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/model/User.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.unimib.disco.mivan.multibook.model; - - -import javax.persistence.*; - -@Entity -public class User extends Person { - - - @Column(name = "username", nullable=false,unique=true) - private String username; - - @Column(name = "email", nullable=false,unique=true) - private String email; - - @Column(name = "password", nullable=false) - private String password; - - - public User() { - super(); - // TODO Auto-generated constructor stub - } - - public User(String firstName, String lastName, String city, String username, String email, String password) { - super(firstName, lastName, city); - this.username = username; - this.email = email; - this.password = password; - } - - - public String getUsername() { - return username; - } - - - public void setUsername(String username) { - this.username = username; - } - - - public String getEmail() { - return email; - } - - - public void setEmail(String email) { - this.email = email; - } - - - public String getPassword() { - return password; - } - - - public void setPassword(String password) { - this.password = password; - } - - - - - - -} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/repository/PersonRepository.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/repository/PersonRepository.java deleted file mode 100644 index 6274ec5..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/repository/PersonRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.unimib.disco.mivan.multibook.repository; - -import java.util.List; - -import org.springframework.data.repository.CrudRepository; - -import com.unimib.disco.mivan.multibook.model.Person; - -public interface PersonRepository extends CrudRepository { - - List findByFirstNameAllIgnoreCase(String firstName); - - List findByLastNameAllIgnoreCase(String lastName); - - List findByirstNameAndLastNameAllIgnoreCase(String firstName, String lastName); - -} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/repository/UserRepository.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/repository/UserRepository.java deleted file mode 100644 index d11e05a..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/repository/UserRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.unimib.disco.mivan.multibook.repository; - -import com.unimib.disco.mivan.multibook.model.User; - -import java.util.Optional; - - -public interface UserRepository extends PersonRepository { - - - public Optional findById(Long id); - - public User findByEmail(String email); - - public User findByUsername(String username); - - - -} diff --git a/multibook/src/main/java/com/unimib/disco/mivan/multibook/service/UserService.java b/multibook/src/main/java/com/unimib/disco/mivan/multibook/service/UserService.java deleted file mode 100644 index 5c2e712..0000000 --- a/multibook/src/main/java/com/unimib/disco/mivan/multibook/service/UserService.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.unimib.disco.mivan.multibook.service; - -import java.util.List; -import java.util.Optional; - -import com.unimib.disco.mivan.multibook.model.User; -import com.unimib.disco.mivan.multibook.repository.UserRepository; - -public class UserService { - - private UserRepository userRepository; - - public UserService(UserRepository userRepository) { - this.userRepository = userRepository; - } - /* - public List getClients(){ - return Lists.newArrayList(userRepository.findAll()); - }*/ - - public Optional getClient(Long id) { - return userRepository.findById(id); - } - - public List getClientsByNameAndSurname(String name, String surname) { - return userRepository.findByirstNameAndLastNameAllIgnoreCase(name, surname); - } - - - public void deleteClient(User client) { - userRepository.delete(client); - } - - public User insertOrUpdateClient(User client) { - return userRepository.save(client); - } -} diff --git a/multibook/src/main/resources/application.properties b/multibook/src/main/resources/application.properties deleted file mode 100644 index 5054168..0000000 --- a/multibook/src/main/resources/application.properties +++ /dev/null @@ -1,23 +0,0 @@ - - -spring.datasource.url=jdbc:h2:./database; -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.username=librarymenagment -spring.datasource.password=password123! -spring.datasource.initialization-mode=always - -spring.h2.console.enabled=true -spring.h2.console.path=/h2 - - -spring.jpa.show-sql=true -spring.jpa.hibernate.ddl-auto=update -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect - - - - -# Used for initialization of db. -# !!! Remove comment for initialize db first time. !!! -# spring.datasource.initialization-mode=always - diff --git a/multibook/src/test/java/com/unimib/disco/mivan/multibook/MultibookApplicationTests.java b/multibook/src/test/java/com/unimib/disco/mivan/multibook/MultibookApplicationTests.java deleted file mode 100644 index cdeb7a8..0000000 --- a/multibook/src/test/java/com/unimib/disco/mivan/multibook/MultibookApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.unimib.disco.mivan.multibook; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class MultibookApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/multibook/src/test/java/com/unimib/disco/mivan/multibook/UserTests.java b/multibook/src/test/java/com/unimib/disco/mivan/multibook/UserTests.java deleted file mode 100644 index 0aac3cb..0000000 --- a/multibook/src/test/java/com/unimib/disco/mivan/multibook/UserTests.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.unimib.disco.mivan.multibook; - - -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.springframework.boot.test.context.SpringBootTest; - -import com.unimib.disco.mivan.multibook.model.User; -import com.unimib.disco.mivan.multibook.service.UserService; - - - -@SpringBootTest -public class UserTests { - - - - //private UserRepository userRepository = new UserRepository(); - private UserService userRepository; - - @Test - void userCreation() { - - User asd = new User("Ivan", "Donati", "Novara", "territory", "ciao.iva@gmail.com", "sonounapassword"); - - userRepository.insertOrUpdateClient(asd); - - //userRepository.insertOrUpdateClient("Ivan", "Donati", "Novara", "territory", "ciao.iva@gmail.com", "sonounapassword"); - - - } - -}