Add crud-mysql module: Spring Boot 4.1 CRUD API on a real MySQL 8.4.6 with JPA, Flyway, validation and ProblemDetail errors
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HhW8LD8r3EigoBaCGrQZx5 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HhW8LD8r3EigoBaCGrQZx5
This commit is contained in:
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# Starts the packaged jar, makes real curl -i calls against it and stops it again. Raw output, headers included,
|
||||
# goes to output/05-real-curl.txt.
|
||||
#
|
||||
# ./scripts/curl-demo.sh
|
||||
#
|
||||
# Needs the same MySQL as the tests, and wipes the book table first.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
mvn -B -q package -DskipTests
|
||||
java -jar target/crud-mysql-1.0.0.jar --server.port=8080 --logging.level.root=WARN > target/app.log 2>&1 &
|
||||
PID=$!
|
||||
trap 'kill $PID 2>/dev/null || true' EXIT
|
||||
for _ in $(seq 1 60); do curl -s -o /dev/null localhost:8080/api/books && break; sleep 1; done
|
||||
|
||||
OUT=output/05-real-curl.txt
|
||||
H='Content-Type: application/json'
|
||||
{
|
||||
echo "# Real curl -i output against the packaged jar (java -jar target/crud-mysql-1.0.0.jar), Date header removed"
|
||||
echo
|
||||
for cmd in \
|
||||
"curl -i -s -X POST localhost:8080/api/books -H '$H' -d '{\"title\":\"Effective Java\",\"author\":\"Joshua Bloch\",\"isbn\":\"9780134685991\",\"price\":45.50}'" \
|
||||
"curl -i -s localhost:8080/api/books/1" \
|
||||
"curl -i -s -X DELETE localhost:8080/api/books/1" \
|
||||
"curl -i -s localhost:8080/api/books/1"; do
|
||||
echo "\$ ${cmd/ -s/}"
|
||||
eval "$cmd" | tr -d '\r' | grep -v '^Date:'
|
||||
echo; echo
|
||||
done
|
||||
} > "$OUT"
|
||||
cat "$OUT"
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Creates the database and the user the application expects. Run as a MySQL administrator:
|
||||
-- mysql -uroot -p < scripts/mysql-setup.sql
|
||||
CREATE DATABASE IF NOT EXISTS library;
|
||||
CREATE USER IF NOT EXISTS 'library'@'%' IDENTIFIED BY 'library';
|
||||
GRANT ALL ON library.* TO 'library'@'%';
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file under output/.
|
||||
#
|
||||
# ./scripts/run-all.sh
|
||||
#
|
||||
# Needs a JDK 21 or newer, Maven 3.9 and a MySQL 8.4 server reachable with the defaults in
|
||||
# src/main/resources/application.properties (localhost:3306, database library, user library, password
|
||||
# library), or the same values in DB_URL / DB_USER / DB_PASSWORD. All four transcripts are written by the
|
||||
# test suite, so every figure in the article is an assertion that fails the build if it stops being true.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
mvn -B test
|
||||
|
||||
echo
|
||||
echo "output:"
|
||||
ls -1 output
|
||||
Reference in New Issue
Block a user