forked from pierront/mylibrary-template
Compare commits
15 Commits
main
...
0ad7e71030
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ad7e71030 | |||
| 2ed99a901a | |||
| 98d41ea409 | |||
| d985e2fa8f | |||
| 2161a0cf01 | |||
| 4552585ef9 | |||
| ce27a686ef | |||
| 2c14ee5e0b | |||
| 213f7f64db | |||
| 8d33d16cb8 | |||
| 82164689cf | |||
| 67b5b83943 | |||
| e125a420a6 | |||
| 3bf4fcad07 | |||
| 6e94316e4b |
@@ -19,6 +19,12 @@
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"PasserCommande": {
|
||||
"input": {
|
||||
"clientId": "uuid",
|
||||
@@ -40,6 +46,12 @@
|
||||
"pointsFideliteGagnes": "integer"
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"GererAvis": {
|
||||
"input": {
|
||||
"clientId": "uuid",
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande;
|
||||
|
||||
public record AdresseInfo(String rue, String ville, String codePostal, String pays) {}
|
||||
@@ -0,0 +1,6 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record ComandeInfo(List<LigneCommandeInfo> listeLigne ,String modePayement) {
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class CommandeDTO {
|
||||
private UUID clientId;
|
||||
private List<LigneCommandeInfo> lignesCommande;
|
||||
private String rue;
|
||||
private String ville;
|
||||
private String codePostal;
|
||||
private String pays;
|
||||
private String modePaiement;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande;
|
||||
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class LigneCommandeDTO {
|
||||
|
||||
int quantite;
|
||||
UUID id;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record LigneCommandeInfo(int quantite) {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande;
|
||||
|
||||
public enum ModePaiement {
|
||||
CB,
|
||||
PAYPAL,
|
||||
POINTS_FIDELITE,
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.converter;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.AdresseInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ComandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.CommandeDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ModePaiement;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||
|
||||
public final class CommandeConverter {
|
||||
|
||||
|
||||
public static Commande toDomain(ComandeInfo commandeInfo, AdresseInfo adressInfo, String modePaiement) {
|
||||
return Commande.builder()
|
||||
.lignesCommande(commandeInfo.listeLigne())
|
||||
.rue(adressInfo.rue())
|
||||
.ville(adressInfo.ville())
|
||||
.codePostal(adressInfo.codePostal())
|
||||
.pays(adressInfo.pays())
|
||||
.modePaiement(modePaiement)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static CommandeDTO toDTO(ComandeInfo commandeInfo, AdresseInfo adressInfo, String modePaiement) {
|
||||
return CommandeDTO.builder()
|
||||
.lignesCommande(commandeInfo.listeLigne())
|
||||
.rue(adressInfo.rue())
|
||||
.ville(adressInfo.ville())
|
||||
.codePostal(adressInfo.codePostal())
|
||||
.pays(adressInfo.pays())
|
||||
.modePaiement(modePaiement)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.converter;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.LigneCommande;
|
||||
|
||||
public final class LigneCommandeConverter {
|
||||
|
||||
public static LigneCommande toDomain(LigneCommandeInfo ligneCommandeInfo) {
|
||||
return LigneCommande.builder()
|
||||
.quantite(ligneCommandeInfo.quantite())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static LigneCommandeDTO toDTO(LigneCommandeInfo ligneCommandeInfo) {
|
||||
return LigneCommandeDTO.builder()
|
||||
.quantite(ligneCommandeInfo.quantite())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.entity;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ModePaiement;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class Commande {
|
||||
private UUID clientId;
|
||||
private List<LigneCommandeInfo> lignesCommande;
|
||||
private String rue;
|
||||
private String ville;
|
||||
private String codePostal;
|
||||
private String pays;
|
||||
private String modePaiement;
|
||||
|
||||
private UUID commandeId ;
|
||||
private double montantTotal ;
|
||||
private Integer pointsFideliteGagnes ;
|
||||
|
||||
public void setRandomUUID() {
|
||||
this.clientId = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public void setRandomUUIDCommande() {
|
||||
this.commandeId = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public int convertPointsFidelite(){
|
||||
if (this.montantTotal==0|| this.montantTotal<=0){
|
||||
return 0;
|
||||
}
|
||||
return (int) Math.ceil(this.getMontantTotal());
|
||||
}
|
||||
|
||||
|
||||
// conversion point de fidéliter
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.entity;
|
||||
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class LigneCommande {
|
||||
|
||||
int quantite;
|
||||
UUID livreId;
|
||||
|
||||
public void setRandomUUID() {
|
||||
this.livreId = UUID.randomUUID();
|
||||
}
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception;
|
||||
|
||||
public class NotValidAdressException extends RuntimeException {
|
||||
public NotValidAdressException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception;
|
||||
|
||||
public class NotValidCommandeException extends RuntimeException {
|
||||
public NotValidCommandeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception;
|
||||
|
||||
public class NotValidLigneCommandeException extends RuntimeException {
|
||||
public NotValidLigneCommandeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.repository;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ComandeRepository {
|
||||
|
||||
private final List<Commande> commande = new ArrayList<>();
|
||||
|
||||
public List<Commande> findAll(){return commande;}
|
||||
|
||||
public Commande save(Commande newCommande){
|
||||
Optional<Commande> optionalCommandeWithSameIsbn = this.findById(newCommande.getCommandeId());
|
||||
optionalCommandeWithSameIsbn.ifPresent(commande::remove);
|
||||
this.commande.add(newCommande);
|
||||
return newCommande;
|
||||
}
|
||||
|
||||
public Optional<Commande> findById(UUID uuid){
|
||||
return this.commande.stream()
|
||||
.filter(customer -> customer.getCommandeId().equals(uuid))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public boolean existsById(UUID uuid) {
|
||||
return this.commande.stream()
|
||||
.anyMatch(customer -> customer.getCommandeId().equals(uuid));
|
||||
}
|
||||
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.validator;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.AdresseInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ComandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidAdressException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidCommandeException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidLigneCommandeException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class CommandeValidator {
|
||||
|
||||
public static final String LIGNE_COMMANDE_IS_NOT_VALIDE = "Ligne commande is not valide";
|
||||
public static final String MODE_PAIEMENT_IS_NOT_VALIDE = "Mode Paiement is not valide";
|
||||
public static final String LIST_LIGNE_COMANDE_IS_NOT_VALIDE = "List ligne commande is not valide";
|
||||
public static final String STREET_IS_NOT_VALIDE = "rue is not valide";
|
||||
|
||||
public static final String CITY_IS_NOT_VALIDE = "city is not valide";
|
||||
public static final String CODE_POSTAL_IS_NOT_VALIDE = "code postal is not valide";
|
||||
public static final String COUNTRY_IS_NOT_VALIDE = "Country is not valide";
|
||||
|
||||
|
||||
public static void validate(LigneCommandeInfo ligneCommandeInfo) {
|
||||
if (ligneCommandeInfo.quantite()<=0){
|
||||
throw new NotValidLigneCommandeException(LIGNE_COMMANDE_IS_NOT_VALIDE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void validate(ComandeInfo comandeInfo) {
|
||||
|
||||
validateModePaiement(comandeInfo);
|
||||
validateListLigneCommande(comandeInfo);
|
||||
}
|
||||
|
||||
public static void validate(AdresseInfo adresseInfo) {
|
||||
validateStreet(adresseInfo);
|
||||
validateCity(adresseInfo);
|
||||
validateCodePostal(adresseInfo);
|
||||
validateCountry(adresseInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void validateModePaiement(ComandeInfo comandeInfo) {
|
||||
if(comandeInfo.modePayement()!="CB"&& comandeInfo.modePayement()!="PAYPAL"&&comandeInfo.modePayement()!="POINTS_FIDELITE"){
|
||||
throw new NotValidCommandeException(MODE_PAIEMENT_IS_NOT_VALIDE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateListLigneCommande(ComandeInfo comandeInfo) {
|
||||
if (comandeInfo.listeLigne() == null
|
||||
|| comandeInfo.listeLigne().isEmpty()
|
||||
|| comandeInfo.listeLigne().stream().anyMatch(Objects::isNull)){
|
||||
throw new NotValidCommandeException(LIST_LIGNE_COMANDE_IS_NOT_VALIDE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void validateStreet(AdresseInfo adresseInfo) {
|
||||
if (adresseInfo.rue() == null || adresseInfo.rue().isBlank()){
|
||||
throw new NotValidAdressException(STREET_IS_NOT_VALIDE);
|
||||
}
|
||||
}
|
||||
private static void validateCity(AdresseInfo adresseInfo) {
|
||||
if (adresseInfo.ville() == null || adresseInfo.ville().isBlank()){
|
||||
throw new NotValidAdressException(CITY_IS_NOT_VALIDE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateCodePostal(AdresseInfo adresseInfo) {
|
||||
if (adresseInfo.codePostal() == null || adresseInfo.codePostal().isBlank()){
|
||||
throw new NotValidAdressException(CODE_POSTAL_IS_NOT_VALIDE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateCountry(AdresseInfo adresseInfo) {
|
||||
if (adresseInfo.pays() == null || adresseInfo.pays().isBlank()){
|
||||
throw new NotValidAdressException(COUNTRY_IS_NOT_VALIDE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.converter;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.*;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class CommandeConverterTest {
|
||||
|
||||
|
||||
@Test
|
||||
void TestConvertCommandeToDomain(){
|
||||
String modePaiement = ModePaiement.CB.name();
|
||||
List<LigneCommandeInfo> listLigne = new ArrayList<>();
|
||||
LigneCommandeInfo ligne = new LigneCommandeInfo(12);
|
||||
LigneCommandeInfo ligne2 = new LigneCommandeInfo(14);
|
||||
listLigne.add(ligne);
|
||||
listLigne.add(ligne2);
|
||||
ComandeInfo commandeInfo = new ComandeInfo(listLigne,modePaiement);
|
||||
AdresseInfo adressInfo = new AdresseInfo("rue du cheval","La Rochette","77000","France");
|
||||
|
||||
|
||||
Commande result = CommandeConverter.toDomain(commandeInfo,adressInfo,modePaiement);
|
||||
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(commandeInfo.listeLigne(), result.getLignesCommande());
|
||||
assertEquals(adressInfo.rue() , result.getRue());
|
||||
assertEquals(adressInfo.ville() , result.getVille());
|
||||
assertEquals(adressInfo.codePostal() , result.getCodePostal());
|
||||
assertEquals(adressInfo.pays() , result.getPays());
|
||||
assertEquals( modePaiement,result.getModePaiement());
|
||||
}
|
||||
|
||||
@Test
|
||||
void TestConvertCommandeToDTO(){
|
||||
String modePaiement = ModePaiement.CB.name();
|
||||
List<LigneCommandeInfo> listLigne = new ArrayList<>();
|
||||
LigneCommandeInfo ligne = new LigneCommandeInfo(12);
|
||||
LigneCommandeInfo ligne2 = new LigneCommandeInfo(14);
|
||||
listLigne.add(ligne);
|
||||
listLigne.add(ligne2);
|
||||
ComandeInfo commandeInfo = new ComandeInfo(listLigne,modePaiement);
|
||||
AdresseInfo adressInfo = new AdresseInfo("rue du cheval","La Rochette","77000","France");
|
||||
|
||||
|
||||
CommandeDTO result = CommandeConverter.toDTO(commandeInfo,adressInfo,modePaiement);
|
||||
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(commandeInfo.listeLigne(), result.getLignesCommande());
|
||||
assertEquals(adressInfo.rue() , result.getRue());
|
||||
assertEquals(adressInfo.ville() , result.getVille());
|
||||
assertEquals(adressInfo.codePostal() , result.getCodePostal());
|
||||
assertEquals(adressInfo.pays() , result.getPays());
|
||||
assertEquals( modePaiement,result.getModePaiement());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.converter;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.LigneCommande;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class LigneCommandeConverterTest {
|
||||
|
||||
|
||||
@Test
|
||||
void TestConvertLigneCommandeToDomain(){
|
||||
LigneCommandeInfo ligne = new LigneCommandeInfo(12);
|
||||
|
||||
LigneCommande result = LigneCommandeConverter.toDomain(ligne);
|
||||
|
||||
|
||||
assertEquals(ligne.quantite(),result.getQuantite());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void TestConvertLigneCommandeToDTO(){
|
||||
LigneCommandeInfo ligne = new LigneCommandeInfo(12);
|
||||
|
||||
LigneCommandeDTO result = LigneCommandeConverter.toDTO(ligne);
|
||||
|
||||
|
||||
assertEquals(ligne.quantite(),result.getQuantite());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.entity;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ModePaiement;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CommandeTest {
|
||||
@Test
|
||||
public void commandeTest(){
|
||||
|
||||
UUID clientId = UUID.randomUUID();
|
||||
List<LigneCommandeInfo> lignesCommande = new ArrayList<>();
|
||||
LigneCommandeInfo commande1 = new LigneCommandeInfo(12);
|
||||
LigneCommandeInfo commande2 = new LigneCommandeInfo(13);
|
||||
lignesCommande.add(commande1);
|
||||
lignesCommande.add(commande2);
|
||||
String rue = "rue du chien" ;
|
||||
String ville = "LKa Rochette" ;
|
||||
String codePostal = "7700" ;
|
||||
String pays = "France" ;
|
||||
String modePayement = ModePaiement.CB.name() ;
|
||||
|
||||
Commande commande = Commande.builder()
|
||||
.clientId(clientId)
|
||||
.lignesCommande(lignesCommande)
|
||||
.rue(rue)
|
||||
.ville(ville)
|
||||
.codePostal(codePostal)
|
||||
.pays(pays)
|
||||
.modePaiement(modePayement)
|
||||
.build();
|
||||
|
||||
assertEquals(clientId, commande.getClientId());
|
||||
assertEquals(lignesCommande, commande.getLignesCommande());
|
||||
assertEquals(rue, commande.getRue());
|
||||
assertEquals(ville, commande.getVille());
|
||||
assertEquals(codePostal, commande.getCodePostal());
|
||||
assertEquals(pays, commande.getPays());
|
||||
assertEquals(modePayement, commande.getModePaiement());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("setRandomUUID should change the ID to a new random UUID")
|
||||
void testSetRandomUUID() {
|
||||
Commande commande = Commande.builder().build();
|
||||
UUID originalId = commande.getClientId();
|
||||
|
||||
commande.setRandomUUID();
|
||||
|
||||
assertNotNull(commande.getClientId());
|
||||
assertNotEquals(originalId, commande.getClientId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("setRandomUUID should change the ID to a new random UUID")
|
||||
void testSetRandomUUIDForCommande() {
|
||||
Commande commande = Commande.builder().build();
|
||||
UUID originalId = commande.getCommandeId();
|
||||
|
||||
commande.setRandomUUIDCommande();
|
||||
|
||||
assertNotNull(commande.getCommandeId());
|
||||
assertNotEquals(originalId, commande.getCommandeId());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testConvertPointsFideliteGagnes(){
|
||||
Commande commande = Commande.builder()
|
||||
.montantTotal(14.34)
|
||||
.build();
|
||||
Integer point = commande.convertPointsFidelite();
|
||||
|
||||
assertEquals(point,(int) Math.ceil(commande.getMontantTotal()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(doubles = {-1.9,0.0})
|
||||
void testConvertPointsFideliteGagnesWhenMontantTotalIsNotGood(){
|
||||
Commande commande = Commande.builder()
|
||||
.montantTotal(14.34)
|
||||
.build();
|
||||
Integer point = commande.convertPointsFidelite();
|
||||
|
||||
assertEquals(point,(int) Math.ceil(commande.getMontantTotal()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.entity;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class LigneCommandeTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Builder should create a valid LigneCommande instance")
|
||||
void TestLigneCommande() {
|
||||
UUID id = UUID.randomUUID();
|
||||
int quantite = 12;
|
||||
|
||||
|
||||
LigneCommande ligneCommande = LigneCommande.builder()
|
||||
.livreId(id)
|
||||
.quantite(quantite)
|
||||
.build();
|
||||
|
||||
assertEquals(id, ligneCommande.getLivreId());
|
||||
assertEquals(quantite, ligneCommande.getQuantite());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("setRandomUUID should change the ID to a new random UUID")
|
||||
void testSetRandomUUID() {
|
||||
LigneCommande ligneCommande = LigneCommande.builder().build();
|
||||
UUID originalId = ligneCommande.getLivreId();
|
||||
|
||||
ligneCommande.setRandomUUID();
|
||||
|
||||
assertNotNull(ligneCommande.getLivreId());
|
||||
assertNotEquals(originalId, ligneCommande.getLivreId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception;
|
||||
|
||||
public class Test {
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.valid;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidAdressException;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class NotValidAdressExceptionTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be created with the provided message")
|
||||
void testExceptionCreation() {
|
||||
String errorMessage = "Adresse is not valid";
|
||||
|
||||
NotValidAdressException exception = new NotValidAdressException(errorMessage);
|
||||
|
||||
assertEquals(errorMessage, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"rue is not valide",
|
||||
"city is not valide",
|
||||
"code postal is not valide",
|
||||
"Country is not valide"
|
||||
})
|
||||
@DisplayName("Exception should handle different validation messages")
|
||||
void testExceptionWithDifferentMessages(String errorMessage) {
|
||||
NotValidAdressException exception = new NotValidAdressException(errorMessage);
|
||||
|
||||
assertEquals(errorMessage, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be properly thrown and caught")
|
||||
void testExceptionCanBeThrownAndCaught() {
|
||||
String errorMessage = "Required field is missing";
|
||||
|
||||
Exception exception = assertThrows(NotValidAdressException.class, () -> {
|
||||
throw new NotValidAdressException(errorMessage);
|
||||
});
|
||||
|
||||
assertEquals(errorMessage, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be catchable as a general Exception")
|
||||
void testExceptionInheritance() {
|
||||
String errorMessage = "Invalid Adresse ";
|
||||
|
||||
try {
|
||||
throw new NotValidAdressException(errorMessage);
|
||||
} catch (Exception e) {
|
||||
assertEquals(NotValidAdressException.class, e.getClass());
|
||||
assertEquals(errorMessage, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.valid;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidCommandeException;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class NotValidCommandeExceptionTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be created with the provided message")
|
||||
void testExceptionCreation() {
|
||||
String errorMessage = "Commande is not valid";
|
||||
|
||||
NotValidCommandeException exception = new NotValidCommandeException(errorMessage);
|
||||
|
||||
assertEquals(errorMessage, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"Mode Paiement is not valide",
|
||||
"List ligne commande is not valide"
|
||||
})
|
||||
@DisplayName("Exception should handle different validation messages")
|
||||
void testExceptionWithDifferentMessages(String errorMessage) {
|
||||
NotValidCommandeException exception = new NotValidCommandeException(errorMessage);
|
||||
|
||||
assertEquals(errorMessage, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be properly thrown and caught")
|
||||
void testExceptionCanBeThrownAndCaught() {
|
||||
String errorMessage = "Required field is missing";
|
||||
|
||||
Exception exception = assertThrows(NotValidCommandeException.class, () -> {
|
||||
throw new NotValidCommandeException(errorMessage);
|
||||
});
|
||||
|
||||
assertEquals(errorMessage, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be catchable as a general Exception")
|
||||
void testExceptionInheritance() {
|
||||
String errorMessage = "Invalid Commande ";
|
||||
|
||||
try {
|
||||
throw new NotValidCommandeException(errorMessage);
|
||||
} catch (Exception e) {
|
||||
assertEquals(NotValidCommandeException.class, e.getClass());
|
||||
assertEquals(errorMessage, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.valid;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidLigneCommandeException;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class NotValidLigneCommandeExceptionTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should handle different validation messages")
|
||||
void testExceptionCreation() {
|
||||
String errorMessage = "Ligne commande is not valide";
|
||||
NotValidLigneCommandeException exception = new NotValidLigneCommandeException(errorMessage);
|
||||
|
||||
assertEquals(errorMessage, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be properly thrown and caught")
|
||||
void testExceptionCanBeThrownAndCaught() {
|
||||
String errorMessage = "Required field is missing";
|
||||
|
||||
Exception exception = assertThrows(NotValidLigneCommandeException.class, () -> {
|
||||
throw new NotValidLigneCommandeException(errorMessage);
|
||||
});
|
||||
|
||||
assertEquals(errorMessage, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be catchable as a general Exception")
|
||||
void testExceptionInheritance() {
|
||||
String errorMessage = "Invalid Commande ";
|
||||
|
||||
try {
|
||||
throw new NotValidLigneCommandeException(errorMessage);
|
||||
} catch (Exception e) {
|
||||
assertEquals(NotValidLigneCommandeException.class, e.getClass());
|
||||
assertEquals(errorMessage, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+246
@@ -0,0 +1,246 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.repository;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ModePaiement;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.repository.CustomerRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class CommandeRepositoryTest {
|
||||
|
||||
private ComandeRepository repository;
|
||||
private Commande commandeN1;
|
||||
private Commande commandeN2;
|
||||
private Commande commandeN3;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
repository = new ComandeRepository();
|
||||
|
||||
UUID clientId = UUID.randomUUID();
|
||||
List<LigneCommandeInfo> lignesCommande = new ArrayList<>();
|
||||
LigneCommandeInfo commande1 = new LigneCommandeInfo(12);
|
||||
LigneCommandeInfo commande2 = new LigneCommandeInfo(13);
|
||||
lignesCommande.add(commande1);
|
||||
lignesCommande.add(commande2);
|
||||
String rue = "rue du chien";
|
||||
String ville = "LKa Rochette";
|
||||
String codePostal = "7700";
|
||||
String pays = "France";
|
||||
String modePayement = ModePaiement.CB.name();
|
||||
|
||||
commandeN1 = Commande.builder()
|
||||
.clientId(clientId)
|
||||
.lignesCommande(lignesCommande)
|
||||
.rue(rue)
|
||||
.ville(ville)
|
||||
.codePostal(codePostal)
|
||||
.pays(pays)
|
||||
.modePaiement(modePayement)
|
||||
.build();
|
||||
commandeN1.setRandomUUIDCommande();
|
||||
|
||||
|
||||
List<LigneCommandeInfo> lignesCommande2 = new ArrayList<>();
|
||||
LigneCommandeInfo commande3 = new LigneCommandeInfo(43);
|
||||
LigneCommandeInfo commande4 = new LigneCommandeInfo(1);
|
||||
lignesCommande2.add(commande3);
|
||||
lignesCommande2.add(commande4);
|
||||
|
||||
commandeN2 = Commande.builder()
|
||||
.clientId(clientId)
|
||||
.lignesCommande(lignesCommande2)
|
||||
.rue(rue)
|
||||
.ville(ville)
|
||||
.codePostal(codePostal)
|
||||
.pays(pays)
|
||||
.modePaiement(modePayement)
|
||||
.build();
|
||||
commandeN2.setRandomUUID();
|
||||
commandeN2.setRandomUUIDCommande();
|
||||
|
||||
List<LigneCommandeInfo> lignesCommande3 = new ArrayList<>();
|
||||
LigneCommandeInfo commande6 = new LigneCommandeInfo(12);
|
||||
LigneCommandeInfo commande7 = new LigneCommandeInfo(13);
|
||||
lignesCommande3.add(commande6);
|
||||
lignesCommande3.add(commande7);
|
||||
String rue2 = "rue du chevre chaud ";
|
||||
String ville2 = "jsp";
|
||||
String codePostal2 = "77";
|
||||
String pays2 = "Lune ";
|
||||
String modePayement2 = ModePaiement.PAYPAL.name();
|
||||
|
||||
commandeN3 = Commande.builder()
|
||||
.lignesCommande(lignesCommande3)
|
||||
.rue(rue2)
|
||||
.ville(ville2)
|
||||
.codePostal(codePostal2)
|
||||
.pays(pays2)
|
||||
.modePaiement(modePayement2)
|
||||
.build();
|
||||
commandeN3.setRandomUUID();
|
||||
commandeN3.setRandomUUIDCommande();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("New repository should be empty")
|
||||
void testNewRepositoryIsEmpty() {
|
||||
List<Commande> commande = repository.findAll();
|
||||
|
||||
assertTrue(commande.isEmpty());
|
||||
assertEquals(0, commande.size());
|
||||
}
|
||||
|
||||
|
||||
@Nested
|
||||
@DisplayName("Save operations")
|
||||
class SaveOperations {
|
||||
@Test
|
||||
@DisplayName("Save should add a new comande")
|
||||
void testSaveNewCommande() {
|
||||
Commande savedCommande = repository.save(commandeN1);
|
||||
|
||||
assertEquals(1, repository.findAll().size());
|
||||
assertEquals(commandeN1.getCommandeId(), savedCommande.getCommandeId());
|
||||
assertEquals(commandeN1.getClientId(), savedCommande.getClientId());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("Save should update existing commande with same ID")
|
||||
void testSaveUpdatesExistingCommande() {
|
||||
repository.save(commandeN1);
|
||||
|
||||
|
||||
List<LigneCommandeInfo> lignesCommande2 = new ArrayList<>();
|
||||
LigneCommandeInfo commande3 = new LigneCommandeInfo(43);
|
||||
LigneCommandeInfo commande4 = new LigneCommandeInfo(1);
|
||||
lignesCommande2.add(commande3);
|
||||
lignesCommande2.add(commande4);
|
||||
|
||||
|
||||
UUID id = commandeN1.getCommandeId();
|
||||
Commande updatedCommande = Commande.builder()
|
||||
.commandeId(id)
|
||||
.lignesCommande(lignesCommande2)
|
||||
.rue("rue")
|
||||
.ville("moi")
|
||||
.codePostal("1")
|
||||
.pays("Russie")
|
||||
.modePaiement(ModePaiement.POINTS_FIDELITE.name())
|
||||
.build();
|
||||
|
||||
Commande savedCommande = repository.save(updatedCommande);
|
||||
|
||||
assertEquals(1, repository.findAll().size());
|
||||
assertEquals(id, savedCommande.getCommandeId());
|
||||
assertEquals("rue", savedCommande.getRue());
|
||||
assertEquals("moi", savedCommande.getVille());
|
||||
assertEquals("1", savedCommande.getCodePostal());
|
||||
assertEquals("Russie", savedCommande.getPays());
|
||||
assertEquals(ModePaiement.POINTS_FIDELITE.name(), savedCommande.getModePaiement());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Save multiple customers should add all of them")
|
||||
void testSaveMultipleCommande() {
|
||||
repository.save(commandeN1);
|
||||
repository.save(commandeN2);
|
||||
|
||||
List<Commande> commande = repository.findAll();
|
||||
|
||||
assertEquals(2, commande.size());
|
||||
assertTrue(commande.contains(commandeN1));
|
||||
assertTrue(commande.contains(commandeN2));
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("Find operations")
|
||||
class FindOperations {
|
||||
|
||||
@BeforeEach
|
||||
void setUpCommande() {
|
||||
repository.save(commandeN1);
|
||||
repository.save(commandeN2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("FindAll should return all commande")
|
||||
void testFindAll() {
|
||||
List<Commande> commande = repository.findAll();
|
||||
|
||||
assertEquals(2, commande.size());
|
||||
assertTrue(commande.contains(commandeN1));
|
||||
assertTrue(commande.contains(commandeN2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("FindById should return commande with matching ID")
|
||||
void testFindById() {
|
||||
Optional<Commande> foundCommande = repository.findById(commandeN1.getCommandeId());
|
||||
|
||||
assertTrue(foundCommande.isPresent());
|
||||
assertEquals(commandeN1.getCommandeId(), foundCommande.get().getCommandeId());
|
||||
assertEquals(commandeN1.getClientId(), foundCommande.get().getClientId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindByIdNotFound(){
|
||||
UUID nonExistentId = UUID.randomUUID();
|
||||
Optional<Commande> foundCommande = repository.findById(nonExistentId);
|
||||
|
||||
assertTrue(foundCommande.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testExistsByIdExists(){
|
||||
boolean exists = repository.existsById(commandeN1.getCommandeId());
|
||||
|
||||
assertTrue(exists);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExistsByIdNotExists(){
|
||||
UUID nonExistentId = UUID.randomUUID();
|
||||
boolean exists = repository.existsById(nonExistentId);
|
||||
|
||||
assertTrue(exists);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Nested
|
||||
@DisplayName("Delete operations")
|
||||
class DeleteOperations {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.validator;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.AdresseInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ComandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ModePaiement;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidAdressException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidCommandeException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidLigneCommandeException;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CommandeValidatorTest {
|
||||
|
||||
|
||||
@Test
|
||||
void testValidateValideLigneCommande () {
|
||||
LigneCommandeInfo ligneCommandeValide = new LigneCommandeInfo(5);
|
||||
|
||||
|
||||
assertDoesNotThrow(() -> CommandeValidator.validate(ligneCommandeValide));
|
||||
}
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {-5,0 })
|
||||
void testValidateNotValideLigneCommande (int notValiteQuantite) {
|
||||
LigneCommandeInfo ligneCommandeNotValide = new LigneCommandeInfo(notValiteQuantite);
|
||||
NotValidLigneCommandeException exception = assertThrows(
|
||||
NotValidLigneCommandeException.class,
|
||||
() -> CommandeValidator.validate(ligneCommandeNotValide)
|
||||
);
|
||||
|
||||
assertEquals(CommandeValidator.LIGNE_COMMANDE_IS_NOT_VALIDE, exception.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = ModePaiement.class, names = {"CB", "PAYPAL", "POINTS_FIDELITE"})
|
||||
void testValidateValideCommande(ModePaiement modePaiement) {
|
||||
LigneCommandeInfo ligneCommandeValide = new LigneCommandeInfo(5);
|
||||
List<LigneCommandeInfo> listeLigne = new ArrayList<>();
|
||||
listeLigne.add(ligneCommandeValide);
|
||||
String modePaiementValide = modePaiement.toString();
|
||||
ComandeInfo commandeValid = new ComandeInfo(listeLigne, modePaiementValide);
|
||||
|
||||
assertDoesNotThrow(() -> CommandeValidator.validate(commandeValid));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"jambon", " ", ""})
|
||||
void testValidateNotValideModePaiement(String modePaiementError) {
|
||||
LigneCommandeInfo ligneCommandeValide = new LigneCommandeInfo(5);
|
||||
List<LigneCommandeInfo> listeLigne = new ArrayList<>();
|
||||
listeLigne.add(ligneCommandeValide);
|
||||
String modePaiementValide = modePaiementError;
|
||||
ComandeInfo commandeValid = new ComandeInfo(listeLigne, modePaiementValide);
|
||||
|
||||
NotValidCommandeException exception = assertThrows(
|
||||
NotValidCommandeException.class,
|
||||
() -> CommandeValidator.validate(commandeValid)
|
||||
);
|
||||
assertEquals(CommandeValidator.MODE_PAIEMENT_IS_NOT_VALIDE, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInvalidOrderLists")
|
||||
void testValidateNotValideListLigneCommande(List<LigneCommandeInfo> listeLigne) {
|
||||
String modePaiementValide = ModePaiement.CB.toString();
|
||||
ComandeInfo commandeValid = new ComandeInfo(listeLigne, modePaiementValide);
|
||||
NotValidCommandeException exception = assertThrows(
|
||||
NotValidCommandeException.class,
|
||||
() -> CommandeValidator.validate(commandeValid)
|
||||
);
|
||||
assertEquals(CommandeValidator.LIST_LIGNE_COMANDE_IS_NOT_VALIDE, exception.getMessage());
|
||||
|
||||
}
|
||||
static Stream<Arguments> provideInvalidOrderLists() {
|
||||
return Stream.of(
|
||||
Arguments.of(Collections.emptyList()),
|
||||
Arguments.of(Arrays.asList(new LigneCommandeInfo(5), null, null, new LigneCommandeInfo(12))),
|
||||
Arguments.of((List<LigneCommandeInfo>) null)
|
||||
);
|
||||
}
|
||||
|
||||
@Nested
|
||||
class TestAdress{
|
||||
|
||||
|
||||
@Test
|
||||
void testValidateValideLigneCommande () {
|
||||
AdresseInfo adress = new AdresseInfo("rue du chien","La Rochette","7700","France");
|
||||
|
||||
assertDoesNotThrow(() -> CommandeValidator.validate(adress));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@ValueSource(strings = {" ", " ", "\t", "\n"})
|
||||
void testValidateNotValideStreet(String notvalideStreet) {
|
||||
AdresseInfo adress = new AdresseInfo(notvalideStreet,"La Rochette","7700","France");
|
||||
NotValidAdressException exception = assertThrows(
|
||||
NotValidAdressException.class,
|
||||
() -> CommandeValidator.validate(adress)
|
||||
);
|
||||
assertEquals(CommandeValidator.STREET_IS_NOT_VALIDE, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@ValueSource(strings = {" ", " ", "\t", "\n"})
|
||||
void testValidateNotValideCity(String notvalideCity) {
|
||||
AdresseInfo adress = new AdresseInfo("rue du chien",notvalideCity,"7700","France");
|
||||
NotValidAdressException exception = assertThrows(
|
||||
NotValidAdressException.class,
|
||||
() -> CommandeValidator.validate(adress)
|
||||
);
|
||||
assertEquals(CommandeValidator.CITY_IS_NOT_VALIDE, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@ValueSource(strings = {" ", " ", "\t", "\n"})
|
||||
void testValidateNotValideCodePostal(String notvalideCodePostal) {
|
||||
AdresseInfo adress = new AdresseInfo("rue du chien","La Rochette",notvalideCodePostal,"France");
|
||||
NotValidAdressException exception = assertThrows(
|
||||
NotValidAdressException.class,
|
||||
() -> CommandeValidator.validate(adress)
|
||||
);
|
||||
assertEquals(CommandeValidator.CODE_POSTAL_IS_NOT_VALIDE, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@ValueSource(strings = {" ", " ", "\t", "\n"})
|
||||
void testValidateNotValideCountry(String notvalideCountry) {
|
||||
AdresseInfo adress = new AdresseInfo("rue du chien","La Rochette","7700",notvalideCountry);
|
||||
NotValidAdressException exception = assertThrows(
|
||||
NotValidAdressException.class,
|
||||
() -> CommandeValidator.validate(adress)
|
||||
);
|
||||
assertEquals(CommandeValidator.COUNTRY_IS_NOT_VALIDE, exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user