From 508898f52c16cc737bc7d08b8ee4c29fab8d1146 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 6 Sep 2026 10:36:54 +0300 Subject: ex-2: add invalid-input fixtures and wire ui-desktop to the service The ex-2 loader has to reject documents that are schema-valid but logically broken, and so far only error-2.xml and error-3.xml exercised that path. Add one fixture per validation rule under test-data/ex-2/invalid, each a copy of small.xml with a single defect described in a leading comment: a non-.xml extension, a duplicate event id, commission outside 0..90 on either side, a duplicate user name, zero or negative initial cash, a market maker referencing an unknown event, and an event with no market maker or with two. Teach LedgerMapper to map individual LedgerEntry records to LedgerEntryDTO, renaming id to seq and time to at and rendering the timestamp through InstantOptions.humanize, so callers can show a ledger history rather than only the account summary. Make ui-desktop depend on api and service in the build tooling and in its Eclipse classpath, since the desktop UI now talks to the service layer directly, and put lib/openjfx on java.library.path for the test run so tests touching JavaFX can load its native libraries. --- .../infrastructure/adapter/LedgerMapper.java | 13 ++++++ test-data/ex-2/invalid/ex1-commission-above-90.xml | 49 ++++++++++++++++++++ test-data/ex-2/invalid/ex1-commission-below-0.xml | 49 ++++++++++++++++++++ test-data/ex-2/invalid/ex1-duplicate-event-id.xml | 49 ++++++++++++++++++++ test-data/ex-2/invalid/ex1-not-xml.txt | 49 ++++++++++++++++++++ test-data/ex-2/invalid/ex2-duplicate-user.xml | 49 ++++++++++++++++++++ test-data/ex-2/invalid/ex2-event-two-mms.xml | 52 ++++++++++++++++++++++ test-data/ex-2/invalid/ex2-event-without-mm.xml | 46 +++++++++++++++++++ test-data/ex-2/invalid/ex2-mm-unknown-event.xml | 52 ++++++++++++++++++++++ .../ex-2/invalid/ex2-negative-initial-cash.xml | 49 ++++++++++++++++++++ test-data/ex-2/invalid/ex2-zero-initial-cash.xml | 49 ++++++++++++++++++++ tools/_util.sh | 2 +- tools/test.sh | 2 +- ui-desktop/.classpath | 3 +- 14 files changed, 510 insertions(+), 3 deletions(-) create mode 100644 test-data/ex-2/invalid/ex1-commission-above-90.xml create mode 100644 test-data/ex-2/invalid/ex1-commission-below-0.xml create mode 100644 test-data/ex-2/invalid/ex1-duplicate-event-id.xml create mode 100644 test-data/ex-2/invalid/ex1-not-xml.txt create mode 100644 test-data/ex-2/invalid/ex2-duplicate-user.xml create mode 100644 test-data/ex-2/invalid/ex2-event-two-mms.xml create mode 100644 test-data/ex-2/invalid/ex2-event-without-mm.xml create mode 100644 test-data/ex-2/invalid/ex2-mm-unknown-event.xml create mode 100644 test-data/ex-2/invalid/ex2-negative-initial-cash.xml create mode 100644 test-data/ex-2/invalid/ex2-zero-initial-cash.xml diff --git a/service/src/main/java/market/guess/service/catalog/infrastructure/adapter/LedgerMapper.java b/service/src/main/java/market/guess/service/catalog/infrastructure/adapter/LedgerMapper.java index 5a46540..9744925 100644 --- a/service/src/main/java/market/guess/service/catalog/infrastructure/adapter/LedgerMapper.java +++ b/service/src/main/java/market/guess/service/catalog/infrastructure/adapter/LedgerMapper.java @@ -1,10 +1,23 @@ package market.guess.service.catalog.infrastructure.adapter; +import java.time.Instant; import market.guess.model.ledger.LedgerDTO; +import market.guess.model.ledger.LedgerEntryDTO; +import market.guess.service.helpers.InstantOptions; import market.guess.service.ledger.Ledger; +import market.guess.service.ledger.LedgerEntry; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; @Mapper public interface LedgerMapper { LedgerDTO ledgerToLedgerDTO(Ledger ledger); + + @Mapping(target = "seq", source = "id") + @Mapping(target = "at", source = "time") + LedgerEntryDTO ledgerEntryToLedgerEntryDTO(LedgerEntry entry); + + default String instantToDisplay(Instant time) { + return time == null ? null : InstantOptions.humanize(time); + } } diff --git a/test-data/ex-2/invalid/ex1-commission-above-90.xml b/test-data/ex-2/invalid/ex1-commission-above-90.xml new file mode 100644 index 0000000..a94845f --- /dev/null +++ b/test-data/ex-2/invalid/ex1-commission-above-90.xml @@ -0,0 +1,49 @@ + + + + + + 1 + This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26 + 5 + + Hell Yea ! + No way ! + + + + 100 + + + + + 2 + Who do you think will win the world cap ? + 91 + + Argentina + Spain + + + + + + + + + 1000 + + + + + + 10000 + + + + + + 100 + + + diff --git a/test-data/ex-2/invalid/ex1-commission-below-0.xml b/test-data/ex-2/invalid/ex1-commission-below-0.xml new file mode 100644 index 0000000..a2433cb --- /dev/null +++ b/test-data/ex-2/invalid/ex1-commission-below-0.xml @@ -0,0 +1,49 @@ + + + + + + 1 + This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26 + -1 + + Hell Yea ! + No way ! + + + + 100 + + + + + 2 + Who do you think will win the world cap ? + 15 + + Argentina + Spain + + + + + + + + + 1000 + + + + + + 10000 + + + + + + 100 + + + diff --git a/test-data/ex-2/invalid/ex1-duplicate-event-id.xml b/test-data/ex-2/invalid/ex1-duplicate-event-id.xml new file mode 100644 index 0000000..5998bb9 --- /dev/null +++ b/test-data/ex-2/invalid/ex1-duplicate-event-id.xml @@ -0,0 +1,49 @@ + + + + + + 1 + This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26 + 5 + + Hell Yea ! + No way ! + + + + 100 + + + + + 1 + Who do you think will win the world cap ? + 15 + + Argentina + Spain + + + + + + + + + 1000 + + + + + + 10000 + + + + + + 100 + + + diff --git a/test-data/ex-2/invalid/ex1-not-xml.txt b/test-data/ex-2/invalid/ex1-not-xml.txt new file mode 100644 index 0000000..488b486 --- /dev/null +++ b/test-data/ex-2/invalid/ex1-not-xml.txt @@ -0,0 +1,49 @@ + + + + + + 1 + This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26 + 5 + + Hell Yea ! + No way ! + + + + 100 + + + + + 2 + Who do you think will win the world cap ? + 15 + + Argentina + Spain + + + + + + + + + 1000 + + + + + + 10000 + + + + + + 100 + + + diff --git a/test-data/ex-2/invalid/ex2-duplicate-user.xml b/test-data/ex-2/invalid/ex2-duplicate-user.xml new file mode 100644 index 0000000..38e8040 --- /dev/null +++ b/test-data/ex-2/invalid/ex2-duplicate-user.xml @@ -0,0 +1,49 @@ + + + + + + 1 + This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26 + 5 + + Hell Yea ! + No way ! + + + + 100 + + + + + 2 + Who do you think will win the world cap ? + 15 + + Argentina + Spain + + + + + + + + + 1000 + + + + + + 10000 + + + + + + 100 + + + diff --git a/test-data/ex-2/invalid/ex2-event-two-mms.xml b/test-data/ex-2/invalid/ex2-event-two-mms.xml new file mode 100644 index 0000000..2a698a2 --- /dev/null +++ b/test-data/ex-2/invalid/ex2-event-two-mms.xml @@ -0,0 +1,52 @@ + + + + + + 1 + This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26 + 5 + + Hell Yea ! + No way ! + + + + 100 + + + + + 2 + Who do you think will win the world cap ? + 15 + + Argentina + Spain + + + + + + + + + 1000 + + + + + + 10000 + + + + + + 100 + + + + + + diff --git a/test-data/ex-2/invalid/ex2-event-without-mm.xml b/test-data/ex-2/invalid/ex2-event-without-mm.xml new file mode 100644 index 0000000..26d1da6 --- /dev/null +++ b/test-data/ex-2/invalid/ex2-event-without-mm.xml @@ -0,0 +1,46 @@ + + + + + + 1 + This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26 + 5 + + Hell Yea ! + No way ! + + + + 100 + + + + + 2 + Who do you think will win the world cap ? + 15 + + Argentina + Spain + + + + + + + + + 1000 + + + + + + 10000 + + + 100 + + + diff --git a/test-data/ex-2/invalid/ex2-mm-unknown-event.xml b/test-data/ex-2/invalid/ex2-mm-unknown-event.xml new file mode 100644 index 0000000..c0c9316 --- /dev/null +++ b/test-data/ex-2/invalid/ex2-mm-unknown-event.xml @@ -0,0 +1,52 @@ + + + + + + 1 + This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26 + 5 + + Hell Yea ! + No way ! + + + + 100 + + + + + 2 + Who do you think will win the world cap ? + 15 + + Argentina + Spain + + + + + + + + + 1000 + + + + + + 10000 + + + + + + 100 + + + + + + diff --git a/test-data/ex-2/invalid/ex2-negative-initial-cash.xml b/test-data/ex-2/invalid/ex2-negative-initial-cash.xml new file mode 100644 index 0000000..04a4894 --- /dev/null +++ b/test-data/ex-2/invalid/ex2-negative-initial-cash.xml @@ -0,0 +1,49 @@ + + + + + + 1 + This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26 + 5 + + Hell Yea ! + No way ! + + + + 100 + + + + + 2 + Who do you think will win the world cap ? + 15 + + Argentina + Spain + + + + + + + + + 1000 + + + + + + 10000 + + + + + + -50 + + + diff --git a/test-data/ex-2/invalid/ex2-zero-initial-cash.xml b/test-data/ex-2/invalid/ex2-zero-initial-cash.xml new file mode 100644 index 0000000..b21593e --- /dev/null +++ b/test-data/ex-2/invalid/ex2-zero-initial-cash.xml @@ -0,0 +1,49 @@ + + + + + + 1 + This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26 + 5 + + Hell Yea ! + No way ! + + + + 100 + + + + + 2 + Who do you think will win the world cap ? + 15 + + Argentina + Spain + + + + + + + + + 1000 + + + + + + 10000 + + + + + + 0 + + + diff --git a/tools/_util.sh b/tools/_util.sh index a041f2d..d6e8db5 100644 --- a/tools/_util.sh +++ b/tools/_util.sh @@ -10,7 +10,7 @@ MODULES="api service ui-console ui-desktop" DEPS_api="" DEPS_service="api" DEPS_ui_console="api service" -DEPS_ui_desktop="" +DEPS_ui_desktop="api service" RUNTIME_LIB_DIRS="pico jaxb gson openjfx" diff --git a/tools/test.sh b/tools/test.sh index e867871..41602f4 100644 --- a/tools/test.sh +++ b/tools/test.sh @@ -49,7 +49,7 @@ mkdir -p build/coverage [ -n "$AGENT_ARG" ] && AGENT_ARG="$AGENT_ARG " AGENT_ARG="$AGENT_ARG-javaagent:$JACOCO_AGENT=destfile=build/coverage/jacoco.exec" -java $AGENT_ARG -jar "$JUNIT_JAR" execute \ +java -Djava.library.path=lib/openjfx $AGENT_ARG -jar "$JUNIT_JAR" execute \ --class-path "$TEST_CP" --scan-class-path --details=summary echo "=== Generating coverage report ===" diff --git a/ui-desktop/.classpath b/ui-desktop/.classpath index bac8826..200bca6 100644 --- a/ui-desktop/.classpath +++ b/ui-desktop/.classpath @@ -11,7 +11,8 @@ - + + -- cgit v1.2.3