forked from pierront/mylibrary-template
		
	Compare commits
	
		
			13 Commits
		
	
	
		
			425c05fd23
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					2b092b62c1 | ||
| 
						 | 
					2d2bdfbcd6 | ||
| 
						 | 
					c3140715e4 | ||
| 6820863c8e | |||
| d8f63d1bdd | |||
| 
						 | 
					9df099691e | ||
| 
						 | 
					554f6f1661 | ||
| 
						 | 
					696b1566f6 | ||
| 
						 | 
					0df33e9e32 | ||
| 
						 | 
					d07de49cc9 | ||
| 
						 | 
					af8d086d01 | ||
| 7af68e52e1 | |||
| 9dd1336ff4 | 
							
								
								
									
										12
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="ExternalStorageConfigurationManager" enabled="true" />
 | 
			
		||||
  <component name="MavenProjectsManager">
 | 
			
		||||
    <option name="originalFiles">
 | 
			
		||||
      <list>
 | 
			
		||||
        <option value="$PROJECT_DIR$/pom.xml" />
 | 
			
		||||
      </list>
 | 
			
		||||
    </option>
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="ProjectRootManager" version="2" languageLevel="JDK_21_PREVIEW" project-jdk-name="ms-21" project-jdk-type="JavaSDK" />
 | 
			
		||||
</project>
 | 
			
		||||
