From fd88c6ff317f974aac71a2a567ceeed6f3577487 Mon Sep 17 00:00:00 2001 From: bruno souza Date: Fri, 9 Oct 2026 19:12:36 +0100 Subject: [PATCH 1/2] feat: delivery status endpoint for add-delivery-status (BRU-145) Co-Authored-By: Claude Sonnet 5.5 --- README.md | 131 +++++++++++++++++++++++++++++- mule-artifact.json | 4 + pom.xml | 59 ++++++++++++++ src/main/mule/delivery-status.xml | 42 ++++++++++ src/main/resources/log4j2.xml | 9 ++ 5 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 mule-artifact.json create mode 100644 pom.xml create mode 100644 src/main/mule/delivery-status.xml create mode 100644 src/main/resources/log4j2.xml diff --git a/README.md b/README.md index 4dbf219..bd0ed03 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,133 @@ Follow it in the commit history and in `openspec/`. ## Status -Work in progress. The first change is being prepared. +The `add-delivery-status` change is implemented and each of its scenarios is +proven with a real call (see [Evidence](#evidence), run on Mule runtime 4.12.3). + +## Evidence + +Each scenario of `add-delivery-status`, run against the application deployed on a +Mule 4.12.3 runtime with `curl -si`. Status line, `Content-Type` and body are the +real responses. + +### Known order in transit + +``` +$ curl -si http://localhost:8081/api/orders/1001/delivery-status +HTTP/1.1 200 OK +content-type: application/json +content-length: 53 + +{ + "orderNumber": "1001", + "status": "IN_TRANSIT" +} +``` + +### Known order pending + +``` +$ curl -si http://localhost:8081/api/orders/1002/delivery-status +HTTP/1.1 200 OK +content-type: application/json +content-length: 50 + +{ + "orderNumber": "1002", + "status": "PENDING" +} +``` + +### Known order delivered + +``` +$ curl -si http://localhost:8081/api/orders/1003/delivery-status +HTTP/1.1 200 OK +content-type: application/json +content-length: 52 + +{ + "orderNumber": "1003", + "status": "DELIVERED" +} +``` + +### Order does not exist + +``` +$ curl -si http://localhost:8081/api/orders/9999/delivery-status +HTTP/1.1 404 Not Found +content-type: application/json +content-length: 39 + +{ + "message": "Order 9999 not found" +} +``` + +### Leading zeros are a different identifier + +``` +$ curl -si http://localhost:8081/api/orders/01001/delivery-status +HTTP/1.1 404 Not Found +content-type: application/json +content-length: 40 + +{ + "message": "Order 01001 not found" +} +``` + +### Non-numeric order number + +``` +$ curl -si http://localhost:8081/api/orders/abc/delivery-status +HTTP/1.1 400 Bad Request +content-type: application/json +content-length: 44 +Connection: close + +{ + "message": "Invalid order number: abc" +} +``` + +### Order number longer than 20 digits + +``` +$ curl -si http://localhost:8081/api/orders/123456789012345678901/delivery-status +HTTP/1.1 400 Bad Request +content-type: application/json +content-length: 62 +Connection: close + +{ + "message": "Invalid order number: 123456789012345678901" +} +``` + +### POST on the endpoint + +``` +$ curl -si -X POST http://localhost:8081/api/orders/1001/delivery-status +HTTP/1.1 405 Method Not Allowed +content-type: application/json +content-length: 37 + +{ + "message": "Method not allowed" +} +``` + +### Method is checked before the order number + +``` +$ curl -si -X POST http://localhost:8081/api/orders/abc/delivery-status +HTTP/1.1 405 Method Not Allowed +content-type: application/json +content-length: 37 + +{ + "message": "Method not allowed" +} +``` diff --git a/mule-artifact.json b/mule-artifact.json new file mode 100644 index 0000000..143b320 --- /dev/null +++ b/mule-artifact.json @@ -0,0 +1,4 @@ +{ + "minMuleVersion": "4.12.0", + "javaSpecificationVersions": ["17"] +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..56d953c --- /dev/null +++ b/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + com.example + delivery-status-api + 1.0.0-SNAPSHOT + mule-application + delivery-status-api + + + UTF-8 + 17 + 4.12.0 + 4.4.0 + + + + + + org.mule.tools.maven + mule-maven-plugin + ${mule.maven.plugin.version} + true + + + + + + + org.mule.connectors + mule-http-connector + 1.10.4 + mule-plugin + + + org.mule.connectors + mule-sockets-connector + 1.2.7 + mule-plugin + + + + + + mulesoft-releases + https://repository.mulesoft.org/releases/ + + + + + + mulesoft-releases + https://repository.mulesoft.org/releases/ + + + diff --git a/src/main/mule/delivery-status.xml b/src/main/mule/delivery-status.xml new file mode 100644 index 0000000..076b580 --- /dev/null +++ b/src/main/mule/delivery-status.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + #[output application/json --- payload.body] + #[{'Content-Type': 'application/json'}] + + + + + + + + + + + diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..3d54995 --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,9 @@ + + + + + + + + + From ed33555ef4884e7ce46c92a211b8cf4790c6e103 Mon Sep 17 00:00:00 2001 From: bruno souza Date: Fri, 9 Oct 2026 19:13:34 +0100 Subject: [PATCH 2/2] chore(openspec): entrega da change add-delivery-status (BRU-145) --- .../.openspec.yaml | 0 .../2026-10-09-add-delivery-status}/design.md | 0 .../proposal.md | 0 .../specs/delivery-status/spec.md | 0 .../2026-10-09-add-delivery-status}/tasks.md | 14 ++-- openspec/specs/delivery-status/spec.md | 83 +++++++++++++++++++ 6 files changed, 90 insertions(+), 7 deletions(-) rename openspec/changes/{add-delivery-status => archive/2026-10-09-add-delivery-status}/.openspec.yaml (100%) rename openspec/changes/{add-delivery-status => archive/2026-10-09-add-delivery-status}/design.md (100%) rename openspec/changes/{add-delivery-status => archive/2026-10-09-add-delivery-status}/proposal.md (100%) rename openspec/changes/{add-delivery-status => archive/2026-10-09-add-delivery-status}/specs/delivery-status/spec.md (100%) rename openspec/changes/{add-delivery-status => archive/2026-10-09-add-delivery-status}/tasks.md (61%) create mode 100644 openspec/specs/delivery-status/spec.md diff --git a/openspec/changes/add-delivery-status/.openspec.yaml b/openspec/changes/archive/2026-10-09-add-delivery-status/.openspec.yaml similarity index 100% rename from openspec/changes/add-delivery-status/.openspec.yaml rename to openspec/changes/archive/2026-10-09-add-delivery-status/.openspec.yaml diff --git a/openspec/changes/add-delivery-status/design.md b/openspec/changes/archive/2026-10-09-add-delivery-status/design.md similarity index 100% rename from openspec/changes/add-delivery-status/design.md rename to openspec/changes/archive/2026-10-09-add-delivery-status/design.md diff --git a/openspec/changes/add-delivery-status/proposal.md b/openspec/changes/archive/2026-10-09-add-delivery-status/proposal.md similarity index 100% rename from openspec/changes/add-delivery-status/proposal.md rename to openspec/changes/archive/2026-10-09-add-delivery-status/proposal.md diff --git a/openspec/changes/add-delivery-status/specs/delivery-status/spec.md b/openspec/changes/archive/2026-10-09-add-delivery-status/specs/delivery-status/spec.md similarity index 100% rename from openspec/changes/add-delivery-status/specs/delivery-status/spec.md rename to openspec/changes/archive/2026-10-09-add-delivery-status/specs/delivery-status/spec.md diff --git a/openspec/changes/add-delivery-status/tasks.md b/openspec/changes/archive/2026-10-09-add-delivery-status/tasks.md similarity index 61% rename from openspec/changes/add-delivery-status/tasks.md rename to openspec/changes/archive/2026-10-09-add-delivery-status/tasks.md index eb2bed6..d039a87 100644 --- a/openspec/changes/add-delivery-status/tasks.md +++ b/openspec/changes/archive/2026-10-09-add-delivery-status/tasks.md @@ -2,15 +2,15 @@ ## 1. Application -- [ ] 1.1 Create the Mule 4 project (Java 17, Maven, runtime 4.12.x) with an HTTP listener; verified by `mvn clean package` succeeding -- [ ] 1.2 Add the sample orders and the `GET /api/orders/{orderNumber}/delivery-status` endpoint with the responses in the spec; verified by `mvn clean package` succeeding (HTTP behaviour is verified in group 2) +- [x] 1.1 Create the Mule 4 project (Java 17, Maven, runtime 4.12.x) with an HTTP listener; verified by `mvn clean package` succeeding +- [x] 1.2 Add the sample orders and the `GET /api/orders/{orderNumber}/delivery-status` endpoint with the responses in the spec; verified by `mvn clean package` succeeding (HTTP behaviour is verified in group 2) ## 2. Evidence Run the application locally. For each task, record in `README.md` the curl call and the real response (status line, `Content-Type` and body). A task is done only when the captured status and `Content-Type` match its scenario and the JSON body matches it structurally (same field names, types and values; whitespace and field order do not matter). -- [ ] 2.1 Scenarios "Known order in transit", "Known order pending" and "Known order delivered" -- [ ] 2.2 Scenarios "Order does not exist" and "Leading zeros are a different identifier" -- [ ] 2.3 Scenarios "Non-numeric order number" and "Order number longer than 20 digits" -- [ ] 2.4 Scenarios "POST on the endpoint" and "Method is checked before the order number" -- [ ] 2.5 Run `openspec validate --all --strict`; verified by it passing +- [x] 2.1 Scenarios "Known order in transit", "Known order pending" and "Known order delivered" +- [x] 2.2 Scenarios "Order does not exist" and "Leading zeros are a different identifier" +- [x] 2.3 Scenarios "Non-numeric order number" and "Order number longer than 20 digits" +- [x] 2.4 Scenarios "POST on the endpoint" and "Method is checked before the order number" +- [x] 2.5 Run `openspec validate --all --strict`; verified by it passing diff --git a/openspec/specs/delivery-status/spec.md b/openspec/specs/delivery-status/spec.md new file mode 100644 index 0000000..d1afe14 --- /dev/null +++ b/openspec/specs/delivery-status/spec.md @@ -0,0 +1,83 @@ +# delivery-status Specification + +## Purpose +Lets a client look up the current delivery status of an order by its order number. + +## Requirements + +### Requirement: Return delivery status by order number +The API SHALL return the current delivery status of an order when called with +`GET /api/orders/{orderNumber}/delivery-status` for an order number it knows. +The order number is an identifier matched exactly as sent: leading zeros are +part of it and are not removed. A successful response SHALL have status `200`, +header `Content-Type: application/json` and a body with exactly two fields: +`orderNumber` (string, as sent) and `status` (one of `PENDING`, `IN_TRANSIT`, +`DELIVERED`). + +#### Scenario: Known order in transit +- **WHEN** a client sends `GET /api/orders/1001/delivery-status` and order `1001` has status `IN_TRANSIT` +- **THEN** the API responds `200` with `Content-Type: application/json` +- **AND** the body is `{"orderNumber": "1001", "status": "IN_TRANSIT"}` + +#### Scenario: Known order pending +- **WHEN** a client sends `GET /api/orders/1002/delivery-status` and order `1002` has status `PENDING` +- **THEN** the API responds `200` with `Content-Type: application/json` +- **AND** the body is `{"orderNumber": "1002", "status": "PENDING"}` + +#### Scenario: Known order delivered +- **WHEN** a client sends `GET /api/orders/1003/delivery-status` and order `1003` has status `DELIVERED` +- **THEN** the API responds `200` with `Content-Type: application/json` +- **AND** the body is `{"orderNumber": "1003", "status": "DELIVERED"}` + +### Requirement: Error responses +Every error response SHALL have header `Content-Type: application/json` and a +body with exactly one field, `message` (string). + +#### Scenario: Error body shape +- **WHEN** the API responds `400`, `404` or `405` to a request on `/api/orders/{orderNumber}/delivery-status` +- **THEN** the response has `Content-Type: application/json` +- **AND** the body has only the field `message` + +### Requirement: Unknown order number +The API SHALL respond `404` with body `{"message": "Order {orderNumber} not found"}` +when the order number is well formed but no order has it. + +#### Scenario: Order does not exist +- **WHEN** a client sends `GET /api/orders/9999/delivery-status` and no order `9999` exists +- **THEN** the API responds `404` +- **AND** the body is `{"message": "Order 9999 not found"}` + +#### Scenario: Leading zeros are a different identifier +- **WHEN** a client sends `GET /api/orders/01001/delivery-status`, order `1001` exists and no order `01001` exists +- **THEN** the API responds `404` +- **AND** the body is `{"message": "Order 01001 not found"}` + +### Requirement: Malformed order number +The API SHALL respond `400` with body `{"message": "Invalid order number: {orderNumber}"}` +when the order number does not match `[0-9]{1,20}` (ASCII digits only, 1 to 20). + +#### Scenario: Non-numeric order number +- **WHEN** a client sends `GET /api/orders/abc/delivery-status` +- **THEN** the API responds `400` +- **AND** the body is `{"message": "Invalid order number: abc"}` + +#### Scenario: Order number longer than 20 digits +- **WHEN** a client sends `GET /api/orders/123456789012345678901/delivery-status` (21 digits) +- **THEN** the API responds `400` +- **AND** the body is `{"message": "Invalid order number: 123456789012345678901"}` + +### Requirement: Unsupported method +The API SHALL respond `405` with body `{"message": "Method not allowed"}` to +`POST`, `PUT`, `PATCH` and `DELETE` on `/api/orders/{orderNumber}/delivery-status`, +whatever the order number: the order number is validated and looked up only for +`GET`. `HEAD`, `OPTIONS` and other methods are out of scope. + +#### Scenario: POST on the endpoint +- **WHEN** a client sends `POST /api/orders/1001/delivery-status` +- **THEN** the API responds `405` +- **AND** the body is `{"message": "Method not allowed"}` + +#### Scenario: Method is checked before the order number +- **WHEN** a client sends `POST /api/orders/abc/delivery-status` +- **THEN** the API responds `405` +- **AND** the body is `{"message": "Method not allowed"}`