diff --git a/src/main/java/fr/eni/demo/bo/Location.java b/src/main/java/fr/eni/demo/bo/Location.java index 64a8649..c8ec88e 100644 --- a/src/main/java/fr/eni/demo/bo/Location.java +++ b/src/main/java/fr/eni/demo/bo/Location.java @@ -27,11 +27,11 @@ public class Location { @Column(name = "LOCATION_END_DATE") private Date endDate; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "CLIENT_ID", nullable = false) private Client client; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "GAME_ID", nullable = false) private Stock stock; } diff --git a/src/test/java/fr/eni/demo/bo/AdresseTest.java b/src/test/java/fr/eni/demo/bo/AdresseTest.java index dee7fcd..1c57483 100644 --- a/src/test/java/fr/eni/demo/bo/AdresseTest.java +++ b/src/test/java/fr/eni/demo/bo/AdresseTest.java @@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; public class AdresseTest { @Test - @DisplayName("-- Test add Adresse builder : SUCCESS --") + @DisplayName("-- Test add Adresse with builder : SUCCESS --") void testAddAdresseSuccess() { Adresse adresse = new Adresse(); adresse.setCodePostal("75000"); @@ -23,7 +23,7 @@ public class AdresseTest { } @Test - @DisplayName("-- Test add Addresse builder : FAILED --") + @DisplayName("-- Test add Addresse with builder : FAILED --") void testAddAdresseFailed() { Adresse adresse = new Adresse(); adresse.setCodePostal("44000"); diff --git a/src/test/java/fr/eni/demo/bo/ClientTest.java b/src/test/java/fr/eni/demo/bo/ClientTest.java index c3ebb84..0659cd3 100644 --- a/src/test/java/fr/eni/demo/bo/ClientTest.java +++ b/src/test/java/fr/eni/demo/bo/ClientTest.java @@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; public class ClientTest { @Test - @DisplayName("-- Test add Client builder with Adresse : SUCESS --") + @DisplayName("-- Test add Client and adresse with builder : SUCESS --") void testAddClientSuccess() { Client client = new Client(); client.setEmail("olivier@test.fr"); @@ -30,7 +30,7 @@ public class ClientTest { } @Test - @DisplayName("-- Test add Client builder without Adresse : FAILED --") + @DisplayName("-- Test add Client with builder: FAILED --") void testAddClientFail() { Client client = new Client(); client.setEmail("julien@test.fr"); diff --git a/src/test/java/fr/eni/demo/bo/GameTypeTest.java b/src/test/java/fr/eni/demo/bo/GameTypeTest.java index af2968f..4e6bf5c 100644 --- a/src/test/java/fr/eni/demo/bo/GameTypeTest.java +++ b/src/test/java/fr/eni/demo/bo/GameTypeTest.java @@ -10,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; public class GameTypeTest { @Test - @DisplayName("-- Test add GameType builder : SUCCESS --") + @DisplayName("-- Test add GameType with builder : SUCCESS --") void testAddGameTypeSuccess() { GameType gt = new GameType(); gt.setName("FPS"); @@ -18,4 +18,5 @@ public class GameTypeTest { assertNotNull(gt); System.out.println(gt); } + // You cant failed to create a GameType... } diff --git a/src/test/java/fr/eni/demo/bo/LocationTest.java b/src/test/java/fr/eni/demo/bo/LocationTest.java index 91db7ed..9392403 100644 --- a/src/test/java/fr/eni/demo/bo/LocationTest.java +++ b/src/test/java/fr/eni/demo/bo/LocationTest.java @@ -17,7 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; public class LocationTest { @Test - @DisplayName("-- Test add Location with game and client builder : SUCCESS") + @DisplayName("-- Test add Location, game and client with builder : SUCCESS --") void testAddLocationGameSuccess() { Adresse adresse = new Adresse(); adresse.setVille("Paris"); @@ -63,7 +63,7 @@ public class LocationTest { } @Test - @DisplayName("-- Test add location with game but without client builder : FAILED --") + @DisplayName("-- Test add location and game but without client with builder : FAILED --") void testAddLocationGameFailure() { GameType gt = new GameType(); gt.setName("Aventure"); diff --git a/src/test/java/fr/eni/demo/bo/StockTest.java b/src/test/java/fr/eni/demo/bo/StockTest.java index ec87db2..9080847 100644 --- a/src/test/java/fr/eni/demo/bo/StockTest.java +++ b/src/test/java/fr/eni/demo/bo/StockTest.java @@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; public class StockTest { @Test - @DisplayName("-- Test add Stock builder : SUCCESS --") + @DisplayName("-- Test add Stock and gameType with builder : SUCCESS --") void testAddStockBuilder() { GameType gt = new GameType(); gt.setName("RPG"); @@ -37,7 +37,7 @@ public class StockTest { } @Test - @DisplayName("-- Test add Stock builder : FAILED --") + @DisplayName("-- Test add Stock and gameType with builder : FAILED --") void testAddStockBuilderFailed() { GameType gt = new GameType(); gt.setName("Plateforme"); @@ -51,6 +51,7 @@ public class StockTest { stock.setDescription("Jeu de plateforme pas compliqué"); stock.setDailyPrice(8.10); stock.setGameType(gtList); + assertNotNull(stock); assertNull(stock.getRef()); } } diff --git a/src/test/java/fr/eni/demo/dal/AdresseRepositoryTest.java b/src/test/java/fr/eni/demo/dal/AdresseRepositoryTest.java new file mode 100644 index 0000000..9daa9c4 --- /dev/null +++ b/src/test/java/fr/eni/demo/dal/AdresseRepositoryTest.java @@ -0,0 +1,43 @@ +package fr.eni.demo.dal; + +import fr.eni.demo.bo.Adresse; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +public class AdresseRepositoryTest { + + @Autowired + AdresseRepository adresseRepo; + + @Test + @DisplayName("-- Test add Adresse with repo : SUCCESS --") + void testAddAdresseRepo() { + Adresse adresse = new Adresse(); + adresse.setCodePostal("75000"); + adresse.setRue("Rue de la paix"); + adresse.setVille("Paris"); + + assertNotNull(adresse); + adresseRepo.save(adresse); + System.out.println(adresse); + } + + @Test + @DisplayName("-- Test add Adresse with repo : FAILED --") + void testAddAdresseRepoFail() { + Adresse adresse = new Adresse(); + adresse.setCodePostal("44000"); + adresse.setRue("Rue d'Orvault"); + adresse.setVille(null); // ville manquante volontairement + + assertThrows(Exception.class, () -> { + adresseRepo.saveAndFlush(adresse); + }); + System.out.println(adresse); + } +} diff --git a/src/test/java/fr/eni/demo/dal/ClientRepositoryTest.java b/src/test/java/fr/eni/demo/dal/ClientRepositoryTest.java new file mode 100644 index 0000000..baa88e1 --- /dev/null +++ b/src/test/java/fr/eni/demo/dal/ClientRepositoryTest.java @@ -0,0 +1,53 @@ +package fr.eni.demo.dal; + +import fr.eni.demo.bo.Adresse; +import fr.eni.demo.bo.Client; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +public class ClientRepositoryTest { + + @Autowired + ClientRepository clientRepo; + + @Test + @DisplayName("-- Test add Client and Adresse with Repo : SUCCESS --") + 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); + clientRepo.save(client); + System.out.println(client); + } + + @Test + @DisplayName("-- Test add Client without Adresse with repo : FAILED --") + void testAddClientFailed() { + Client client = new Client(); + client.setEmail("julien@test.fr"); + client.setNom("Chateau"); + client.setPrenom("Julien"); + + assertNull(client.getAdresse()); + assertThrows(Exception.class, () -> { + clientRepo.saveAndFlush(client); + }); + System.out.println(client); + System.out.println(client.getAdresse()); + } +} diff --git a/src/test/java/fr/eni/demo/dal/GameTypeRepositoryTest.java b/src/test/java/fr/eni/demo/dal/GameTypeRepositoryTest.java new file mode 100644 index 0000000..5c9d9c6 --- /dev/null +++ b/src/test/java/fr/eni/demo/dal/GameTypeRepositoryTest.java @@ -0,0 +1,28 @@ +package fr.eni.demo.dal; + +import fr.eni.demo.bo.GameType; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@SpringBootTest +public class GameTypeRepositoryTest { + + @Autowired + GameTypeRepository gameTypeRepo; + + @Test + @DisplayName("-- Test add GameType with repo : SUCCESS --") + void testAddGameTypeSuccess() { + GameType gt = new GameType(); + gt.setName("FPS"); + + assertNotNull(gt); + gameTypeRepo.save(gt); + System.out.println(gt); + } + // You cant failed to create a GameType... +} diff --git a/src/test/java/fr/eni/demo/dal/LocationRepositoryTest.java b/src/test/java/fr/eni/demo/dal/LocationRepositoryTest.java new file mode 100644 index 0000000..5b2bc7c --- /dev/null +++ b/src/test/java/fr/eni/demo/dal/LocationRepositoryTest.java @@ -0,0 +1,92 @@ +package fr.eni.demo.dal; + +import fr.eni.demo.bo.*; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +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.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@SpringBootTest +public class LocationRepositoryTest { + + @Autowired + LocationRepository locationRepo; + + @Test + @DisplayName("-- Test add Location, game and client with repo : SUCCESS --") + void testAddLocationGameSuccess() { + 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); + + GameType gt = new GameType(); + gt.setName("FPS"); + List gtList = new ArrayList<>(); + assertNotNull(gt); + gtList.add(gt); + + Stock stock = new Stock(); + stock.setGameType(gtList); + stock.setRef("ZEG45456ZGJNZG4GSG"); + stock.setName("Counter Strike 2"); + stock.setDailyPrice(15.25); + stock.setDescription("Jeu de tir a la première personne stratégique"); + 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); + locationRepo.saveAndFlush(l); + System.out.println(l); + } + + @Test + @DisplayName("-- Test add Location and game but without client with repo : FAILED --") + void testAddLocationGameFailure() { + GameType gt = new GameType(); + gt.setName("FPS"); + List gtList = new ArrayList<>(); + gtList.add(gt); + assertNotNull(gt); + + Stock stock = new Stock(); + stock.setGameType(gtList); + stock.setRef("ZEG45456ZGJNZG4GSG"); + stock.setName("Counter Strike 2"); + stock.setDailyPrice(15.25); + stock.setDescription("Jeu de tir a la première personne stratégique"); + assertNotNull(stock); + System.out.println(stock); + + Location l = new Location(); + l.setStock(stock); + l.setStartDate(Date.valueOf(LocalDate.of(2025, 7, 8))); + assertNotNull(l); + assertNull(l.getClient()); + assertThrows(Exception.class, () -> { + locationRepo.saveAndFlush(l); + }); + System.out.println(l); + } +} diff --git a/src/test/java/fr/eni/demo/dal/StockRepositoryTest.java b/src/test/java/fr/eni/demo/dal/StockRepositoryTest.java new file mode 100644 index 0000000..4d4e365 --- /dev/null +++ b/src/test/java/fr/eni/demo/dal/StockRepositoryTest.java @@ -0,0 +1,62 @@ +package fr.eni.demo.dal; + +import fr.eni.demo.bo.GameType; +import fr.eni.demo.bo.Stock; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +public class StockRepositoryTest { + + @Autowired + StockRepository stockRepo; + + @Test + @DisplayName("-- Test add Stock with GameType with repo : SUCCESS --") + void testAddStockSuccess() { + GameType gt = new GameType(); + gt.setName("FPS"); + List gtList = new ArrayList<>(); + gtList.add(gt); + + Stock stock = new Stock(); + stock.setGameType(gtList); + stock.setRef("ZEG45456ZGJNZG4GSG"); + stock.setName("Counter Strike 2"); + stock.setDailyPrice(15.25); + stock.setDescription("Jeu de tir a la première personne stratégique"); + assertNotNull(stock); + stockRepo.save(stock); + System.out.println(stock); + } + + @Test + @DisplayName("-- Test add Stock and GameType with repo : FAILED --") + void testAddStockFailed() { + GameType gt = new GameType(); + gt.setName("FPS"); + List gtList = new ArrayList<>(); + gtList.add(gt); + + Stock stock = new Stock(); + stock.setGameType(gtList); + stock.setName("Super Mario Bros"); + stock.setDailyPrice(8.10); + stock.setDescription("Jeu de plateforme pas compliqué"); + assertNotNull(stock); + assertNull(stock.getRef()); + assertThrows(Exception.class, () -> { + stockRepo.saveAndFlush(stock); + }); + System.out.println(stock); + } +}