@@ -22,8 +22,6 @@ public class Book {
 | 
			
		||||
        this.language = language;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Getters (setters optionnels si besoin)
 | 
			
		||||
 | 
			
		||||
    public String getIsbn() {
 | 
			
		||||
        return isbn;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,36 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class OrderDTO {
 | 
			
		||||
    private UUID id;
 | 
			
		||||
    private UUID customerId;
 | 
			
		||||
    private List<OrderInfo.OrderLineDto> orderLines;
 | 
			
		||||
    private double totalPrice;
 | 
			
		||||
    private double totalPriceToPay;
 | 
			
		||||
    private OrderInfo.Address address;
 | 
			
		||||
    private String paymentMethod;
 | 
			
		||||
 | 
			
		||||
    // Getters et setters
 | 
			
		||||
    public UUID getId() { return id; }
 | 
			
		||||
    public void setId(UUID id) { this.id = id; }
 | 
			
		||||
 | 
			
		||||
    public UUID getCustomerId() { return customerId; }
 | 
			
		||||
    public void setCustomerId(UUID customerId) { this.customerId = customerId; }
 | 
			
		||||
 | 
			
		||||
    public List<OrderInfo.OrderLineDto> getOrderLines() { return orderLines; }
 | 
			
		||||
    public void setOrderLines(List<OrderInfo.OrderLineDto> orderLines) { this.orderLines = orderLines; }
 | 
			
		||||
 | 
			
		||||
    public double getTotalPrice() { return totalPrice; }
 | 
			
		||||
    public void setTotalPrice(double totalPrice) { this.totalPrice = totalPrice; }
 | 
			
		||||
 | 
			
		||||
    public double getTotalPriceToPay() { return totalPriceToPay; }
 | 
			
		||||
    public void setTotalPriceToPay(double totalPriceToPay) { this.totalPriceToPay = totalPriceToPay; }
 | 
			
		||||
 | 
			
		||||
    public OrderInfo.Address getAddress() { return address; }
 | 
			
		||||
    public void setAddress(OrderInfo.Address address) { this.address = address; }
 | 
			
		||||
 | 
			
		||||
    public String getPaymentMethod() { return paymentMethod; }
 | 
			
		||||
    public void setPaymentMethod(String paymentMethod) { this.paymentMethod = paymentMethod; }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,72 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class OrderInfo {
 | 
			
		||||
    private UUID customerId;
 | 
			
		||||
    private List<OrderLineDto> orderLineDtos;
 | 
			
		||||
    private Address address;
 | 
			
		||||
    private String paymentMethod; // "CREDIT_CARD" ou "LOYALTY_POINTS"
 | 
			
		||||
 | 
			
		||||
    // POJO interne pour OrderLineDto
 | 
			
		||||
    public static class OrderLineDto {
 | 
			
		||||
        private long bookId;
 | 
			
		||||
        private int quantity;
 | 
			
		||||
 | 
			
		||||
        public OrderLineDto() {}
 | 
			
		||||
 | 
			
		||||
        public OrderLineDto(long bookId, int quantity) {
 | 
			
		||||
            this.bookId = bookId;
 | 
			
		||||
            this.quantity = quantity;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public long getBookId() { return bookId; }
 | 
			
		||||
        public void setBookId(long bookId) { this.bookId = bookId; }
 | 
			
		||||
 | 
			
		||||
        public int getQuantity() { return quantity; }
 | 
			
		||||
        public void setQuantity(int quantity) { this.quantity = quantity; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // POJO interne pour Address
 | 
			
		||||
    public static class Address {
 | 
			
		||||
        private String street;
 | 
			
		||||
        private String city;
 | 
			
		||||
        private String postalCode;
 | 
			
		||||
        private String country;
 | 
			
		||||
 | 
			
		||||
        public Address() {}
 | 
			
		||||
 | 
			
		||||
        public Address(String street, String city, String postalCode, String country) {
 | 
			
		||||
            this.street = street;
 | 
			
		||||
            this.city = city;
 | 
			
		||||
            this.postalCode = postalCode;
 | 
			
		||||
            this.country = country;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public String getStreet() { return street; }
 | 
			
		||||
        public void setStreet(String street) { this.street = street; }
 | 
			
		||||
 | 
			
		||||
        public String getCity() { return city; }
 | 
			
		||||
        public void setCity(String city) { this.city = city; }
 | 
			
		||||
 | 
			
		||||
        public String getPostalCode() { return postalCode; }
 | 
			
		||||
        public void setPostalCode(String postalCode) { this.postalCode = postalCode; }
 | 
			
		||||
 | 
			
		||||
        public String getCountry() { return country; }
 | 
			
		||||
        public void setCountry(String country) { this.country = country; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Getters et setters
 | 
			
		||||
    public UUID getCustomerId() { return customerId; }
 | 
			
		||||
    public void setCustomerId(UUID customerId) { this.customerId = customerId; }
 | 
			
		||||
 | 
			
		||||
    public List<OrderLineDto> getOrderLineDtos() { return orderLineDtos; }
 | 
			
		||||
    public void setOrderLineDtos(List<OrderLineDto> orderLineDtos) { this.orderLineDtos = orderLineDtos; }
 | 
			
		||||
 | 
			
		||||
    public Address getAddress() { return address; }
 | 
			
		||||
    public void setAddress(Address address) { this.address = address; }
 | 
			
		||||
 | 
			
		||||
    public String getPaymentMethod() { return paymentMethod; }
 | 
			
		||||
    public void setPaymentMethod(String paymentMethod) { this.paymentMethod = paymentMethod; }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,4 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.converter;
 | 
			
		||||
 | 
			
		||||
public class OrderConverterTest {
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,34 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.entity;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderInfo;
 | 
			
		||||
 | 
			
		||||
public class Order {
 | 
			
		||||
    private UUID id;
 | 
			
		||||
    private UUID customerId;
 | 
			
		||||
    private List<OrderInfo.OrderLineDto> orderLines;
 | 
			
		||||
    private double totalPrice;
 | 
			
		||||
    private double totalPriceToPay;
 | 
			
		||||
    private OrderInfo.Address address;
 | 
			
		||||
    private String paymentMethod;
 | 
			
		||||
 | 
			
		||||
    public Order(UUID id, UUID customerId, List<OrderInfo.OrderLineDto> orderLines, double totalPrice, double totalPriceToPay, OrderInfo.Address address, String paymentMethod) {
 | 
			
		||||
        this.id = id;
 | 
			
		||||
        this.customerId = customerId;
 | 
			
		||||
        this.orderLines = orderLines;
 | 
			
		||||
        this.totalPrice = totalPrice;
 | 
			
		||||
        this.totalPriceToPay = totalPriceToPay;
 | 
			
		||||
        this.address = address;
 | 
			
		||||
        this.paymentMethod = paymentMethod;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Getters
 | 
			
		||||
    public UUID getId() { return id; }
 | 
			
		||||
    public UUID getCustomerId() { return customerId; }
 | 
			
		||||
    public List<OrderInfo.OrderLineDto> getOrderLines() { return orderLines; }
 | 
			
		||||
    public double getTotalPrice() { return totalPrice; }
 | 
			
		||||
    public double getTotalPriceToPay() { return totalPriceToPay; }
 | 
			
		||||
    public OrderInfo.Address getAddress() { return address; }
 | 
			
		||||
    public String getPaymentMethod() { return paymentMethod; }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.exception;
 | 
			
		||||
 | 
			
		||||
import java.text.MessageFormat;
 | 
			
		||||
 | 
			
		||||
public class BookQuantityInsufficientException extends Exception {
 | 
			
		||||
 | 
			
		||||
    public static final String BOOK_QUANTITY_INSUFFICIENT = "Cannot order {0} books, only {1} in stock";
 | 
			
		||||
 | 
			
		||||
    public BookQuantityInsufficientException(int requested, int available) {
 | 
			
		||||
        super(MessageFormat.format(BOOK_QUANTITY_INSUFFICIENT, requested, available));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,16 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.exception;
 | 
			
		||||
 | 
			
		||||
import java.text.MessageFormat;
 | 
			
		||||
 | 
			
		||||
public class InvalidOrderException extends Exception {
 | 
			
		||||
 | 
			
		||||
    public static final String INVALID_ORDER_DETAILS_OR_ADDRESS = "Invalid order details or address";
 | 
			
		||||
 | 
			
		||||
    public InvalidOrderException() {
 | 
			
		||||
        super(INVALID_ORDER_DETAILS_OR_ADDRESS);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public InvalidOrderException(String details) {
 | 
			
		||||
        super(details);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.exception;
 | 
			
		||||
 | 
			
		||||
import java.text.MessageFormat;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class OrderNotFoundException extends Exception {
 | 
			
		||||
 | 
			
		||||
    public static final String THE_ORDER_WITH_ID_DOES_NOT_EXIST_MESSAGE = "The order with id {0} does not exist";
 | 
			
		||||
 | 
			
		||||
    public OrderNotFoundException(UUID uuid) {
 | 
			
		||||
        super(MessageFormat.format(THE_ORDER_WITH_ID_DOES_NOT_EXIST_MESSAGE, uuid));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,30 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.repository;
 | 
			
		||||
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderInfo;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.entity.Order;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class OrderRepository {
 | 
			
		||||
 | 
			
		||||
    private final Map<UUID, Order> orders = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    public Order save(OrderInfo info) {
 | 
			
		||||
        UUID id = UUID.randomUUID();
 | 
			
		||||
        Order order = new Order(
 | 
			
		||||
            id,
 | 
			
		||||
            info.getCustomerId(),
 | 
			
		||||
            info.getOrderLineDtos(),
 | 
			
		||||
            0.0, // totalPrice à calculer selon la logique métier
 | 
			
		||||
            0.0, // totalPriceToPay à calculer
 | 
			
		||||
            info.getAddress(),
 | 
			
		||||
            info.getPaymentMethod()
 | 
			
		||||
        );
 | 
			
		||||
        orders.put(id, order);
 | 
			
		||||
        return order;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<Order> findById(UUID id) {
 | 
			
		||||
        return Optional.ofNullable(orders.get(id));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,45 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.usecase;
 | 
			
		||||
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderInfo;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderDTO;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.entity.Order;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.repository.OrderRepository;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.validator.OrderValidator;
 | 
			
		||||
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class OrderUseCase {
 | 
			
		||||
 | 
			
		||||
    private final OrderRepository repository;
 | 
			
		||||
 | 
			
		||||
    public OrderUseCase(OrderRepository repository) {
 | 
			
		||||
        this.repository = repository;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public OrderDTO createOrder(OrderInfo info) throws Exception {
 | 
			
		||||
        if (!OrderValidator.isValidOrderInfo(info)) {
 | 
			
		||||
            throw new IllegalArgumentException("Invalid order details or address");
 | 
			
		||||
        }
 | 
			
		||||
        // Ici, on suppose que le repository gère la logique métier (stock, client, etc.)
 | 
			
		||||
        Order order = repository.save(info);
 | 
			
		||||
        return toDto(order);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<OrderDTO> getOrderById(UUID id) {
 | 
			
		||||
        Optional<Order> order = repository.findById(id);
 | 
			
		||||
        return order.map(this::toDto);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private OrderDTO toDto(Order order) {
 | 
			
		||||
        OrderDTO dto = new OrderDTO();
 | 
			
		||||
        dto.setId(order.getId());
 | 
			
		||||
        dto.setCustomerId(order.getCustomerId());
 | 
			
		||||
        dto.setOrderLines(order.getOrderLines());
 | 
			
		||||
        dto.setTotalPrice(order.getTotalPrice());
 | 
			
		||||
        dto.setTotalPriceToPay(order.getTotalPriceToPay());
 | 
			
		||||
        dto.setAddress(order.getAddress());
 | 
			
		||||
        dto.setPaymentMethod(order.getPaymentMethod());
 | 
			
		||||
        return dto;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,47 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.validator;
 | 
			
		||||
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderInfo;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class OrderValidator {
 | 
			
		||||
 | 
			
		||||
    public static boolean isValidUUID(String uuid) {
 | 
			
		||||
        try {
 | 
			
		||||
            UUID.fromString(uuid);
 | 
			
		||||
            return true;
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isValidOrderInfo(OrderInfo info) {
 | 
			
		||||
        if (info == null) return false;
 | 
			
		||||
        if (info.getCustomerId() == null) return false;
 | 
			
		||||
        if (info.getOrderLineDtos() == null || info.getOrderLineDtos().isEmpty()) return false;
 | 
			
		||||
        if (info.getPaymentMethod() == null || info.getPaymentMethod().isBlank()) return false;
 | 
			
		||||
 | 
			
		||||
        // Vérifie chaque ligne de commande
 | 
			
		||||
        for (OrderInfo.OrderLineDto line : info.getOrderLineDtos()) {
 | 
			
		||||
            if (line == null) return false;
 | 
			
		||||
            if (line.getBookId() <= 0) return false;
 | 
			
		||||
            if (line.getQuantity() <= 0) return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Vérifie l'adresse
 | 
			
		||||
        if (info.getAddress() == null) return false;
 | 
			
		||||
        OrderInfo.Address addr = info.getAddress();
 | 
			
		||||
        if (addr.getStreet() == null || addr.getStreet().isBlank()) return false;
 | 
			
		||||
        if (addr.getCity() == null || addr.getCity().isBlank()) return false;
 | 
			
		||||
        if (addr.getPostalCode() == null || addr.getPostalCode().isBlank()) return false;
 | 
			
		||||
        if (addr.getCountry() == null || addr.getCountry().isBlank()) return false;
 | 
			
		||||
 | 
			
		||||
        // Vérifie le mode de paiement
 | 
			
		||||
        if (!info.getPaymentMethod().equals("CREDIT_CARD") && !info.getPaymentMethod().equals("LOYALTY_POINTS")) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review;
 | 
			
		||||
 | 
			
		||||
import lombok.Builder;
 | 
			
		||||
import lombok.Getter;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
@Builder
 | 
			
		||||
@Getter
 | 
			
		||||
public class ReviewDto {
 | 
			
		||||
    private UUID reviewId;
 | 
			
		||||
    private long bookId;
 | 
			
		||||
    private String customerName;
 | 
			
		||||
    private String comment;
 | 
			
		||||
    private int rating;
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review;
 | 
			
		||||
 | 
			
		||||
import lombok.Builder;
 | 
			
		||||
import lombok.Getter;
 | 
			
		||||
 | 
			
		||||
@Builder
 | 
			
		||||
@Getter
 | 
			
		||||
public class ReviewInfo {
 | 
			
		||||
    private String customerId;
 | 
			
		||||
    private long isbn;
 | 
			
		||||
    private int rating;
 | 
			
		||||
    private String comment;
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,31 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.converter;
 | 
			
		||||
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.review.entity.Review;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.review.ReviewDto;
 | 
			
		||||
import lombok.experimental.UtilityClass;
 | 
			
		||||
 | 
			
		||||
@UtilityClass
 | 
			
		||||
public class ReviewConverter {
 | 
			
		||||
 | 
			
		||||
    public static ReviewDto toDto(Review review) {
 | 
			
		||||
        if (review == null) return null;
 | 
			
		||||
        return ReviewDto.builder()
 | 
			
		||||
                .reviewId(review.getReviewId())
 | 
			
		||||
                .bookId(review.getBookId())
 | 
			
		||||
                .customerName(review.getCustomerName())
 | 
			
		||||
                .comment(review.getComment())
 | 
			
		||||
                .rating(review.getRating())
 | 
			
		||||
                .build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Review fromDto(ReviewDto dto) {
 | 
			
		||||
        if (dto == null) return null;
 | 
			
		||||
        return Review.builder()
 | 
			
		||||
                .reviewId(dto.getReviewId())
 | 
			
		||||
                .bookId(dto.getBookId())
 | 
			
		||||
                .customerName(dto.getCustomerName())
 | 
			
		||||
                .comment(dto.getComment())
 | 
			
		||||
                .rating(dto.getRating())
 | 
			
		||||
                .build();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,29 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.entity;
 | 
			
		||||
 | 
			
		||||
import lombok.Builder;
 | 
			
		||||
import lombok.Getter;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
@Builder
 | 
			
		||||
@Getter
 | 
			
		||||
public class Review {
 | 
			
		||||
    private UUID reviewId;
 | 
			
		||||
    private long bookId;
 | 
			
		||||
    private String customerName;
 | 
			
		||||
    private String comment;
 | 
			
		||||
    private int rating;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean equals(Object o) {
 | 
			
		||||
        if (this == o) return true;
 | 
			
		||||
        if (!(o instanceof Review)) return false;
 | 
			
		||||
        Review review = (Review) o;
 | 
			
		||||
        return Objects.equals(reviewId, review.reviewId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int hashCode() {
 | 
			
		||||
        return Objects.hash(reviewId);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,10 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.exception;
 | 
			
		||||
 | 
			
		||||
public class DuplicateReviewException extends RuntimeException {
 | 
			
		||||
 | 
			
		||||
    public static final String REVIEW_ALREADY_EXISTS = "A review already exists for customer %s and book %s";
 | 
			
		||||
 | 
			
		||||
    public DuplicateReviewException(String customerId, long bookId) {
 | 
			
		||||
        super(String.format(REVIEW_ALREADY_EXISTS, customerId, String.valueOf(bookId)));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,8 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.exception;
 | 
			
		||||
 | 
			
		||||
public class InvalidReviewException extends RuntimeException {
 | 
			
		||||
 | 
			
		||||
    public InvalidReviewException(String message) {
 | 
			
		||||
        super(message);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,10 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.exception;
 | 
			
		||||
 | 
			
		||||
public class ReviewNotAllowedException extends RuntimeException {
 | 
			
		||||
 | 
			
		||||
    public static final String REVIEW_NOT_ALLOWED = "Customer %s is not allowed to review book %s";
 | 
			
		||||
 | 
			
		||||
    public ReviewNotAllowedException(String customerId, long bookId) {
 | 
			
		||||
        super(String.format(REVIEW_NOT_ALLOWED, customerId, String.valueOf(bookId)));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.exception;
 | 
			
		||||
 | 
			
		||||
import java.text.MessageFormat;
 | 
			
		||||
 | 
			
		||||
public class ReviewNotFoundException extends RuntimeException {
 | 
			
		||||
 | 
			
		||||
    public static final String REVIEW_NOT_FOUND = "The review with id {0} does not exist";
 | 
			
		||||
 | 
			
		||||
    public ReviewNotFoundException(String reviewId) {
 | 
			
		||||
        super(MessageFormat.format(REVIEW_NOT_FOUND, reviewId));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,55 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.repository;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class ReviewRepository {
 | 
			
		||||
    private final Map<String, Map<String, String>> reviews = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    public void clear() {
 | 
			
		||||
        reviews.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void save(Map<String, String> review) {
 | 
			
		||||
        reviews.put(review.get("reviewId"), review);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Map<String, String> findById(String reviewId) {
 | 
			
		||||
        return reviews.get(reviewId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<Map<String, String>> findAll() {
 | 
			
		||||
        return new ArrayList<>(reviews.values());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void deleteById(String reviewId) {
 | 
			
		||||
        reviews.remove(reviewId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int count() {
 | 
			
		||||
        return reviews.size();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean existsById(String reviewId) {
 | 
			
		||||
        return reviews.containsKey(reviewId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<Map<String, String>> findByCustomerName(String customerName) {
 | 
			
		||||
        List<Map<String, String>> result = new ArrayList<>();
 | 
			
		||||
        for (Map<String, String> review : reviews.values()) {
 | 
			
		||||
            if (review.get("customerName").equals(customerName)) {
 | 
			
		||||
                result.add(review);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<Map<String, String>> findByBookId(String bookId) {
 | 
			
		||||
        List<Map<String, String>> result = new ArrayList<>();
 | 
			
		||||
        for (Map<String, String> review : reviews.values()) {
 | 
			
		||||
            if (review.get("bookId").equals(bookId)) {
 | 
			
		||||
                result.add(review);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,53 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.usecase;
 | 
			
		||||
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.review.repository.ReviewRepository;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.review.validator.ReviewValidator;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class ReviewUseCase {
 | 
			
		||||
 | 
			
		||||
    private final ReviewRepository repository;
 | 
			
		||||
 | 
			
		||||
    public ReviewUseCase(ReviewRepository repository) {
 | 
			
		||||
        this.repository = repository;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String submitReview(Map<String, String> review) {
 | 
			
		||||
        String customerId = review.get("customerId");
 | 
			
		||||
        String isbn = review.get("isbn");
 | 
			
		||||
        String rating = review.get("rating");
 | 
			
		||||
 | 
			
		||||
        if (!ReviewValidator.isValidReviewDetails(customerId, isbn, rating)) {
 | 
			
		||||
            throw new IllegalArgumentException("Invalid review details");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Génère un UUID pour la review
 | 
			
		||||
        String reviewId = UUID.randomUUID().toString();
 | 
			
		||||
        review.put("reviewId", reviewId);
 | 
			
		||||
        repository.save(review);
 | 
			
		||||
        return reviewId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<Map<String, String>> getReviewsByCustomerName(String customerName) {
 | 
			
		||||
        return repository.findByCustomerName(customerName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<Map<String, String>> getReviewsByBookId(String bookId) {
 | 
			
		||||
        return repository.findByBookId(bookId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void deleteReview(String reviewId) {
 | 
			
		||||
        if (!ReviewValidator.isValidUUID(reviewId)) {
 | 
			
		||||
            throw new IllegalArgumentException("Invalid reviewId format");
 | 
			
		||||
        }
 | 
			
		||||
        if (!repository.existsById(reviewId)) {
 | 
			
		||||
            throw new NoSuchElementException("Review not found");
 | 
			
		||||
        }
 | 
			
		||||
        repository.deleteById(reviewId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int countReviews() {
 | 
			
		||||
        return repository.count();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,22 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.validator;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class ReviewValidator {
 | 
			
		||||
 | 
			
		||||
    public static boolean isValidUUID(String id) {
 | 
			
		||||
        if (id == null) return false;
 | 
			
		||||
        try {
 | 
			
		||||
            UUID.fromString(id);
 | 
			
		||||
            return true;
 | 
			
		||||
        } catch (IllegalArgumentException e) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isValidReviewDetails(String customerId, String isbn, String rating) {
 | 
			
		||||
        return customerId != null && !customerId.isBlank()
 | 
			
		||||
            && isbn != null && !isbn.isBlank()
 | 
			
		||||
            && rating != null && !rating.isBlank();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,56 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.subscription;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalDate;
 | 
			
		||||
 | 
			
		||||
public class Subscription {
 | 
			
		||||
    private String subscriptionId;
 | 
			
		||||
    private String customerId;
 | 
			
		||||
    private int durationInMonths;
 | 
			
		||||
    private LocalDate startDate;
 | 
			
		||||
    private LocalDate endDate;
 | 
			
		||||
 | 
			
		||||
    public Subscription(String subscriptionId, String customerId, int durationInMonths, LocalDate startDate) {
 | 
			
		||||
        this.subscriptionId = subscriptionId;
 | 
			
		||||
        this.customerId = customerId;
 | 
			
		||||
        this.durationInMonths = durationInMonths;
 | 
			
		||||
        this.startDate = startDate;
 | 
			
		||||
        this.endDate = startDate.plusMonths(durationInMonths).minusDays(1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getSubscriptionId() {
 | 
			
		||||
        return subscriptionId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getCustomerId() {
 | 
			
		||||
        return customerId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getDurationInMonths() {
 | 
			
		||||
        return durationInMonths;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LocalDate getStartDate() {
 | 
			
		||||
        return startDate;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LocalDate getEndDate() {
 | 
			
		||||
        return endDate;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSubscriptionId(String subscriptionId) {
 | 
			
		||||
        this.subscriptionId = subscriptionId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCustomerId(String customerId) {
 | 
			
		||||
        this.customerId = customerId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDurationInMonths(int durationInMonths) {
 | 
			
		||||
        this.durationInMonths = durationInMonths;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setStartDate(LocalDate startDate) {
 | 
			
		||||
        this.startDate = startDate;
 | 
			
		||||
        this.endDate = startDate.plusMonths(durationInMonths).minusDays(1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,48 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.subscription;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalDate;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class SubscriptionManagement {
 | 
			
		||||
    private final Map<String, Subscription> subscriptions = new HashMap<>();
 | 
			
		||||
    private int subscriptionCounter = 1;
 | 
			
		||||
 | 
			
		||||
    public Subscription createSubscription(String customerId, int duration, String paymentMethod, LocalDate startDate, Map<String, String> customer) throws Exception {
 | 
			
		||||
        if (customerId == null || customerId.isBlank() ||
 | 
			
		||||
                paymentMethod == null || paymentMethod.isBlank() ||
 | 
			
		||||
                startDate == null) {
 | 
			
		||||
            throw new IllegalArgumentException("Invalid subscription details or payment method");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (customer == null) {
 | 
			
		||||
            throw new IllegalArgumentException("Customer not found");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (paymentMethod.equals("LOYALTY_POINTS")) {
 | 
			
		||||
            int points = Integer.parseInt(customer.getOrDefault("loyaltyPoints", "0"));
 | 
			
		||||
            if (points < duration * 10) {
 | 
			
		||||
                throw new IllegalArgumentException("Not enough loyalty points");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        String newId = "sub-" + (subscriptions.size() + 1);
 | 
			
		||||
        Subscription sub = new Subscription(newId, customerId, duration, startDate);
 | 
			
		||||
        subscriptions.put(newId, sub);
 | 
			
		||||
        return sub;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Subscription getSubscriptionForCustomer(String customerId) {
 | 
			
		||||
        for (Subscription s : subscriptions.values()) {
 | 
			
		||||
            if (s.getCustomerId().equals(customerId)) return s;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getSubscriptionCount() {
 | 
			
		||||
        return subscriptions.size();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Collection<Subscription> getAllSubscriptions() {
 | 
			
		||||
        return subscriptions.values();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,54 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.error;
 | 
			
		||||
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.*;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.*;
 | 
			
		||||
import org.junit.jupiter.api.*;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
@DisplayName("Book error and failure scenarios")
 | 
			
		||||
public class BookErrorTest {
 | 
			
		||||
 | 
			
		||||
    private BookManagement bookManagement;
 | 
			
		||||
 | 
			
		||||
    @BeforeEach
 | 
			
		||||
    void setUp() {
 | 
			
		||||
        bookManagement = new BookManagement();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Registration fails when book data is invalid")
 | 
			
		||||
    void testRegistrationFailsInvalidData() {
 | 
			
		||||
        Book invalidBook = new Book("", "", "", "", "", "", "", "");
 | 
			
		||||
        InvalidBookDataException exception = assertThrows(InvalidBookDataException.class, () -> {
 | 
			
		||||
            bookManagement.registerBook(invalidBook);
 | 
			
		||||
        });
 | 
			
		||||
        assertTrue(exception.getMessage().contains("Invalid"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Registration fails when duplicate book ISBN")
 | 
			
		||||
    void testRegistrationFailsDuplicateBook() throws Exception {
 | 
			
		||||
        Book book = new Book("123", "Title", "Author", "Publisher", "2024-01-01", "10", "5", "FR");
 | 
			
		||||
        bookManagement.registerBook(book);
 | 
			
		||||
 | 
			
		||||
        DuplicateBookException exception = assertThrows(DuplicateBookException.class, () -> {
 | 
			
		||||
            bookManagement.registerBook(book);
 | 
			
		||||
        });
 | 
			
		||||
        assertTrue(exception.getMessage().contains("Conflict"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Get book by ISBN throws BookNotFoundException if not found")
 | 
			
		||||
    void testGetBookByIsbnNotFound() {
 | 
			
		||||
        BookNotFoundException exception = assertThrows(BookNotFoundException.class, () -> {
 | 
			
		||||
            bookManagement.getBookByIsbn("non-existent-isbn");
 | 
			
		||||
        });
 | 
			
		||||
        assertTrue(exception.getMessage().contains("not found"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Empty book list when no books registered")
 | 
			
		||||
    void testEmptyBookList() {
 | 
			
		||||
        assertTrue(bookManagement.getAllBooks().isEmpty());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,43 +0,0 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.error;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.*;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
@DisplayName("Book error and failure scenarios")
 | 
			
		||||
public class bookErrorTest {
 | 
			
		||||
 | 
			
		||||
    private String lastErrorMessage;
 | 
			
		||||
    private boolean lastOperationSuccess;
 | 
			
		||||
    private List<Map<String, String>> lastBookResult;
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Registration fails when data is invalid")
 | 
			
		||||
    void testRegistrationFails() {
 | 
			
		||||
        lastOperationSuccess = false;
 | 
			
		||||
        assertFalse(lastOperationSuccess);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Error message contains expected substring")
 | 
			
		||||
    void testErrorMessageContains() {
 | 
			
		||||
        lastErrorMessage = "Conflict with existing book in database";
 | 
			
		||||
        assertNotNull(lastErrorMessage);
 | 
			
		||||
        assertTrue(lastErrorMessage.contains("Conflict"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Receiving an empty list of books")
 | 
			
		||||
    void testEmptyBookList() {
 | 
			
		||||
        lastBookResult = new ArrayList<>();
 | 
			
		||||
        assertNotNull(lastBookResult);
 | 
			
		||||
        assertTrue(lastBookResult.isEmpty());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Request fails")
 | 
			
		||||
    void testRequestFails() {
 | 
			
		||||
        lastOperationSuccess = false;
 | 
			
		||||
        assertFalse(lastOperationSuccess);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,148 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.function;
 | 
			
		||||
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.*;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.*;
 | 
			
		||||
import org.junit.jupiter.api.*;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@DisplayName("Book retrieval scenarios and data registration")
 | 
			
		||||
public class BookFunctionTest {
 | 
			
		||||
 | 
			
		||||
    private BookManagement bookManagement;
 | 
			
		||||
    private boolean lastOperationSuccess;
 | 
			
		||||
    private String lastErrorMessage;
 | 
			
		||||
    private List<Book> lastBookResult;
 | 
			
		||||
    private Book lastSingleBookResult;
 | 
			
		||||
 | 
			
		||||
    @BeforeEach
 | 
			
		||||
    void setUp() {
 | 
			
		||||
        bookManagement = new BookManagement();
 | 
			
		||||
        lastOperationSuccess = false;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
        lastBookResult = null;
 | 
			
		||||
        lastSingleBookResult = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Register a new book with valid data")
 | 
			
		||||
    void testRegisterNewBook() throws Exception {
 | 
			
		||||
        Book newBook = new Book(
 | 
			
		||||
                "999",
 | 
			
		||||
                "La vie de Bob",
 | 
			
		||||
                "Boby Bob",
 | 
			
		||||
                "Bob",
 | 
			
		||||
                "2025-01-01",
 | 
			
		||||
                "29.99",
 | 
			
		||||
                "10",
 | 
			
		||||
                "FR"
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            bookManagement.registerBook(newBook);
 | 
			
		||||
            lastOperationSuccess = true;
 | 
			
		||||
        } catch (InvalidBookDataException | DuplicateBookException e) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = e.getMessage();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        assertTrue(lastOperationSuccess);
 | 
			
		||||
        assertNull(lastErrorMessage);
 | 
			
		||||
        assertEquals(1, bookManagement.getBookCount());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Request all books")
 | 
			
		||||
    void testRequestAllBooks() throws Exception {
 | 
			
		||||
        bookManagement.registerBook(new Book("1", "Livre A", "Auteur", "Éditeur", "2024-01-01", "10", "1", "FR"));
 | 
			
		||||
        bookManagement.registerBook(new Book("2", "Livre B", "Auteur", "Éditeur", "2024-01-01", "12", "1", "FR"));
 | 
			
		||||
 | 
			
		||||
        lastBookResult = bookManagement.getAllBooks();
 | 
			
		||||
 | 
			
		||||
        assertNotNull(lastBookResult);
 | 
			
		||||
        assertEquals(2, lastBookResult.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Request single book by ISBN")
 | 
			
		||||
    void testRequestBookByIsbn() throws Exception {
 | 
			
		||||
        Book book = new Book("123", "blabla", "Auteur", "Éditeur", "2024-01-01", "15", "1", "FR");
 | 
			
		||||
        bookManagement.registerBook(book);
 | 
			
		||||
 | 
			
		||||
        lastSingleBookResult = bookManagement.getBookByIsbn("123");
 | 
			
		||||
 | 
			
		||||
        assertNotNull(lastSingleBookResult);
 | 
			
		||||
        assertEquals("blabla", lastSingleBookResult.getTitle());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Attempt to register a duplicate book")
 | 
			
		||||
    void testRegisterDuplicateBook() {
 | 
			
		||||
        Map<String, String> bookData = Map.of(
 | 
			
		||||
                "isbn", "666",
 | 
			
		||||
                "title", "La vie de Boby",
 | 
			
		||||
                "author", "Boby Bob",
 | 
			
		||||
                "publisher", "bob",
 | 
			
		||||
                "publicationDate", "2025-01-01",
 | 
			
		||||
                "price", "25.00",
 | 
			
		||||
                "quantity", "10",
 | 
			
		||||
                "language", "FR"
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        iRegisterANewBookWithTheFollowingInformation(bookData);
 | 
			
		||||
        assertTrue(lastOperationSuccess);
 | 
			
		||||
 | 
			
		||||
        iTryToRegisterANewBookWithTheFollowingInformation(bookData);
 | 
			
		||||
        assertFalse(lastOperationSuccess);
 | 
			
		||||
        assertNotNull(lastErrorMessage);
 | 
			
		||||
        assertTrue(lastErrorMessage.contains("Conflict"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void iRegisterANewBookWithTheFollowingInformation(Map<String, String> row) {
 | 
			
		||||
        Book newBook = new Book(
 | 
			
		||||
                row.get("isbn"),
 | 
			
		||||
                row.get("title"),
 | 
			
		||||
                row.get("author"),
 | 
			
		||||
                row.get("publisher"),
 | 
			
		||||
                row.get("publicationDate"),
 | 
			
		||||
                row.get("price"),
 | 
			
		||||
                row.get("quantity"),
 | 
			
		||||
                row.get("language")
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            bookManagement.registerBook(newBook);
 | 
			
		||||
            lastOperationSuccess = true;
 | 
			
		||||
            lastErrorMessage = null;
 | 
			
		||||
        } catch (InvalidBookDataException | DuplicateBookException e) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = e.getMessage();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void iTryToRegisterANewBookWithTheFollowingInformation(Map<String, String> row) {
 | 
			
		||||
        iRegisterANewBookWithTheFollowingInformation(row);
 | 
			
		||||
        if (lastOperationSuccess) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Expected failure but succeeded";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Request all books with specific title")
 | 
			
		||||
    void testRequestBooksByTitle() throws Exception {
 | 
			
		||||
        bookManagement.registerBook(new Book("1", "Bien", "X", "Y", "2020", "1", "1", "FR"));
 | 
			
		||||
        bookManagement.registerBook(new Book("2", "Troop", "X", "Y", "2020", "1", "1", "FR"));
 | 
			
		||||
        bookManagement.registerBook(new Book("3", "Bien", "X", "Y", "2020", "1", "1", "FR"));
 | 
			
		||||
 | 
			
		||||
        lastBookResult = bookManagement.getBooksByTitle("Bien");
 | 
			
		||||
 | 
			
		||||
        assertNotNull(lastBookResult);
 | 
			
		||||
        assertEquals(2, lastBookResult.size());
 | 
			
		||||
        for (Book b : lastBookResult) {
 | 
			
		||||
            assertEquals("Bien", b.getTitle());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,145 +0,0 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.function;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
import io.cucumber.datatable.DataTable;
 | 
			
		||||
import org.junit.jupiter.api.*;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
@DisplayName("Book retrieval scenarios and data registration")
 | 
			
		||||
public class bookFunctionTest {
 | 
			
		||||
 | 
			
		||||
    private Map<String, Map<String, String>> books;
 | 
			
		||||
    private List<Map<String, String>> lastBookResult;
 | 
			
		||||
    private Map<String, String> lastSingleBookResult;
 | 
			
		||||
    private boolean lastOperationSuccess;
 | 
			
		||||
    private String lastErrorMessage;
 | 
			
		||||
 | 
			
		||||
    @BeforeEach
 | 
			
		||||
    void setUp() {
 | 
			
		||||
        books = new HashMap<>();
 | 
			
		||||
        lastBookResult = new ArrayList<>();
 | 
			
		||||
        lastSingleBookResult = null;
 | 
			
		||||
        lastOperationSuccess = false;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Register a new book with valid data")
 | 
			
		||||
    void testRegisterNewBook() {
 | 
			
		||||
        DataTable dataTable = DataTable.create(
 | 
			
		||||
                List.of(
 | 
			
		||||
                        List.of("isbn", "title", "author", "publisher", "publicationDate", "price", "quantity", "language"),
 | 
			
		||||
                        List.of("999", "La vie de Bob", "Boby Bob", "Bob", "2025-01-01", "29.99", "10", "FR")
 | 
			
		||||
                )
 | 
			
		||||
        );
 | 
			
		||||
        iRegisterANewBookWithTheFollowingInformation(dataTable);
 | 
			
		||||
        assertTrue(lastOperationSuccess);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void iRegisterANewBookWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        Map<String, String> newBook = dataTable.asMaps(String.class, String.class).get(0);
 | 
			
		||||
        String isbn = newBook.get("isbn");
 | 
			
		||||
 | 
			
		||||
        if (isbn == null || isbn.isBlank()
 | 
			
		||||
                || newBook.get("title") == null || newBook.get("title").isBlank()
 | 
			
		||||
                || newBook.get("author") == null || newBook.get("author").isBlank()
 | 
			
		||||
                || newBook.get("publisher") == null || newBook.get("publisher").isBlank()
 | 
			
		||||
                || newBook.get("publicationDate") == null || newBook.get("publicationDate").isBlank()
 | 
			
		||||
                || newBook.get("price") == null || newBook.get("price").isBlank()
 | 
			
		||||
                || newBook.get("quantity") == null || newBook.get("quantity").isBlank()
 | 
			
		||||
                || newBook.get("language") == null || newBook.get("language").isBlank()) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Invalid book data provided";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (books.containsKey(isbn)) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Conflict with existing book in database";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        books.put(isbn, new HashMap<>(newBook));
 | 
			
		||||
        lastOperationSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Request all books")
 | 
			
		||||
    void testRequestAllBooks() {
 | 
			
		||||
        books.put("1", Map.of("title", "Livre A"));
 | 
			
		||||
        books.put("2", Map.of("title", "Livre B"));
 | 
			
		||||
 | 
			
		||||
        iRequestAllBooks();
 | 
			
		||||
        assertEquals(2, lastBookResult.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void iRequestAllBooks() {
 | 
			
		||||
        lastBookResult = new ArrayList<>(books.values());
 | 
			
		||||
        lastOperationSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Request single book by ID")
 | 
			
		||||
    void testRequestBookById() {
 | 
			
		||||
        books.put("123", Map.of("isbn", "123", "title", "blabla"));
 | 
			
		||||
        iRequestTheBookWithId("123");
 | 
			
		||||
 | 
			
		||||
        assertNotNull(lastSingleBookResult);
 | 
			
		||||
        assertEquals("blabla", lastSingleBookResult.get("title"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void iRequestTheBookWithId(String isbn) {
 | 
			
		||||
        if (!books.containsKey(isbn)) {
 | 
			
		||||
            lastSingleBookResult = null;
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Book not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        lastSingleBookResult = books.get(isbn);
 | 
			
		||||
        lastOperationSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Attempt to register a book that should fail")
 | 
			
		||||
    void testRegisterBookWithExpectedFailure() {
 | 
			
		||||
        DataTable dataTable = DataTable.create(
 | 
			
		||||
                List.of(
 | 
			
		||||
                        List.of("isbn", "title", "author", "publisher", "publicationDate", "price", "quantity", "language"),
 | 
			
		||||
                        List.of("666", "La vie de Boby", "Boby Bob", "bob", "2025-01-01", "25.00", "10", "FR")
 | 
			
		||||
                )
 | 
			
		||||
        );
 | 
			
		||||
        iTryToRegisterANewBookWithTheFollowingInformation(dataTable);
 | 
			
		||||
        assertFalse(lastOperationSuccess);
 | 
			
		||||
        assertNotNull(lastErrorMessage);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void iTryToRegisterANewBookWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        iRegisterANewBookWithTheFollowingInformation(dataTable);
 | 
			
		||||
        if (lastOperationSuccess) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Expected failure but succeeded";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Request all books with specific title")
 | 
			
		||||
    void testRequestBooksByTitle() {
 | 
			
		||||
        books.put("1", Map.of("title", "Wouah"));
 | 
			
		||||
        books.put("2", Map.of("title", "Troop"));
 | 
			
		||||
        books.put("3", Map.of("title", "Bien"));
 | 
			
		||||
 | 
			
		||||
        iRequestAllBooksWithTitle("Bien");
 | 
			
		||||
        assertEquals(2, lastBookResult.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void iRequestAllBooksWithTitle(String titleFilter) {
 | 
			
		||||
        lastBookResult = books.values().stream()
 | 
			
		||||
                .filter(book -> book.get("title").equalsIgnoreCase(titleFilter))
 | 
			
		||||
                .toList();
 | 
			
		||||
        lastOperationSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,61 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.result;
 | 
			
		||||
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.Book;
 | 
			
		||||
import org.junit.jupiter.api.*;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@DisplayName("Book result success scenarios")
 | 
			
		||||
public class BookResultTest {
 | 
			
		||||
 | 
			
		||||
    private Map<String, Book> books;
 | 
			
		||||
    private Book sampleBook;
 | 
			
		||||
 | 
			
		||||
    @BeforeEach
 | 
			
		||||
    void setUp() {
 | 
			
		||||
        books = new HashMap<>();
 | 
			
		||||
        books.put("123", new Book("123", "Livre A", "Auteur", "Éditeur", "2024-01-01", "10", "1", "FR"));
 | 
			
		||||
        books.put("456", new Book("456", "Livre B", "Auteur", "Éditeur", "2024-01-01", "12", "2", "FR"));
 | 
			
		||||
 | 
			
		||||
        sampleBook = new Book(
 | 
			
		||||
                "888",
 | 
			
		||||
                "La vie de Bob",
 | 
			
		||||
                "Boby Bob",
 | 
			
		||||
                "Bob",
 | 
			
		||||
                "2025-01-01",
 | 
			
		||||
                "29.99",
 | 
			
		||||
                "10",
 | 
			
		||||
                "FR"
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Book is successfully created with correct data")
 | 
			
		||||
    void testBookCreation() {
 | 
			
		||||
        assertEquals("888", sampleBook.getIsbn());
 | 
			
		||||
        assertEquals("La vie de Bob", sampleBook.getTitle());
 | 
			
		||||
        assertEquals("Boby Bob", sampleBook.getAuthor());
 | 
			
		||||
        assertEquals("Bob", sampleBook.getPublisher());
 | 
			
		||||
        assertEquals("2025-01-01", sampleBook.getPublicationDate());
 | 
			
		||||
        assertEquals("29.99", sampleBook.getPrice());
 | 
			
		||||
        assertEquals("10", sampleBook.getQuantity());
 | 
			
		||||
        assertEquals("FR", sampleBook.getLanguage());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Books map contains expected number of books")
 | 
			
		||||
    void testBooksMapSize() {
 | 
			
		||||
        assertEquals(2, books.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Books map contains expected books")
 | 
			
		||||
    void testBooksMapContent() {
 | 
			
		||||
        assertTrue(books.containsKey("123"));
 | 
			
		||||
        assertTrue(books.containsKey("456"));
 | 
			
		||||
        assertEquals("Livre A", books.get("123").getTitle());
 | 
			
		||||
        assertEquals("Livre B", books.get("456").getTitle());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,81 +0,0 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.result;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.*;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
@DisplayName("Book result success scenarios")
 | 
			
		||||
public class bookResultTest {
 | 
			
		||||
    private Map<String, String> lastSingleBookResult;
 | 
			
		||||
    private Map<String, Map<String, String>> books;
 | 
			
		||||
 | 
			
		||||
    @BeforeEach
 | 
			
		||||
    void setUp() {
 | 
			
		||||
        books = new HashMap<>();
 | 
			
		||||
        books.put("123", Map.of("titre", "Livre A"));
 | 
			
		||||
        books.put("456", Map.of("title", "Livre B"));
 | 
			
		||||
 | 
			
		||||
        lastSingleBookResult = Map.of(
 | 
			
		||||
                "isbn", "888",
 | 
			
		||||
                "title", "La vie de Bob",
 | 
			
		||||
                "author", "Boby Bob",
 | 
			
		||||
                "publisher", "Bob",
 | 
			
		||||
                "publicationDate", "2025-01-01",
 | 
			
		||||
                "price", "29.99",
 | 
			
		||||
                "quantity", "10",
 | 
			
		||||
                "language", "Fr"
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Book is successfully registered")
 | 
			
		||||
    void testBookRegistrationSuccess() {
 | 
			
		||||
        boolean lastOperationSuccess = true;
 | 
			
		||||
        assertTrue(lastOperationSuccess);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("Receive detailed information of a single book")
 | 
			
		||||
    void testReceiveSingleBookInformation() {
 | 
			
		||||
        lastSingleBookResult = Map.of(
 | 
			
		||||
                "isbn", "777",
 | 
			
		||||
                "title", "La vie de Bob",
 | 
			
		||||
                "author", "Boby Bob",
 | 
			
		||||
                "publisher", "Bob",
 | 
			
		||||
                "publicationDate", "2025-01-01",
 | 
			
		||||
                "price", "29.99",
 | 
			
		||||
                "quantity", "10",
 | 
			
		||||
                "language", "Fr"
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        List<Map<String, String>> expectedList = List.of(Map.of(
 | 
			
		||||
                "isbn", "001",
 | 
			
		||||
                "title", "La vie de mary",
 | 
			
		||||
                "author", "Mary Mard",
 | 
			
		||||
                "publisher", "Mary",
 | 
			
		||||
                "publicationDate", "2025-02-02",
 | 
			
		||||
                "price", "29.99",
 | 
			
		||||
                "quantity", "10",
 | 
			
		||||
                "language", "Fr"
 | 
			
		||||
        ));
 | 
			
		||||
 | 
			
		||||
        Map<String, String> expectedBook = expectedList.get(0);
 | 
			
		||||
        assertNotNull(lastSingleBookResult);
 | 
			
		||||
 | 
			
		||||
        for (String key : expectedBook.keySet()) {
 | 
			
		||||
            assertEquals(expectedBook.get(key), lastSingleBookResult.get(key));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("System has expected number of books after registration")
 | 
			
		||||
    void testSystemHasBooks() {
 | 
			
		||||
        assertEquals(2, books.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DisplayName("System still has expected number of books")
 | 
			
		||||
    void testSystemStillHasBooks() {
 | 
			
		||||
        assertEquals(2, books.size());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -12,5 +12,166 @@ import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class OrderSteps {
 | 
			
		||||
 | 
			
		||||
    private final Map<String, Map<String, String>> customers = new HashMap<>();
 | 
			
		||||
    private final Map<Long, Map<String, String>> books = new HashMap<>();
 | 
			
		||||
    private final Map<String, Map<String, String>> orders = new HashMap<>();
 | 
			
		||||
    private String lastOrderId;
 | 
			
		||||
    private String lastOrderError;
 | 
			
		||||
    private boolean lastOrderSuccess;
 | 
			
		||||
    private Map<String, String> lastOrderFetched;
 | 
			
		||||
 | 
			
		||||
    @Given("the order system has the following customers:")
 | 
			
		||||
    public void theOrderSystemHasTheFollowingCustomers(DataTable dataTable) {
 | 
			
		||||
        customers.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            customers.put(row.get("id"), new HashMap<>(row));
 | 
			
		||||
        }
 | 
			
		||||
        assertEquals(dataTable.asMaps().size(), customers.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("the order system has the following books:")
 | 
			
		||||
    public void theOrderSystemHasTheFollowingBooks(DataTable dataTable) {
 | 
			
		||||
        books.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            books.put(Long.parseLong(row.get("isbn")), new HashMap<>(row));
 | 
			
		||||
        }
 | 
			
		||||
        assertEquals(dataTable.asMaps().size(), books.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("the order system has the following orders:")
 | 
			
		||||
    public void theOrderSystemHasTheFollowingOrders(DataTable dataTable) {
 | 
			
		||||
        orders.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            orders.put(row.get("id"), new HashMap<>(row));
 | 
			
		||||
        }
 | 
			
		||||
        assertEquals(dataTable.asMaps().size(), orders.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I create a new order with the following information:")
 | 
			
		||||
    public void iCreateANewOrderWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        Map<String, String> info = dataTable.asMaps(String.class, String.class).getFirst();
 | 
			
		||||
        String customerId = info.get("customerId");
 | 
			
		||||
        String paymentMethod = info.get("paymentMethod");
 | 
			
		||||
        String orderLineDtos = info.get("orderLineDtos");
 | 
			
		||||
        String addressStreet = info.get("addressStreet");
 | 
			
		||||
        String addressCity = info.get("addressCity");
 | 
			
		||||
        String addressPostalCode = info.get("addressPostalCode");
 | 
			
		||||
        String addressCountry = info.get("addressCountry");
 | 
			
		||||
 | 
			
		||||
        // Validation simple
 | 
			
		||||
        if (customerId == null || customerId.isBlank() ||
 | 
			
		||||
            paymentMethod == null || paymentMethod.isBlank() ||
 | 
			
		||||
            orderLineDtos == null || orderLineDtos.isBlank() ||
 | 
			
		||||
            addressStreet == null || addressStreet.isBlank() ||
 | 
			
		||||
            addressCity == null || addressCity.isBlank() ||
 | 
			
		||||
            addressPostalCode == null || addressPostalCode.isBlank() ||
 | 
			
		||||
            addressCountry == null || addressCountry.isBlank()) {
 | 
			
		||||
            lastOrderSuccess = false;
 | 
			
		||||
            lastOrderError = "Invalid order details or address";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if (!customers.containsKey(customerId)) {
 | 
			
		||||
            lastOrderSuccess = false;
 | 
			
		||||
            lastOrderError = "Customer not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            String content = orderLineDtos.replace("[", "").replace("]", "").replace("{", "").replace("}", "");
 | 
			
		||||
            String[] pairs = content.split(",");
 | 
			
		||||
            Long bookId = null;
 | 
			
		||||
            int quantity = 0;
 | 
			
		||||
            for (String pair : pairs) {
 | 
			
		||||
                String[] kv = pair.trim().replace("\"", "").split(":");
 | 
			
		||||
                if (kv.length == 2) {
 | 
			
		||||
                    if (kv[0].trim().equals("bookId")) bookId = Long.parseLong(kv[1].trim());
 | 
			
		||||
                    if (kv[0].trim().equals("quantity")) quantity = Integer.parseInt(kv[1].trim());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (bookId == null || !books.containsKey(bookId)) {
 | 
			
		||||
                lastOrderSuccess = false;
 | 
			
		||||
                lastOrderError = "Invalid order details or address";
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            int stock = Integer.parseInt(books.get(bookId).get("quantity"));
 | 
			
		||||
            if (quantity > stock) {
 | 
			
		||||
                lastOrderSuccess = false;
 | 
			
		||||
                lastOrderError = "book quantity insufficient";
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            // Décrémente le stock fictivement
 | 
			
		||||
            books.get(bookId).put("quantity", String.valueOf(stock - quantity));
 | 
			
		||||
            // Création de la commande
 | 
			
		||||
            String newOrderId = "ord-" + (orders.size() + 1);
 | 
			
		||||
            Map<String, String> order = new HashMap<>();
 | 
			
		||||
            order.put("id", newOrderId);
 | 
			
		||||
            order.put("customerId", customerId);
 | 
			
		||||
            order.put("totalPrice", String.valueOf(
 | 
			
		||||
                Double.parseDouble(books.get(bookId).get("price")) * quantity
 | 
			
		||||
            ));
 | 
			
		||||
            order.put("paymentMethod", paymentMethod);
 | 
			
		||||
            orders.put(newOrderId, order);
 | 
			
		||||
            lastOrderId = newOrderId;
 | 
			
		||||
            lastOrderSuccess = true;
 | 
			
		||||
            lastOrderError = null;
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            lastOrderSuccess = false;
 | 
			
		||||
            lastOrderError = "Invalid order details or address";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the order is created successfully")
 | 
			
		||||
    public void theOrderIsCreatedSuccessfully() {
 | 
			
		||||
        assertTrue(lastOrderSuccess);
 | 
			
		||||
        assertNotNull(lastOrderId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("the order system now has {int} orders")
 | 
			
		||||
    public void theOrderSystemNowHasOrders(int expected) {
 | 
			
		||||
        assertEquals(expected, orders.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I request the order with id {string}")
 | 
			
		||||
    public void iRequestTheOrderWithId(String id) {
 | 
			
		||||
        lastOrderFetched = orders.get(id);
 | 
			
		||||
        lastOrderSuccess = lastOrderFetched != null;
 | 
			
		||||
        if (!lastOrderSuccess) lastOrderError = "Order not found";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("I receive the following order information:")
 | 
			
		||||
    public void iReceiveTheFollowingOrderInformation(DataTable dataTable) {
 | 
			
		||||
        Map<String, String> expected = dataTable.asMaps(String.class, String.class).getFirst();
 | 
			
		||||
        assertNotNull(lastOrderFetched);
 | 
			
		||||
        for (String key : expected.keySet()) {
 | 
			
		||||
            assertEquals(expected.get(key), lastOrderFetched.get(key));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I try to create a new order with the following information:")
 | 
			
		||||
    public void iTryToCreateANewOrderWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        iCreateANewOrderWithTheFollowingInformation(dataTable);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the order creation fails")
 | 
			
		||||
    public void theOrderCreationFails() {
 | 
			
		||||
        assertFalse(lastOrderSuccess);
 | 
			
		||||
        assertNotNull(lastOrderError);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("I receive an order error message containing {string}")
 | 
			
		||||
    public void iReceiveAnOrderErrorMessageContaining(String msg) {
 | 
			
		||||
        assertNotNull(lastOrderError);
 | 
			
		||||
        assertTrue(lastOrderError.contains(msg), "Expected error message to contain: \"" + msg + "\" but was: \"" + lastOrderError + "\"");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("the order system still has {int} order")
 | 
			
		||||
    public void theOrderSystemStillHasOrder(int expected) {
 | 
			
		||||
        assertEquals(expected, orders.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the order request fails")
 | 
			
		||||
    public void theOrderRequestFails() {
 | 
			
		||||
        assertFalse(lastOrderSuccess);
 | 
			
		||||
        assertNotNull(lastOrderError);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,96 +9,109 @@ import io.cucumber.java.en.Then;
 | 
			
		||||
import io.cucumber.java.en.When;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class ReviewSteps {
 | 
			
		||||
 | 
			
		||||
    private final Map<String, Map<String, String>> reviewCustomers = new HashMap<>();
 | 
			
		||||
    private final Map<String, Map<String, String>> reviewBooks = new HashMap<>();
 | 
			
		||||
    private final Map<String, Map<String, String>> customers = new HashMap<>();
 | 
			
		||||
    private final Map<Long, Map<String, String>> books = new HashMap<>();
 | 
			
		||||
    private final Map<String, Map<String, String>> reviews = new HashMap<>();
 | 
			
		||||
    private final Set<String> purchases = new HashSet<>(); // Ajout pour les achats
 | 
			
		||||
    private String lastReviewId;
 | 
			
		||||
    private boolean lastOperationSuccess = false;
 | 
			
		||||
    private String lastErrorMessage = null;
 | 
			
		||||
    private String lastReviewError;
 | 
			
		||||
    private boolean lastReviewSuccess;
 | 
			
		||||
    private List<Map<String, String>> lastReviewsFetched;
 | 
			
		||||
 | 
			
		||||
    @Given("the review system has the following review customers:")
 | 
			
		||||
    public void theReviewSystemHasTheFollowingReviewCustomers(DataTable dataTable) {
 | 
			
		||||
        reviewCustomers.clear();
 | 
			
		||||
        customers.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            reviewCustomers.put(row.get("id"), row);
 | 
			
		||||
            customers.put(row.get("id"), new HashMap<>(row));
 | 
			
		||||
        }
 | 
			
		||||
        assertEquals(dataTable.asMaps().size(), customers.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Given("the review system has the following review books:")
 | 
			
		||||
    @And("the review system has the following review books:")
 | 
			
		||||
    public void theReviewSystemHasTheFollowingReviewBooks(DataTable dataTable) {
 | 
			
		||||
        reviewBooks.clear();
 | 
			
		||||
        books.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            reviewBooks.put(row.get("isbn"), row);
 | 
			
		||||
            books.put(Long.parseLong(row.get("isbn")), new HashMap<>(row));
 | 
			
		||||
        }
 | 
			
		||||
        assertEquals(dataTable.asMaps().size(), books.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Given("the review system has the following reviews:")
 | 
			
		||||
    @And("the review system has the following reviews:")
 | 
			
		||||
    public void theReviewSystemHasTheFollowingReviews(DataTable dataTable) {
 | 
			
		||||
        reviews.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            reviews.put(row.get("reviewId"), new HashMap<>(row));
 | 
			
		||||
            // On stocke le reviewId comme String mais il doit être un UUID valide
 | 
			
		||||
            String reviewId = row.get("reviewId");
 | 
			
		||||
            UUID.fromString(reviewId); // Valide que c'est bien un UUID
 | 
			
		||||
            reviews.put(reviewId, new HashMap<>(row));
 | 
			
		||||
        }
 | 
			
		||||
        assertEquals(dataTable.asMaps().size(), reviews.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("the review system has the following purchases:")
 | 
			
		||||
    public void theReviewSystemHasTheFollowingPurchases(DataTable dataTable) {
 | 
			
		||||
        purchases.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            String customerId = row.get("customerId");
 | 
			
		||||
            String bookId = row.get("bookId");
 | 
			
		||||
            purchases.add(customerId + ":" + bookId);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I submit a new review with the following information:")
 | 
			
		||||
    public void iSubmitANewReviewWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        Map<String, String> reviewInfo = dataTable.asMaps(String.class, String.class).getFirst();
 | 
			
		||||
        String reviewId = "rev-" + (reviews.size() + 1);
 | 
			
		||||
        reviews.put(reviewId, new HashMap<>(reviewInfo));
 | 
			
		||||
        lastReviewId = reviewId;
 | 
			
		||||
        lastOperationSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
        Map<String, String> info = dataTable.asMaps(String.class, String.class).getFirst();
 | 
			
		||||
        String customerId = info.get("customerId");
 | 
			
		||||
        String isbnStr = info.get("isbn");
 | 
			
		||||
        String rating = info.get("rating");
 | 
			
		||||
        String comment = info.get("comment");
 | 
			
		||||
 | 
			
		||||
    @When("I try to submit a new review with the following information:")
 | 
			
		||||
    public void iTryToSubmitANewReviewWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        // Simule un échec de soumission
 | 
			
		||||
        lastOperationSuccess = false;
 | 
			
		||||
        lastErrorMessage = "Simulated review submission error";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I request all reviews by customer {string}")
 | 
			
		||||
    public void iRequestAllReviewsByCustomer(String customerId) {
 | 
			
		||||
        // Simule la récupération des reviews pour un client
 | 
			
		||||
        boolean found = reviews.values().stream().anyMatch(r -> customerId.equals(r.get("customerId")));
 | 
			
		||||
        lastOperationSuccess = found;
 | 
			
		||||
        if (!found) {
 | 
			
		||||
            lastErrorMessage = "Book or customer not found";
 | 
			
		||||
        } else {
 | 
			
		||||
            lastErrorMessage = null;
 | 
			
		||||
        if (customerId == null || customerId.isBlank() ||
 | 
			
		||||
            isbnStr == null || isbnStr.isBlank() ||
 | 
			
		||||
            rating == null || rating.isBlank()) {
 | 
			
		||||
            lastReviewSuccess = false;
 | 
			
		||||
            lastReviewError = "Invalid review details";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I request all reviews for book {string}")
 | 
			
		||||
    public void iRequestAllReviewsForBook(String isbn) {
 | 
			
		||||
        // Simule la récupération des reviews pour un livre
 | 
			
		||||
        boolean found = reviews.values().stream().anyMatch(r -> isbn.equals(r.get("bookId")));
 | 
			
		||||
        lastOperationSuccess = found;
 | 
			
		||||
        if (!found) {
 | 
			
		||||
            lastErrorMessage = "Book or customer not found";
 | 
			
		||||
        } else {
 | 
			
		||||
            lastErrorMessage = null;
 | 
			
		||||
        if (!customers.containsKey(customerId) || !books.containsKey(Long.parseLong(isbnStr))) {
 | 
			
		||||
            lastReviewSuccess = false;
 | 
			
		||||
            lastReviewError = "Book or customer not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I try to delete the review with id {string}")
 | 
			
		||||
    public void iTryToDeleteTheReviewWithId(String reviewId) {
 | 
			
		||||
        if (reviews.containsKey(reviewId)) {
 | 
			
		||||
            reviews.remove(reviewId);
 | 
			
		||||
            lastOperationSuccess = true;
 | 
			
		||||
            lastErrorMessage = null;
 | 
			
		||||
        } else {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Review not found";
 | 
			
		||||
        for (Map<String, String> review : reviews.values()) {
 | 
			
		||||
            if (review.get("customerName").equals(customers.get(customerId).get("firstName") + " " + customers.get(customerId).get("lastName"))
 | 
			
		||||
                && review.get("bookId").equals(isbnStr)) {
 | 
			
		||||
                lastReviewSuccess = false;
 | 
			
		||||
                lastReviewError = "Review already exists";
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (!purchases.contains(customerId + ":" + isbnStr)) {
 | 
			
		||||
            lastReviewSuccess = false;
 | 
			
		||||
            lastReviewError = "customer hasn't purchased the book";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        String newReviewId = UUID.randomUUID().toString();
 | 
			
		||||
        Map<String, String> review = new HashMap<>();
 | 
			
		||||
        review.put("reviewId", newReviewId);
 | 
			
		||||
        review.put("bookId", isbnStr);
 | 
			
		||||
        review.put("customerName", customers.get(customerId).get("firstName") + " " + customers.get(customerId).get("lastName"));
 | 
			
		||||
        review.put("comment", comment);
 | 
			
		||||
        review.put("rating", rating);
 | 
			
		||||
        reviews.put(newReviewId, review);
 | 
			
		||||
        lastReviewId = newReviewId;
 | 
			
		||||
        lastReviewSuccess = true;
 | 
			
		||||
        lastReviewError = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the review is created successfully")
 | 
			
		||||
    public void theReviewIsCreatedSuccessfully() {
 | 
			
		||||
        assertTrue(lastOperationSuccess);
 | 
			
		||||
        assertTrue(lastReviewSuccess);
 | 
			
		||||
        assertNotNull(lastReviewId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("the review system now has {int} reviews")
 | 
			
		||||
@@ -106,40 +119,52 @@ public class ReviewSteps {
 | 
			
		||||
        assertEquals(expected, reviews.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I request all reviews by customer {string}")
 | 
			
		||||
    public void iRequestAllReviewsByCustomer(String customerId) {
 | 
			
		||||
        lastReviewsFetched = new ArrayList<>();
 | 
			
		||||
        if (!customers.containsKey(customerId)) {
 | 
			
		||||
            lastReviewSuccess = false;
 | 
			
		||||
            lastReviewError = "Book or customer not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        String customerName = customers.get(customerId).get("firstName") + " " + customers.get(customerId).get("lastName");
 | 
			
		||||
        for (Map<String, String> review : reviews.values()) {
 | 
			
		||||
            if (review.get("customerName").equals(customerName)) {
 | 
			
		||||
                lastReviewsFetched.add(review);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        lastReviewSuccess = true;
 | 
			
		||||
        lastReviewError = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("I receive the following reviews:")
 | 
			
		||||
    public void iReceiveTheFollowingReviews(DataTable dataTable) {
 | 
			
		||||
        List<Map<String, String>> expected = dataTable.asMaps(String.class, String.class);
 | 
			
		||||
        for (Map<String, String> exp : expected) {
 | 
			
		||||
            boolean match = reviews.values().stream().anyMatch(r ->
 | 
			
		||||
                Objects.equals(exp.get("reviewId"), r.get("reviewId")) &&
 | 
			
		||||
                Objects.equals(exp.get("bookId"), r.get("bookId")) &&
 | 
			
		||||
                Objects.equals(exp.get("customerName"), r.get("customerName")) &&
 | 
			
		||||
                Objects.equals(exp.get("comment"), r.get("comment")) &&
 | 
			
		||||
                Objects.equals(exp.get("rating"), r.get("rating"))
 | 
			
		||||
            );
 | 
			
		||||
            assertTrue(match, "Expected review not found: " + exp);
 | 
			
		||||
        assertEquals(expected.size(), lastReviewsFetched.size());
 | 
			
		||||
        for (int i = 0; i < expected.size(); i++) {
 | 
			
		||||
            Map<String, String> exp = expected.get(i);
 | 
			
		||||
            Map<String, String> act = lastReviewsFetched.get(i);
 | 
			
		||||
            for (String key : exp.keySet()) {
 | 
			
		||||
                assertEquals(exp.get(key), act.get(key));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I try to submit a new review with the following information:")
 | 
			
		||||
    public void iTryToSubmitANewReviewWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        iSubmitANewReviewWithTheFollowingInformation(dataTable);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the review submission fails")
 | 
			
		||||
    public void theReviewSubmissionFails() {
 | 
			
		||||
        assertFalse(lastOperationSuccess);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the review request fails")
 | 
			
		||||
    public void theReviewRequestFails() {
 | 
			
		||||
        assertFalse(lastOperationSuccess);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the review deletion fails")
 | 
			
		||||
    public void theReviewDeletionFails() {
 | 
			
		||||
        assertFalse(lastOperationSuccess);
 | 
			
		||||
        assertFalse(lastReviewSuccess);
 | 
			
		||||
        assertNotNull(lastReviewError);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("I receive a review error message containing {string}")
 | 
			
		||||
    public void iReceiveAReviewErrorMessageContaining(String msg) {
 | 
			
		||||
        assertNotNull(lastErrorMessage);
 | 
			
		||||
        assertTrue(lastErrorMessage.contains(msg));
 | 
			
		||||
        assertNotNull(lastReviewError);
 | 
			
		||||
        assertTrue(lastReviewError.contains(msg), "Expected error message to contain: \"" + msg + "\" but was: \"" + lastReviewError + "\"");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("the review system still has {int} review")
 | 
			
		||||
@@ -147,8 +172,51 @@ public class ReviewSteps {
 | 
			
		||||
        assertEquals(expected, reviews.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("the review system still has {int} reviews")
 | 
			
		||||
    public void theReviewSystemStillHasReviews(int expected) {
 | 
			
		||||
        assertEquals(expected, reviews.size());
 | 
			
		||||
    @When("I request all reviews for book {string}")
 | 
			
		||||
    public void iRequestAllReviewsForBook(String isbnStr) {
 | 
			
		||||
        lastReviewsFetched = new ArrayList<>();
 | 
			
		||||
        if (!books.containsKey(Long.parseLong(isbnStr))) {
 | 
			
		||||
            lastReviewSuccess = false;
 | 
			
		||||
            lastReviewError = "Book or customer not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        for (Map<String, String> review : reviews.values()) {
 | 
			
		||||
            if (review.get("bookId").equals(isbnStr)) {
 | 
			
		||||
                lastReviewsFetched.add(review);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        lastReviewSuccess = true;
 | 
			
		||||
        lastReviewError = null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    @Then("the review request fails")
 | 
			
		||||
    public void theReviewRequestFails() {
 | 
			
		||||
        assertFalse(lastReviewSuccess);
 | 
			
		||||
        assertNotNull(lastReviewError);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I try to delete the review with id {string}")
 | 
			
		||||
    public void iTryToDeleteTheReviewWithId(String reviewId) {
 | 
			
		||||
        try {
 | 
			
		||||
            UUID.fromString(reviewId); // Vérifie que c'est bien un UUID
 | 
			
		||||
        } catch (IllegalArgumentException e) {
 | 
			
		||||
            lastReviewSuccess = false;
 | 
			
		||||
            lastReviewError = "Invalid reviewId format";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if (!reviews.containsKey(reviewId)) {
 | 
			
		||||
            lastReviewSuccess = false;
 | 
			
		||||
            lastReviewError = "Review not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        reviews.remove(reviewId);
 | 
			
		||||
        lastReviewSuccess = true;
 | 
			
		||||
        lastReviewError = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the review deletion fails")
 | 
			
		||||
    public void theReviewDeletionFails() {
 | 
			
		||||
        assertFalse(lastReviewSuccess);
 | 
			
		||||
        assertNotNull(lastReviewError);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -126,7 +126,7 @@ public class SubscriptionSteps {
 | 
			
		||||
    @When("I try to request a new subscription with the following information:")
 | 
			
		||||
    public void iTryToRequestANewSubscriptionWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        iRequestANewSubscriptionWithTheFollowingInformation(dataTable);
 | 
			
		||||
        lastRequestSuccess = false; // Pour forcer l'échec dans les assertions
 | 
			
		||||
        lastRequestSuccess = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the subscription request fails")
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,38 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.converter;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.entity.Order;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderDTO;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderInfo;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class OrderConverterTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testOrderToOrderDTO() {
 | 
			
		||||
        UUID id = UUID.randomUUID();
 | 
			
		||||
        UUID customerId = UUID.randomUUID();
 | 
			
		||||
        List<OrderInfo.OrderLineDto> lines = List.of(new OrderInfo.OrderLineDto(1234567890123L, 1));
 | 
			
		||||
        OrderInfo.Address address = new OrderInfo.Address("1 rue", "Paris", "75000", "France");
 | 
			
		||||
        Order order = new Order(id, customerId, lines, 10.0, 10.0, address, "CREDIT_CARD");
 | 
			
		||||
 | 
			
		||||
        OrderDTO dto = new OrderDTO();
 | 
			
		||||
        dto.setId(order.getId());
 | 
			
		||||
        dto.setCustomerId(order.getCustomerId());
 | 
			
		||||
        dto.setOrderLines(order.getOrderLines());
 | 
			
		||||
        dto.setTotalPrice(order.getTotalPrice());
 | 
			
		||||
        dto.setTotalPriceToPay(order.getTotalPriceToPay());
 | 
			
		||||
        dto.setAddress(order.getAddress());
 | 
			
		||||
        dto.setPaymentMethod(order.getPaymentMethod());
 | 
			
		||||
 | 
			
		||||
        assertEquals(order.getId(), dto.getId());
 | 
			
		||||
        assertEquals(order.getCustomerId(), dto.getCustomerId());
 | 
			
		||||
        assertEquals(order.getOrderLines(), dto.getOrderLines());
 | 
			
		||||
        assertEquals(order.getTotalPrice(), dto.getTotalPrice());
 | 
			
		||||
        assertEquals(order.getTotalPriceToPay(), dto.getTotalPriceToPay());
 | 
			
		||||
        assertEquals(order.getAddress(), dto.getAddress());
 | 
			
		||||
        assertEquals(order.getPaymentMethod(), dto.getPaymentMethod());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,31 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.entity;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderInfo;
 | 
			
		||||
 | 
			
		||||
public class OrderTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testOrderConstructorAndGetters() {
 | 
			
		||||
        UUID id = UUID.randomUUID();
 | 
			
		||||
        UUID customerId = UUID.randomUUID();
 | 
			
		||||
        List<OrderInfo.OrderLineDto> orderLines = new ArrayList<>();
 | 
			
		||||
        orderLines.add(new OrderInfo.OrderLineDto(1234567890123L, 2));
 | 
			
		||||
        double totalPrice = 50.0;
 | 
			
		||||
        double totalPriceToPay = 45.0;
 | 
			
		||||
        OrderInfo.Address address = new OrderInfo.Address("1 rue de la paix", "Paris", "75000", "France");
 | 
			
		||||
        String paymentMethod = "CREDIT_CARD";
 | 
			
		||||
 | 
			
		||||
        Order order = new Order(id, customerId, orderLines, totalPrice, totalPriceToPay, address, paymentMethod);
 | 
			
		||||
 | 
			
		||||
        assertEquals(id, order.getId());
 | 
			
		||||
        assertEquals(customerId, order.getCustomerId());
 | 
			
		||||
        assertEquals(orderLines, order.getOrderLines());
 | 
			
		||||
        assertEquals(totalPrice, order.getTotalPrice());
 | 
			
		||||
        assertEquals(totalPriceToPay, order.getTotalPriceToPay());
 | 
			
		||||
        assertEquals(address, order.getAddress());
 | 
			
		||||
        assertEquals(paymentMethod, order.getPaymentMethod());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.exception;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
public class BookQuantityInsufficientExceptionTest {
 | 
			
		||||
    @Test
 | 
			
		||||
    void testMessage() {
 | 
			
		||||
        BookQuantityInsufficientException ex = new BookQuantityInsufficientException(5, 2);
 | 
			
		||||
        assertEquals("Cannot order 5 books, only 2 in stock", ex.getMessage());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.exception;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
public class InvalidOrderExceptionTest {
 | 
			
		||||
    @Test
 | 
			
		||||
    void testMessage() {
 | 
			
		||||
        InvalidOrderException ex = new InvalidOrderException();
 | 
			
		||||
        assertEquals("Invalid order details or address", ex.getMessage());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,14 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.exception;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class OrderNotFoundExceptionTest {
 | 
			
		||||
    @Test
 | 
			
		||||
    void testMessage() {
 | 
			
		||||
        UUID uuid = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
 | 
			
		||||
        OrderNotFoundException ex = new OrderNotFoundException(uuid);
 | 
			
		||||
        assertEquals("The order with id 123e4567-e89b-12d3-a456-426614174000 does not exist", ex.getMessage());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,28 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.repository;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderInfo;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.entity.Order;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class OrderRepositoryTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testSaveAndFindById() {
 | 
			
		||||
        OrderRepository repo = new OrderRepository();
 | 
			
		||||
        OrderInfo info = new OrderInfo();
 | 
			
		||||
        info.setCustomerId(UUID.randomUUID());
 | 
			
		||||
        info.setOrderLineDtos(List.of(new OrderInfo.OrderLineDto(1234567890123L, 1)));
 | 
			
		||||
        info.setAddress(new OrderInfo.Address("1 rue", "Paris", "75000", "France"));
 | 
			
		||||
        info.setPaymentMethod("CREDIT_CARD");
 | 
			
		||||
 | 
			
		||||
        Order saved = repo.save(info);
 | 
			
		||||
        assertNotNull(saved.getId());
 | 
			
		||||
 | 
			
		||||
        Optional<Order> found = repo.findById(saved.getId());
 | 
			
		||||
        assertTrue(found.isPresent());
 | 
			
		||||
        assertEquals(saved.getId(), found.get().getId());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,44 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.usecase;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.repository.OrderRepository;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderInfo;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderDTO;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class OrderUseCaseTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testCreateAndGetOrder() throws Exception {
 | 
			
		||||
        OrderRepository repo = new OrderRepository();
 | 
			
		||||
        OrderUseCase useCase = new OrderUseCase(repo);
 | 
			
		||||
 | 
			
		||||
        OrderInfo info = new OrderInfo();
 | 
			
		||||
        UUID customerId = UUID.randomUUID();
 | 
			
		||||
        info.setCustomerId(customerId);
 | 
			
		||||
        info.setOrderLineDtos(List.of(new OrderInfo.OrderLineDto(1234567890123L, 1)));
 | 
			
		||||
        info.setAddress(new OrderInfo.Address("1 rue", "Paris", "75000", "France"));
 | 
			
		||||
        info.setPaymentMethod("CREDIT_CARD");
 | 
			
		||||
 | 
			
		||||
        OrderDTO dto = useCase.createOrder(info);
 | 
			
		||||
        assertNotNull(dto.getId());
 | 
			
		||||
        assertEquals(customerId, dto.getCustomerId());
 | 
			
		||||
 | 
			
		||||
        Optional<OrderDTO> found = useCase.getOrderById(dto.getId());
 | 
			
		||||
        assertTrue(found.isPresent());
 | 
			
		||||
        assertEquals(dto.getId(), found.get().getId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testCreateOrderInvalid() {
 | 
			
		||||
        OrderRepository repo = new OrderRepository();
 | 
			
		||||
        OrderUseCase useCase = new OrderUseCase(repo);
 | 
			
		||||
 | 
			
		||||
        OrderInfo info = new OrderInfo(); // champs manquants
 | 
			
		||||
 | 
			
		||||
        Exception ex = assertThrows(IllegalArgumentException.class, () -> useCase.createOrder(info));
 | 
			
		||||
        assertEquals("Invalid order details or address", ex.getMessage());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,81 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.order.validator;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.order.OrderInfo;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class OrderValidatorTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testIsValidUUID() {
 | 
			
		||||
        assertTrue(OrderValidator.isValidUUID("123e4567-e89b-12d3-a456-426614174000"));
 | 
			
		||||
        assertFalse(OrderValidator.isValidUUID("not-a-uuid"));
 | 
			
		||||
        assertFalse(OrderValidator.isValidUUID(""));
 | 
			
		||||
        assertFalse(OrderValidator.isValidUUID(null));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testIsValidOrderInfo_valid() {
 | 
			
		||||
        OrderInfo info = new OrderInfo();
 | 
			
		||||
        info.setCustomerId(UUID.randomUUID());
 | 
			
		||||
        List<OrderInfo.OrderLineDto> lines = new ArrayList<>();
 | 
			
		||||
        lines.add(new OrderInfo.OrderLineDto(1234567890123L, 2));
 | 
			
		||||
        info.setOrderLineDtos(lines);
 | 
			
		||||
        OrderInfo.Address address = new OrderInfo.Address("1 rue", "Paris", "75000", "France");
 | 
			
		||||
        info.setAddress(address);
 | 
			
		||||
        info.setPaymentMethod("CREDIT_CARD");
 | 
			
		||||
 | 
			
		||||
        assertTrue(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testIsValidOrderInfo_missingFields() {
 | 
			
		||||
        OrderInfo info = new OrderInfo();
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
 | 
			
		||||
        info.setCustomerId(UUID.randomUUID());
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
 | 
			
		||||
        info.setOrderLineDtos(new ArrayList<>());
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
 | 
			
		||||
        List<OrderInfo.OrderLineDto> lines = new ArrayList<>();
 | 
			
		||||
        lines.add(new OrderInfo.OrderLineDto(0, 2)); // bookId <= 0
 | 
			
		||||
        info.setOrderLineDtos(lines);
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
 | 
			
		||||
        lines.clear();
 | 
			
		||||
        lines.add(new OrderInfo.OrderLineDto(1234567890123L, 0)); // quantity <= 0
 | 
			
		||||
        info.setOrderLineDtos(lines);
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
 | 
			
		||||
        lines.clear();
 | 
			
		||||
        lines.add(new OrderInfo.OrderLineDto(1234567890123L, 2));
 | 
			
		||||
        info.setOrderLineDtos(lines);
 | 
			
		||||
        info.setPaymentMethod("CREDIT_CARD");
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
 | 
			
		||||
        OrderInfo.Address address = new OrderInfo.Address("", "Paris", "75000", "France");
 | 
			
		||||
        info.setAddress(address);
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
 | 
			
		||||
        address = new OrderInfo.Address("1 rue", "", "75000", "France");
 | 
			
		||||
        info.setAddress(address);
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
 | 
			
		||||
        address = new OrderInfo.Address("1 rue", "Paris", "", "France");
 | 
			
		||||
        info.setAddress(address);
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
 | 
			
		||||
        address = new OrderInfo.Address("1 rue", "Paris", "75000", "");
 | 
			
		||||
        info.setAddress(address);
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
 | 
			
		||||
        address = new OrderInfo.Address("1 rue", "Paris", "75000", "France");
 | 
			
		||||
        info.setAddress(address);
 | 
			
		||||
        info.setPaymentMethod("UNKNOWN");
 | 
			
		||||
        assertFalse(OrderValidator.isValidOrderInfo(info));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,64 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.converter;
 | 
			
		||||
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.review.entity.Review;
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.review.ReviewDto;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
class ReviewConverterTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void toDtoShouldConvertReviewToDto() {
 | 
			
		||||
        UUID uuid = UUID.randomUUID();
 | 
			
		||||
        Review review = Review.builder()
 | 
			
		||||
                .reviewId(uuid)
 | 
			
		||||
                .bookId(978333333L)
 | 
			
		||||
                .customerName("Carol White")
 | 
			
		||||
                .comment("Great book!")
 | 
			
		||||
                .rating(5)
 | 
			
		||||
                .build();
 | 
			
		||||
 | 
			
		||||
        ReviewDto dto = ReviewConverter.toDto(review);
 | 
			
		||||
 | 
			
		||||
        assertNotNull(dto);
 | 
			
		||||
        assertEquals(uuid, dto.getReviewId());
 | 
			
		||||
        assertEquals(978333333L, dto.getBookId());
 | 
			
		||||
        assertEquals("Carol White", dto.getCustomerName());
 | 
			
		||||
        assertEquals("Great book!", dto.getComment());
 | 
			
		||||
        assertEquals(5, dto.getRating());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void fromDtoShouldConvertDtoToReview() {
 | 
			
		||||
        UUID uuid = UUID.randomUUID();
 | 
			
		||||
        ReviewDto dto = ReviewDto.builder()
 | 
			
		||||
                .reviewId(uuid)
 | 
			
		||||
                .bookId(978333333L)
 | 
			
		||||
                .customerName("Carol White")
 | 
			
		||||
                .comment("Great book!")
 | 
			
		||||
                .rating(5)
 | 
			
		||||
                .build();
 | 
			
		||||
 | 
			
		||||
        Review review = ReviewConverter.fromDto(dto);
 | 
			
		||||
 | 
			
		||||
        assertNotNull(review);
 | 
			
		||||
        assertEquals(uuid, review.getReviewId());
 | 
			
		||||
        assertEquals(978333333L, review.getBookId());
 | 
			
		||||
        assertEquals("Carol White", review.getCustomerName());
 | 
			
		||||
        assertEquals("Great book!", review.getComment());
 | 
			
		||||
        assertEquals(5, review.getRating());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void toDtoShouldReturnNullForNullInput() {
 | 
			
		||||
        assertNull(ReviewConverter.toDto(null));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void fromDtoShouldReturnNullForNullInput() {
 | 
			
		||||
        assertNull(ReviewConverter.fromDto(null));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,42 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.entity;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
class ReviewTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void builderShouldCreateValidReview() {
 | 
			
		||||
        UUID uuid = UUID.randomUUID();
 | 
			
		||||
        Review review = Review.builder()
 | 
			
		||||
            .reviewId(uuid)
 | 
			
		||||
            .bookId(978333333L)
 | 
			
		||||
            .customerName("Carol White")
 | 
			
		||||
            .comment("Great book!")
 | 
			
		||||
            .rating(5)
 | 
			
		||||
            .build();
 | 
			
		||||
 | 
			
		||||
        assertEquals(uuid, review.getReviewId());
 | 
			
		||||
        assertEquals(978333333L, review.getBookId());
 | 
			
		||||
        assertEquals("Carol White", review.getCustomerName());
 | 
			
		||||
        assertEquals("Great book!", review.getComment());
 | 
			
		||||
        assertEquals(5, review.getRating());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void reviewsWithSameIdShouldBeEqual() {
 | 
			
		||||
        UUID uuid = UUID.randomUUID();
 | 
			
		||||
        Review r1 = Review.builder().reviewId(uuid).build();
 | 
			
		||||
        Review r2 = Review.builder().reviewId(uuid).build();
 | 
			
		||||
        assertEquals(r1, r2);
 | 
			
		||||
        assertEquals(r1.hashCode(), r2.hashCode());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void reviewsWithDifferentIdShouldNotBeEqual() {
 | 
			
		||||
        Review r1 = Review.builder().reviewId(UUID.randomUUID()).build();
 | 
			
		||||
        Review r2 = Review.builder().reviewId(UUID.randomUUID()).build();
 | 
			
		||||
        assertNotEquals(r1, r2);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.exception;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
class DuplicateReviewExceptionTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testFormattedMessage() {
 | 
			
		||||
        DuplicateReviewException ex = new DuplicateReviewException("c1", 1234567890123L);
 | 
			
		||||
        assertEquals("A review already exists for customer c1 and book 1234567890123", ex.getMessage());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.exception;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
class InvalidReviewExceptionTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testMessage() {
 | 
			
		||||
        InvalidReviewException ex = new InvalidReviewException("Invalid review details");
 | 
			
		||||
        assertEquals("Invalid review details", ex.getMessage());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.exception;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
class ReviewNotAllowedExceptionTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testFormattedMessage() {
 | 
			
		||||
        ReviewNotAllowedException ex = new ReviewNotAllowedException("c2", 9876543210123L);
 | 
			
		||||
        assertEquals("Customer c2 is not allowed to review book 9876543210123", ex.getMessage());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.exception;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
class ReviewNotFoundExceptionTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testFormattedMessage() {
 | 
			
		||||
        ReviewNotFoundException ex = new ReviewNotFoundException("rev-42");
 | 
			
		||||
        assertEquals("The review with id rev-42 does not exist", ex.getMessage());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,72 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.repository;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.BeforeEach;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
public class ReviewRepositoryTest {
 | 
			
		||||
 | 
			
		||||
    private ReviewRepository repository;
 | 
			
		||||
 | 
			
		||||
    @BeforeEach
 | 
			
		||||
    void setUp() {
 | 
			
		||||
        repository = new ReviewRepository();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testSaveAndFindById() {
 | 
			
		||||
        Map<String, String> review = new HashMap<>();
 | 
			
		||||
        review.put("reviewId", "11111111-1111-1111-1111-111111111111");
 | 
			
		||||
        review.put("customerName", "Alice Smith");
 | 
			
		||||
        review.put("bookId", "978333333");
 | 
			
		||||
        repository.save(review);
 | 
			
		||||
 | 
			
		||||
        Map<String, String> found = repository.findById("11111111-1111-1111-1111-111111111111");
 | 
			
		||||
        assertNotNull(found);
 | 
			
		||||
        assertEquals("Alice Smith", found.get("customerName"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testDeleteById() {
 | 
			
		||||
        Map<String, String> review = new HashMap<>();
 | 
			
		||||
        review.put("reviewId", "22222222-2222-2222-2222-222222222222");
 | 
			
		||||
        repository.save(review);
 | 
			
		||||
        assertTrue(repository.existsById("22222222-2222-2222-2222-222222222222"));
 | 
			
		||||
        repository.deleteById("22222222-2222-2222-2222-222222222222");
 | 
			
		||||
        assertFalse(repository.existsById("22222222-2222-2222-2222-222222222222"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testFindByCustomerName() {
 | 
			
		||||
        Map<String, String> review1 = new HashMap<>();
 | 
			
		||||
        review1.put("reviewId", "1");
 | 
			
		||||
        review1.put("customerName", "Bob");
 | 
			
		||||
        Map<String, String> review2 = new HashMap<>();
 | 
			
		||||
        review2.put("reviewId", "2");
 | 
			
		||||
        review2.put("customerName", "Alice");
 | 
			
		||||
        repository.save(review1);
 | 
			
		||||
        repository.save(review2);
 | 
			
		||||
 | 
			
		||||
        List<Map<String, String>> found = repository.findByCustomerName("Alice");
 | 
			
		||||
        assertEquals(1, found.size());
 | 
			
		||||
        assertEquals("2", found.get(0).get("reviewId"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testFindByBookId() {
 | 
			
		||||
        Map<String, String> review1 = new HashMap<>();
 | 
			
		||||
        review1.put("reviewId", "1");
 | 
			
		||||
        review1.put("bookId", "A");
 | 
			
		||||
        Map<String, String> review2 = new HashMap<>();
 | 
			
		||||
        review2.put("reviewId", "2");
 | 
			
		||||
        review2.put("bookId", "B");
 | 
			
		||||
        repository.save(review1);
 | 
			
		||||
        repository.save(review2);
 | 
			
		||||
 | 
			
		||||
        List<Map<String, String>> found = repository.findByBookId("A");
 | 
			
		||||
        assertEquals(1, found.size());
 | 
			
		||||
        assertEquals("1", found.get(0).get("reviewId"));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,91 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.review.usecase;
 | 
			
		||||
 | 
			
		||||
import fr.iut_fbleau.but3.dev62.mylibrary.review.repository.ReviewRepository;
 | 
			
		||||
import org.junit.jupiter.api.BeforeEach;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
public class ReviewUseCaseTest {
 | 
			
		||||
 | 
			
		||||
    private ReviewRepository repository;
 | 
			
		||||
    private ReviewUseCase useCase;
 | 
			
		||||
 | 
			
		||||
    @BeforeEach
 | 
			
		||||
    void setUp() {
 | 
			
		||||
        repository = new ReviewRepository();
 | 
			
		||||
        useCase = new ReviewUseCase(repository);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testSubmitReviewAndCount() {
 | 
			
		||||
        Map<String, String> review = new HashMap<>();
 | 
			
		||||
        review.put("customerId", "c1");
 | 
			
		||||
        review.put("isbn", "978333333");
 | 
			
		||||
        review.put("rating", "5");
 | 
			
		||||
        review.put("customerName", "Alice Smith");
 | 
			
		||||
        review.put("comment", "Super livre !");
 | 
			
		||||
        String reviewId = useCase.submitReview(review);
 | 
			
		||||
        assertNotNull(reviewId);
 | 
			
		||||
        assertEquals(1, useCase.countReviews());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testSubmitReviewInvalidDetails() {
 | 
			
		||||
        Map<String, String> review = new HashMap<>();
 | 
			
		||||
        review.put("customerId", "");
 | 
			
		||||
        review.put("isbn", "978333333");
 | 
			
		||||
        review.put("rating", "5");
 | 
			
		||||
        assertThrows(IllegalArgumentException.class, () -> useCase.submitReview(review));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testDeleteReview() {
 | 
			
		||||
        Map<String, String> review = new HashMap<>();
 | 
			
		||||
        review.put("customerId", "c1");
 | 
			
		||||
        review.put("isbn", "978333333");
 | 
			
		||||
        review.put("rating", "5");
 | 
			
		||||
        review.put("customerName", "Alice Smith");
 | 
			
		||||
        review.put("comment", "Super livre !");
 | 
			
		||||
        String reviewId = useCase.submitReview(review);
 | 
			
		||||
        assertEquals(1, useCase.countReviews());
 | 
			
		||||
        useCase.deleteReview(reviewId);
 | 
			
		||||
        assertEquals(0, useCase.countReviews());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testDeleteReviewInvalidUUID() {
 | 
			
		||||
        assertThrows(IllegalArgumentException.class, () -> useCase.deleteReview("not-a-uuid"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testDeleteReviewNotFound() {
 | 
			
		||||
        String uuid = UUID.randomUUID().toString();
 | 
			
		||||
        assertThrows(NoSuchElementException.class, () -> useCase.deleteReview(uuid));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testGetReviewsByCustomerName() {
 | 
			
		||||
        Map<String, String> review1 = new HashMap<>();
 | 
			
		||||
        review1.put("customerId", "c1");
 | 
			
		||||
        review1.put("isbn", "978333333");
 | 
			
		||||
        review1.put("rating", "5");
 | 
			
		||||
        review1.put("customerName", "Alice Smith");
 | 
			
		||||
        review1.put("comment", "Super livre !");
 | 
			
		||||
        useCase.submitReview(review1);
 | 
			
		||||
 | 
			
		||||
        Map<String, String> review2 = new HashMap<>();
 | 
			
		||||
        review2.put("customerId", "c2");
 | 
			
		||||
        review2.put("isbn", "978444444");
 | 
			
		||||
        review2.put("rating", "4");
 | 
			
		||||
        review2.put("customerName", "Bob White");
 | 
			
		||||
        review2.put("comment", "Bien !");
 | 
			
		||||
        useCase.submitReview(review2);
 | 
			
		||||
 | 
			
		||||
        List<Map<String, String>> aliceReviews = useCase.getReviewsByCustomerName("Alice Smith");
 | 
			
		||||
        assertEquals(1, aliceReviews.size());
 | 
			
		||||
        assertEquals("Alice Smith", aliceReviews.get(0).get("customerName"));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user