Compare commits

...

31 Commits

Author SHA1 Message Date
Kroccmou
2d2bdfbcd6 Update SubscriptionFunctionTest.java 2025-06-14 01:56:15 +02:00
Kroccmou
c3140715e4 Update SubscriptionErrorTest.java 2025-06-14 01:56:11 +02:00
6820863c8e Merge branch 'main' of grond.iut-fbleau.fr:daniel/mylibrary 2025-06-14 01:50:46 +02:00
d8f63d1bdd subscription step 2025-06-14 01:49:19 +02:00
Kroccmou
9df099691e Tout review test et code 2025-06-14 01:06:30 +02:00
Kroccmou
554f6f1661 Update OrderSteps.java 2025-06-14 00:21:43 +02:00
Kroccmou
696b1566f6 Update ReviewSteps.java 2025-06-14 00:21:40 +02:00
Kroccmou
0df33e9e32 Update review.feature 2025-06-14 00:21:38 +02:00
Kroccmou
d07de49cc9 Update OrderSteps.java 2025-06-14 00:08:47 +02:00
Kroccmou
af8d086d01 Rename test book 2025-06-14 00:03:27 +02:00
7af68e52e1 Merge branch 'main' of grond.iut-fbleau.fr:daniel/mylibrary 2025-06-13 23:57:14 +02:00
9dd1336ff4 book end 2025-06-13 23:52:34 +02:00
Kroccmou
425c05fd23 Update OrderSteps.java 2025-06-13 23:50:26 +02:00
Kroccmou
11a123a2ed Update order.feature 2025-06-13 23:50:21 +02:00
Kroccmou
6218b38817 correction subscriptions feature et steps 2025-06-13 23:44:46 +02:00
Kroccmou
be51f5288f Correction review feature et step 2025-06-13 23:44:08 +02:00
Kroccmou
b8091da304 Delete misc.xml 2025-06-13 23:01:50 +02:00
Kroccmou
52994a20a3 Update .gitignore 2025-06-13 23:01:04 +02:00
Kroccmou
c20be4d5f6 renommage review 2025-06-13 22:59:51 +02:00
459d03b36b book Exeception 2025-06-13 22:10:29 +02:00
d18a9074a3 book respect convention de nomage 2025-06-13 21:40:22 +02:00
cdf4c046bc book end 2025-06-13 21:12:24 +02:00
cc4dfa140a step book end 2025-06-12 23:45:47 +02:00
Kroccmou
1b70a8d123 Merge branch 'main' of https://grond.iut-fbleau.fr/daniel/mylibrary 2025-06-12 22:44:38 +02:00
Kroccmou
bf0f309963 Review step et feature 2025-06-12 22:44:25 +02:00
a27dba9ad2 step book 2025-06-12 22:01:51 +02:00
76f2145629 start step 2025-06-12 21:08:35 +02:00
91b3cfe76a start step 2025-06-12 20:50:23 +02:00
Kroccmou
c7230c889e Fichier feature 2025-06-12 20:02:10 +02:00
0b1d59390f feature suite 2025-06-12 12:59:07 +02:00
80d857747c first feature 2025-06-10 21:15:14 +02:00
47 changed files with 2255 additions and 1 deletions

3
.gitignore vendored
View File

@@ -8,6 +8,7 @@ target/
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea/misc.xml
*.iws
*.iml
*.ipr
@@ -35,4 +36,4 @@ build/
.vscode/
### Mac OS ###
.DS_Store
.DS_Store

5
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Environment-dependent path to Maven home directory
/mavenHomeManager.xml

7
.idea/encodings.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

