Make real Test for BO only
This commit is contained in:
@@ -1,17 +1,7 @@
|
|||||||
package fr.eni.demo.bll;
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
import fr.eni.demo.bo.Adresse;
|
import fr.eni.demo.bo.Adresse;
|
||||||
import fr.eni.demo.dal.AdresseRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
public interface AdresseService {
|
||||||
public class AdresseService {
|
void add(Adresse adresse);
|
||||||
|
|
||||||
@Autowired
|
|
||||||
AdresseRepository adresseRepository;
|
|
||||||
|
|
||||||
public void add(Adresse adresse) {
|
|
||||||
adresseRepository.save(adresse);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/main/java/fr/eni/demo/bll/AdresseServiceImpl.java
Normal file
21
src/main/java/fr/eni/demo/bll/AdresseServiceImpl.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
|
import fr.eni.demo.bo.Adresse;
|
||||||
|
import fr.eni.demo.dal.AdresseRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AdresseServiceImpl implements AdresseService{
|
||||||
|
|
||||||
|
private AdresseRepository adresseRepository;
|
||||||
|
|
||||||
|
public AdresseServiceImpl(AdresseRepository adresseRepository) {
|
||||||
|
this.adresseRepository = adresseRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(Adresse adresse) {
|
||||||
|
adresseRepository.save(adresse);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,10 @@
|
|||||||
package fr.eni.demo.bll;
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
import fr.eni.demo.bo.Client;
|
import fr.eni.demo.bo.Client;
|
||||||
import fr.eni.demo.dal.ClientRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
public interface ClientService {
|
||||||
public class ClientService {
|
void add(Client client);
|
||||||
|
Optional<Client> findById(Long clientId);
|
||||||
@Autowired
|
|
||||||
private ClientRepository clientRepository;
|
|
||||||
|
|
||||||
public void add(Client client) {
|
|
||||||
clientRepository.save(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Client> findById(Long clientId) {
|
|
||||||
return clientRepository.findById(clientId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
28
src/main/java/fr/eni/demo/bll/ClientServiceImpl.java
Normal file
28
src/main/java/fr/eni/demo/bll/ClientServiceImpl.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
|
import fr.eni.demo.bo.Client;
|
||||||
|
import fr.eni.demo.dal.ClientRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ClientServiceImpl implements ClientService {
|
||||||
|
|
||||||
|
private ClientRepository clientRepository;
|
||||||
|
|
||||||
|
public ClientServiceImpl(ClientRepository clientRepository) {
|
||||||
|
this.clientRepository = clientRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(Client client) {
|
||||||
|
clientRepository.save(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Client> findById(Long clientId) {
|
||||||
|
return clientRepository.findById(clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package fr.eni.demo.bll;
|
|
||||||
|
|
||||||
import fr.eni.demo.bo.Employe;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface EmployeService {
|
|
||||||
void ajouter(Employe employe);
|
|
||||||
|
|
||||||
List<Employe> chargerTousEmployes();
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package fr.eni.demo.bll;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import fr.eni.demo.bo.Employe;
|
|
||||||
import fr.eni.demo.dal.EmployeRepository;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
//Permet de faire injecter la couche DAL associée
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Service
|
|
||||||
public class EmployeServiceImpl implements EmployeService {
|
|
||||||
private EmployeRepository employeRepository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void ajouter(Employe employe) {
|
|
||||||
// Validation des données de l'employé avant sauvegarde
|
|
||||||
if (employe == null) {
|
|
||||||
throw new RuntimeException("L'employé n'est pas renseigné");
|
|
||||||
}
|
|
||||||
validerImmatriculation(employe);
|
|
||||||
validerChaineNonNulle(employe.getNom(), "Vous devez renseigner le nom");
|
|
||||||
validerChaineNonNulle(employe.getPrenom(), "Vous devez renseigner le prénom");
|
|
||||||
validerChaineNonNulle(employe.getEmail(), "Vous devez renseigner un email");
|
|
||||||
employeRepository.create(employe);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Employe> chargerTousEmployes() {
|
|
||||||
return employeRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validerChaineNonNulle(String chaine, String msgErreur) {
|
|
||||||
if (chaine == null || chaine.isBlank())
|
|
||||||
throw new RuntimeException(msgErreur);
|
|
||||||
}
|
|
||||||
private void validerImmatriculation(Employe employe) {
|
|
||||||
// Valider que l'immatriculation n'est pas nule ou vide
|
|
||||||
validerChaineNonNulle(employe.getImmatriculation(), "L'immatriculation n'a pas été renseignée");
|
|
||||||
// Immatriculation doit être unique
|
|
||||||
Employe employeDB = employeRepository.findByImmatriculation(employe.getImmatriculation());
|
|
||||||
if (employeDB != null) {
|
|
||||||
throw new RuntimeException("L'immatriculation doit être unique");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +1,7 @@
|
|||||||
package fr.eni.demo.bll;
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
import fr.eni.demo.bo.GameType;
|
import fr.eni.demo.bo.GameType;
|
||||||
import fr.eni.demo.dal.GameTypeRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
public interface GameTypeService {
|
||||||
public class GameTypeService {
|
void add(GameType gameType);
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private GameTypeRepository gameTypeRepository;
|
|
||||||
|
|
||||||
public void add(GameType gameType) {
|
|
||||||
gameTypeRepository.save(gameType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/main/java/fr/eni/demo/bll/GameTypeServiceImpl.java
Normal file
21
src/main/java/fr/eni/demo/bll/GameTypeServiceImpl.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
|
import fr.eni.demo.bo.GameType;
|
||||||
|
import fr.eni.demo.dal.GameTypeRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GameTypeServiceImpl implements GameTypeService {
|
||||||
|
|
||||||
|
private GameTypeRepository gameTypeRepository;
|
||||||
|
|
||||||
|
public GameTypeServiceImpl(GameTypeRepository gameTypeRepository) {
|
||||||
|
this.gameTypeRepository = gameTypeRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(GameType gameType) {
|
||||||
|
gameTypeRepository.save(gameType);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,7 @@
|
|||||||
package fr.eni.demo.bll;
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
import fr.eni.demo.bo.Location;
|
import fr.eni.demo.bo.Location;
|
||||||
import fr.eni.demo.dal.LocationRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
public interface LocationService {
|
||||||
public class LocationService {
|
void add(Location location);
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private LocationRepository locationRepository;
|
|
||||||
|
|
||||||
public void add(Location location) {
|
|
||||||
locationRepository.save(location);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/main/java/fr/eni/demo/bll/LocationServiceImpl.java
Normal file
20
src/main/java/fr/eni/demo/bll/LocationServiceImpl.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
|
import fr.eni.demo.bo.Location;
|
||||||
|
import fr.eni.demo.dal.LocationRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class LocationServiceImpl implements LocationService {
|
||||||
|
private LocationRepository locationRepository;
|
||||||
|
|
||||||
|
public LocationServiceImpl(LocationRepository locationRepository) {
|
||||||
|
this.locationRepository = locationRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(Location location) {
|
||||||
|
locationRepository.save(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,11 @@
|
|||||||
package fr.eni.demo.bll;
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
import fr.eni.demo.bo.Stock;
|
import fr.eni.demo.bo.Stock;
|
||||||
import fr.eni.demo.dal.StockRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
public interface StockService {
|
||||||
public class StockService {
|
void add(Stock game);
|
||||||
|
Optional<Stock> findById(Long gameId);
|
||||||
@Autowired
|
|
||||||
private StockRepository stockRepository;
|
|
||||||
|
|
||||||
public void add(Stock stock) {
|
|
||||||
stockRepository.save(stock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Stock> findById(Long gameId) {
|
|
||||||
return stockRepository.findById(gameId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
28
src/main/java/fr/eni/demo/bll/StockServiceImpl.java
Normal file
28
src/main/java/fr/eni/demo/bll/StockServiceImpl.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
|
import fr.eni.demo.bo.Stock;
|
||||||
|
import fr.eni.demo.dal.StockRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class StockServiceImpl implements StockService{
|
||||||
|
|
||||||
|
private StockRepository stockRepository;
|
||||||
|
|
||||||
|
public StockServiceImpl(StockRepository stockRepository) {
|
||||||
|
this.stockRepository = stockRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(Stock game) {
|
||||||
|
stockRepository.save(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Stock> findById(Long gameId) {
|
||||||
|
return stockRepository.findById(gameId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package fr.eni.demo.bo;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
//@Data
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@EqualsAndHashCode(of= {"immatriculation"})
|
|
||||||
@ToString
|
|
||||||
//@Builder
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name="EMPLOYES")
|
|
||||||
public class Employe {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
@Column(name = "EMPLOYEE_ID")
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
@Column(name= "LAST_NAME", nullable = false, length = 90)
|
|
||||||
private String nom;
|
|
||||||
|
|
||||||
@Column(name= "FIRST_NAME", nullable = false, length = 150)
|
|
||||||
private String prenom;
|
|
||||||
|
|
||||||
@Column(nullable = false, unique = true)
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@Column(name= "EMPLOYE_REGISTRATION", nullable = false, unique = true, length = 100)
|
|
||||||
private String immatriculation;
|
|
||||||
|
|
||||||
@Column(name= "HOME_PHONE_NUMBER", nullable = false, length = 12)
|
|
||||||
private String numDom;
|
|
||||||
|
|
||||||
@Column(name= "PHONE_NUMBER", nullable = false, length = 12)
|
|
||||||
private String numPortable;
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package fr.eni.demo.dal;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import fr.eni.demo.bo.Employe;
|
|
||||||
|
|
||||||
public interface EmployeRepository {
|
|
||||||
void create(Employe employe);
|
|
||||||
|
|
||||||
Employe read(Integer id);
|
|
||||||
|
|
||||||
Employe findByImmatriculation(String immatriculation);
|
|
||||||
|
|
||||||
List<Employe> findAll();
|
|
||||||
|
|
||||||
void update(Employe employe);
|
|
||||||
|
|
||||||
void delete(Employe employe);
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package fr.eni.demo.dal;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import fr.eni.demo.bo.Employe;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public class EmployeRepositoryImpl implements EmployeRepository {
|
|
||||||
private List<Employe> employes = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(Employe employe) {
|
|
||||||
employes.add(employe);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Employe read(Integer id) {
|
|
||||||
return employes.stream().filter(item -> item.getId() == id).findAny().orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Employe findByImmatriculation(String immatriculation) {
|
|
||||||
return employes.stream().filter(item -> item.getImmatriculation() == immatriculation).findAny().orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Employe> findAll() {
|
|
||||||
return employes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(Employe employe) {
|
|
||||||
Employe emp = read(employe.getId());
|
|
||||||
if (emp != null) {
|
|
||||||
emp.setEmail(employe.getEmail());
|
|
||||||
emp.setPrenom(employe.getPrenom());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Override public void delete(Employe employe) {
|
|
||||||
employes.remove(employe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,15 +17,15 @@ import java.util.Optional;
|
|||||||
class DemoApplicationTests {
|
class DemoApplicationTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ClientService clientService;
|
private ClientServiceImpl clientServiceImpl;
|
||||||
@Autowired
|
@Autowired
|
||||||
private AdresseService adresseService;
|
private AdresseServiceImpl adresseServiceImpl;
|
||||||
@Autowired
|
@Autowired
|
||||||
private GameTypeService gameTypeService;
|
private GameTypeServiceImpl gameTypeService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private StockService stockService;
|
private StockServiceImpl stockServiceImpl;
|
||||||
@Autowired
|
@Autowired
|
||||||
private LocationService locationService;
|
private LocationServiceImpl locationServiceImpl;
|
||||||
|
|
||||||
// DEPREACTED CAUSE : Cant add Client without Location
|
// DEPREACTED CAUSE : Cant add Client without Location
|
||||||
// @Test
|
// @Test
|
||||||
@@ -71,7 +71,7 @@ class DemoApplicationTests {
|
|||||||
|
|
||||||
//Ajout de la location au client
|
//Ajout de la location au client
|
||||||
client.setAdresse(adresse);
|
client.setAdresse(adresse);
|
||||||
clientService.add(client);
|
clientServiceImpl.add(client);
|
||||||
|
|
||||||
System.out.println(client);
|
System.out.println(client);
|
||||||
System.out.println(adresse);
|
System.out.println(adresse);
|
||||||
@@ -94,7 +94,7 @@ class DemoApplicationTests {
|
|||||||
game.setDailyPrice(25.10);
|
game.setDailyPrice(25.10);
|
||||||
game.setDescription("Jeu RPG avec de multiple fin c'est incroyable");
|
game.setDescription("Jeu RPG avec de multiple fin c'est incroyable");
|
||||||
game.setRef("10GBRESF148KQF");
|
game.setRef("10GBRESF148KQF");
|
||||||
stockService.add(game);
|
stockServiceImpl.add(game);
|
||||||
System.out.println(game);
|
System.out.println(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ class DemoApplicationTests {
|
|||||||
|
|
||||||
// Ajout des genres de jeu au jeu
|
// Ajout des genres de jeu au jeu
|
||||||
game.setGameType(gameTypes);
|
game.setGameType(gameTypes);
|
||||||
stockService.add(game);
|
stockServiceImpl.add(game);
|
||||||
System.out.println(game);
|
System.out.println(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,16 +130,16 @@ class DemoApplicationTests {
|
|||||||
@DisplayName("-- Test add location game to a client --")
|
@DisplayName("-- Test add location game to a client --")
|
||||||
void testAddLocationGame() {
|
void testAddLocationGame() {
|
||||||
// Find a client by his ID
|
// Find a client by his ID
|
||||||
Optional<Client> client = clientService.findById(1L);
|
Optional<Client> client = clientServiceImpl.findById(1L);
|
||||||
// Find a Game by his ID
|
// Find a Game by his ID
|
||||||
Optional<Stock> game = stockService.findById(1L);
|
Optional<Stock> game = stockServiceImpl.findById(1L);
|
||||||
|
|
||||||
// Create the Location line for this client and the game
|
// Create the Location line for this client and the game
|
||||||
Location gameLocation = new Location();
|
Location gameLocation = new Location();
|
||||||
gameLocation.setStartDate(Date.valueOf(LocalDate.of(2025, 7, 8)));
|
gameLocation.setStartDate(Date.valueOf(LocalDate.of(2025, 7, 8)));
|
||||||
gameLocation.setClient(client.get());
|
gameLocation.setClient(client.get());
|
||||||
gameLocation.setStock(game.get());
|
gameLocation.setStock(game.get());
|
||||||
locationService.add(gameLocation);
|
locationServiceImpl.add(gameLocation);
|
||||||
System.out.println(gameLocation);
|
System.out.println(gameLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
35
src/test/java/fr/eni/demo/bo/AdresseTest.java
Normal file
35
src/test/java/fr/eni/demo/bo/AdresseTest.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package fr.eni.demo.bo;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class AdresseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("-- Test add Adresse builder : SUCCESS --")
|
||||||
|
void testAddAdresseSuccess() {
|
||||||
|
Adresse adresse = new Adresse();
|
||||||
|
adresse.setCodePostal("75000");
|
||||||
|
adresse.setRue("Rue de la paix");
|
||||||
|
adresse.setVille("Paris");
|
||||||
|
|
||||||
|
assertNotNull(adresse);
|
||||||
|
System.out.println(adresse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("-- Test add Addresse builder : FAILED --")
|
||||||
|
void testAddAdresseFailed() {
|
||||||
|
Adresse adresse = new Adresse();
|
||||||
|
adresse.setCodePostal("44000");
|
||||||
|
adresse.setRue("Rue d'Orvault");
|
||||||
|
|
||||||
|
assertNull(adresse.getVille());
|
||||||
|
System.out.println(adresse);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/test/java/fr/eni/demo/bo/ClientTest.java
Normal file
47
src/test/java/fr/eni/demo/bo/ClientTest.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package fr.eni.demo.bo;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class ClientTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("-- Test add Client builder with Adresse : SUCESS --")
|
||||||
|
void testAddClientSuccess() {
|
||||||
|
Client client = new Client();
|
||||||
|
client.setEmail("olivier@test.fr");
|
||||||
|
client.setNom("Parpaillon");
|
||||||
|
client.setPrenom("Olivier");
|
||||||
|
|
||||||
|
Adresse adresse = new Adresse();
|
||||||
|
adresse.setRue("666 Rue des Enfers");
|
||||||
|
adresse.setCodePostal("44000");
|
||||||
|
adresse.setVille("Nantes");
|
||||||
|
client.setAdresse(adresse);
|
||||||
|
|
||||||
|
assertNotNull(adresse);
|
||||||
|
assertNotNull(client);
|
||||||
|
System.out.println(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("-- Test add Client builder without Adresse : FAILED --")
|
||||||
|
void testAddClientFail() {
|
||||||
|
Client client = new Client();
|
||||||
|
client.setEmail("julien@test.fr");
|
||||||
|
client.setNom("Chateau");
|
||||||
|
client.setPrenom("Julien");
|
||||||
|
|
||||||
|
assertNotNull(client);
|
||||||
|
assertNull(client.getAdresse());
|
||||||
|
System.out.println(client);
|
||||||
|
System.out.println(client.getAdresse());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
21
src/test/java/fr/eni/demo/bo/GameTypeTest.java
Normal file
21
src/test/java/fr/eni/demo/bo/GameTypeTest.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package fr.eni.demo.bo;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class GameTypeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("-- Test add GameType builder : SUCCESS --")
|
||||||
|
void testAddGameTypeSuccess() {
|
||||||
|
GameType gt = new GameType();
|
||||||
|
gt.setName("FPS");
|
||||||
|
|
||||||
|
assertNotNull(gt);
|
||||||
|
System.out.println(gt);
|
||||||
|
}
|
||||||
|
}
|
||||||
93
src/test/java/fr/eni/demo/bo/LocationTest.java
Normal file
93
src/test/java/fr/eni/demo/bo/LocationTest.java
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package fr.eni.demo.bo;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class LocationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("-- Test add Location with game and client builder : SUCCESS")
|
||||||
|
void testAddLocationGameSuccess() {
|
||||||
|
Adresse adresse = new Adresse();
|
||||||
|
adresse.setVille("Paris");
|
||||||
|
adresse.setRue("Rue de la paix");
|
||||||
|
adresse.setCodePostal("75000");
|
||||||
|
|
||||||
|
assertNotNull(adresse);
|
||||||
|
System.out.println(adresse);
|
||||||
|
|
||||||
|
Client client = new Client();
|
||||||
|
client.setEmail("test@test.fr");
|
||||||
|
client.setAdresse(adresse);
|
||||||
|
client.setPrenom("test");
|
||||||
|
client.setNom("test");
|
||||||
|
|
||||||
|
assertNotNull(client);
|
||||||
|
System.out.println(client);
|
||||||
|
|
||||||
|
GameType gt = new GameType();
|
||||||
|
gt.setName("Plateforme");
|
||||||
|
List<GameType> gtList = new ArrayList<>();
|
||||||
|
gtList.add(gt);
|
||||||
|
assertNotNull(gt);
|
||||||
|
assertThat(gtList).hasSize(1);
|
||||||
|
System.out.println(gtList);
|
||||||
|
|
||||||
|
Stock stock = new Stock();
|
||||||
|
stock.setName("Super Mario Bros");
|
||||||
|
stock.setDescription("Jeu de plateforme pas compliqué");
|
||||||
|
stock.setDailyPrice(8.10);
|
||||||
|
stock.setGameType(gtList);
|
||||||
|
stock.setRef("654POAZJIHGOG646");
|
||||||
|
|
||||||
|
assertNotNull(stock);
|
||||||
|
System.out.println(stock);
|
||||||
|
|
||||||
|
Location l = new Location();
|
||||||
|
l.setClient(client);
|
||||||
|
l.setStock(stock);
|
||||||
|
l.setStartDate(Date.valueOf(LocalDate.of(2025, 7, 8)));
|
||||||
|
assertNotNull(l);
|
||||||
|
System.out.println(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("-- Test add location with game but without client builder : FAILED --")
|
||||||
|
void testAddLocationGameFailure() {
|
||||||
|
GameType gt = new GameType();
|
||||||
|
gt.setName("Aventure");
|
||||||
|
List<GameType> gtList = new ArrayList<>();
|
||||||
|
gtList.add(gt);
|
||||||
|
assertNotNull(gt);
|
||||||
|
assertThat(gtList).hasSize(1);
|
||||||
|
System.out.println(gtList);
|
||||||
|
|
||||||
|
Stock stock = new Stock();
|
||||||
|
stock.setName("Tomb Raider");
|
||||||
|
stock.setDescription("Jeu d'aventure et d'archéologie coolos");
|
||||||
|
stock.setDailyPrice(18.10);
|
||||||
|
stock.setGameType(gtList);
|
||||||
|
stock.setRef("ZOIGHE45ZPIG452");
|
||||||
|
|
||||||
|
assertNotNull(stock);
|
||||||
|
System.out.println(stock);
|
||||||
|
|
||||||
|
Location l = new Location();
|
||||||
|
l.setStock(stock);
|
||||||
|
l.setStartDate(Date.valueOf(LocalDate.of(2025, 7, 8)));
|
||||||
|
assertNull(l.getClient());
|
||||||
|
assertNotNull(l);
|
||||||
|
System.out.println(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
56
src/test/java/fr/eni/demo/bo/StockTest.java
Normal file
56
src/test/java/fr/eni/demo/bo/StockTest.java
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package fr.eni.demo.bo;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class StockTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("-- Test add Stock builder : SUCCESS --")
|
||||||
|
void testAddStockBuilder() {
|
||||||
|
GameType gt = new GameType();
|
||||||
|
gt.setName("RPG");
|
||||||
|
List<GameType> gtList = new ArrayList<>();
|
||||||
|
gtList.add(gt);
|
||||||
|
assertNotNull(gt);
|
||||||
|
assertThat(gtList).hasSize(1);
|
||||||
|
|
||||||
|
Stock stock = new Stock();
|
||||||
|
stock.setName("Baldurs Gate 3");
|
||||||
|
stock.setDescription("Jeu RPG au possibilité infinie");
|
||||||
|
stock.setRef("154ZOIGZ54");
|
||||||
|
stock.setDailyPrice(15.20);
|
||||||
|
stock.setGameType(gtList);
|
||||||
|
|
||||||
|
assertNotNull(stock);
|
||||||
|
System.out.println(stock);
|
||||||
|
System.out.println(gtList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("-- Test add Stock builder : FAILED --")
|
||||||
|
void testAddStockBuilderFailed() {
|
||||||
|
GameType gt = new GameType();
|
||||||
|
gt.setName("Plateforme");
|
||||||
|
List<GameType> gtList = new ArrayList<>();
|
||||||
|
gtList.add(gt);
|
||||||
|
assertNotNull(gt);
|
||||||
|
assertThat(gtList).hasSize(1);
|
||||||
|
|
||||||
|
Stock stock = new Stock();
|
||||||
|
stock.setName("Super Mario Bros");
|
||||||
|
stock.setDescription("Jeu de plateforme pas compliqué");
|
||||||
|
stock.setDailyPrice(8.10);
|
||||||
|
stock.setGameType(gtList);
|
||||||
|
assertNull(stock.getRef());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user