Test for all Repository done and all passed
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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...
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
43
src/test/java/fr/eni/demo/dal/AdresseRepositoryTest.java
Normal file
43
src/test/java/fr/eni/demo/dal/AdresseRepositoryTest.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
53
src/test/java/fr/eni/demo/dal/ClientRepositoryTest.java
Normal file
53
src/test/java/fr/eni/demo/dal/ClientRepositoryTest.java
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
28
src/test/java/fr/eni/demo/dal/GameTypeRepositoryTest.java
Normal file
28
src/test/java/fr/eni/demo/dal/GameTypeRepositoryTest.java
Normal file
@@ -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...
|
||||
}
|
||||
92
src/test/java/fr/eni/demo/dal/LocationRepositoryTest.java
Normal file
92
src/test/java/fr/eni/demo/dal/LocationRepositoryTest.java
Normal file
@@ -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<GameType> 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<GameType> 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);
|
||||
}
|
||||
}
|
||||
62
src/test/java/fr/eni/demo/dal/StockRepositoryTest.java
Normal file
62
src/test/java/fr/eni/demo/dal/StockRepositoryTest.java
Normal file
@@ -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<GameType> 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<GameType> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user