12
.idea/misc.xml generated Normal file
View 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>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -0,0 +1,50 @@
package fr.iut_fbleau.but3.dev62.mylibrary.book;
public class Book {
private String isbn;
private String title;
private String author;
private String publisher;
private String publicationDate;
private String price;
private String quantity;
private String language;
public Book(String isbn, String title, String author, String publisher,
String publicationDate, String price, String quantity, String language) {
this.isbn = isbn;
this.title = title;
this.author = author;
this.publisher = publisher;
this.publicationDate = publicationDate;
this.price = price;
this.quantity = quantity;
this.language = language;
}
public String getIsbn() {
return isbn;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public String getPublisher() {
return publisher;
}
public String getPublicationDate() {
return publicationDate;
}
public String getPrice() {
return price;
}
public String getQuantity() {
return quantity;
}
public String getLanguage() {
return language;
}
}

View File

@@ -0,0 +1,57 @@
package fr.iut_fbleau.but3.dev62.mylibrary.book;
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.*;
import java.util.*;
public class BookManagement {
private final Map<String, Book> books = new LinkedHashMap<>();
public boolean registerBook(Book book) throws InvalidBookDataException, DuplicateBookException {
if (!isValid(book)) {
throw new InvalidBookDataException("Invalid book data provided");
}
if (books.containsKey(book.getIsbn())) {
throw new DuplicateBookException("Conflict with existing book in database");
}
books.put(book.getIsbn(), book);
return true;
}
public List<Book> getAllBooks() {
return new ArrayList<>(books.values());
}
public Book getBookByIsbn(String isbn) throws BookNotFoundException {
if (!books.containsKey(isbn)) {
throw new BookNotFoundException("Book not found");
}
return books.get(isbn);
}
public List<Book> getBooksByTitle(String title) {
return books.values().stream()
.filter(book -> book.getTitle().equalsIgnoreCase(title))
.toList();
}
public int getBookCount() {
return books.size();
}
private boolean isValid(Book book) {
return book != null &&
notEmpty(book.getIsbn()) &&
notEmpty(book.getTitle()) &&
notEmpty(book.getAuthor()) &&
notEmpty(book.getPublisher()) &&
notEmpty(book.getPublicationDate()) &&
notEmpty(book.getPrice()) &&
notEmpty(book.getQuantity()) &&
notEmpty(book.getLanguage());
}
private boolean notEmpty(String value) {
return value != null && !value.isBlank();
}
}

View File

@@ -0,0 +1,7 @@
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
public class BookNotFoundException extends Exception {
public BookNotFoundException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,7 @@
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
public class DuplicateBookException extends Exception {
public DuplicateBookException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,7 @@
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
public class InvalidBookDataException extends Exception {
public InvalidBookDataException(String message) {
super(message);
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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)));
}
}

View File

@@ -0,0 +1,8 @@
package fr.iut_fbleau.but3.dev62.mylibrary.review.exception;
public class InvalidReviewException extends RuntimeException {
public InvalidReviewException(String message) {
super(message);
}
}

View File

@@ -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)));
}
}

View File

@@ -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));
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}
}

View File

@@ -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());
}
}

View File

