création des test sur toDTO

This commit is contained in:
2026-05-25 18:45:14 +02:00
committed by Marvin AUBERT
parent 28a923c126
commit 3ace5810f8
6 changed files with 92 additions and 5 deletions
@@ -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;
}
@@ -2,6 +2,7 @@ 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.AdresseInfo;
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ComandeInfo; 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.ModePaiement;
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande; import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
@@ -18,4 +19,16 @@ public final class CommandeConverter {
.modePaiement(modePaiement) .modePaiement(modePaiement)
.build(); .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();
}
} }
@@ -1,5 +1,6 @@
package fr.iut_fbleau.but3.dev62.mylibrary.commande.converter; 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.LigneCommandeInfo;
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande; import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.LigneCommande; import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.LigneCommande;
@@ -11,4 +12,11 @@ public final class LigneCommandeConverter {
.quantite(ligneCommandeInfo.quantite()) .quantite(ligneCommandeInfo.quantite())
.build(); .build();
} }
public static LigneCommandeDTO toDTO(LigneCommandeInfo ligneCommandeInfo) {
return LigneCommandeDTO.builder()
.quantite(ligneCommandeInfo.quantite())
.build();
}
} }
@@ -1,9 +1,6 @@
package fr.iut_fbleau.but3.dev62.mylibrary.commande.converter; 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.*;
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.entity.Commande; import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -33,7 +30,30 @@ public class CommandeConverterTest {
assertNotNull(result); assertNotNull(result);
//assertEquals(commandeInfo.clientId(),result.getClientId()); 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(commandeInfo.listeLigne(), result.getLignesCommande());
assertEquals(adressInfo.rue() , result.getRue()); assertEquals(adressInfo.rue() , result.getRue());
assertEquals(adressInfo.ville() , result.getVille()); assertEquals(adressInfo.ville() , result.getVille());
@@ -1,5 +1,6 @@
package fr.iut_fbleau.but3.dev62.mylibrary.commande.converter; 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.LigneCommandeInfo;
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.LigneCommande; import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.LigneCommande;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -16,6 +17,17 @@ public class LigneCommandeConverterTest {
LigneCommande result = LigneCommandeConverter.toDomain(ligne); 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()); assertEquals(ligne.quantite(),result.getQuantite());
} }