Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 092a020059 | |||
| 8708686994 | |||
| a595750194 | |||
| 00e90aaa0c | |||
| 009ac7f5f7 | |||
| 9080b8e67e | |||
| 179f259c3d | |||
| 1aa83b0911 | |||
| abbd3ee95d | |||
| efa6fc49eb | |||
| 4008ef4a9b | |||
| b99dcd8592 | |||
| 4e1a0b24f4 |
Generated
+41
-3
@@ -12,6 +12,7 @@
|
||||
"@testing-library/jest-dom": "^6.9.1",
|
||||
"@testing-library/react": "^16.3.2",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"axios": "^1.17.0",
|
||||
"react": "^19.2.4",
|
||||
"react-dom": "^19.2.4",
|
||||
"react-router-dom": "^7.13.1",
|
||||
@@ -4804,6 +4805,34 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.17.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.17.0.tgz",
|
||||
"integrity": "sha512-J8SwNxprqqpbfenehxWYXE7CW+wM1BB4w3+N+g+/Wx40xM4rsLrfPmHHxSWIxJLYDgSY/HqlFPIYb2/S3rxafw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.16.0",
|
||||
"form-data": "^4.0.5",
|
||||
"https-proxy-agent": "^5.0.1",
|
||||
"proxy-from-env": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/axios/node_modules/form-data": {
|
||||
"version": "4.0.5",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.5.tgz",
|
||||
"integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"es-set-tostringtag": "^2.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/axobject-query": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.1.0.tgz",
|
||||
@@ -8090,9 +8119,9 @@
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.11",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz",
|
||||
"integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==",
|
||||
"version": "1.16.0",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz",
|
||||
"integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -13456,6 +13485,15 @@
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz",
|
||||
"integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/psl": {
|
||||
"version": "1.15.0",
|
||||
"resolved": "https://registry.npmjs.org/psl/-/psl-1.15.0.tgz",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"@testing-library/jest-dom": "^6.9.1",
|
||||
"@testing-library/react": "^16.3.2",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"axios": "^1.17.0",
|
||||
"react": "^19.2.4",
|
||||
"react-dom": "^19.2.4",
|
||||
"react-router-dom": "^7.13.1",
|
||||
|
||||
+12
-5
@@ -1,14 +1,21 @@
|
||||
import { Routes, Route } from 'react-router-dom';
|
||||
import Navbar from './components/Navbar';
|
||||
import Layout from './components/Layout';
|
||||
import Home from './pages/Home';
|
||||
import Books from './pages/Books';
|
||||
import Orders from './pages/Orders';
|
||||
import Profile from './pages/Profile';
|
||||
import NotFound from './pages/NotFound';
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<>
|
||||
<Navbar />
|
||||
<Routes>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path="/" element={<Layout />}>
|
||||
<Route index element={<Home />} />
|
||||
<Route path="books" element={<Books />} />
|
||||
<Route path="orders" element={<Orders />} />
|
||||
<Route path="profile" element={<Profile />} />
|
||||
<Route path="*" element={<NotFound />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import client from './client';
|
||||
|
||||
export function getBooks(page = 0, size = 20) {
|
||||
return client.get('/api/books', { params: { page, size } });
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const client = axios.create({
|
||||
baseURL: 'http://localhost:8080',
|
||||
});
|
||||
|
||||
export default client;
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Outlet } from 'react-router-dom';
|
||||
import Navbar from './Navbar';
|
||||
|
||||
export default function Layout() {
|
||||
return (
|
||||
<>
|
||||
<Navbar />
|
||||
<Outlet />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { getBooks } from '../api/books';
|
||||
|
||||
export default function Books() {
|
||||
const [books, setBooks] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
getBooks()
|
||||
.then((response) => {
|
||||
console.log(response.data);
|
||||
setBooks(response.data.content);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
setError("Impossible de charger les livres.");
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
}, []);
|
||||
|
||||
if (loading) return <main><p>Chargement…</p></main>;
|
||||
if (error) return <main><p>{error}</p></main>;
|
||||
|
||||
return (
|
||||
<main>
|
||||
<h1>Catalogue</h1>
|
||||
<ul>
|
||||
{books.map((book) => (
|
||||
<li key={book.isbn}>
|
||||
<strong>{book.title}</strong> - {book.author}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -1,91 +1,9 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import '../styles/home.css';
|
||||
|
||||
const features = [
|
||||
{ icon: '📚', title: 'Enregistrer un livre', desc: 'Ajoutez un nouveau titre au catalogue de la bibliothèque.', role: 'admin', path: '/books/new' },
|
||||
{ icon: '🛒', title: 'Passer une commande', desc: 'Commandez vos livres préférés en quelques secondes.', role: 'user', path: '/orders/new' },
|
||||
{ icon: '🏷️', title: 'Appliquer une promotion', desc: 'Créez et gérez vos codes promotionnels.', role: 'admin', path: '/promotions/new' },
|
||||
{ icon: '📌', title: 'Réserver un livre', desc: 'Réservez un exemplaire avant sa disponibilité.', role: 'user', path: '/reservations/new' },
|
||||
{ icon: '↩️', title: 'Retour de livre', desc: 'Gérez les retours et remises en stock.', role: 'admin', path: '/returns/new' },
|
||||
{ icon: '⭐', title: 'Points de fidélité', desc: 'Consultez et utilisez vos points cumulés.', role: 'user', path: '/loyalty' },
|
||||
{ icon: '💬', title: 'Laisser un avis', desc: 'Partagez votre opinion sur vos dernières lectures.', role: 'user', path: '/reviews/new' },
|
||||
{ icon: '🎫', title: 'Créer un abonnement', desc: 'Souscrivez à un abonnement mensuel ou annuel.', role: 'user', path: '/subscriptions/new' },
|
||||
{ icon: '🤝', title: 'Prêt entre lecteurs', desc: "Prêtez vos livres à d'autres membres de la communauté.", role: 'user', path: '/loans/new' },
|
||||
{ icon: '👥', title: 'Commande groupée', desc: 'Participez à des achats groupés avantageux.', role: 'user', path: '/group-orders' },
|
||||
];
|
||||
|
||||
const stats = [
|
||||
{ value: '10 000+', label: 'Livres disponibles' },
|
||||
{ value: '5 000+', label: 'Lecteurs actifs' },
|
||||
{ value: '50+', label: 'Catégories' },
|
||||
];
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main>
|
||||
{/* Hero */}
|
||||
<section className="hero">
|
||||
<p className="hero__eyebrow">Votre bibliothèque en ligne</p>
|
||||
<h1 className="hero__title">
|
||||
Des livres pour tous,
|
||||
<span className="hero__title-italic">partout, toujours.</span>
|
||||
</h1>
|
||||
<div className="hero__rule" />
|
||||
<p className="hero__subtitle">
|
||||
Commandez, réservez, prêtez et partagez vos lectures.
|
||||
Une plateforme pensée pour les vrais amoureux des livres.
|
||||
</p>
|
||||
<div className="hero__actions">
|
||||
<Link to="/books">
|
||||
<button className="hero__btn-primary">Explorer le catalogue</button>
|
||||
</Link>
|
||||
<button className="hero__btn-secondary">En savoir plus</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Stats */}
|
||||
<section className="stats">
|
||||
{stats.map(({ value, label }) => (
|
||||
<div key={label} className="stats__item">
|
||||
<div className="stats__value">{value}</div>
|
||||
<div className="stats__label">{label}</div>
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
|
||||
{/* Features */}
|
||||
<div className="section-header">
|
||||
<p className="section-header__eyebrow">Fonctionnalités</p>
|
||||
<h2 className="section-header__title">Tout ce dont vous avez besoin</h2>
|
||||
</div>
|
||||
|
||||
<section className="features">
|
||||
<div className="features__grid">
|
||||
{features.map((f) => (
|
||||
<Link to={f.path} key={f.title} className="feature-card">
|
||||
<div className="feature-card__glyph">{f.icon}</div>
|
||||
<span className={`badge badge--${f.role}`}>
|
||||
{f.role === 'admin' ? 'Administrateur' : 'Utilisateur'}
|
||||
</span>
|
||||
<h3 className="feature-card__title">{f.title}</h3>
|
||||
<p className="feature-card__desc">{f.desc}</p>
|
||||
<span className="feature-card__arrow">→ Accéder</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Footer CTA */}
|
||||
<section className="home-cta">
|
||||
<div className="home-cta__rule" />
|
||||
<h2 className="home-cta__title">
|
||||
Prêt à commencer<br />votre aventure ?
|
||||
</h2>
|
||||
<p className="home-cta__sub">Rejoignez des milliers de lecteurs dès aujourd'hui.</p>
|
||||
<Link to="/register">
|
||||
<span className="home-cta__btn">Créer un compte gratuit</span>
|
||||
</Link>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function NotFound() {
|
||||
return <main><h1>404 Page introuvable</h1></main>;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function Orders() {
|
||||
return <main><h1>Mes commandes</h1></main>;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function Profile() {
|
||||
return <main><h1>Mon compte</h1></main>;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:root {
|
||||
--bg: #0d0b08;
|
||||
--bg-raised: #111009;
|
||||
--bg-card: #0f0d0a;
|
||||
--gold: #c9a84c;
|
||||
--gold-dim: rgba(201, 168, 76, 0.45);
|
||||
--gold-faint:rgba(201, 168, 76, 0.1);
|
||||
--parchment: #f0e6d0;
|
||||
--text: #e8dcc8;
|
||||
--text-muted:rgba(232, 220, 200, 0.45);
|
||||
--text-dim: rgba(232, 220, 200, 0.25);
|
||||
--rust: #c05a2a;
|
||||
--rust-dim: rgba(192, 90, 42, 0.4);
|
||||
--border: rgba(180, 150, 80, 0.15);
|
||||
--border-hi: rgba(180, 150, 80, 0.3);
|
||||
--font-title:'Cinzel', 'Palatino Linotype', Georgia, serif;
|
||||
--font-body: 'Cormorant Garamond', 'Palatino Linotype', Georgia, serif;
|
||||
}
|
||||
|
||||
html { scroll-behavior: smooth; }
|
||||
|
||||
body {
|
||||
background-color: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: var(--font-body);
|
||||
font-size: 18px;
|
||||
line-height: 1.7;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4 {
|
||||
font-family: var(--font-title);
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
font-family: var(--font-title);
|
||||
border: none;
|
||||
outline: none;
|
||||
background: none;
|
||||
}
|
||||
@@ -1,372 +0,0 @@
|
||||
/* ── Hero ───────────────────────────── */
|
||||
.hero {
|
||||
padding: 110px 48px 90px;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid var(--border);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.hero::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: -80px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 600px;
|
||||
height: 400px;
|
||||
background: radial-gradient(ellipse, rgba(180, 140, 50, 0.06) 0%, transparent 70%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.hero__eyebrow {
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.65rem;
|
||||
letter-spacing: 0.28em;
|
||||
text-transform: uppercase;
|
||||
color: var(--gold);
|
||||
opacity: 0.75;
|
||||
margin-bottom: 22px;
|
||||
opacity: 0;
|
||||
animation: fadeUp 0.7s 0.1s ease forwards;
|
||||
}
|
||||
|
||||
.hero__title {
|
||||
font-family: var(--font-title);
|
||||
font-size: clamp(2.4rem, 5.5vw, 4.5rem);
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
line-height: 1.1;
|
||||
color: var(--parchment);
|
||||
max-width: 820px;
|
||||
margin: 0 auto 0;
|
||||
opacity: 0;
|
||||
animation: fadeUp 0.7s 0.2s ease forwards;
|
||||
}
|
||||
|
||||
.hero__title-italic {
|
||||
display: block;
|
||||
font-family: var(--font-body);
|
||||
font-style: italic;
|
||||
font-weight: 400;
|
||||
font-size: clamp(2.8rem, 6vw, 5rem);
|
||||
color: var(--gold);
|
||||
margin-top: 4px;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.hero__rule {
|
||||
width: 80px;
|
||||
height: 1px;
|
||||
background: linear-gradient(90deg, transparent, var(--gold), transparent);
|
||||
margin: 28px auto;
|
||||
opacity: 0;
|
||||
animation: fadeUp 0.7s 0.3s ease forwards;
|
||||
}
|
||||
|
||||
.hero__subtitle {
|
||||
font-family: var(--font-body);
|
||||
font-style: italic;
|
||||
font-size: 1.1rem;
|
||||
color: var(--text-muted);
|
||||
max-width: 500px;
|
||||
margin: 0 auto 40px;
|
||||
line-height: 1.85;
|
||||
opacity: 0;
|
||||
animation: fadeUp 0.7s 0.35s ease forwards;
|
||||
}
|
||||
|
||||
.hero__actions {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
opacity: 0;
|
||||
animation: fadeUp 0.7s 0.45s ease forwards;
|
||||
}
|
||||
|
||||
.hero__btn-primary {
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.68rem;
|
||||
letter-spacing: 0.16em;
|
||||
text-transform: uppercase;
|
||||
color: var(--gold);
|
||||
padding: 13px 30px;
|
||||
border: 1px solid var(--gold-dim);
|
||||
background: var(--gold-faint);
|
||||
transition: background 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.hero__btn-primary:hover {
|
||||
background: rgba(201, 168, 76, 0.2);
|
||||
border-color: var(--gold);
|
||||
}
|
||||
|
||||
.hero__btn-secondary {
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.68rem;
|
||||
letter-spacing: 0.16em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-muted);
|
||||
padding: 13px 30px;
|
||||
border: 1px solid rgba(232, 220, 200, 0.15);
|
||||
transition: color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.hero__btn-secondary:hover {
|
||||
color: var(--text);
|
||||
border-color: rgba(232, 220, 200, 0.35);
|
||||
}
|
||||
|
||||
@keyframes fadeUp {
|
||||
from { opacity: 0; transform: translateY(20px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
/* ── Stats ───────────────────────────── */
|
||||
.stats {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.stats__item {
|
||||
flex: 1;
|
||||
max-width: 240px;
|
||||
text-align: center;
|
||||
padding: 36px 16px;
|
||||
border-right: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.stats__item:last-child {
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
.stats__value {
|
||||
font-family: var(--font-title);
|
||||
font-size: 2rem;
|
||||
font-weight: 600;
|
||||
color: var(--gold);
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.stats__label {
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.6rem;
|
||||
letter-spacing: 0.18em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-dim);
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
/* ── Section header ──────────────────── */
|
||||
.section-header {
|
||||
text-align: center;
|
||||
padding: 80px 24px 0;
|
||||
}
|
||||
|
||||
.section-header__eyebrow {
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.6rem;
|
||||
letter-spacing: 0.28em;
|
||||
text-transform: uppercase;
|
||||
color: rgba(201, 168, 76, 0.55);
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.section-header__title {
|
||||
font-family: var(--font-title);
|
||||
font-size: clamp(1.4rem, 3vw, 2.2rem);
|
||||
font-weight: 600;
|
||||
color: var(--parchment);
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
/* ── Features ────────────────────────── */
|
||||
.features {
|
||||
padding: 40px 0 80px;
|
||||
}
|
||||
|
||||
.features__grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 1px;
|
||||
background: var(--border);
|
||||
border-top: 1px solid var(--border);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
@media (max-width: 1000px) {
|
||||
.features__grid { grid-template-columns: repeat(3, 1fr); }
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.features__grid { grid-template-columns: repeat(2, 1fr); }
|
||||
.hero { padding: 80px 24px 60px; }
|
||||
.navbar { padding: 0 20px; }
|
||||
.stats { flex-direction: column; align-items: center; }
|
||||
.stats__item { border-right: none; border-bottom: 1px solid var(--border); max-width: 100%; width: 100%; }
|
||||
}
|
||||
|
||||
@media (max-width: 420px) {
|
||||
.features__grid { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
/* ── Feature card ────────────────────── */
|
||||
.feature-card {
|
||||
background: var(--bg);
|
||||
padding: 30px 24px 26px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 9px;
|
||||
text-decoration: none;
|
||||
color: var(--text);
|
||||
transition: background 0.25s;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.feature-card::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 1px;
|
||||
background: linear-gradient(90deg, transparent, var(--gold), transparent);
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.feature-card:hover {
|
||||
background: #131007;
|
||||
}
|
||||
|
||||
.feature-card:hover::after {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.feature-card__glyph {
|
||||
font-size: 1.4rem;
|
||||
margin-bottom: 4px;
|
||||
opacity: 0.8;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.feature-card__title {
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--parchment);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.feature-card__desc {
|
||||
font-family: var(--font-body);
|
||||
font-style: italic;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-muted);
|
||||
line-height: 1.65;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.feature-card__arrow {
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.65rem;
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-dim);
|
||||
transition: color 0.2s;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.feature-card:hover .feature-card__arrow {
|
||||
color: var(--gold);
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.55rem;
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
padding: 3px 9px;
|
||||
align-self: flex-start;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.badge--admin {
|
||||
border: 1px solid var(--rust-dim);
|
||||
color: var(--rust);
|
||||
}
|
||||
|
||||
.badge--user {
|
||||
border: 1px solid var(--gold-dim);
|
||||
color: rgba(201, 168, 76, 0.65);
|
||||
}
|
||||
|
||||
/* ── Footer CTA ──────────────────────── */
|
||||
.home-cta {
|
||||
padding: 100px 24px;
|
||||
text-align: center;
|
||||
border-top: 1px solid var(--border);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.home-cta::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -60px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 500px;
|
||||
height: 300px;
|
||||
background: radial-gradient(ellipse, rgba(180, 140, 50, 0.05) 0%, transparent 70%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.home-cta__rule {
|
||||
width: 60px;
|
||||
height: 1px;
|
||||
background: linear-gradient(90deg, transparent, var(--gold), transparent);
|
||||
margin: 0 auto 32px;
|
||||
}
|
||||
|
||||
.home-cta__title {
|
||||
font-family: var(--font-title);
|
||||
font-size: clamp(1.8rem, 4vw, 3rem);
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.04em;
|
||||
color: var(--parchment);
|
||||
margin-bottom: 16px;
|
||||
line-height: 1.15;
|
||||
}
|
||||
|
||||
.home-cta__sub {
|
||||
font-family: var(--font-body);
|
||||
font-style: italic;
|
||||
font-size: 1rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
.home-cta__btn {
|
||||
display: inline-block;
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.68rem;
|
||||
letter-spacing: 0.18em;
|
||||
text-transform: uppercase;
|
||||
color: var(--gold);
|
||||
padding: 13px 36px;
|
||||
border: 1px solid var(--gold-dim);
|
||||
background: var(--gold-faint);
|
||||
transition: background 0.2s, border-color 0.2s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.home-cta__btn:hover {
|
||||
background: rgba(201, 168, 76, 0.2);
|
||||
border-color: var(--gold);
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
.navbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 200;
|
||||
height: 56px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 48px;
|
||||
background: rgba(13, 11, 8, 0.94);
|
||||
border-bottom: 1px solid var(--border);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.navbar__logo {
|
||||
font-family: var(--font-title);
|
||||
font-size: 1.05rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.22em;
|
||||
color: var(--gold);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.navbar__links {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.navbar__links a {
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.7rem;
|
||||
letter-spacing: 0.14em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-muted);
|
||||
padding: 6px 14px;
|
||||
transition: color 0.2s;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.navbar__links a::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 14px;
|
||||
right: 14px;
|
||||
height: 1px;
|
||||
background: var(--gold);
|
||||
transform: scaleX(0);
|
||||
transition: transform 0.25s ease;
|
||||
}
|
||||
|
||||
.navbar__links a:hover {
|
||||
color: var(--gold);
|
||||
}
|
||||
|
||||
.navbar__links a:hover::after {
|
||||
transform: scaleX(1);
|
||||
}
|
||||
|
||||
.navbar__actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.65rem;
|
||||
letter-spacing: 0.14em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-muted);
|
||||
padding: 7px 16px;
|
||||
border: 1px solid rgba(232, 220, 200, 0.15);
|
||||
transition: color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.btn-ghost:hover {
|
||||
color: var(--text);
|
||||
border-color: rgba(232, 220, 200, 0.35);
|
||||
}
|
||||
|
||||
.btn-cta {
|
||||
font-family: var(--font-title);
|
||||
font-size: 0.65rem;
|
||||
letter-spacing: 0.14em;
|
||||
text-transform: uppercase;
|
||||
color: var(--gold);
|
||||
padding: 7px 16px;
|
||||
border: 1px solid var(--gold-dim);
|
||||
background: var(--gold-faint);
|
||||
transition: background 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.btn-cta:hover {
|
||||
background: rgba(201, 168, 76, 0.18);
|
||||
border-color: var(--gold);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
@@ -0,0 +1,78 @@
|
||||
# mylibrary — back-end Java (méthode BDD)
|
||||
|
||||
Back-end du projet **2026-DEV-BUT3**. Reproduit, en Java pur, le cœur métier
|
||||
de l'API consommée par le front React `my-library/`.
|
||||
|
||||
## Méthode
|
||||
|
||||
Conformément au cours `maintenanceApplicativeCours1.pdf` (Behavior-Driven
|
||||
Development), pour chaque comportement on :
|
||||
|
||||
1. Écrit le scénario attendu (en Gherkin / `.feature` ou en `@DisplayName` JUnit)
|
||||
2. Écrit le test qui le vérifie
|
||||
3. Implémente le code qui fait passer le test
|
||||
|
||||
## Structure (calquée sur le module `customer` fourni par le prof)
|
||||
|
||||
```
|
||||
src/main/java/fr/iut_fbleau/but3/dev62/mylibrary/
|
||||
├─ customer/ Module fourni par l'enseignant (intact)
|
||||
│ ├─ CustomerInfo.java record d'entrée
|
||||
│ ├─ CustomerDTO.java DTO de sortie
|
||||
│ ├─ entity/ Customer (objet métier, règles fidélité)
|
||||
│ ├─ exception/ Exceptions métier
|
||||
│ ├─ converter/ Mapping Info <-> entity <-> DTO
|
||||
│ ├─ validator/ Règles de validation
|
||||
│ ├─ repository/ Stockage en mémoire (List)
|
||||
│ └─ usecase/ Cas d'usage (orchestration)
|
||||
└─ book/ Module développé en miroir (notre travail)
|
||||
└─ … (mêmes sous-paquets, même découpage)
|
||||
|
||||
src/test/java/.../mylibrary/
|
||||
├─ customer/ Tests JUnit fournis par l'enseignant
|
||||
├─ book/ Tests JUnit que nous avons écrits
|
||||
└─ features/
|
||||
├─ RunCucumberTest.java (du prof, intact)
|
||||
├─ client/CustomerSteps.java (du prof, intact)
|
||||
├─ book/BookSteps.java (notre travail)
|
||||
└─ resources/features/
|
||||
├─ client.feature (du prof, intact)
|
||||
└─ book.feature (notre travail)
|
||||
```
|
||||
|
||||
## Dépendances
|
||||
|
||||
Strictement les mêmes que dans le template du prof :
|
||||
|
||||
- JUnit 5 (jupiter-api, params, engine + platform-suite, platform-engine, platform-launcher)
|
||||
- Mockito (core, junit-jupiter)
|
||||
- Cucumber (cucumber-java, cucumber-junit-platform-engine)
|
||||
- Lombok
|
||||
|
||||
## Build & test
|
||||
|
||||
Pré-requis : **JDK 21** + **Maven 3.9+**
|
||||
|
||||
```bash
|
||||
mvn -f mylibrary test
|
||||
```
|
||||
|
||||
Cette commande exécute :
|
||||
|
||||
- les tests unitaires JUnit (entity, validator, converter, repository, usecase, exceptions)
|
||||
- les scénarios Cucumber (`client.feature` + `book.feature`) via `RunCucumberTest`
|
||||
|
||||
## Périmètre couvert
|
||||
|
||||
Conformément à la consigne (« reproduire le strict nécessaire pour démontrer
|
||||
la maîtrise »), l'API se limite aux deux domaines présents dans le swagger
|
||||
qui structurent l'app React :
|
||||
|
||||
- **Catalogue** (`book`) : enregistrer, consulter par ISBN, lister tous les livres,
|
||||
refuser ISBN dupliqué, refuser un livre invalide, gérer le stock.
|
||||
- **Comptes clients** (`customer`) : enregistrer, consulter par téléphone, mettre
|
||||
à jour, supprimer, ajouter / retirer des points de fidélité (module fourni).
|
||||
|
||||
L'exposition HTTP réelle utilisée par les développeurs front est l'API du prof
|
||||
(`mylibrary-0.0.1-SNAPSHOT.jar`) ; ce module sert à démontrer la maîtrise
|
||||
de la **conception métier en BDD/TDD**.
|
||||
@@ -0,0 +1,151 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>fr.iut_fbleau.but3.dev62</groupId>
|
||||
<artifactId>mylibrary</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<!-- Your java version-->
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<!-- Main dependencies -->
|
||||
<lombok.version>1.18.36</lombok.version>
|
||||
|
||||
<!-- Test Verisons-->
|
||||
<junit.version>5.11.4</junit.version>
|
||||
<junit.platform.version>1.11.4</junit.platform.version>
|
||||
<cucumber.version>7.21.1</cucumber.version>
|
||||
<mockito.version>5.16.0</mockito.version>
|
||||
|
||||
<!-- Maven build version -->
|
||||
<maven.compiler.version>3.13.0</maven.compiler.version>
|
||||
<maven.surefire.version>3.5.2</maven.surefire.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-bom</artifactId>
|
||||
<version>${cucumber.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-java</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-junit-platform-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-suite</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-engine</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-launcher</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven.compiler.version}</version>
|
||||
<configuration>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven.surefire.version}</version>
|
||||
<configuration>
|
||||
<properties>
|
||||
<!-- Work around. Surefire does not include enough
|
||||
information to disambiguate between different
|
||||
examples and scenarios. -->
|
||||
<configurationParameters>
|
||||
cucumber.junit-platform.naming-strategy=long
|
||||
</configurationParameters>
|
||||
</properties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,22 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Category;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class BookDTO {
|
||||
private final long isbn;
|
||||
private final String title;
|
||||
private final String author;
|
||||
private final String publisher;
|
||||
private final LocalDate publicationDate;
|
||||
private final double price;
|
||||
private final int quantity;
|
||||
private final List<Category> categories;
|
||||
private final String description;
|
||||
private final String language;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Category;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
public record BookInfo(
|
||||
long isbn,
|
||||
String title,
|
||||
String author,
|
||||
String publisher,
|
||||
LocalDate publicationDate,
|
||||
double price,
|
||||
int quantity,
|
||||
List<Category> categories,
|
||||
String description,
|
||||
String language
|
||||
) {
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.converter;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
||||
|
||||
public final class BookConverter {
|
||||
|
||||
private BookConverter() {
|
||||
|
||||
}
|
||||
|
||||
public static Book toDomain(BookInfo book) {
|
||||
return Book.builder()
|
||||
.isbn(book.isbn())
|
||||
.title(book.title())
|
||||
.author(book.author())
|
||||
.publisher(book.publisher())
|
||||
.publicationDate(book.publicationDate())
|
||||
.price(book.price())
|
||||
.quantity(book.quantity())
|
||||
.categories(book.categories())
|
||||
.description(book.description())
|
||||
.language(book.language())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static BookDTO toDTO(Book book) {
|
||||
return BookDTO.builder()
|
||||
.isbn(book.getIsbn())
|
||||
.title(book.getTitle())
|
||||
.author(book.getAuthor())
|
||||
.publisher(book.getPublisher())
|
||||
.publicationDate(book.getPublicationDate())
|
||||
.price(book.getPrice())
|
||||
.quantity(book.getQuantity())
|
||||
.categories(book.getCategories())
|
||||
.description(book.getDescription())
|
||||
.language(book.getLanguage())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.entity;
|
||||
|
||||
public enum Category {
|
||||
FICTION,
|
||||
NON_FICTION,
|
||||
SCIENCE_FICTION,
|
||||
FANTASY,
|
||||
MYSTERY,
|
||||
THRILLER,
|
||||
ROMANCE,
|
||||
BIOGRAPHY,
|
||||
HISTORY,
|
||||
POETRY,
|
||||
CHILDRENS,
|
||||
YOUNG_ADULT,
|
||||
SCIENCE,
|
||||
PHILOSOPHY,
|
||||
SELF_HELP,
|
||||
TRAVEL,
|
||||
COOKING,
|
||||
ART,
|
||||
RELIGION,
|
||||
REFERENCE
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
public class BookAlreadyExistsException extends Exception {
|
||||
|
||||
public static final String A_BOOK_WITH_ISBN_ALREADY_EXISTS_MESSAGE = "A book with isbn {0} already exists";
|
||||
|
||||
public BookAlreadyExistsException(long isbn) {
|
||||
// ISBN passe en String pour ne pas que MessageFormat ajoute le separateur de milliers
|
||||
super(MessageFormat.format(A_BOOK_WITH_ISBN_ALREADY_EXISTS_MESSAGE, String.valueOf(isbn)));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
public class BookNotFoundException extends Exception {
|
||||
|
||||
public static final String THE_BOOK_WITH_ISBN_DOES_NOT_EXIST_MESSAGE = "The book with isbn {0} does not exist";
|
||||
|
||||
public BookNotFoundException(long isbn) {
|
||||
// ISBN passe en String pour ne pas que MessageFormat ajoute le separateur de milliers
|
||||
super(MessageFormat.format(THE_BOOK_WITH_ISBN_DOES_NOT_EXIST_MESSAGE, String.valueOf(isbn)));
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
public class IllegalBookQuantityException extends Exception {
|
||||
|
||||
public static final String CANNOT_REMOVE_STOCK = "Cannot remove {0} units from {1} units in stock";
|
||||
|
||||
public IllegalBookQuantityException(int needed, int actual) {
|
||||
super(MessageFormat.format(CANNOT_REMOVE_STOCK, needed, actual));
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
|
||||
|
||||
public class NotValidBookException extends Exception {
|
||||
|
||||
public NotValidBookException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.repository;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
public final class BookRepository {
|
||||
|
||||
private final List<Book> books = new ArrayList<>();
|
||||
|
||||
public List<Book> findAll() {
|
||||
return books;
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
books.clear();
|
||||
}
|
||||
|
||||
public Book save(Book book) {
|
||||
Optional<Book> existing = findByIsbn(book.getIsbn());
|
||||
existing.ifPresent(books::remove);
|
||||
books.add(book);
|
||||
return book;
|
||||
}
|
||||
|
||||
public Optional<Book> findByIsbn(long isbn) {
|
||||
return books.stream()
|
||||
.filter(b -> b.getIsbn() == isbn)
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public boolean existsByIsbn(long isbn) {
|
||||
return books.stream().anyMatch(b -> b.getIsbn() == isbn);
|
||||
}
|
||||
|
||||
public void delete(Book book) {
|
||||
books.remove(book);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.usecase;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.converter.BookConverter;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.BookAlreadyExistsException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.BookNotFoundException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.NotValidBookException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.repository.BookRepository;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.validator.BookValidator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class BookUseCase {
|
||||
|
||||
private final BookRepository bookRepository;
|
||||
|
||||
public BookUseCase(BookRepository bookRepository) {
|
||||
this.bookRepository = bookRepository;
|
||||
}
|
||||
|
||||
public long registerBook(BookInfo bookInfo) throws NotValidBookException, BookAlreadyExistsException {
|
||||
BookValidator.validate(bookInfo);
|
||||
if (bookRepository.existsByIsbn(bookInfo.isbn())) {
|
||||
throw new BookAlreadyExistsException(bookInfo.isbn());
|
||||
}
|
||||
Book toRegister = BookConverter.toDomain(bookInfo);
|
||||
Book registered = bookRepository.save(toRegister);
|
||||
return registered.getIsbn();
|
||||
}
|
||||
|
||||
public BookDTO getBookByIsbn(long isbn) throws BookNotFoundException {
|
||||
Optional<Book> optional = bookRepository.findByIsbn(isbn);
|
||||
if (optional.isEmpty()) {
|
||||
throw new BookNotFoundException(isbn);
|
||||
}
|
||||
return BookConverter.toDTO(optional.get());
|
||||
}
|
||||
|
||||
public List<BookDTO> getAllBooks() {
|
||||
return bookRepository.findAll().stream()
|
||||
.map(BookConverter::toDTO)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.validator;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.NotValidBookException;
|
||||
|
||||
public final class BookValidator {
|
||||
|
||||
public static final int TITLE_MAX_LENGTH = 255;
|
||||
|
||||
public static final String ISBN_MUST_BE_POSITIVE = "Isbn must be a positive number";
|
||||
public static final String TITLE_CANNOT_BE_BLANK = "Title cannot be blank";
|
||||
public static final String TITLE_TOO_LONG = "Title cannot exceed " + TITLE_MAX_LENGTH + " characters";
|
||||
public static final String AUTHOR_CANNOT_BE_BLANK = "Author cannot be blank";
|
||||
public static final String PUBLISHER_CANNOT_BE_BLANK = "Publisher cannot be blank";
|
||||
public static final String PUBLICATION_DATE_REQUIRED = "Publication date is required";
|
||||
public static final String PRICE_MUST_BE_POSITIVE = "Price must be strictly positive";
|
||||
public static final String QUANTITY_MUST_BE_POSITIVE_OR_ZERO = "Quantity must be >= 0";
|
||||
public static final String CATEGORIES_REQUIRED = "At least one category is required";
|
||||
public static final String LANGUAGE_CANNOT_BE_BLANK = "Language cannot be blank";
|
||||
|
||||
private BookValidator() {
|
||||
|
||||
}
|
||||
|
||||
public static void validate(BookInfo book) throws NotValidBookException {
|
||||
validateIsbn(book);
|
||||
validateTitle(book);
|
||||
validateAuthor(book);
|
||||
validatePublisher(book);
|
||||
validatePublicationDate(book);
|
||||
validatePrice(book);
|
||||
validateQuantity(book);
|
||||
validateCategories(book);
|
||||
validateLanguage(book);
|
||||
}
|
||||
|
||||
private static void validateIsbn(BookInfo book) throws NotValidBookException {
|
||||
if (book.isbn() <= 0) {
|
||||
throw new NotValidBookException(ISBN_MUST_BE_POSITIVE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateTitle(BookInfo book) throws NotValidBookException {
|
||||
if (book.title() == null || book.title().isBlank()) {
|
||||
throw new NotValidBookException(TITLE_CANNOT_BE_BLANK);
|
||||
}
|
||||
if (book.title().length() > TITLE_MAX_LENGTH) {
|
||||
throw new NotValidBookException(TITLE_TOO_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateAuthor(BookInfo book) throws NotValidBookException {
|
||||
if (book.author() == null || book.author().isBlank()) {
|
||||
throw new NotValidBookException(AUTHOR_CANNOT_BE_BLANK);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validatePublisher(BookInfo book) throws NotValidBookException {
|
||||
if (book.publisher() == null || book.publisher().isBlank()) {
|
||||
throw new NotValidBookException(PUBLISHER_CANNOT_BE_BLANK);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validatePublicationDate(BookInfo book) throws NotValidBookException {
|
||||
if (book.publicationDate() == null) {
|
||||
throw new NotValidBookException(PUBLICATION_DATE_REQUIRED);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validatePrice(BookInfo book) throws NotValidBookException {
|
||||
if (book.price() <= 0) {
|
||||
throw new NotValidBookException(PRICE_MUST_BE_POSITIVE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateQuantity(BookInfo book) throws NotValidBookException {
|
||||
if (book.quantity() < 0) {
|
||||
throw new NotValidBookException(QUANTITY_MUST_BE_POSITIVE_OR_ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateCategories(BookInfo book) throws NotValidBookException {
|
||||
if (book.categories() == null || book.categories().isEmpty()) {
|
||||
throw new NotValidBookException(CATEGORIES_REQUIRED);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateLanguage(BookInfo book) throws NotValidBookException {
|
||||
if (book.language() == null || book.language().isBlank()) {
|
||||
throw new NotValidBookException(LANGUAGE_CANNOT_BE_BLANK);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer;
|
||||
|
||||
import java.util.UUID;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class CustomerDTO {
|
||||
private final UUID id;
|
||||
private final String firstName;
|
||||
private final String lastName;
|
||||
private final String phoneNumber;
|
||||
private final int loyaltyPoints;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer;
|
||||
|
||||
public record CustomerInfo(String firstName, String lastName, String phoneNumber) {
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer.converter;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.CustomerDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.CustomerInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
|
||||
|
||||
public final class CustomerConverter {
|
||||
private CustomerConverter(){
|
||||
|
||||
}
|
||||
|
||||
public static Customer toDomain(CustomerInfo newCustomer) {
|
||||
return Customer.builder()
|
||||
.firstName(newCustomer.firstName())
|
||||
.lastName(newCustomer.lastName())
|
||||
.phoneNumber(newCustomer.phoneNumber())
|
||||
.loyaltyPoints(0)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static CustomerDTO toDTO(Customer customer) {
|
||||
return CustomerDTO.builder()
|
||||
.id(customer.getId())
|
||||
.firstName(customer.getFirstName())
|
||||
.lastName(customer.getLastName())
|
||||
.phoneNumber(customer.getPhoneNumber())
|
||||
.loyaltyPoints(customer.getLoyaltyPoints())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer.entity;
|
||||
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.exception.IllegalCustomerPointException;
|
||||
import java.util.UUID;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class Customer {
|
||||
private UUID id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String phoneNumber;
|
||||
private int loyaltyPoints;
|
||||
|
||||
public void setRandomUUID() {
|
||||
this.id = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public void addLoyaltyPoints(int loyaltyPointToAdd) {
|
||||
this.loyaltyPoints += loyaltyPointToAdd;
|
||||
}
|
||||
|
||||
public void removeLoyaltyPoints(int loyaltyPointToRemove) throws IllegalCustomerPointException {
|
||||
if (loyaltyPointToRemove > this.loyaltyPoints) throw new IllegalCustomerPointException(loyaltyPointToRemove, this.loyaltyPoints);
|
||||
this.loyaltyPoints -= loyaltyPointToRemove;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer.exception;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CustomerNotFoundException extends Exception {
|
||||
|
||||
public static final String THE_CUSTOMER_WITH_ID_DOES_NOT_EXIST_MESSAGE = "The customer with id {0} does not exist";
|
||||
|
||||
public CustomerNotFoundException(UUID uuid) {
|
||||
super(MessageFormat.format(THE_CUSTOMER_WITH_ID_DOES_NOT_EXIST_MESSAGE, uuid));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer.exception;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
public class IllegalCustomerPointException extends Exception {
|
||||
|
||||
public static final String CANNOT_REMOVE_LOYALTY_POINTS = "Cannot remove {0} points from {1} points";
|
||||
|
||||
public IllegalCustomerPointException(int needed, int actual) {
|
||||
super(MessageFormat.format(CANNOT_REMOVE_LOYALTY_POINTS, needed,
|
||||
actual));
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer.exception;
|
||||
|
||||
public class NotValidCustomerException extends Exception {
|
||||
|
||||
public NotValidCustomerException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer.repository;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
public final class CustomerRepository {
|
||||
private final List<Customer> customers = new ArrayList<>();
|
||||
|
||||
public List<Customer> findAll() {
|
||||
return customers;
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
customers.clear();
|
||||
}
|
||||
|
||||
public Customer save(Customer newCustomer) {
|
||||
Optional<Customer> optionalCustomerWithSameId = this.findById(newCustomer.getId());
|
||||
optionalCustomerWithSameId.ifPresentOrElse(customers::remove, newCustomer::setRandomUUID);
|
||||
this.customers.add(newCustomer);
|
||||
return newCustomer;
|
||||
}
|
||||
|
||||
public Optional<Customer> findById(UUID uuid) {
|
||||
return this.customers.stream()
|
||||
.filter(customer -> customer.getId().equals(uuid))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public boolean existsById(UUID uuid) {
|
||||
return this.customers.stream()
|
||||
.anyMatch(customer -> customer.getId().equals(uuid));
|
||||
}
|
||||
|
||||
public Optional<Customer> findByPhoneNumber(String phoneNumber) {
|
||||
return this.customers.stream()
|
||||
.filter(customer -> customer.getPhoneNumber().equals(phoneNumber))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public void delete(Customer customer) {
|
||||
this.customers.remove(customer);
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer.usecase;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.CustomerDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.CustomerInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.converter.CustomerConverter;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.exception.CustomerNotFoundException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.exception.IllegalCustomerPointException;
|
||||
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.validator.CustomerValidator;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class CustomerUseCase {
|
||||
|
||||
private final CustomerRepository customerRepository;
|
||||
|
||||
public CustomerUseCase(CustomerRepository customerRepository) {
|
||||
this.customerRepository = customerRepository;
|
||||
}
|
||||
|
||||
public UUID registerCustomer(CustomerInfo newCustomer) throws NotValidCustomerException {
|
||||
CustomerValidator.validate(newCustomer);
|
||||
Customer customerToRegister = CustomerConverter.toDomain(newCustomer);
|
||||
Customer customerToRegistered = customerRepository.save(customerToRegister);
|
||||
return customerToRegistered.getId();
|
||||
}
|
||||
|
||||
public Optional<CustomerDTO> findCustomerByPhoneNumber(String phoneNumber) {
|
||||
Optional<Customer> optionalCustomer = customerRepository.findByPhoneNumber(phoneNumber);
|
||||
return optionalCustomer.map(CustomerConverter::toDTO);
|
||||
}
|
||||
|
||||
public CustomerDTO updateCustomer(UUID uuid, CustomerInfo customerInfo)
|
||||
throws CustomerNotFoundException, NotValidCustomerException {
|
||||
CustomerValidator.validate(customerInfo);
|
||||
Customer customerByUUID = getCustomerIfDoesNotExistThrowCustomerNotFoundException(
|
||||
uuid);
|
||||
Customer customer = Customer.builder()
|
||||
.id(uuid)
|
||||
.firstName(customerInfo.firstName())
|
||||
.lastName(customerInfo.lastName())
|
||||
.phoneNumber(customerInfo.phoneNumber())
|
||||
.loyaltyPoints(customerByUUID.getLoyaltyPoints())
|
||||
.build();
|
||||
Customer updatedCustomer = customerRepository.save(customer);
|
||||
return CustomerConverter.toDTO(updatedCustomer);
|
||||
}
|
||||
|
||||
public void deleteCustomer(UUID uuid) throws CustomerNotFoundException {
|
||||
Customer customerToDelete = getCustomerIfDoesNotExistThrowCustomerNotFoundException(uuid);
|
||||
this.customerRepository.delete(customerToDelete);
|
||||
}
|
||||
|
||||
public int addLoyaltyPoints(UUID uuid, int loyaltyPointToAdd) throws CustomerNotFoundException {
|
||||
Customer customerToAddLoyaltyPoints = getCustomerIfDoesNotExistThrowCustomerNotFoundException(
|
||||
uuid);
|
||||
customerToAddLoyaltyPoints.addLoyaltyPoints(loyaltyPointToAdd);
|
||||
customerRepository.save(customerToAddLoyaltyPoints);
|
||||
return customerToAddLoyaltyPoints.getLoyaltyPoints();
|
||||
}
|
||||
|
||||
public int subtractLoyaltyPoints(UUID uuid, int loyaltyPointToRemove)
|
||||
throws CustomerNotFoundException, IllegalCustomerPointException {
|
||||
Customer customerToSubtractLoyaltyPoints = getCustomerIfDoesNotExistThrowCustomerNotFoundException(
|
||||
uuid);
|
||||
customerToSubtractLoyaltyPoints.removeLoyaltyPoints(loyaltyPointToRemove);
|
||||
customerRepository.save(customerToSubtractLoyaltyPoints);
|
||||
return customerToSubtractLoyaltyPoints.getLoyaltyPoints();
|
||||
}
|
||||
|
||||
private Customer getCustomerIfDoesNotExistThrowCustomerNotFoundException(UUID uuid)
|
||||
throws CustomerNotFoundException {
|
||||
Optional<Customer> optionalCustomerById = customerRepository.findById(uuid);
|
||||
if (optionalCustomerById.isEmpty()) {
|
||||
throw new CustomerNotFoundException(uuid);
|
||||
}
|
||||
return optionalCustomerById.get();
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer.validator;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.CustomerInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.exception.NotValidCustomerException;
|
||||
|
||||
public final class CustomerValidator {
|
||||
|
||||
public static final String PHONE_NUMBER_IS_NOT_VALID = "Phone number is not valid";
|
||||
public static final String LAST_NAME_CANNOT_BE_BLANK = "Last name cannot be blank";
|
||||
public static final String FIRST_NAME_CANNOT_BE_BLANK = "First name cannot be blank";
|
||||
public static final String PHONE_NUMBER_REGEX = "0([67])\\d{8}";
|
||||
|
||||
private CustomerValidator() {
|
||||
|
||||
}
|
||||
|
||||
public static void validate(CustomerInfo newCustomer) throws NotValidCustomerException {
|
||||
validateFirstName(newCustomer);
|
||||
validateLastName(newCustomer);
|
||||
validatePhoneNumber(newCustomer);
|
||||
}
|
||||
|
||||
private static void validatePhoneNumber(CustomerInfo newCustomer)
|
||||
throws NotValidCustomerException {
|
||||
if (newCustomer.phoneNumber().isBlank()) {
|
||||
throw new NotValidCustomerException("Phone number cannot be blank");
|
||||
}
|
||||
if (!newCustomer.phoneNumber().matches(PHONE_NUMBER_REGEX)) {
|
||||
throw new NotValidCustomerException(PHONE_NUMBER_IS_NOT_VALID);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateLastName(CustomerInfo newCustomer) throws NotValidCustomerException {
|
||||
if (newCustomer.lastName().isBlank()) {
|
||||
throw new NotValidCustomerException(LAST_NAME_CANNOT_BE_BLANK);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateFirstName(CustomerInfo newCustomer) throws NotValidCustomerException {
|
||||
if (newCustomer.firstName().isBlank()) {
|
||||
throw new NotValidCustomerException(FIRST_NAME_CANNOT_BE_BLANK);
|
||||
}
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.converter;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Category;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BookConverterTest {
|
||||
|
||||
@Nested
|
||||
@DisplayName("toDomain() method tests")
|
||||
class ToDomainTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should convert BookInfo to Book entity preserving all fields")
|
||||
void testToDomain() {
|
||||
BookInfo info = new BookInfo(
|
||||
9780321125217L,
|
||||
"DDD",
|
||||
"Evans",
|
||||
"Addison-Wesley",
|
||||
LocalDate.of(2003, 8, 22),
|
||||
54.99,
|
||||
10,
|
||||
List.of(Category.SCIENCE),
|
||||
"desc",
|
||||
"EN"
|
||||
);
|
||||
|
||||
Book book = BookConverter.toDomain(info);
|
||||
|
||||
assertEquals(info.isbn(), book.getIsbn());
|
||||
assertEquals(info.title(), book.getTitle());
|
||||
assertEquals(info.author(), book.getAuthor());
|
||||
assertEquals(info.publisher(), book.getPublisher());
|
||||
assertEquals(info.publicationDate(), book.getPublicationDate());
|
||||
assertEquals(info.price(), book.getPrice());
|
||||
assertEquals(info.quantity(), book.getQuantity());
|
||||
assertEquals(info.categories(), book.getCategories());
|
||||
assertEquals(info.description(), book.getDescription());
|
||||
assertEquals(info.language(), book.getLanguage());
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("toDTO() method tests")
|
||||
class ToDTOTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should convert Book entity to BookDTO preserving all fields")
|
||||
void testToDTO() {
|
||||
Book book = Book.builder()
|
||||
.isbn(123L)
|
||||
.title("T")
|
||||
.author("A")
|
||||
.publisher("P")
|
||||
.publicationDate(LocalDate.of(2020, 1, 1))
|
||||
.price(9.99)
|
||||
.quantity(5)
|
||||
.categories(List.of(Category.FICTION))
|
||||
.description("d")
|
||||
.language("FR")
|
||||
.build();
|
||||
|
||||
BookDTO dto = BookConverter.toDTO(book);
|
||||
|
||||
assertEquals(123L, dto.getIsbn());
|
||||
assertEquals("T", dto.getTitle());
|
||||
assertEquals("A", dto.getAuthor());
|
||||
assertEquals("P", dto.getPublisher());
|
||||
assertEquals(LocalDate.of(2020, 1, 1), dto.getPublicationDate());
|
||||
assertEquals(9.99, dto.getPrice());
|
||||
assertEquals(5, dto.getQuantity());
|
||||
assertEquals(List.of(Category.FICTION), dto.getCategories());
|
||||
assertEquals("d", dto.getDescription());
|
||||
assertEquals("FR", dto.getLanguage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.entity;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.IllegalBookQuantityException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BookTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Builder should create a valid Book instance")
|
||||
void testBookBuilder() {
|
||||
long isbn = 9780321125217L;
|
||||
Book book = Book.builder()
|
||||
.isbn(isbn)
|
||||
.title("Domain-Driven Design")
|
||||
.author("Eric Evans")
|
||||
.publisher("Addison-Wesley")
|
||||
.publicationDate(LocalDate.of(2003, 8, 22))
|
||||
.price(54.99)
|
||||
.quantity(10)
|
||||
.categories(List.of(Category.SCIENCE, Category.REFERENCE))
|
||||
.description("Tackling complexity in the heart of software")
|
||||
.language("EN")
|
||||
.build();
|
||||
|
||||
assertEquals(isbn, book.getIsbn());
|
||||
assertEquals("Domain-Driven Design", book.getTitle());
|
||||
assertEquals("Eric Evans", book.getAuthor());
|
||||
assertEquals("Addison-Wesley", book.getPublisher());
|
||||
assertEquals(LocalDate.of(2003, 8, 22), book.getPublicationDate());
|
||||
assertEquals(54.99, book.getPrice());
|
||||
assertEquals(10, book.getQuantity());
|
||||
assertEquals(List.of(Category.SCIENCE, Category.REFERENCE), book.getCategories());
|
||||
assertEquals("EN", book.getLanguage());
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("Stock management")
|
||||
class StockTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("addStock should increase the quantity")
|
||||
void testAddStock() {
|
||||
Book book = Book.builder().quantity(5).build();
|
||||
book.addStock(7);
|
||||
assertEquals(12, book.getQuantity());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("removeStock should decrease the quantity")
|
||||
void testRemoveStock() throws IllegalBookQuantityException {
|
||||
Book book = Book.builder().quantity(5).build();
|
||||
book.removeStock(3);
|
||||
assertEquals(2, book.getQuantity());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("removeStock should throw when removing more than available")
|
||||
void testRemoveTooMuchStock() {
|
||||
Book book = Book.builder().quantity(5).build();
|
||||
IllegalBookQuantityException exception = assertThrows(
|
||||
IllegalBookQuantityException.class,
|
||||
() -> book.removeStock(10)
|
||||
);
|
||||
assertEquals(5, book.getQuantity());
|
||||
assertTrue(exception.getMessage().contains("10"));
|
||||
assertTrue(exception.getMessage().contains("5"));
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BookAlreadyExistsExceptionTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception message should contain the ISBN provided")
|
||||
void testExceptionMessageContainsIsbn() {
|
||||
long isbn = 9780321125217L;
|
||||
|
||||
BookAlreadyExistsException exception = new BookAlreadyExistsException(isbn);
|
||||
|
||||
assertTrue(exception.getMessage().contains(String.valueOf(isbn)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should expose its message constant")
|
||||
void testConstantMessage() {
|
||||
assertEquals("A book with isbn {0} already exists",
|
||||
BookAlreadyExistsException.A_BOOK_WITH_ISBN_ALREADY_EXISTS_MESSAGE);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BookNotFoundExceptionTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception message should contain the ISBN provided")
|
||||
void testExceptionMessageContainsIsbn() {
|
||||
long isbn = 9780321125217L;
|
||||
|
||||
BookNotFoundException exception = new BookNotFoundException(isbn);
|
||||
|
||||
assertTrue(exception.getMessage().contains(String.valueOf(isbn)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should expose its message constant")
|
||||
void testConstantMessage() {
|
||||
assertEquals("The book with isbn {0} does not exist",
|
||||
BookNotFoundException.THE_BOOK_WITH_ISBN_DOES_NOT_EXIST_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be properly thrown and caught")
|
||||
void testExceptionCanBeThrownAndCaught() {
|
||||
long isbn = 1L;
|
||||
try {
|
||||
throw new BookNotFoundException(isbn);
|
||||
} catch (BookNotFoundException e) {
|
||||
assertTrue(e.getMessage().contains("1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class IllegalBookQuantityExceptionTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception message should contain the requested and actual quantities")
|
||||
void testExceptionMessageContainsQuantities() {
|
||||
IllegalBookQuantityException exception = new IllegalBookQuantityException(10, 3);
|
||||
String expected = "Cannot remove 10 units from 3 units in stock";
|
||||
assertEquals(expected, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"10, 3",
|
||||
"100, 0",
|
||||
"5, 4"
|
||||
})
|
||||
@DisplayName("Message should be formatted using the constant template")
|
||||
void testFormattedMessage(int needed, int actual) {
|
||||
IllegalBookQuantityException exception = new IllegalBookQuantityException(needed, actual);
|
||||
String expected = MessageFormat.format(IllegalBookQuantityException.CANNOT_REMOVE_STOCK, needed, actual);
|
||||
assertEquals(expected, exception.getMessage());
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class NotValidBookExceptionTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be created with the provided message")
|
||||
void testExceptionCreation() {
|
||||
String msg = "title cannot be blank";
|
||||
NotValidBookException exception = new NotValidBookException(msg);
|
||||
assertEquals(msg, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"Title cannot be blank",
|
||||
"Author cannot be blank",
|
||||
"Price must be strictly positive",
|
||||
"At least one category is required"
|
||||
})
|
||||
@DisplayName("Exception should propagate any validation message")
|
||||
void testExceptionWithDifferentMessages(String message) {
|
||||
NotValidBookException exception = new NotValidBookException(message);
|
||||
assertEquals(message, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception should be catchable as a general Exception")
|
||||
void testExceptionInheritance() {
|
||||
String msg = "invalid book";
|
||||
try {
|
||||
throw new NotValidBookException(msg);
|
||||
} catch (Exception e) {
|
||||
assertEquals(NotValidBookException.class, e.getClass());
|
||||
assertEquals(msg, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.repository;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Category;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BookRepositoryTest {
|
||||
|
||||
private BookRepository repository;
|
||||
private Book book1;
|
||||
private Book book2;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
repository = new BookRepository();
|
||||
|
||||
book1 = Book.builder()
|
||||
.isbn(1111111111111L)
|
||||
.title("Book One")
|
||||
.author("Author A")
|
||||
.publisher("Pub")
|
||||
.publicationDate(LocalDate.of(2020, 1, 1))
|
||||
.price(10.0)
|
||||
.quantity(2)
|
||||
.categories(List.of(Category.FICTION))
|
||||
.language("EN")
|
||||
.build();
|
||||
|
||||
book2 = Book.builder()
|
||||
.isbn(2222222222222L)
|
||||
.title("Book Two")
|
||||
.author("Author B")
|
||||
.publisher("Pub")
|
||||
.publicationDate(LocalDate.of(2021, 1, 1))
|
||||
.price(20.0)
|
||||
.quantity(0)
|
||||
.categories(List.of(Category.HISTORY))
|
||||
.language("FR")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("New repository should be empty")
|
||||
void testNewRepositoryIsEmpty() {
|
||||
assertTrue(repository.findAll().isEmpty());
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("Save operations")
|
||||
class SaveOperations {
|
||||
|
||||
@Test
|
||||
@DisplayName("Save should add a new book")
|
||||
void testSave() {
|
||||
Book saved = repository.save(book1);
|
||||
assertEquals(1, repository.findAll().size());
|
||||
assertEquals(book1.getIsbn(), saved.getIsbn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Save should replace existing book with same ISBN (idempotency)")
|
||||
void testSaveReplacesExisting() {
|
||||
repository.save(book1);
|
||||
Book updated = Book.builder()
|
||||
.isbn(book1.getIsbn())
|
||||
.title("New title")
|
||||
.author("Author A")
|
||||
.publisher("Pub")
|
||||
.publicationDate(LocalDate.of(2020, 1, 1))
|
||||
.price(10.0)
|
||||
.quantity(99)
|
||||
.categories(List.of(Category.FICTION))
|
||||
.language("EN")
|
||||
.build();
|
||||
|
||||
repository.save(updated);
|
||||
|
||||
assertEquals(1, repository.findAll().size());
|
||||
assertEquals(99, repository.findByIsbn(book1.getIsbn()).orElseThrow().getQuantity());
|
||||
assertEquals("New title", repository.findByIsbn(book1.getIsbn()).orElseThrow().getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("Find operations")
|
||||
class FindOperations {
|
||||
|
||||
@BeforeEach
|
||||
void seed() {
|
||||
repository.save(book1);
|
||||
repository.save(book2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("findByIsbn returns the matching book")
|
||||
void testFindByIsbn() {
|
||||
Optional<Book> found = repository.findByIsbn(book1.getIsbn());
|
||||
assertTrue(found.isPresent());
|
||||
assertEquals(book1.getTitle(), found.get().getTitle());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("findByIsbn returns empty when not found")
|
||||
void testFindByIsbnNotFound() {
|
||||
assertTrue(repository.findByIsbn(99L).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("existsByIsbn returns true / false consistently")
|
||||
void testExistsByIsbn() {
|
||||
assertTrue(repository.existsByIsbn(book1.getIsbn()));
|
||||
assertFalse(repository.existsByIsbn(99L));
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("Delete operations")
|
||||
class DeleteOperations {
|
||||
|
||||
@BeforeEach
|
||||
void seed() {
|
||||
repository.save(book1);
|
||||
repository.save(book2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("delete should remove the specified book")
|
||||
void testDelete() {
|
||||
repository.delete(book1);
|
||||
assertEquals(1, repository.findAll().size());
|
||||
assertFalse(repository.existsByIsbn(book1.getIsbn()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("deleteAll should clear the repository")
|
||||
void testDeleteAll() {
|
||||
repository.deleteAll();
|
||||
assertTrue(repository.findAll().isEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.usecase;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Category;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.BookAlreadyExistsException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.BookNotFoundException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.NotValidBookException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.repository.BookRepository;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class BookUseCaseTest {
|
||||
|
||||
@Mock
|
||||
private BookRepository bookRepository;
|
||||
|
||||
@InjectMocks
|
||||
private BookUseCase bookUseCase;
|
||||
|
||||
private BookInfo validInfo;
|
||||
private Book validBook;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
validInfo = new BookInfo(
|
||||
9780321125217L,
|
||||
"DDD",
|
||||
"Evans",
|
||||
"Addison-Wesley",
|
||||
LocalDate.of(2003, 8, 22),
|
||||
54.99,
|
||||
10,
|
||||
List.of(Category.SCIENCE),
|
||||
"desc",
|
||||
"EN"
|
||||
);
|
||||
validBook = Book.builder()
|
||||
.isbn(validInfo.isbn())
|
||||
.title(validInfo.title())
|
||||
.author(validInfo.author())
|
||||
.publisher(validInfo.publisher())
|
||||
.publicationDate(validInfo.publicationDate())
|
||||
.price(validInfo.price())
|
||||
.quantity(validInfo.quantity())
|
||||
.categories(validInfo.categories())
|
||||
.description(validInfo.description())
|
||||
.language(validInfo.language())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("registerBook tests")
|
||||
class RegisterTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should register a new book and return its ISBN")
|
||||
void testRegisterBook() throws NotValidBookException, BookAlreadyExistsException {
|
||||
when(bookRepository.existsByIsbn(validInfo.isbn())).thenReturn(false);
|
||||
when(bookRepository.save(any(Book.class))).thenReturn(validBook);
|
||||
|
||||
long isbn = bookUseCase.registerBook(validInfo);
|
||||
|
||||
assertEquals(validInfo.isbn(), isbn);
|
||||
verify(bookRepository).existsByIsbn(validInfo.isbn());
|
||||
verify(bookRepository).save(any(Book.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should reject invalid book information without touching the repository")
|
||||
void testRegisterInvalidBook() {
|
||||
BookInfo invalid = new BookInfo(0L, "", "", "", null, -1, -1, null, "", "");
|
||||
assertThrows(NotValidBookException.class, () -> bookUseCase.registerBook(invalid));
|
||||
verifyNoInteractions(bookRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should reject duplicate ISBN")
|
||||
void testRegisterDuplicate() {
|
||||
when(bookRepository.existsByIsbn(validInfo.isbn())).thenReturn(true);
|
||||
assertThrows(BookAlreadyExistsException.class, () -> bookUseCase.registerBook(validInfo));
|
||||
verify(bookRepository).existsByIsbn(validInfo.isbn());
|
||||
verify(bookRepository, never()).save(any(Book.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("getBookByIsbn tests")
|
||||
class GetByIdTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should return the BookDTO when ISBN exists")
|
||||
void testGetById() throws BookNotFoundException {
|
||||
when(bookRepository.findByIsbn(validInfo.isbn())).thenReturn(Optional.of(validBook));
|
||||
|
||||
BookDTO dto = bookUseCase.getBookByIsbn(validInfo.isbn());
|
||||
|
||||
assertEquals(validInfo.isbn(), dto.getIsbn());
|
||||
assertEquals(validInfo.title(), dto.getTitle());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should throw when ISBN does not exist")
|
||||
void testGetByIdNotFound() {
|
||||
when(bookRepository.findByIsbn(99L)).thenReturn(Optional.empty());
|
||||
assertThrows(BookNotFoundException.class, () -> bookUseCase.getBookByIsbn(99L));
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("getAllBooks tests")
|
||||
class GetAllBooksTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should map every book returned by the repository to a DTO")
|
||||
void testGetAllBooks() {
|
||||
when(bookRepository.findAll()).thenReturn(List.of(validBook));
|
||||
|
||||
List<BookDTO> result = bookUseCase.getAllBooks();
|
||||
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(validBook.getIsbn(), result.getFirst().getIsbn());
|
||||
assertEquals(validBook.getTitle(), result.getFirst().getTitle());
|
||||
verify(bookRepository).findAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should return an empty list when no book is stored")
|
||||
void testGetAllBooksWhenEmpty() {
|
||||
when(bookRepository.findAll()).thenReturn(List.of());
|
||||
|
||||
List<BookDTO> result = bookUseCase.getAllBooks();
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.book.validator;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Category;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.NotValidBookException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BookValidatorTest {
|
||||
|
||||
private BookInfo valid() {
|
||||
return new BookInfo(
|
||||
9780321125217L,
|
||||
"Domain-Driven Design",
|
||||
"Eric Evans",
|
||||
"Addison-Wesley",
|
||||
LocalDate.of(2003, 8, 22),
|
||||
54.99,
|
||||
10,
|
||||
List.of(Category.SCIENCE),
|
||||
"Tackling complexity in the heart of software",
|
||||
"EN"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should accept a valid BookInfo")
|
||||
void testValidBook() {
|
||||
assertDoesNotThrow(() -> BookValidator.validate(valid()));
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("ISBN validation")
|
||||
class IsbnTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(longs = {0L, -1L, -9999L})
|
||||
@DisplayName("Should reject ISBN that is not strictly positive")
|
||||
void testInvalidIsbn(long isbn) {
|
||||
BookInfo info = new BookInfo(isbn, "T", "A", "P", LocalDate.now(), 1.0, 0, List.of(Category.SCIENCE), "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.ISBN_MUST_BE_POSITIVE, ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("Title validation")
|
||||
class TitleTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"", " ", "\t", "\n"})
|
||||
@DisplayName("Should reject blank title")
|
||||
void testBlankTitle(String title) {
|
||||
BookInfo info = new BookInfo(1L, title, "A", "P", LocalDate.now(), 1.0, 0, List.of(Category.SCIENCE), "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.TITLE_CANNOT_BE_BLANK, ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should reject null title")
|
||||
void testNullTitle() {
|
||||
BookInfo info = new BookInfo(1L, null, "A", "P", LocalDate.now(), 1.0, 0, List.of(Category.SCIENCE), "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.TITLE_CANNOT_BE_BLANK, ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should reject title longer than 255 characters")
|
||||
void testTitleTooLong() {
|
||||
String longTitle = "a".repeat(256);
|
||||
BookInfo info = new BookInfo(1L, longTitle, "A", "P", LocalDate.now(), 1.0, 0, List.of(Category.SCIENCE), "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.TITLE_TOO_LONG, ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("Author / Publisher validation")
|
||||
class AuthorPublisherTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"", " ", "\t"})
|
||||
@DisplayName("Should reject blank author")
|
||||
void testBlankAuthor(String author) {
|
||||
BookInfo info = new BookInfo(1L, "T", author, "P", LocalDate.now(), 1.0, 0, List.of(Category.SCIENCE), "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.AUTHOR_CANNOT_BE_BLANK, ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"", " ", "\t"})
|
||||
@DisplayName("Should reject blank publisher")
|
||||
void testBlankPublisher(String publisher) {
|
||||
BookInfo info = new BookInfo(1L, "T", "A", publisher, LocalDate.now(), 1.0, 0, List.of(Category.SCIENCE), "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.PUBLISHER_CANNOT_BE_BLANK, ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("Date / Price / Quantity validation")
|
||||
class NumericTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should reject null publication date")
|
||||
void testNullDate() {
|
||||
BookInfo info = new BookInfo(1L, "T", "A", "P", null, 1.0, 0, List.of(Category.SCIENCE), "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.PUBLICATION_DATE_REQUIRED, ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(doubles = {0.0, -0.01, -10.0})
|
||||
@DisplayName("Should reject non-positive price")
|
||||
void testNonPositivePrice(double price) {
|
||||
BookInfo info = new BookInfo(1L, "T", "A", "P", LocalDate.now(), price, 0, List.of(Category.SCIENCE), "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.PRICE_MUST_BE_POSITIVE, ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {-1, -100})
|
||||
@DisplayName("Should reject negative quantity")
|
||||
void testNegativeQuantity(int quantity) {
|
||||
BookInfo info = new BookInfo(1L, "T", "A", "P", LocalDate.now(), 1.0, quantity, List.of(Category.SCIENCE), "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.QUANTITY_MUST_BE_POSITIVE_OR_ZERO, ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("Categories / Language validation")
|
||||
class MetadataTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should reject empty categories")
|
||||
void testEmptyCategories() {
|
||||
BookInfo info = new BookInfo(1L, "T", "A", "P", LocalDate.now(), 1.0, 0, List.of(), "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.CATEGORIES_REQUIRED, ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should reject null categories")
|
||||
void testNullCategories() {
|
||||
BookInfo info = new BookInfo(1L, "T", "A", "P", LocalDate.now(), 1.0, 0, null, "", "EN");
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.CATEGORIES_REQUIRED, ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"", " ", "\t"})
|
||||
@DisplayName("Should reject blank language")
|
||||
void testBlankLanguage(String language) {
|
||||
BookInfo info = new BookInfo(1L, "T", "A", "P", LocalDate.now(), 1.0, 0, List.of(Category.SCIENCE), "", language);
|
||||
NotValidBookException ex = assertThrows(NotValidBookException.class, () -> BookValidator.validate(info));
|
||||
assertEquals(BookValidator.LANGUAGE_CANNOT_BE_BLANK, ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.customer.converter;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.CustomerDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.CustomerInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
|
||||
import java.util.UUID;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
@DisplayName("CustomerConverter Unit Tests")
|
||||
class CustomerConverterTest {
|
||||
|
||||
@Nested
|
||||
@DisplayName("toDomain() method tests")
|
||||
class ToDomainTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should convert CustomerInfo to Customer domain object with loyalty points initialized to 0")
|
||||
void shouldConvertCustomerInfoToDomain() {
|
||||
// Given
|
||||
CustomerInfo customerInfo = new CustomerInfo("John", "Doe", "0123456789");
|
||||
|
||||
// When
|
||||
Customer result = CustomerConverter.toDomain(customerInfo);
|
||||
|
||||
// Then
|
||||
assertNotNull(result);
|
||||
assertEquals(customerInfo.firstName(), result.getFirstName());
|
||||
assertEquals(customerInfo.lastName(), result.getLastName());
|
||||
assertEquals(customerInfo.phoneNumber(), result.getPhoneNumber());
|
||||
assertEquals(0, result.getLoyaltyPoints());
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("toDTO() method tests")
|
||||
class ToDTOTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should convert Customer domain object to CustomerDTO with all fields mapped correctly")
|
||||
void shouldConvertCustomerToDTO() {
|
||||
Customer customer = Customer.builder()
|
||||
.id(UUID.randomUUID())
|
||||
.firstName("Jane")
|
||||
.lastName("Smith")
|
||||
.phoneNumber("9876543210")
|
||||
.loyaltyPoints(100)
|
||||
.build();
|
||||
|
||||
CustomerDTO result = CustomerConverter.toDTO(customer);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(customer.getId(), result.getId());
|
||||
assertEquals(customer.getFirstName(), result.getFirstName());
|
||||
assertEquals(customer.getLastName(), result.getLastName());
|
||||
assertEquals(customer.getPhoneNumber(), result.getPhoneNumber());
|
||||
assertEquals(customer.getLoyaltyPoints(), result.getLoyaltyPoints());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should handle null values properly when converting between objects")
|
||||
void shouldHandleNullValuesGracefully() {
|
||||
Customer customer = Customer.builder()
|
||||
.id(UUID.randomUUID())
|
||||
.firstName(null)
|
||||
.lastName("NullTest")
|
||||
.phoneNumber(null)
|
||||
.loyaltyPoints(50)
|
||||
.build();
|
||||
|
||||
CustomerDTO result = CustomerConverter.toDTO(customer);
|
||||
|
||||
assertNotNull(result);
|
||||
assertNull(result.getFirstName());
|
||||
assertEquals("NullTest", result.getLastName());
|
||||
assertNull(result.getPhoneNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should preserve empty string values during conversion")
|
||||
void shouldPreserveEmptyStrings() {
|
||||
CustomerInfo customerInfo = new CustomerInfo("", "", "");
|
||||
|
||||
Customer domainResult = CustomerConverter.toDomain(customerInfo);
|
||||
CustomerDTO dtoResult = CustomerConverter.toDTO(domainResult);
|
||||
|
||||
assertEquals("", dtoResult.getFirstName());
|
||||
assertEquals("", dtoResult.getLastName());
|
||||
assertEquals("", dtoResult.getPhoneNumber());
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user