@@ -0,0 +1,161 @@
package fr.iut_fbleau.but3.dev62.mylibrary.features.book;
import fr.iut_fbleau.but3.dev62.mylibrary.book.*;
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.*;
import static org.junit.jupiter.api.Assertions.*;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.en.*;
import java.util.*;
public class BookSteps {
private final BookManagement bookManagement = new BookManagement();
private List<Book> lastBookResult;
private Book lastSingleBookResult;
private String lastErrorMessage;
private boolean lastOperationSuccess;
// ----------------------------Background--------------------------------
@Given("the system has the following books:")
public void theSystemHasTheFollowingBooks(DataTable dataTable) {
for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
try {
Book book = 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")
);
bookManagement.registerBook(book);
} catch (Exception ignored) {}
}
}
// ----------------------------Scénario 1 et 4 (succès ou échec)---------------------------------
@When("I register a new book with the following information:")
@When("I try to register a new book with the following information:")
public void iRegisterANewBookWithTheFollowingInformation(DataTable dataTable) {
Map<String, String> row = dataTable.asMaps(String.class, String.class).get(0);
try {
Book book = 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")
);
bookManagement.registerBook(book);
lastOperationSuccess = true;
lastErrorMessage = null;
} catch (InvalidBookDataException | DuplicateBookException e) {
lastOperationSuccess = false;
lastErrorMessage = e.getMessage();
}
}
@Then("the book is successfully registered")
public void theBookIsSuccessfullyRegistered() {
assertTrue(lastOperationSuccess);
}
@Then("the registration fails")
public void theRegistrationFails() {
assertFalse(lastOperationSuccess);
}
@And("I receive an error message containing {string}")
public void iReceiveAnErrorMessageContaining(String msg) {
assertNotNull(lastErrorMessage);
assertTrue(lastErrorMessage.contains(msg));
}
@And("the system now has {int} books")
@And("the system still has {int} books")
public void theSystemHasBooks(int expectedCount) {
assertEquals(expectedCount, bookManagement.getBookCount());
}
// ----------------------------Scénario 2---------------------------------
@When("I request all books")
public void iRequestAllBooks() {
lastBookResult = bookManagement.getAllBooks();
lastOperationSuccess = true;
lastErrorMessage = null;
}
@Then("I receive the following books:")
public void iReceiveTheFollowingBooks(DataTable expectedTable) {
List<Map<String, String>> expected = expectedTable.asMaps(String.class, String.class);
assertNotNull(lastBookResult);
assertEquals(expected.size(), lastBookResult.size());
for (int i = 0; i < expected.size(); i++) {
Book actual = lastBookResult.get(i);
Map<String, String> expectedBook = expected.get(i);
assertEquals(expectedBook.get("isbn"), actual.getIsbn());
assertEquals(expectedBook.get("title"), actual.getTitle());
assertEquals(expectedBook.get("author"), actual.getAuthor());
assertEquals(expectedBook.get("publisher"), actual.getPublisher());
assertEquals(expectedBook.get("publicationDate"), actual.getPublicationDate());
assertEquals(expectedBook.get("price"), actual.getPrice());
assertEquals(expectedBook.get("quantity"), actual.getQuantity());
assertEquals(expectedBook.get("language"), actual.getLanguage());
}
}
// ----------------------------Scénario 3---------------------------------
@When("I request the book with id {string}")
public void iRequestTheBookWithId(String isbn) {
try {
lastSingleBookResult = bookManagement.getBookByIsbn(isbn);
lastOperationSuccess = true;
lastErrorMessage = null;
} catch (BookNotFoundException e) {
lastOperationSuccess = false;
lastErrorMessage = e.getMessage();
}
}
@Then("I receive the following book information:")
public void iReceiveTheFollowingBookInformation(DataTable expectedTable) {
Map<String, String> expectedBook = expectedTable.asMaps(String.class, String.class).get(0);
assertNotNull(lastSingleBookResult);
assertEquals(expectedBook.get("isbn"), lastSingleBookResult.getIsbn());
assertEquals(expectedBook.get("title"), lastSingleBookResult.getTitle());
assertEquals(expectedBook.get("author"), lastSingleBookResult.getAuthor());
assertEquals(expectedBook.get("publisher"), lastSingleBookResult.getPublisher());
assertEquals(expectedBook.get("publicationDate"), lastSingleBookResult.getPublicationDate());
assertEquals(expectedBook.get("price"), lastSingleBookResult.getPrice());
assertEquals(expectedBook.get("quantity"), lastSingleBookResult.getQuantity());
assertEquals(expectedBook.get("language"), lastSingleBookResult.getLanguage());
}
// ----------------------------Scénario 6---------------------------------
@When("I request all books with title {string}")
public void iRequestAllBooksWithTitle(String titleFilter) {
lastBookResult = bookManagement.getBooksByTitle(titleFilter);
lastOperationSuccess = true;
lastErrorMessage = null;
}
@Then("I receive an empty list of books")
public void iReceiveAnEmptyListOfBooks() {
assertNotNull(lastBookResult);
assertTrue(lastBookResult.isEmpty());
}
@When("the request fails")
public void theRequestFails() {
assertFalse(lastOperationSuccess);
}
}

View File

@@ -14,6 +14,8 @@ import fr.iut_fbleau.but3.dev62.mylibrary.customer.exception.IllegalCustomerPoin
import fr.iut_fbleau.but3.dev62.mylibrary.customer.exception.NotValidCustomerException;
import fr.iut_fbleau.but3.dev62.mylibrary.customer.repository.CustomerRepository;
import fr.iut_fbleau.but3.dev62.mylibrary.customer.usecase.CustomerUseCase;
import io.cucumber.datatable.DataTable;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;

