diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..3dd1f91
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,28 @@
+name: CI
+
+on:
+ push:
+ branches: ["**"]
+ pull_request:
+ branches: ["**"]
+
+jobs:
+ build:
+ name: Build & test (Java 21)
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Set up Temurin JDK 21
+ uses: actions/setup-java@v4
+ with:
+ distribution: temurin
+ java-version: "21"
+ cache: maven
+
+ # Compiles all modules, runs the JUnit 5 regression tests and builds the
+ # jar/wars/ear. `package` stops before the integration-test phases, so the
+ # Liberty runtime is not required for CI.
+ - name: Build and test
+ run: mvn -B clean package
diff --git a/.travis.yml b/.travis.yml
index 8e607e3..ef20bf4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,10 @@
language: java
jdk:
- - openjdk8
+ - openjdk21
env:
- - TEST_COMMAND="gradle clean build"
- - TEST_COMMAND="mvn clean install"
+ - TEST_COMMAND="mvn clean package"
script:
- (eval "$TEST_COMMAND")
diff --git a/MIGRATION.md b/MIGRATION.md
new file mode 100644
index 0000000..b42c442
--- /dev/null
+++ b/MIGRATION.md
@@ -0,0 +1,107 @@
+# DayTrader3 — Java 8 → Java 21 Migration Plan
+
+Jira: **JEFF-DT3-JAVA21** (Java 21 upgrade for DayTrader3)
+
+This document is the written migration plan produced during repository discovery, before
+code changes. It captures the current state, the Java 8 / Java EE 6 assumptions that break
+on a modern JDK, the required vs. optional work, and the high-risk areas on the trade path.
+
+## 1. Architecture summary (as-is)
+
+DayTrader3 is a Java EE 6 benchmark modelling an online stock-trading system (login,
+portfolio, quotes, buy/sell orders, holdings). It is a Maven **and** Gradle multi-module
+reactor targeting IBM WebSphere Liberty.
+
+| Module | Packaging | Role |
+| --- | --- | --- |
+| `daytrader3-ee6-ejb` | jar (`dt-ejb.jar`) | Core business logic + JPA entities. EJB session beans (`TradeSLSBBean`), MDBs, and a JDBC "direct" mode (`TradeDirect`). Domain beans: `AccountDataBean`, `AccountProfileDataBean`, `QuoteDataBean`, `HoldingDataBean`, `OrderDataBean`, `MarketSummaryDataBean`; utilities `FinancialUtils`, `TradeConfig`. |
+| `daytrader3-ee6-web` | war (`web.war`) | Servlets, JSPs, JSF managed beans (portfolio/quote/account UI). |
+| `daytrader3-ee6-rest` | war (`Rest.war`) | JAX-RS (JSR-311) sample address-book endpoints using JAXB binding. |
+| `daytrader3-ee6` | ear | Assembles the EJB jar + two wars; copies the Derby driver; wires the Liberty plugin for functional tests. |
+| `daytrader3-ee6-wlpcfg` | pom | Liberty server configuration (`server.xml`, features). |
+
+Runtime data store: **Apache Derby** (embedded), shipped as a copied driver jar.
+
+Persistence/transactions are container-managed (JPA 2.0 + JTA 1.1). Messaging uses JMS 1.1
+MDBs. All `javax.*` EE APIs (`javax.ejb`, `javax.jms`, `javax.persistence`, `javax.servlet`,
+`javax.faces`, `javax.ws.rs`) are supplied by the container at runtime and by `provided`
+Maven dependencies at compile time — they are **not** part of the JDK, so JDK removals do
+not affect them.
+
+## 2. Java 8 / legacy assumptions that break on Java 21
+
+| # | Assumption | Impact on Java 21 | Required action |
+| --- | --- | --- | --- |
+| A1 | Compiler `source/target = 1.7` (Maven parent `java7-parent`; Gradle `sourceCompatibility = 1.7`) | javac 21 no longer supports `-source/-target 7` (min is 8). Build fails immediately. | Set release/source/target to **21** in Maven and Gradle. |
+| A2 | REST module imports `javax.xml.bind.*` (JAXB) | **JAXB was removed from the JDK in Java 11** (JEP 320, `java.se.ee`). Compile fails. | Add `javax.xml.bind:jaxb-api` (+ `jaxb-runtime` at runtime) as explicit dependencies, keeping the `javax` namespace so no source changes are needed. |
+| A3 | `javax.annotation.*` (`@PostConstruct`, `@Resource`) in EJB + web modules | **Common Annotations removed from the JDK in Java 11** (JEP 320). Compile fails. | Add `javax.annotation:javax.annotation-api` as a `provided` dependency (namespace preserved). |
+| A4 | Legacy Maven plugin versions inherited from `java7-parent` (compiler, surefire, ear, war) | Old plugin versions can fail under a Java 21 toolchain and cannot run JUnit 5. | Pin modern plugin versions via `pluginManagement` in the root POM. |
+| A5 | Apache **Derby 10.10.1.1** (2013) | Runs on old JDKs only and carries known CVEs (see §5). Newer Derby lines require newer JDKs. | Upgrade to **Derby 10.17.1.0** (the current line, which requires Java 21). |
+| A6 | CI pinned to `openjdk8` (Travis) | Does not exercise Java 21. | Add a GitHub Actions workflow building + testing on **Temurin 21**; keep Travis JDK aligned. |
+
+Notes on things that are **fine** and deliberately left unchanged:
+- Deprecated boxing constructors (`new Integer(...)`, `new BigDecimal(double)`, etc., ~30
+ sites) still compile on Java 21 (deprecation warnings only). Rewriting them is optional
+ style churn and is intentionally **out of scope** to protect trade-path semantics.
+- No usage of removed CORBA / JAX-WS / `sun.*` internal APIs was found.
+- The `javax` EE namespace is retained end-to-end (no Jakarta `jakarta.*` rename), because
+ the target runtime (WebSphere Liberty EE6/`javaee-6.0`) expects `javax`. A Jakarta EE
+ migration is a separate, larger effort and would change runtime behavior — out of scope.
+
+## 3. Required migration work vs. optional refactoring
+
+**Required (in this PR):**
+1. Compiler/runtime targets → Java 21 (Maven + Gradle).
+2. Add JDK-removed EE APIs back as explicit dependencies (JAXB, Common Annotations).
+3. Modern Maven plugin versions (compiler, surefire, ear, war).
+4. Derby 10.10.1.1 → 10.17.1.0 (CVE remediation + Java 21 support).
+5. Regression tests (none exist today) around order creation, quote retrieval, buy/sell
+ execution math, and holdings valuation.
+6. CI on Java 21; refreshed docs.
+
+**Optional (explicitly deferred, not done here):**
+- Jakarta EE 9+ (`javax.*` → `jakarta.*`) namespace migration.
+- Replacing deprecated boxing/`BigDecimal(double)` constructors.
+- Replacing the raw-JDBC "direct" mode or the JMS MDB workload.
+- Virtual threads / records / other Java 21 language adoption in domain code.
+
+## 4. High-risk, trade-path changes to review carefully
+
+- **Derby major upgrade (10.10 → 10.17).** Derby 10.15+ is modularized (`derby`,
+ `derbyshared`, `derbytools`, `derbyclient`). The embedded driver class and SQL dialect
+ used by `TradeDirect` are unchanged, but the runtime now needs the companion jars on the
+ server classpath. Money math (balances, holdings, order fees) must be re-verified against
+ a running server. This is the single highest-risk item for externally observable behavior.
+- **Order fee / balance arithmetic.** `TradeConfig.getOrderFee` (flat `24.95` for BUY/SELL)
+ and `FinancialUtils` gain/holdings computations drive user-visible P&L. Covered by new
+ regression tests; must not change.
+- **JAXB provider at runtime.** The REST address-book sample relies on a JAXB
+ implementation being present; on a modular JDK it must come from a dependency, not the
+ platform. Low business impact (sample endpoint), but verify the REST war still deploys.
+
+## 5. Security findings addressed
+
+Apache Derby 10.10.1.1 → 10.17.1.0 remediates:
+- **CVE-2015-1832** — XXE in Derby (fixed 10.12.1.1).
+- **CVE-2018-1313** — information disclosure via crafted SQL (fixed 10.14.2.0).
+- **CVE-2022-46337** — LDAP-injection / auth bypass, "alwaysAllow" (fixed 10.16.1.1).
+
+10.17.1.0 is at or above every fixed line above.
+
+## 6. Verification strategy
+
+- `mvn clean package` on JDK 21 compiles all modules, runs the new JUnit 5 unit tests, and
+ builds the jar/wars/ear — **without** requiring a Liberty download (the Liberty plugin
+ goals are bound to the integration-test phases, which `package` does not reach).
+- Full end-to-end trade-path validation (login → quote → buy → portfolio → sell) runs
+ against a live Liberty + Derby server and is **not** part of unit CI; it remains a manual
+ functional test (see README) and is called out in the human-review checklist.
+
+## 7. Rollback guidance
+
+The change set is confined to build files (`pom.xml`, `build.gradle`), a Derby version bump,
+added test sources, CI config, and docs — no domain/business logic is modified.
+- To roll back: revert this PR (single squashed commit) and redeploy the previous EAR built
+ on Java 8; the schema and Derby data format are unchanged, so no data migration is needed.
+- Partial rollback: if only Derby is problematic, revert the `derby.version` property to the
+ prior value while keeping the Java 21 compiler settings.
diff --git a/README.md b/README.md
index 76b5d36..1d50bc5 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# sample.daytrader3 [](https://travis-ci.org/WASdev/sample.daytrader3)
+# sample.daytrader3 [](https://github.com/COG-GTM/sample.daytrader3/actions/workflows/ci.yml)
# Java EE6: DayTrader3 Sample
@@ -9,6 +9,14 @@ This sample contains the DayTrader 3 benchmark, which is an application built ar
DayTrader is an end-to-end benchmark and performance sample application. It provides a real world Java EE workload.
+## Runtime requirements
+
+This sample builds and runs on **Java 21** (LTS). The build targets Java 21 in both
+Maven and Gradle, and the embedded Apache Derby driver has been upgraded to a
+current, security-patched line. The application still targets the Java EE 6 (`javax.*`)
+programming model on WebSphere Liberty. See [MIGRATION.md](/MIGRATION.md) for the full
+Java 8 → Java 21 migration notes.
+
## Getting Started
Browse the code to see what it does, or build and run it yourself:
@@ -16,6 +24,18 @@ Browse the code to see what it does, or build and run it yourself:
* [Building and running using Eclipse and WebSphere Development Tools (WDT)](/docs/Using-WDT.md)
* [Downloading WAS Liberty](/docs/Downloading-WAS-Liberty.md)
+### Quick build & test
+
+```bash
+# Requires JDK 21 on PATH / JAVA_HOME
+mvn clean package
+```
+
+This compiles all modules, runs the JUnit 5 regression tests (order creation, quote
+retrieval, buy/sell execution math, holdings valuation) and assembles the EAR. It does
+not require a Liberty runtime; the Liberty functional tests remain bound to the
+integration-test phases.
+
Once the server has been started, go to [http://localhost:9083/daytrader](http://localhost:9083/daytrader) to interact with the sample.
## Notice
diff --git a/daytrader3-ee6-ejb/build.gradle b/daytrader3-ee6-ejb/build.gradle
index d8c846d..ce50a30 100644
--- a/daytrader3-ee6-ejb/build.gradle
+++ b/daytrader3-ee6-ejb/build.gradle
@@ -14,6 +14,14 @@ dependencies {
compile group: 'javax.ejb', name: 'ejb-api', version: '3.0'
compile group: 'javax.jms', name: 'jms-api', version: '1.1-rev-1'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
+ // Common Annotations removed from the JDK in Java 11 (JEP 320).
+ compileOnly group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
+ testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.10.2'
}
-sourceCompatibility = 1.7
+sourceCompatibility = JavaVersion.VERSION_21
+targetCompatibility = JavaVersion.VERSION_21
+
+test {
+ useJUnitPlatform()
+}
diff --git a/daytrader3-ee6-ejb/pom.xml b/daytrader3-ee6-ejb/pom.xml
index c8a1e16..e443a7f 100644
--- a/daytrader3-ee6-ejb/pom.xml
+++ b/daytrader3-ee6-ejb/pom.xml
@@ -37,6 +37,21 @@
1.1
provided
+
+
+ javax.annotation
+ javax.annotation-api
+ ${javax.annotation.version}
+ provided
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ ${junit.jupiter.version}
+ test
+
diff --git a/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/AccountDataBeanTest.java b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/AccountDataBeanTest.java
new file mode 100644
index 0000000..37c6ed3
--- /dev/null
+++ b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/AccountDataBeanTest.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.ibm.websphere.samples.daytrader;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import javax.ejb.EJBException;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Regression tests for the login/logout behaviour exposed to users.
+ */
+public class AccountDataBeanTest {
+
+ private AccountDataBean accountWithProfile(String userId, String password) {
+ AccountDataBean account = new AccountDataBean(0, 0, new Date(), new Date(),
+ new BigDecimal("1000000"), new BigDecimal("1000000"), userId);
+ AccountProfileDataBean profile =
+ new AccountProfileDataBean(userId, password, "full name", "addr", "e@mail", "1-2-3-4");
+ account.setProfile(profile);
+ return account;
+ }
+
+ @Test
+ public void successfulLoginIncrementsLoginCountAndSetsLastLogin() {
+ AccountDataBean account = accountWithProfile("uid:0", "secret");
+ account.login("secret");
+ assertEquals(1, account.getLoginCount());
+ assertNotNull(account.getLastLogin());
+ }
+
+ @Test
+ public void wrongPasswordThrowsAndDoesNotIncrementLogin() {
+ AccountDataBean account = accountWithProfile("uid:0", "secret");
+ assertThrows(EJBException.class, () -> account.login("wrong"));
+ assertEquals(0, account.getLoginCount());
+ }
+
+ @Test
+ public void missingProfileThrowsOnLogin() {
+ AccountDataBean account = new AccountDataBean(0, 0, new Date(), new Date(),
+ new BigDecimal("1000000"), new BigDecimal("1000000"), "uid:0");
+ assertThrows(EJBException.class, () -> account.login("secret"));
+ }
+
+ @Test
+ public void logoutIncrementsLogoutCount() {
+ AccountDataBean account = accountWithProfile("uid:0", "secret");
+ account.logout();
+ account.logout();
+ assertEquals(2, account.getLogoutCount());
+ }
+}
diff --git a/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/BuySellExecutionTest.java b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/BuySellExecutionTest.java
new file mode 100644
index 0000000..7bbeefc
--- /dev/null
+++ b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/BuySellExecutionTest.java
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.ibm.websphere.samples.daytrader;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+
+import org.junit.jupiter.api.Test;
+
+import com.ibm.websphere.samples.daytrader.util.FinancialUtils;
+
+/**
+ * Regression tests for the money movement of buy/sell execution, expressed with
+ * the domain model (account balance, holdings, order fee and holdings
+ * valuation). These lock down the externally observable arithmetic that the
+ * EJB/JDBC trade path implements against the database:
+ *
+ * buy: balance' = balance - (price * quantity) - orderFee, new holding created
+ * sell: balance' = balance + (price * quantity) - orderFee, holding removed
+ */
+public class BuySellExecutionTest {
+
+ private static final BigDecimal FEE = TradeConfig.getOrderFee("buy"); // 24.95
+
+ private AccountDataBean account(BigDecimal balance) {
+ return new AccountDataBean(0, 0, new Date(), new Date(), balance, balance, "uid:0");
+ }
+
+ @Test
+ public void buyDebitsBalanceByCostPlusFeeAndCreatesHolding() {
+ AccountDataBean account = account(new BigDecimal("10000.00"));
+ QuoteDataBean quote = new QuoteDataBean("s:1", "Acme", 1000d,
+ new BigDecimal("50.00"), new BigDecimal("50.00"),
+ new BigDecimal("48.00"), new BigDecimal("52.00"), 0d);
+ double quantity = 100d;
+
+ BigDecimal cost = quote.getPrice().multiply(new BigDecimal(quantity));
+ BigDecimal newBalance = account.getBalance().subtract(cost).subtract(FEE);
+ account.setBalance(newBalance);
+
+ HoldingDataBean holding =
+ new HoldingDataBean(quantity, quote.getPrice(), new Date(), account, quote);
+
+ // 10000.00 - (50.00 * 100) - 24.95 = 4975.05
+ assertEquals(0, new BigDecimal("4975.05").compareTo(account.getBalance()));
+ assertEquals(100d, holding.getQuantity());
+ assertEquals(0, new BigDecimal("50.00").compareTo(holding.getPurchasePrice()));
+ assertEquals("s:1", holding.getQuoteID());
+ }
+
+ @Test
+ public void sellCreditsBalanceByProceedsMinusFee() {
+ AccountDataBean account = account(new BigDecimal("4975.05"));
+ QuoteDataBean quote = new QuoteDataBean("s:1", "Acme", 1000d,
+ new BigDecimal("55.00"), new BigDecimal("50.00"),
+ new BigDecimal("48.00"), new BigDecimal("56.00"), 0d);
+ HoldingDataBean holding =
+ new HoldingDataBean(100d, new BigDecimal("50.00"), new Date(), account, quote);
+
+ BigDecimal proceeds = quote.getPrice().multiply(new BigDecimal(holding.getQuantity()));
+ BigDecimal newBalance = account.getBalance().add(proceeds).subtract(FEE);
+ account.setBalance(newBalance);
+
+ // 4975.05 + (55.00 * 100) - 24.95 = 10450.10
+ assertEquals(0, new BigDecimal("10450.10").compareTo(account.getBalance()));
+ }
+
+ @Test
+ public void portfolioValueIsBalancePlusHoldingsValuation() {
+ AccountDataBean account = account(new BigDecimal("4975.05"));
+ Collection holdings = new ArrayList<>();
+ holdings.add(new HoldingDataBean(100d, new BigDecimal("50.00"), new Date(), account, null));
+
+ BigDecimal holdingsTotal = FinancialUtils.computeHoldingsTotal(holdings);
+ BigDecimal portfolio = account.getBalance().add(holdingsTotal);
+
+ // 4975.05 + (100 * 50.00) = 9975.05
+ assertEquals(0, new BigDecimal("9975.05").compareTo(portfolio));
+ }
+
+ @Test
+ public void roundTripBuyThenSellAtHigherPriceIsProfitable() {
+ AccountDataBean account = account(new BigDecimal("10000.00"));
+
+ // buy 100 @ 50.00
+ BigDecimal buyCost = new BigDecimal("50.00").multiply(new BigDecimal(100d));
+ account.setBalance(account.getBalance().subtract(buyCost).subtract(FEE));
+
+ // sell 100 @ 55.00
+ BigDecimal proceeds = new BigDecimal("55.00").multiply(new BigDecimal(100d));
+ account.setBalance(account.getBalance().add(proceeds).subtract(FEE));
+
+ BigDecimal gain = FinancialUtils.computeGain(account.getBalance(), new BigDecimal("10000.00"));
+ // net = +500 (price move) - 49.90 (two fees) = 450.10
+ assertEquals(0, new BigDecimal("450.10").compareTo(gain));
+ assertTrue(gain.signum() > 0);
+ }
+}
diff --git a/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/HoldingDataBeanTest.java b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/HoldingDataBeanTest.java
new file mode 100644
index 0000000..4934982
--- /dev/null
+++ b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/HoldingDataBeanTest.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.ibm.websphere.samples.daytrader;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Regression tests for holdings: quantity, purchase price and the symbol a
+ * holding is associated with.
+ */
+public class HoldingDataBeanTest {
+
+ @Test
+ public void holdingRetainsQuantityAndPurchasePrice() {
+ HoldingDataBean holding = new HoldingDataBean(10.0d,
+ new BigDecimal("50.00"), new Date(), null, null);
+ assertEquals(10.0d, holding.getQuantity());
+ assertEquals(new BigDecimal("50.00"), holding.getPurchasePrice());
+ }
+
+ @Test
+ public void quoteIdResolvesFromAssociatedQuote() {
+ HoldingDataBean holding = new HoldingDataBean(5.0d, new BigDecimal("12.00"), new Date(), null, null);
+ holding.setQuoteID("s:7");
+ assertEquals("s:7", holding.getQuoteID());
+
+ holding.setQuote(new QuoteDataBean("s:8"));
+ assertEquals("s:8", holding.getQuoteID());
+ }
+}
diff --git a/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/MarketSummaryDataBeanTest.java b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/MarketSummaryDataBeanTest.java
new file mode 100644
index 0000000..a26e886
--- /dev/null
+++ b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/MarketSummaryDataBeanTest.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.ibm.websphere.samples.daytrader;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Regression test for the market summary gain percentage shown on the home page.
+ */
+public class MarketSummaryDataBeanTest {
+
+ @Test
+ public void gainPercentIsComputedFromTsiaAndOpenTsia() {
+ MarketSummaryDataBean summary = new MarketSummaryDataBean(
+ new BigDecimal("110.00"), new BigDecimal("100.00"), 1234d,
+ new ArrayList(), new ArrayList());
+
+ assertEquals(0, new BigDecimal("10").compareTo(summary.getGainPercent()));
+ }
+}
diff --git a/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/OrderDataBeanTest.java b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/OrderDataBeanTest.java
new file mode 100644
index 0000000..4565ba2
--- /dev/null
+++ b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/OrderDataBeanTest.java
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.ibm.websphere.samples.daytrader;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Regression tests around order creation and order lifecycle classification.
+ * These lock down the externally observable buy/sell order semantics.
+ */
+public class OrderDataBeanTest {
+
+ private OrderDataBean newOrder(String type, String status) {
+ return new OrderDataBean(type, status, new Date(), null,
+ 100.0d, new BigDecimal("12.34"),
+ TradeConfig.getOrderFee(type), null, null, null);
+ }
+
+ @Test
+ public void buyOrderIsClassifiedAsBuyAndOpen() {
+ OrderDataBean order = newOrder("buy", "open");
+ assertTrue(order.isBuy());
+ assertFalse(order.isSell());
+ assertTrue(order.isOpen());
+ assertFalse(order.isCompleted());
+ assertEquals(new BigDecimal("24.95"), order.getOrderFee());
+ }
+
+ @Test
+ public void sellOrderIsClassifiedAsSell() {
+ OrderDataBean order = newOrder("sell", "open");
+ assertTrue(order.isSell());
+ assertFalse(order.isBuy());
+ assertEquals(new BigDecimal("24.95"), order.getOrderFee());
+ }
+
+ @Test
+ public void processingOrderIsStillOpen() {
+ OrderDataBean order = newOrder("buy", "processing");
+ assertTrue(order.isOpen());
+ }
+
+ @Test
+ public void completedOrderIsNotOpen() {
+ OrderDataBean order = newOrder("buy", "completed");
+ assertTrue(order.isCompleted());
+ assertFalse(order.isOpen());
+ }
+
+ @Test
+ public void cancelMovesOrderToCancelledState() {
+ OrderDataBean order = newOrder("buy", "open");
+ order.cancel();
+ assertEquals("cancelled", order.getOrderStatus());
+ assertTrue(order.isCancelled());
+ assertTrue(order.isCompleted());
+ }
+
+ @Test
+ public void symbolResolvesFromQuoteWhenPresent() {
+ OrderDataBean order = newOrder("buy", "open");
+ order.setSymbol("s:1");
+ assertEquals("s:1", order.getSymbol());
+
+ QuoteDataBean quote = new QuoteDataBean("s:99");
+ order.setQuote(quote);
+ assertEquals("s:99", order.getSymbol());
+ }
+}
diff --git a/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/QuoteDataBeanTest.java b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/QuoteDataBeanTest.java
new file mode 100644
index 0000000..3d97ffd
--- /dev/null
+++ b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/QuoteDataBeanTest.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.ibm.websphere.samples.daytrader;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.math.BigDecimal;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Regression tests for quote retrieval: the values a user sees when looking up
+ * a stock quote (symbol, company, price, open/high/low, change, volume).
+ */
+public class QuoteDataBeanTest {
+
+ @Test
+ public void quoteRetainsAllRetrievedFields() {
+ QuoteDataBean quote = new QuoteDataBean("s:1", "s:1 Incorporated",
+ 7500.0d, new BigDecimal("55.25"), new BigDecimal("50.00"),
+ new BigDecimal("49.10"), new BigDecimal("60.00"), 5.25d);
+
+ assertEquals("s:1", quote.getSymbol());
+ assertEquals("s:1 Incorporated", quote.getCompanyName());
+ assertEquals(7500.0d, quote.getVolume());
+ assertEquals(new BigDecimal("55.25"), quote.getPrice());
+ assertEquals(new BigDecimal("50.00"), quote.getOpen());
+ assertEquals(new BigDecimal("49.10"), quote.getLow());
+ assertEquals(new BigDecimal("60.00"), quote.getHigh());
+ assertEquals(5.25d, quote.getChange());
+ }
+
+ @Test
+ public void zeroValueQuoteExposesOnlySymbol() {
+ QuoteDataBean quote = new QuoteDataBean("s:42");
+ assertEquals("s:42", quote.getSymbol());
+ }
+
+ @Test
+ public void priceChangeIsMutable() {
+ QuoteDataBean quote = new QuoteDataBean("s:2");
+ quote.setPrice(new BigDecimal("10.00"));
+ quote.setChange(-1.5d);
+ assertEquals(new BigDecimal("10.00"), quote.getPrice());
+ assertEquals(-1.5d, quote.getChange());
+ }
+}
diff --git a/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/TradeConfigTest.java b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/TradeConfigTest.java
new file mode 100644
index 0000000..44b0b78
--- /dev/null
+++ b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/TradeConfigTest.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.ibm.websphere.samples.daytrader;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.math.BigDecimal;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Regression tests for the order-fee schedule that must not change across the
+ * migration (buy/sell trades are charged a flat commission; cash operations
+ * are free).
+ */
+public class TradeConfigTest {
+
+ @Test
+ public void buyAndSellAreChargedTheStandardCommission() {
+ assertEquals(0, new BigDecimal("24.95").compareTo(TradeConfig.getOrderFee("buy")));
+ assertEquals(0, new BigDecimal("24.95").compareTo(TradeConfig.getOrderFee("SELL")));
+ }
+
+ @Test
+ public void nonTradeOperationsAreFree() {
+ assertEquals(0, BigDecimal.ZERO.compareTo(TradeConfig.getOrderFee("deposit")));
+ }
+}
diff --git a/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/util/FinancialUtilsTest.java b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/util/FinancialUtilsTest.java
new file mode 100644
index 0000000..2b4a95c
--- /dev/null
+++ b/daytrader3-ee6-ejb/src/test/java/com/ibm/websphere/samples/daytrader/util/FinancialUtilsTest.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.ibm.websphere.samples.daytrader.util;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+
+import org.junit.jupiter.api.Test;
+
+import com.ibm.websphere.samples.daytrader.HoldingDataBean;
+
+/**
+ * Regression tests for the portfolio P&L math that drives user-visible gains
+ * and holdings valuation.
+ */
+public class FinancialUtilsTest {
+
+ @Test
+ public void computeGainIsCurrentMinusOpen() {
+ BigDecimal gain = FinancialUtils.computeGain(new BigDecimal("110.00"), new BigDecimal("100.00"));
+ assertEquals(0, new BigDecimal("10.00").compareTo(gain));
+ }
+
+ @Test
+ public void computeGainPercentIsRelativeChangeTimesHundred() {
+ BigDecimal pct = FinancialUtils.computeGainPercent(new BigDecimal("110.00"), new BigDecimal("100.00"));
+ assertEquals(0, new BigDecimal("10").compareTo(pct));
+ }
+
+ @Test
+ public void computeGainPercentGuardsAgainstZeroOpenBalance() {
+ BigDecimal pct = FinancialUtils.computeGainPercent(new BigDecimal("110.00"), new BigDecimal("0.00"));
+ assertEquals(0, FinancialUtils.ZERO.compareTo(pct));
+ }
+
+ @Test
+ public void computeHoldingsTotalSumsPriceTimesQuantity() {
+ Collection holdings = new ArrayList<>();
+ holdings.add(new HoldingDataBean(10.0d, new BigDecimal("50.00"), new Date(), null, null));
+ holdings.add(new HoldingDataBean(2.0d, new BigDecimal("25.00"), new Date(), null, null));
+
+ BigDecimal total = FinancialUtils.computeHoldingsTotal(holdings);
+ // (10 * 50.00) + (2 * 25.00) = 550.00
+ assertEquals(0, new BigDecimal("550.00").compareTo(total));
+ }
+
+ @Test
+ public void computeHoldingsTotalOfNullIsZero() {
+ assertEquals(0, FinancialUtils.ZERO.compareTo(FinancialUtils.computeHoldingsTotal(null)));
+ }
+}
diff --git a/daytrader3-ee6-rest/build.gradle b/daytrader3-ee6-rest/build.gradle
index c3d6187..e45d63d 100644
--- a/daytrader3-ee6-rest/build.gradle
+++ b/daytrader3-ee6-rest/build.gradle
@@ -22,8 +22,13 @@ repositories { mavenCentral(); }
dependencies {
providedCompile group:'javax.ws.rs', name: 'jsr311-api', version: '1.1.1'
+ // JAXB API removed from the JDK in Java 11 (JEP 320).
+ providedCompile group:'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
}
+sourceCompatibility = JavaVersion.VERSION_21
+targetCompatibility = JavaVersion.VERSION_21
+
// Set the Eclipse facets to use 3.1 of the Dynamic Web Module which requires Java 1.7 by default.
diff --git a/daytrader3-ee6-rest/pom.xml b/daytrader3-ee6-rest/pom.xml
index ffb3fb6..c558619 100644
--- a/daytrader3-ee6-rest/pom.xml
+++ b/daytrader3-ee6-rest/pom.xml
@@ -21,5 +21,13 @@
jsr311-api
1.1.1
+
+
+ javax.xml.bind
+ jaxb-api
+ ${jaxb.api.version}
+ provided
+
diff --git a/daytrader3-ee6-web/build.gradle b/daytrader3-ee6-web/build.gradle
index b26655b..84d902f 100644
--- a/daytrader3-ee6-web/build.gradle
+++ b/daytrader3-ee6-web/build.gradle
@@ -24,9 +24,14 @@ dependencies {
providedCompile group: 'javax.ejb', name: 'ejb-api', version: '3.0'
providedCompile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.1.Final'
providedCompile group:'javax.faces', name:'javax.faces-api', version:'2.1'
+ // Common Annotations removed from the JDK in Java 11 (JEP 320).
+ providedCompile group:'javax.annotation', name:'javax.annotation-api', version:'1.3.2'
compile group:'taglibs', name:'standard',version:'1.1.1'
}
+sourceCompatibility = JavaVersion.VERSION_21
+targetCompatibility = JavaVersion.VERSION_21
+
// Set the Eclipse facets to use 3.1 of the Dynamic Web Module which requires Java 1.7 by default.
diff --git a/daytrader3-ee6-web/pom.xml b/daytrader3-ee6-web/pom.xml
index 7a91f63..c799506 100644
--- a/daytrader3-ee6-web/pom.xml
+++ b/daytrader3-ee6-web/pom.xml
@@ -48,6 +48,14 @@
2.1
provided
+
+
+ javax.annotation
+ javax.annotation-api
+ ${javax.annotation.version}
+ provided
+
net.wasdev.wlp.sample
daytrader3-ee6-ejb
diff --git a/daytrader3-ee6/build.gradle b/daytrader3-ee6/build.gradle
index d90ee45..9bf8920 100644
--- a/daytrader3-ee6/build.gradle
+++ b/daytrader3-ee6/build.gradle
@@ -67,7 +67,12 @@ dependencies {
deploy project (path: ':daytrader3-ee6-ejb', configuration: 'archives')
deploy project (path: ':daytrader3-ee6-web', configuration: 'archives')
deploy project (path: ':daytrader3-ee6-rest', configuration: 'archives')
- compile group: 'org.apache.derby', name: 'derby', version: '10.10.1.1'
+ // Apache Derby upgraded from 10.10.1.1 for Java 21 support and CVE
+ // remediation (CVE-2015-1832, CVE-2018-1313, CVE-2022-46337). Derby 10.15+
+ // is modularized into derby/derbyshared/derbytools.
+ compile group: 'org.apache.derby', name: 'derby', version: '10.17.1.0'
+ compile group: 'org.apache.derby', name: 'derbyshared', version: '10.17.1.0'
+ compile group: 'org.apache.derby', name: 'derbytools', version: '10.17.1.0'
}
String getHttpPort() {
def DEFAULT_HTTP_PORT = 9083
diff --git a/daytrader3-ee6/pom.xml b/daytrader3-ee6/pom.xml
index d366d66..07d4e55 100644
--- a/daytrader3-ee6/pom.xml
+++ b/daytrader3-ee6/pom.xml
@@ -49,7 +49,7 @@
maven-ear-plugin
6
- no-version
+ @{artifactId}@.@{extension}@
net.wasdev.wlp.sample
@@ -88,7 +88,19 @@
org.apache.derby
derby
- 10.10.1.1
+ ${derby.version}
+ jar
+
+
+ org.apache.derby
+ derbyshared
+ ${derby.version}
+ jar
+
+
+ org.apache.derby
+ derbytools
+ ${derby.version}
jar
diff --git a/pom.xml b/pom.xml
index ff8c3b0..34390b0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,6 +30,56 @@
git@github.com:WASdev/sample.async.jaxrss.git
-->
+
+ 21
+ 21
+ 21
+ UTF-8
+ UTF-8
+
+
+ 10.17.1.0
+
+
+ 2.3.1
+ 2.3.9
+ 1.3.2
+
+ 5.10.2
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+ ${maven.compiler.release}
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.2.5
+
+
+ org.apache.maven.plugins
+ maven-ear-plugin
+ 3.3.0
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ 3.4.0
+
+
+
+
+
daytrader3-ee6-ejb