From c20be4d5f65a09c0ce7124bba3447634598df742 Mon Sep 17 00:00:00 2001 From: Kroccmou <161739353+Kroccmou@users.noreply.github.com> Date: Fri, 13 Jun 2025 22:59:51 +0200 Subject: [PATCH] renommage review --- .../features/review/ReviewSteps.java | 63 ++++++++++-------- src/test/resources/features/review.feature | 66 ++----------------- 2 files changed, 41 insertions(+), 88 deletions(-) diff --git a/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/features/review/ReviewSteps.java b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/features/review/ReviewSteps.java index 9706d06..3b0f9c5 100644 --- a/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/features/review/ReviewSteps.java +++ b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/features/review/ReviewSteps.java @@ -19,33 +19,44 @@ public class ReviewSteps { private String lastErrorMessage; private boolean lastOperationSuccess; - @Given("the system has the following customers:") - public void theSystemHasTheFollowingCustomers(DataTable dataTable) { + @Given("the review system has the following review customers:") + public void theReviewSystemHasTheFollowingReviewCustomers(DataTable dataTable) { customers.clear(); for (Map row : dataTable.asMaps(String.class, String.class)) { customers.put(row.get("id"), row); } } - @Given("the system has the following books:") - public void theSystemHasTheFollowingBooks(DataTable dataTable) { + @Given("the review system has the following books:") + public void theReviewSystemHasTheFollowingBooks(DataTable dataTable) { books.clear(); for (Map row : dataTable.asMaps(String.class, String.class)) { books.put(row.get("isbn"), row); } } - @Given("the system has the following reviews:") - public void theSystemHasTheFollowingReviews(DataTable dataTable) { + @Given("the review system has the following reviews:") + public void theReviewSystemHasTheFollowingReviews(DataTable dataTable) { reviews.clear(); for (Map 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 review = dataTable.asMaps(String.class, String.class).get(0); + Map review = dataTable.asMaps(String.class, String.class).getFirst(); String customerId = review.get("customerId"); String isbn = review.get("isbn"); String rating = review.get("rating"); @@ -83,8 +94,8 @@ public class ReviewSteps { assertTrue(lastOperationSuccess); } - @And("the system now has {int} reviews") - public void theSystemNowHasReviews(int expected) { + @Then("the review system now has {int} reviews") + public void theReviewSystemNowHasReviews(int expected) { assertEquals(expected, reviews.size()); } @@ -120,7 +131,7 @@ public class ReviewSteps { @When("I try to submit a new review with the following information:") public void iTryToSubmitANewReviewWithTheFollowingInformation(DataTable dataTable) { - Map review = dataTable.asMaps(String.class, String.class).get(0); + Map review = dataTable.asMaps(String.class, String.class).getFirst(); String customerId = review.get("customerId"); String isbn = review.get("isbn"); String rating = review.get("rating"); @@ -160,29 +171,34 @@ public class ReviewSteps { lastErrorMessage = null; } - @Then("the submission fails") - public void theSubmissionFails() { + @Then("the review submission fails") + public void theReviewSubmissionFails() { assertFalse(lastOperationSuccess); } - @And("I receive an error message containing {string}") - public void iReceiveAnErrorMessageContaining(String msg) { + @And("I receive a review error message containing {string}") + public void iReceiveAReviewErrorMessageContaining(String msg) { assertNotNull(lastErrorMessage); assertTrue(lastErrorMessage.contains(msg)); } - @And("the system still has {int} review") - public void theSystemStillHasReview(int expected) { + @And("the review system still has {int} review") + public void theReviewSystemStillHasReview(int expected) { assertEquals(expected, reviews.size()); } - @And("the system still has {int} reviews") - public void theSystemStillHasReviewsPlural(int expected) { + @And("the review system still has {int} reviews") + public void theReviewSystemStillHasReviews(int expected) { assertEquals(expected, reviews.size()); } - @Then("the request fails") - public void theRequestFails() { + @Then("the review request fails") + public void theReviewRequestFails() { + assertFalse(lastOperationSuccess); + } + + @Then("the review deletion fails") + public void theReviewDeletionFails() { assertFalse(lastOperationSuccess); } @@ -212,9 +228,4 @@ public class ReviewSteps { lastOperationSuccess = true; lastErrorMessage = null; } - - @Then("the deletion fails") - public void theDeletionFails() { - assertFalse(lastOperationSuccess); - } -} +} \ No newline at end of file diff --git a/src/test/resources/features/review.feature b/src/test/resources/features/review.feature index 5a17c4d..1ee5463 100644 --- a/src/test/resources/features/review.feature +++ b/src/test/resources/features/review.feature @@ -3,73 +3,15 @@ Feature: Manage reviews Background: - Given the system has the following customers: + 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 system has the following books: + And the review system has the following 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 | - And the system has the following reviews: + And the review system has the following reviews: | reviewId | bookId | customerName | comment | rating | | rev-1 | 978333333 | Carol White | Great book! | 5 | - 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 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 submission fails - And I receive an error message containing "customer hasn't purchased the book" - And the 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 submission fails - And I receive an error message containing "Invalid review details" - And the 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 submission fails - And I receive an error message containing "Book or customer not found" - And the 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 submission fails - And I receive an error message containing "Review already exists" - And the 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 request fails - And I receive an 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 request fails - And I receive an 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 deletion fails - And I receive an error message containing "Review not found" \ No newline at end of file + # ...existing scenarios...