View File

@@ -0,0 +1,177 @@
package fr.iut_fbleau.but3.dev62.mylibrary.features.order;
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.*;
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);
}
}

View File

@@ -0,0 +1,222 @@
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.And;
import io.cucumber.java.en.Given;
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>> 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 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) {
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 review system has the following review books:")
public void theReviewSystemHasTheFollowingReviewBooks(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 review system has the following reviews:")
public void theReviewSystemHasTheFollowingReviews(DataTable dataTable) {
reviews.clear();
for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
// 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> 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");
if (customerId == null || customerId.isBlank() ||
isbnStr == null || isbnStr.isBlank() ||
rating == null || rating.isBlank()) {
lastReviewSuccess = false;
lastReviewError = "Invalid review details";
return;
}
if (!customers.containsKey(customerId) || !books.containsKey(Long.parseLong(isbnStr))) {
lastReviewSuccess = false;
lastReviewError = "Book or customer not found";
return;
}
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(lastReviewSuccess);
assertNotNull(lastReviewId);
}
@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) {
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);
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(lastReviewSuccess);
assertNotNull(lastReviewError);
}
@And("I receive a review error message containing {string}")
public void iReceiveAReviewErrorMessageContaining(String msg) {
assertNotNull(lastReviewError);
assertTrue(lastReviewError.contains(msg), "Expected error message to contain: \"" + msg + "\" but was: \"" + lastReviewError + "\"");
}
@And("the review system still has {int} review")
public void theReviewSystemStillHasReview(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);
}
}

View File

@@ -0,0 +1,147 @@
package fr.iut_fbleau.but3.dev62.mylibrary.features.subscription;
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.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;
}
@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());
}
}

View File

@@ -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));
}
}

View File

@@ -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);
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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"));
}
}

View File

@@ -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"));
}
}

View File

@@ -0,0 +1,26 @@
package fr.iut_fbleau.but3.dev62.mylibrary.review.validator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class ReviewValidatorTest {
@Test
void testIsValidUUID() {
assertTrue(ReviewValidator.isValidUUID("11111111-1111-1111-1111-111111111111"));
assertFalse(ReviewValidator.isValidUUID("not-a-uuid"));
assertFalse(ReviewValidator.isValidUUID(""));
assertFalse(ReviewValidator.isValidUUID(null));
}
@Test
void testIsValidReviewDetails() {
assertTrue(ReviewValidator.isValidReviewDetails("id", "isbn", "5"));
assertFalse(ReviewValidator.isValidReviewDetails("", "isbn", "5"));
assertFalse(ReviewValidator.isValidReviewDetails("id", "", "5"));
assertFalse(ReviewValidator.isValidReviewDetails("id", "isbn", ""));
assertFalse(ReviewValidator.isValidReviewDetails(null, "isbn", "5"));
assertFalse(ReviewValidator.isValidReviewDetails("id", null, "5"));
assertFalse(ReviewValidator.isValidReviewDetails("id", "isbn", null));
}
}

View File

@@ -0,0 +1,19 @@
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.error;
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.function.SubscriptionFunctionTest;
import static org.junit.jupiter.api.Assertions.*;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Then;
public class SubscriptionErrorTest extends SubscriptionFunctionTest {
@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));
}
}

View File

@@ -0,0 +1,111 @@
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.function;
import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDate;
import java.util.*;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.en.And;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Given;
public class SubscriptionFunctionTest {
private final Map<String, Map<String, String>> subscriptions = new HashMap<>();
private final Map<String, Map<String, String>> customers = new HashMap<>();
protected boolean lastRequestSuccess;
protected String lastErrorMessage;
protected Map<String, String> lastSubscriptionCreated;
protected 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().getFirst();
String customerId = info.get("customerId");
String duration = info.get("durationInMonths");
String paymentMethod = info.get("paymentMethod");
String requestedStartDate = info.get("requestedStartDate");
// (logique copiée, à remplacer ensuite par SubscriptionManagement)
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;
}
@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";
}
}
@When("I try to request a new subscription with the following information:")
public void iTryToRequestANewSubscriptionWithTheFollowingInformation(DataTable dataTable) {
iRequestANewSubscriptionWithTheFollowingInformation(dataTable);
lastRequestSuccess = false;
}
}

