Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ A catalogue of runnable Mule 4 examples of design and integration patterns, one

HTTP endpoint paths are referenced by published articles; do not change them when moving files.

EIP examples use the kit Mule naming rules; SOLID keeps the names its published articles quote.

## Technology declarations

- `app.runtime = 4.9.17` — [pom.xml](pom.xml).
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ curl -s 'localhost:8081/lsp/before/orders/ORD-1001?provider=new'
mvn clean test
```

MUnit runs on the Mule Enterprise runtime, so Maven needs access to the MuleSoft Enterprise repository (credentials in `~/.m2/settings.xml`, as in any MuleSoft project). The build fails below 80% application coverage; the current suites cover 181 cases at about 98.8%.
MUnit runs on the Mule Enterprise runtime, so Maven needs access to the MuleSoft Enterprise repository (credentials in `~/.m2/settings.xml`, as in any MuleSoft project). The build fails below 80% application coverage; the current suites cover 183 cases at about 99.5%.

## SOLID in MuleSoft

Expand Down Expand Up @@ -123,7 +123,7 @@ What the wave 2 suites show, observed on Mule 4.9.17 with MUnit 3.7.1 and Aggreg
What the wave 3 suites show, observed on Mule 4.9.17 with MUnit 3.7.1:

- The message translator turns two CSV rows into one order with numeric quantities (`2`, not `"2"`) and prices in units (`1250` cents become `12.5`); an unknown product code is rejected by name (`unknown product code: LAMP-99`).
- The same order sent by the marketplace as JSON and by a partner as XML gives the same canonical items and the same invoicing lines, total and warehouse rows; only the ids and `source` differ (`cdm-partner-xml-gives-the-same-target-documents`). The target translators are called with a canonical order alone, without any source, and they take the `CanonicalOrder` type, so an order without a currency fails at the call (`cdm-module-target-translator-rejects-an-order-that-is-not-canonical`). An order without a currency, or with lines in two currencies, gets 400; no currency is assumed.
- The same order sent by the marketplace as JSON and by a partner as XML gives the same canonical items and the same invoicing lines, total and warehouse rows; only the ids and `source` differ (`cdm-partner-xml-gives-the-same-target-documents`). The target translators are called with a canonical order alone, without any source, and they take the `CanonicalOrder` type, so an order without a currency fails at the call (`cdm-module-target-translator-rejects-an-order-that-is-not-canonical`). An order without a currency, or with lines in two currencies, gets 400; no currency is assumed. Over real HTTP both source listeners, and the message translator's, answer the status the error handler set: an invalid order is 400 in JSON, not 200 (`mt-over-http-error-answers-400-and-success-200`, `cdm-over-http-errors-answer-400-and-success-200`).
- What the simulated invoicing system received has exactly the seven allowed fields; the card number and the email do not appear anywhere in it, and neither does a `loyaltyCardNumber` added to the order (`cf-field-added-to-the-order-later-does-not-leak`).
- For a 200,000-byte document the archive receives a message with three fields (`orderId`, `claimKey`, `fileName`) and still archives 200,000 bytes, fetched with the key. The same key works again after the archive has used it, and 5 seconds after check-in it gets 404 (`cc-claim-expires-after-its-time-to-live`), so the claim check suite takes about 6 seconds. Over real HTTP, check-in answers 202 and check-out answers 200 with the document as `application/json` (`cc-check-out-does-not-remove-the-document`).
- In the content enricher, a spy before the merge sees the order as payload after the CRM call, and `vars.vCustomer` holds only the customer part of the answer (no `meta`), while the payload still has only the order's keys (`orderId`, `customerId`, `items`). When the CRM answers 503, a value that `vCustomer` held before the call is still there afterwards (`ce-crm-down-sets-no-target-variable-and-returns-503`), the merge does not run and the endpoint answers 503; `HTTP:CONNECTIVITY` and `HTTP:TIMEOUT` give the same 503 (`ce-crm-unreachable-returns-503`, `ce-crm-timeout-returns-503`).
Expand All @@ -141,7 +141,7 @@ What the wave 5 suites show, observed on Mule 4.9.17 with MUnit 3.7.1 (calls go

- Guaranteed delivery: the 202 comes back with the whole order already in the persistent outbox (read directly with `os:retrieve`) and not yet at fulfilment (404). With fulfilment down two passes leave it `STORED`, `attempts` 2, `lastError` `HTTP:SERVICE_UNAVAILABLE`; the pass after fulfilment is back delivers it (`attempts` 3, received once). When removing it from the outbox fails after delivery (mocked, as a crash at that point would), the next pass sends it again and fulfilment receives it twice and processes it once. Fulfilment answering 400 to order A moves A to the dead store (`DEAD`, `HTTP:BAD_REQUEST`) while order B is delivered in the same pass; with fulfilment down the fifth failed attempt moves the order to the dead store and a later pass does not send it. A second POST of a stored or delivered `orderId` gets 409. The Scheduler test polls the status (Until Successful) instead of sleeping. The order is in a store declared `persistent="true"`; surviving a restart is the connector's guarantee, not shown by MUnit.
- Transactional client: with the second write mocked to fail with `OS:STORE_NOT_AVAILABLE`, the Try with `ALWAYS_BEGIN` answers 500 and leaves the 50.00 debit with the order unpaid; the compensated version answers 503 and leaves neither record; with the undo also mocked to fail it answers 500 `compensation failed` and the debit stays. The 500 of the "before" Try shows the outcome, not an effect of `ALWAYS_BEGIN`: the Try holds no transactional resource. A second payment of a paid order gets 409 from both endpoints.
- Message expiration: a request that expires in a minute is `QUEUED` until the consumer runs and then `RESERVED`; one sent already expired becomes `EXPIRED` with the reason and no reservation; one queued with `expiresAt` already past (the queue does not check it, only the consumer does, so no sleep is needed) is `EXPIRED` while one with a minute left in the same pass is `RESERVED`. A stored request whose `expiresAt` no longer parses becomes `FAILED` and the request after it is still `RESERVED` in the same run. A `quantity` of 0, -3, 1.5 or `"two"` gets 400. The Scheduler test polls (Until Successful) instead of sleeping.
- Message expiration: a request that expires in a minute is `QUEUED` until the consumer runs and then `RESERVED`; one sent already expired becomes `EXPIRED` with the reason and no reservation; one queued with `expiresAt` already past (the queue does not check it, only the consumer does, so no sleep is needed) is `EXPIRED` while one with a minute left in the same pass is `RESERVED`. A stored request whose `expiresAt` no longer parses becomes `FAILED` and the request after it is still `RESERVED` in the same run. A `quantity` of 0, -3, 1.5 or `"two"` gets 400 and is not queued; a request without one is reserved with quantity 1. The Scheduler test polls (Until Successful) instead of sleeping.
- Invalid message channel: malformed JSON, a schema violation (all three listed in the reason), an XML body and a JSON array each get 400 and one entry in the invalid channel with the reason and the body as received; the 400 names the same invalid-message id, and the request is not stored. A valid request is 202 and leaves the channel empty, also when sent as `Application/JSON; charset=UTF-8`; a second valid request with the same `orderId` gets 409 and the first is kept.

Notes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
two target documents it produced.
-->
<flow name="canonical-order-from-marketplace" doc:description="Canonical data model: POST /eip/canonical/orders/marketplace translates a marketplace JSON order into the canonical order and from it into the invoicing and warehouse documents.">
<http:listener doc:name="POST /eip/canonical/orders/marketplace" config-ref="http-listener-config" path="/eip/canonical/orders/marketplace" allowedMethods="POST" />
<http:listener doc:name="POST /eip/canonical/orders/marketplace" config-ref="http-listener-config" path="/eip/canonical/orders/marketplace" allowedMethods="POST">
<http:response statusCode="#[vars.httpStatus default 200]" />
</http:listener>
<ee:transform doc:name="Translate Marketplace Order To Canonical">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
Expand All @@ -48,7 +50,9 @@ toCanonical(payload)]]></ee:set-payload>
</flow>

<flow name="canonical-order-from-partner" doc:description="Canonical data model: POST /eip/canonical/orders/partner translates a partner XML purchase order into the canonical order and from it into the invoicing and warehouse documents.">
<http:listener doc:name="POST /eip/canonical/orders/partner" config-ref="http-listener-config" path="/eip/canonical/orders/partner" allowedMethods="POST" />
<http:listener doc:name="POST /eip/canonical/orders/partner" config-ref="http-listener-config" path="/eip/canonical/orders/partner" allowedMethods="POST">
<http:response statusCode="#[vars.httpStatus default 200]" />
</http:listener>
<ee:transform doc:name="Translate Partner Purchase Order To Canonical">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
Expand Down
Loading