forked from pierront/mylibrary-template
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			b8091da304
			...
			6218b38817
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					6218b38817 | ||
| 
						 | 
					be51f5288f | 
@@ -3,35 +3,35 @@ package fr.iut_fbleau.but3.dev62.mylibrary.features.review;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
import io.cucumber.datatable.DataTable;
 | 
			
		||||
import io.cucumber.java.en.*;
 | 
			
		||||
import io.cucumber.java.en.And;
 | 
			
		||||
import io.cucumber.java.en.Given;
 | 
			
		||||
import io.cucumber.java.en.Then;
 | 
			
		||||
import io.cucumber.java.en.When;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class ReviewSteps {
 | 
			
		||||
 | 
			
		||||
    // Simulations des repositories en mémoire
 | 
			
		||||
    private final Map<String, Map<String, String>> customers = new HashMap<>();
 | 
			
		||||
    private final Map<String, Map<String, String>> books = new HashMap<>();
 | 
			
		||||
    private final Map<String, Map<String, String>> reviews = new LinkedHashMap<>();
 | 
			
		||||
 | 
			
		||||
    // Pour stocker les résultats/intermédiaires
 | 
			
		||||
    private List<Map<String, String>> lastReviewResult;
 | 
			
		||||
    private String lastErrorMessage;
 | 
			
		||||
    private boolean lastOperationSuccess;
 | 
			
		||||
    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>> reviews = new HashMap<>();
 | 
			
		||||
    private String lastReviewId;
 | 
			
		||||
    private boolean lastOperationSuccess = false;
 | 
			
		||||
    private String lastErrorMessage = null;
 | 
			
		||||
 | 
			
		||||
    @Given("the review system has the following review customers:")
 | 
			
		||||
    public void theReviewSystemHasTheFollowingReviewCustomers(DataTable dataTable) {
 | 
			
		||||
        customers.clear();
 | 
			
		||||
        reviewCustomers.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            customers.put(row.get("id"), row);
 | 
			
		||||
            reviewCustomers.put(row.get("id"), row);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Given("the review system has the following books:")
 | 
			
		||||
    public void theReviewSystemHasTheFollowingBooks(DataTable dataTable) {
 | 
			
		||||
        books.clear();
 | 
			
		||||
    @Given("the review system has the following review books:")
 | 
			
		||||
    public void theReviewSystemHasTheFollowingReviewBooks(DataTable dataTable) {
 | 
			
		||||
        reviewBooks.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            books.put(row.get("isbn"), row);
 | 
			
		||||
            reviewBooks.put(row.get("isbn"), row);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -39,143 +39,103 @@ public class ReviewSteps {
 | 
			
		||||
    public void theReviewSystemHasTheFollowingReviews(DataTable dataTable) {
 | 
			
		||||
        reviews.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            // Vérifie que toutes les colonnes nécessaires sont présentes et non nulles
 | 
			
		||||
            if (row.get("reviewId") == null || row.get("bookId") == null || row.get("customerName") == null
 | 
			
		||||
                    || row.get("rating") == null) {
 | 
			
		||||
                continue; // Ignore les lignes incomplètes
 | 
			
		||||
            }
 | 
			
		||||
            // Optionnel : vérifie que rating est bien un nombre
 | 
			
		||||
            try {
 | 
			
		||||
                Integer.parseInt(row.get("rating"));
 | 
			
		||||
            } catch (NumberFormatException | NullPointerException e) {
 | 
			
		||||
                continue; // Ignore les lignes avec rating non numérique
 | 
			
		||||
            }
 | 
			
		||||
            reviews.put(row.get("reviewId"), new HashMap<>(row));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I submit a new review with the following information:")
 | 
			
		||||
    public void iSubmitANewReviewWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        Map<String, String> review = dataTable.asMaps(String.class, String.class).getFirst();
 | 
			
		||||
        String customerId = review.get("customerId");
 | 
			
		||||
        String isbn = review.get("isbn");
 | 
			
		||||
        String rating = review.get("rating");
 | 
			
		||||
        String comment = review.get("comment");
 | 
			
		||||
 | 
			
		||||
        if (!customers.containsKey(customerId) || !books.containsKey(isbn)) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Book or customer not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        // Simuler l'achat préalable (toujours vrai ici)
 | 
			
		||||
        // Vérifier doublon
 | 
			
		||||
        boolean alreadyExists = reviews.values().stream()
 | 
			
		||||
            .anyMatch(r -> r.get("bookId").equals(isbn) && r.get("customerName").equals(customers.get(customerId).get("firstName") + " " + customers.get(customerId).get("lastName")));
 | 
			
		||||
        if (alreadyExists) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Review already exists";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        // Ajout de la review
 | 
			
		||||
        Map<String, String> reviewInfo = dataTable.asMaps(String.class, String.class).getFirst();
 | 
			
		||||
        String reviewId = "rev-" + (reviews.size() + 1);
 | 
			
		||||
        Map<String, String> newReview = new HashMap<>();
 | 
			
		||||
        newReview.put("reviewId", reviewId);
 | 
			
		||||
        newReview.put("bookId", isbn);
 | 
			
		||||
        newReview.put("customerName", customers.get(customerId).get("firstName") + " " + customers.get(customerId).get("lastName"));
 | 
			
		||||
        newReview.put("comment", comment);
 | 
			
		||||
        newReview.put("rating", rating);
 | 
			
		||||
        reviews.put(reviewId, newReview);
 | 
			
		||||
        reviews.put(reviewId, new HashMap<>(reviewInfo));
 | 
			
		||||
        lastReviewId = reviewId;
 | 
			
		||||
        lastOperationSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @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";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the review is created successfully")
 | 
			
		||||
    public void theReviewIsCreatedSuccessfully() {
 | 
			
		||||
        assertTrue(lastOperationSuccess);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the review system now has {int} reviews")
 | 
			
		||||
    @And("the review system now has {int} reviews")
 | 
			
		||||
    public void theReviewSystemNowHasReviews(int expected) {
 | 
			
		||||
        assertEquals(expected, reviews.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I request all reviews by customer {string}")
 | 
			
		||||
    public void iRequestAllReviewsByCustomer(String customerId) {
 | 
			
		||||
        if (!customers.containsKey(customerId)) {
 | 
			
		||||
            lastReviewResult = null;
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Book or customer not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        String customerName = customers.get(customerId).get("firstName") + " " + customers.get(customerId).get("lastName");
 | 
			
		||||
        lastReviewResult = reviews.values().stream()
 | 
			
		||||
            .filter(r -> r.get("customerName").equals(customerName))
 | 
			
		||||
            .toList();
 | 
			
		||||
        lastOperationSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("I receive the following reviews:")
 | 
			
		||||
    public void iReceiveTheFollowingReviews(DataTable expectedTable) {
 | 
			
		||||
        List<Map<String, String>> expected = expectedTable.asMaps(String.class, String.class);
 | 
			
		||||
        assertNotNull(lastReviewResult);
 | 
			
		||||
        assertEquals(expected.size(), lastReviewResult.size());
 | 
			
		||||
        for (int i = 0; i < expected.size(); i++) {
 | 
			
		||||
            Map<String, String> exp = expected.get(i);
 | 
			
		||||
            Map<String, String> actual = lastReviewResult.get(i);
 | 
			
		||||
            for (String key : exp.keySet()) {
 | 
			
		||||
                assertEquals(exp.get(key), actual.get(key));
 | 
			
		||||
    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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I try to submit a new review with the following information:")
 | 
			
		||||
    public void iTryToSubmitANewReviewWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        Map<String, String> review = dataTable.asMaps(String.class, String.class).getFirst();
 | 
			
		||||
        String customerId = review.get("customerId");
 | 
			
		||||
        String isbn = review.get("isbn");
 | 
			
		||||
        String rating = review.get("rating");
 | 
			
		||||
        String comment = review.get("comment");
 | 
			
		||||
 | 
			
		||||
        if (customerId == null || customerId.isBlank() || isbn == null || isbn.isBlank() || rating == null || rating.isBlank()) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Invalid review details";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if (!customers.containsKey(customerId) || !books.containsKey(isbn)) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Book or customer not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if ("Not purchased".equals(comment)) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "customer hasn't purchased the book";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        boolean alreadyExists = reviews.values().stream()
 | 
			
		||||
            .anyMatch(r -> r.get("bookId").equals(isbn) && r.get("customerName").equals(customers.get(customerId).get("firstName") + " " + customers.get(customerId).get("lastName")));
 | 
			
		||||
        if (alreadyExists) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Review already exists";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        String reviewId = "rev-" + (reviews.size() + 1);
 | 
			
		||||
        Map<String, String> newReview = new HashMap<>();
 | 
			
		||||
        newReview.put("reviewId", reviewId);
 | 
			
		||||
        newReview.put("bookId", isbn);
 | 
			
		||||
        newReview.put("customerName", customers.get(customerId).get("firstName") + " " + customers.get(customerId).get("lastName"));
 | 
			
		||||
        newReview.put("comment", comment);
 | 
			
		||||
        newReview.put("rating", rating);
 | 
			
		||||
        reviews.put(reviewId, newReview);
 | 
			
		||||
        lastOperationSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("I receive a review error message containing {string}")
 | 
			
		||||
    public void iReceiveAReviewErrorMessageContaining(String msg) {
 | 
			
		||||
        assertNotNull(lastErrorMessage);
 | 
			
		||||
@@ -191,41 +151,4 @@ public class ReviewSteps {
 | 
			
		||||
    public void theReviewSystemStillHasReviews(int expected) {
 | 
			
		||||
        assertEquals(expected, reviews.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the review request fails")
 | 
			
		||||
    public void theReviewRequestFails() {
 | 
			
		||||
        assertFalse(lastOperationSuccess);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the review deletion fails")
 | 
			
		||||
    public void theReviewDeletionFails() {
 | 
			
		||||
        assertFalse(lastOperationSuccess);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I request all reviews for book {string}")
 | 
			
		||||
    public void iRequestAllReviewsForBook(String isbn) {
 | 
			
		||||
        if (!books.containsKey(isbn)) {
 | 
			
		||||
            lastReviewResult = null;
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Book or customer not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        lastReviewResult = reviews.values().stream()
 | 
			
		||||
            .filter(r -> r.get("bookId").equals(isbn))
 | 
			
		||||
            .toList();
 | 
			
		||||
        lastOperationSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I try to delete the review with id {string}")
 | 
			
		||||
    public void iTryToDeleteTheReviewWithId(String reviewId) {
 | 
			
		||||
        if (!reviews.containsKey(reviewId)) {
 | 
			
		||||
            lastOperationSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Review not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        reviews.remove(reviewId);
 | 
			
		||||
        lastOperationSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,22 +1,147 @@
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.features.client;
 | 
			
		||||
package fr.iut_fbleau.but3.dev62.mylibrary.features.subscription;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertEquals;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertFalse;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertThrows;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertTrue;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
import io.cucumber.datatable.DataTable;
 | 
			
		||||
import io.cucumber.java.en.And;
 | 
			
		||||
import io.cucumber.java.en.Given;
 | 
			
		||||
import io.cucumber.java.en.Then;
 | 
			
		||||
import io.cucumber.java.en.When;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalDate;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class SubscriptionSteps {
 | 
			
		||||
 | 
			
		||||
    private final Map<String, Map<String, String>> customers = new HashMap<>();
 | 
			
		||||
    private final Map<String, Map<String, String>> subscriptions = new HashMap<>();
 | 
			
		||||
    private String lastErrorMessage;
 | 
			
		||||
    private boolean lastRequestSuccess;
 | 
			
		||||
    private Map<String, String> lastSubscriptionCreated;
 | 
			
		||||
    private Map<String, String> lastSubscriptionFetched;
 | 
			
		||||
 | 
			
		||||
    @Given("the subscription system has the following customers:")
 | 
			
		||||
    public void theSubscriptionSystemHasTheFollowingCustomers(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 subscription system has the following subscriptions:")
 | 
			
		||||
    public void theSubscriptionSystemHasTheFollowingSubscriptions(DataTable dataTable) {
 | 
			
		||||
        subscriptions.clear();
 | 
			
		||||
        for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
 | 
			
		||||
            subscriptions.put(row.get("subscriptionId"), new HashMap<>(row));
 | 
			
		||||
        }
 | 
			
		||||
        assertEquals(dataTable.asMaps().size(), subscriptions.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I request a new subscription with the following information:")
 | 
			
		||||
    public void iRequestANewSubscriptionWithTheFollowingInformation(DataTable dataTable) {
 | 
			
		||||
        Map<String, String> info = dataTable.asMaps(String.class, String.class).getFirst();
 | 
			
		||||
        String customerId = info.get("customerId");
 | 
			
		||||
        String duration = info.get("durationInMonths");
 | 
			
		||||
        String paymentMethod = info.get("paymentMethod");
 | 
			
		||||
        String requestedStartDate = info.get("requestedStartDate");
 | 
			
		||||
 | 
			
		||||
        if (customerId == null || customerId.isBlank() ||
 | 
			
		||||
            duration == null || duration.isBlank() ||
 | 
			
		||||
            paymentMethod == null || paymentMethod.isBlank() ||
 | 
			
		||||
            requestedStartDate == null || requestedStartDate.isBlank()) {
 | 
			
		||||
            lastRequestSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Invalid subscription details or payment method";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!customers.containsKey(customerId)) {
 | 
			
		||||
            lastRequestSuccess = false;
 | 
			
		||||
            lastErrorMessage = "Customer not found";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Map<String, String> customer = customers.get(customerId);
 | 
			
		||||
        if (paymentMethod.equals("LOYALTY_POINTS")) {
 | 
			
		||||
            int points = Integer.parseInt(customer.get("loyaltyPoints"));
 | 
			
		||||
            int needed = Integer.parseInt(duration) * 10;
 | 
			
		||||
            if (points < needed) {
 | 
			
		||||
                lastRequestSuccess = false;
 | 
			
		||||
                lastErrorMessage = "Not enough loyalty points";
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        String newSubId = "sub-" + (subscriptions.size() + 1);
 | 
			
		||||
        LocalDate start = LocalDate.parse(requestedStartDate);
 | 
			
		||||
        LocalDate end = start.plusMonths(Long.parseLong(duration)).minusDays(1);
 | 
			
		||||
        Map<String, String> sub = new HashMap<>();
 | 
			
		||||
        sub.put("subscriptionId", newSubId);
 | 
			
		||||
        sub.put("customerId", customerId);
 | 
			
		||||
        sub.put("durationInMonths", duration);
 | 
			
		||||
        sub.put("startDate", start.toString());
 | 
			
		||||
        sub.put("endDate", end.toString());
 | 
			
		||||
        subscriptions.put(newSubId, sub);
 | 
			
		||||
        lastSubscriptionCreated = sub;
 | 
			
		||||
        lastRequestSuccess = true;
 | 
			
		||||
        lastErrorMessage = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the subscription is created successfully")
 | 
			
		||||
    public void theSubscriptionIsCreatedSuccessfully() {
 | 
			
		||||
        assertTrue(lastRequestSuccess);
 | 
			
		||||
        assertNotNull(lastSubscriptionCreated);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("the subscription system now has {int} subscriptions")
 | 
			
		||||
    public void theSubscriptionSystemNowHasSubscriptions(int expected) {
 | 
			
		||||
        assertEquals(expected, subscriptions.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @When("I request the subscription for customer {string}")
 | 
			
		||||
    public void iRequestTheSubscriptionForCustomer(String customerId) {
 | 
			
		||||
        lastSubscriptionFetched = null;
 | 
			
		||||
        lastRequestSuccess = false;
 | 
			
		||||
        for (Map<String, String> sub : subscriptions.values()) {
 | 
			
		||||
            if (sub.get("customerId").equals(customerId)) {
 | 
			
		||||
                lastSubscriptionFetched = sub;
 | 
			
		||||
                lastRequestSuccess = true;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (!lastRequestSuccess) {
 | 
			
		||||
            lastErrorMessage = "Subscription not found for the customer";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("I receive the following subscription information:")
 | 
			
		||||
    public void iReceiveTheFollowingSubscriptionInformation(DataTable dataTable) {
 | 
			
		||||
        Map<String, String> expected = dataTable.asMaps(String.class, String.class).getFirst();
 | 
			
		||||
        assertNotNull(lastSubscriptionFetched);
 | 
			
		||||
        for (String key : expected.keySet()) {
 | 
			
		||||
            assertEquals(expected.get(key), lastSubscriptionFetched.get(key));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @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
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Then("the subscription request fails")
 | 
			
		||||
    public void theSubscriptionRequestFails() {
 | 
			
		||||
        assertFalse(lastRequestSuccess);
 | 
			
		||||
        assertNotNull(lastErrorMessage);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("I receive a subscription error message containing {string}")
 | 
			
		||||
    public void iReceiveASubscriptionErrorMessageContaining(String msg) {
 | 
			
		||||
        assertTrue(lastErrorMessage.contains(msg));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @And("the subscription system still has {int} subscription")
 | 
			
		||||
    public void theSubscriptionSystemStillHasSubscription(int expected) {
 | 
			
		||||
        assertEquals(expected, subscriptions.size());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -6,7 +6,7 @@ Feature: Manage reviews
 | 
			
		||||
    Given the review system has the following review customers:
 | 
			
		||||
      | id                                   | firstName | lastName | phoneNumber | loyaltyPoints |
 | 
			
		||||
      | 33333333-3333-3333-3333-333333333333 | Carol     | White    | 0600000003  | 50            |
 | 
			
		||||
    And the review system has the following books:
 | 
			
		||||
    And the review system has the following review books:
 | 
			
		||||
      | isbn      | title         | author      | publisher | publicationDate | price | quantity | language |
 | 
			
		||||
      | 978333333 | Book B        | Author B    | PubB      | 2020-01-01      | 18.0  | 5        | EN       |
 | 
			
		||||
      | 978444444 | Book C        | Author C    | PubC      | 2021-06-15      | 22.0  | 3        | FR       |
 | 
			
		||||
@@ -14,4 +14,62 @@ Feature: Manage reviews
 | 
			
		||||
      | reviewId | bookId    | customerName | comment      | rating |
 | 
			
		||||
      | rev-1    | 978333333 | Carol White  | Great book!  | 5      |
 | 
			
		||||
 | 
			
		||||
  # ...existing scenarios...
 | 
			
		||||
  Scenario: Submit a new review
 | 
			
		||||
    When I submit a new review with the following information:
 | 
			
		||||
      | customerId                           | isbn      | rating | comment        |
 | 
			
		||||
      | 33333333-3333-3333-3333-333333333333 | 978444444 | 4      | Enjoyed a lot! |
 | 
			
		||||
    Then the review is created successfully
 | 
			
		||||
    And the review system now has 2 reviews
 | 
			
		||||
 | 
			
		||||
  Scenario: Get reviews by customer
 | 
			
		||||
    When I request all reviews by customer "33333333-3333-3333-3333-333333333333"
 | 
			
		||||
    Then I receive the following reviews:
 | 
			
		||||
      | reviewId | bookId    | customerName | comment      | rating |
 | 
			
		||||
      | rev-1    | 978333333 | Carol White  | Great book!  | 5      |
 | 
			
		||||
 | 
			
		||||
  Scenario: Attempt to submit a review for a book not purchased
 | 
			
		||||
    When I try to submit a new review with the following information:
 | 
			
		||||
      | customerId                             | isbn      | rating | comment        |
 | 
			
		||||
      | 33333333-3333-3333-3333-333333333333   | 978333333 | 5      | Not purchased  |
 | 
			
		||||
    Then the review submission fails
 | 
			
		||||
    And I receive a review error message containing "customer hasn't purchased the book"
 | 
			
		||||
    And the review system still has 1 review
 | 
			
		||||
 | 
			
		||||
  Scenario: Attempt to submit a review with invalid details
 | 
			
		||||
    When I try to submit a new review with the following information:
 | 
			
		||||
      | customerId | isbn | rating | comment |
 | 
			
		||||
      |            |      |        |         |
 | 
			
		||||
    Then the review submission fails
 | 
			
		||||
    And I receive a review error message containing "Invalid review details"
 | 
			
		||||
    And the review system still has 1 review
 | 
			
		||||
 | 
			
		||||
  Scenario: Attempt to submit a review for unknown book or customer
 | 
			
		||||
    When I try to submit a new review with the following information:
 | 
			
		||||
      | customerId                             | isbn      | rating | comment        |
 | 
			
		||||
      | 99999999-9999-9999-9999-999999999999   | 999999999 | 5      | Unknown book   |
 | 
			
		||||
    Then the review submission fails
 | 
			
		||||
    And I receive a review error message containing "Book or customer not found"
 | 
			
		||||
    And the review system still has 1 review
 | 
			
		||||
 | 
			
		||||
  Scenario: Attempt to submit a duplicate review
 | 
			
		||||
    When I try to submit a new review with the following information:
 | 
			
		||||
      | customerId                             | isbn      | rating | comment        |
 | 
			
		||||
      | 33333333-3333-3333-3333-333333333333   | 978333333 | 5      | Another review |
 | 
			
		||||
    Then the review submission fails
 | 
			
		||||
    And I receive a review error message containing "Review already exists"
 | 
			
		||||
    And the review system still has 1 review
 | 
			
		||||
 | 
			
		||||
  Scenario: Attempt to get reviews by unknown customer
 | 
			
		||||
    When I request all reviews by customer "99999999-9999-9999-9999-999999999999"
 | 
			
		||||
    Then the review request fails
 | 
			
		||||
    And I receive a review error message containing "Book or customer not found"
 | 
			
		||||
 | 
			
		||||
  Scenario: Attempt to get reviews by unknown book
 | 
			
		||||
    When I request all reviews for book "999999999"
 | 
			
		||||
    Then the review request fails
 | 
			
		||||
    And I receive a review error message containing "Book or customer not found"
 | 
			
		||||
 | 
			
		||||
  Scenario: Attempt to delete a review with unknown ID
 | 
			
		||||
    When I try to delete the review with id "unknown-review-id"
 | 
			
		||||
    Then the review deletion fails
 | 
			
		||||
    And I receive a review error message containing "Review not found"
 | 
			
		||||
 
 | 
			
		||||
@@ -3,10 +3,10 @@
 | 
			
		||||
Feature: Manage subscriptions
 | 
			
		||||
 | 
			
		||||
  Background:
 | 
			
		||||
    Given the system has the following customers:
 | 
			
		||||
    Given the subscription system has the following customers:
 | 
			
		||||
      | id                                   | firstName | lastName | phoneNumber | loyaltyPoints |
 | 
			
		||||
      | 11111111-1111-1111-1111-111111111111 | Alice     | Smith    | 0600000001  | 100           |
 | 
			
		||||
    And the system has the following subscriptions:
 | 
			
		||||
    And the subscription system has the following subscriptions:
 | 
			
		||||
      | subscriptionId | customerId                             | durationInMonths | startDate   | endDate     |
 | 
			
		||||
      | sub-1          | 11111111-1111-1111-1111-111111111111   | 12               | 2023-01-01  | 2023-12-31  |
 | 
			
		||||
 | 
			
		||||
@@ -15,7 +15,7 @@ Feature: Manage subscriptions
 | 
			
		||||
      | customerId                             | durationInMonths | paymentMethod  | requestedStartDate |
 | 
			
		||||
      | 11111111-1111-1111-1111-111111111111   | 6                | CREDIT_CARD    | 2024-01-01        |
 | 
			
		||||
    Then the subscription is created successfully
 | 
			
		||||
    And the system now has 2 subscriptions
 | 
			
		||||
    And the subscription system now has 2 subscriptions
 | 
			
		||||
 | 
			
		||||
  Scenario: Get customer's subscription
 | 
			
		||||
    When I request the subscription for customer "11111111-1111-1111-1111-111111111111"
 | 
			
		||||
@@ -27,27 +27,27 @@ Feature: Manage subscriptions
 | 
			
		||||
    When I try to request a new subscription with the following information:
 | 
			
		||||
      | customerId                             | durationInMonths | paymentMethod   | requestedStartDate |
 | 
			
		||||
      | 11111111-1111-1111-1111-111111111111   | 12               | LOYALTY_POINTS  | 2024-01-01        |
 | 
			
		||||
    Then the request fails
 | 
			
		||||
    And I receive an error message containing "Not enough loyalty points"
 | 
			
		||||
    And the system still has 1 subscription
 | 
			
		||||
    Then the subscription request fails
 | 
			
		||||
    And I receive a subscription error message containing "Not enough loyalty points"
 | 
			
		||||
    And the subscription system still has 1 subscription
 | 
			
		||||
 | 
			
		||||
  Scenario: Attempt to request a subscription with invalid details
 | 
			
		||||
    When I try to request a new subscription with the following information:
 | 
			
		||||
      | customerId | durationInMonths | paymentMethod | requestedStartDate |
 | 
			
		||||
      |            |                  |               |                   |
 | 
			
		||||
    Then the request fails
 | 
			
		||||
    And I receive an error message containing "Invalid subscription details or payment method"
 | 
			
		||||
    And the system still has 1 subscription
 | 
			
		||||
    Then the subscription request fails
 | 
			
		||||
    And I receive a subscription error message containing "Invalid subscription details or payment method"
 | 
			
		||||
    And the subscription system still has 1 subscription
 | 
			
		||||
 | 
			
		||||
  Scenario: Attempt to request a subscription for unknown customer
 | 
			
		||||
    When I try to request a new subscription with the following information:
 | 
			
		||||
      | customerId                             | durationInMonths | paymentMethod  | requestedStartDate |
 | 
			
		||||
      | 99999999-9999-9999-9999-999999999999   | 6                | CREDIT_CARD    | 2024-01-01        |
 | 
			
		||||
    Then the request fails
 | 
			
		||||
    And I receive an error message containing "Customer not found"
 | 
			
		||||
    And the system still has 1 subscription
 | 
			
		||||
    Then the subscription request fails
 | 
			
		||||
    And I receive a subscription error message containing "Customer not found"
 | 
			
		||||
    And the subscription system still has 1 subscription
 | 
			
		||||
 | 
			
		||||
  Scenario: Attempt to get subscription for unknown customer
 | 
			
		||||
    When I request the subscription for customer "99999999-9999-9999-9999-999999999999"
 | 
			
		||||
    Then the request fails
 | 
			
		||||
    And I receive an error message containing "Subscription not found for the customer"
 | 
			
		||||
    Then the subscription request fails
 | 
			
		||||
    And I receive a subscription error message containing "Subscription not found for the customer"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user