View File

@@ -0,0 +1,32 @@
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.result;
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.function.SubscriptionFunctionTest;
import static org.junit.jupiter.api.Assertions.*;
import io.cucumber.cienvironment.internal.com.eclipsesource.json.JsonArray;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Then;
import java.util.*;
public class SubscriptionResultTest extends SubscriptionFunctionTest {
private final Map<String, Map<String, String>> subscriptions = new HashMap<>();
@And("the subscription system still has {int} subscription")
public void theSubscriptionSystemStillHasSubscription(int expected) {
assertEquals(expected, subscriptions.size());
}
@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));
}
}
@And("the subscription system now has {int} subscriptions")
public void theSubscriptionSystemNowHasSubscriptions(int expected) {
assertEquals(expected, subscriptions.size());
}
}

View File

@@ -0,0 +1,63 @@
# language: en
Feature: Manage books
# ----------------------------Background---------------------------------
Background:
Given the system has the following books:
| isbn | title | author | publisher | publicationDate | price | quantity | language |
| 978123456 | The Odyssey | Homer | Penguin | 2000-01-01 | 10.0 | 5 | EN |
| 978654321 | War and Peace | Leo Tolstoy | Vintage | 2005-05-10 | 15.0 | 2 | EN |
# ----------------------------Scénario 1---------------------------------
Scenario: Register a new book
When I register a new book with the following information:
| isbn | title | author | publisher | publicationDate | price | quantity | language |
| 978111111 | New Book | New Author | NewPub | 2022-10-10 | 20.0 | 10 | EN |
Then the book is successfully registered
And the system now has 3 books
# ----------------------------Scénario 2---------------------------------
Scenario: Get all books
When I request all books
Then I receive the following books:
| isbn | title | author | publisher | publicationDate | price | quantity | language |
| 978123456 | The Odyssey | Homer | Penguin | 2000-01-01 | 10.0 | 5 | EN |
| 978654321 | War and Peace | Leo Tolstoy | Vintage | 2005-05-10 | 15.0 | 2 | EN |
# ----------------------------Scénario 3---------------------------------
Scenario: Get a book by ID
When I request the book with id "978123456"
Then I receive the following book information:
| isbn | title | author | publisher | publicationDate | price | quantity | language |
| 978123456 | The Odyssey | Homer | Penguin | 2000-01-01 | 10.0 | 5 | EN |
# ----------------------------Scénario 4---------------------------------
Scenario: Attempt to register a book with invalid data
When I try to register a new book with the following information:
| isbn | title | author | publisher | publicationDate | price | quantity | language |
| | | | | | | | |
Then the registration fails
And I receive an error message containing "Invalid book data provided"
And the system still has 2 books
# ----------------------------Scénario 5---------------------------------
Scenario: Attempt to register a book with an existing ISBN
When I try to register a new book with the following information:
| isbn | title | author | publisher | publicationDate | price | quantity | language |
| 978123456 | The Odyssey | Homer | Penguin | 2000-01-01 | 10.0 | 5 | EN |
Then the registration fails
And I receive an error message containing "Conflict with existing book in database"
And the system still has 2 books
# ----------------------------Scénario 6---------------------------------
Scenario: Attempt to get a book with unknown ID
When I request the book with id "999999999"
Then the request fails
And I receive an error message containing "Book not found"
# ----------------------------Scénario 7---------------------------------
Scenario: Attempt to get all books with a filter that matches nothing
When I request all books with title "Nonexistent Book"
Then I receive an empty list of books

View File

@@ -0,0 +1,56 @@
# language: en
Feature: Manage orders
Background:
Given the order system has the following customers:
| id | firstName | lastName | phoneNumber | loyaltyPoints |
| 22222222-2222-2222-2222-222222222222 | Bob | Brown | 0600000002 | 200 |
And the order system has the following books:
| isbn | title | author | publisher | publicationDate | price | quantity | language |
| 978222222 | Book A | Author A | PubA | 2021-01-01 | 12.0 | 10 | EN |
And the order system has the following orders:
| id | customerId | totalPrice | paymentMethod |
| ord-1 | 22222222-2222-2222-2222-222222222222 | 24.0 | CREDIT_CARD |
Scenario: Create a new order
When I create a new order with the following information:
| customerId | paymentMethod | orderLineDtos | addressStreet | addressCity | addressPostalCode | addressCountry |
| 22222222-2222-2222-2222-222222222222 | CREDIT_CARD | [{ "bookId":978222222, "quantity":2 }] | 1 Main St | Paris | 75000 | France |
Then the order is created successfully
And the order system now has 2 orders
Scenario: Get order by ID
When I request the order with id "ord-1"
Then I receive the following order information:
| id | customerId | totalPrice | paymentMethod |
| ord-1 | 22222222-2222-2222-2222-222222222222 | 24.0 | CREDIT_CARD |
Scenario: Attempt to create an order with insufficient book quantity
When I try to create a new order with the following information:
| customerId | paymentMethod | orderLineDtos | addressStreet | addressCity | addressPostalCode | addressCountry |
| 22222222-2222-2222-2222-222222222222 | CREDIT_CARD | [{ "bookId":978222222, "quantity":20 }] | 1 Main St | Paris | 75000 | France |
Then the order creation fails
And I receive an order error message containing "book quantity insufficient"
And the order system still has 1 order
Scenario: Attempt to create an order with invalid details
When I try to create a new order with the following information:
| customerId | paymentMethod | orderLineDtos | addressStreet | addressCity | addressPostalCode | addressCountry |
| | | | | | | |
Then the order creation fails
And I receive an order error message containing "Invalid order details or address"
And the order system still has 1 order
Scenario: Attempt to create an order for unknown customer
When I try to create a new order with the following information:
| customerId | paymentMethod | orderLineDtos | addressStreet | addressCity | addressPostalCode | addressCountry |
| 99999999-9999-9999-9999-999999999999 | CREDIT_CARD | [{ "bookId":978222222, "quantity":2 }] | 1 Main St | Paris | 75000 | France |
Then the order creation fails
And I receive an order error message containing "Customer not found"
And the order system still has 1 order
Scenario: Attempt to get order by unknown ID
When I request the order with id "unknown-order-id"
Then the order request fails
And I receive an order error message containing "Order not found"

View File

@@ -0,0 +1,80 @@
# language: en
Feature: Manage reviews
Background:
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 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 |
| 978555555 | Book D | Author D | PubD | 2022-03-10 | 25.0 | 2 | DE |
And the review system has the following reviews:
| reviewId | bookId | customerName | comment | rating |
| 11111111-1111-1111-1111-111111111111 | 978333333 | Carol White | Great book! | 5 |
And the review system has the following purchases:
| customerId | bookId | purchaseDate |
| 33333333-3333-3333-3333-333333333333 | 978333333 | 2021-01-01 |
| 33333333-3333-3333-3333-333333333333 | 978444444 | 2021-06-15 |
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 |
| 11111111-1111-1111-1111-111111111111 | 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 | 978555555 | 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 "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
Then the review deletion fails
And I receive a review error message containing "Review not found"

View File

@@ -0,0 +1,53 @@
# language: en
Feature: Manage subscriptions
Background:
Given the subscription system has the following customers:
| id | firstName | lastName | phoneNumber | loyaltyPoints |
| 11111111-1111-1111-1111-111111111111 | Alice | Smith | 0600000001 | 100 |
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 |
Scenario: Request a new subscription
When I request a new subscription with the following information:
| customerId | durationInMonths | paymentMethod | requestedStartDate |
| 11111111-1111-1111-1111-111111111111 | 6 | CREDIT_CARD | 2024-01-01 |
Then the subscription is created successfully
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"
Then I receive the following subscription information:
| subscriptionId | customerId | durationInMonths | startDate | endDate |
| sub-1 | 11111111-1111-1111-1111-111111111111 | 12 | 2023-01-01 | 2023-12-31 |
Scenario: Attempt to request a subscription with not enough loyalty points
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 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 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 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 subscription request fails
And I receive a subscription error message containing "Subscription not found for the customer"