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
131 changes: 130 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```
4 changes: 4 additions & 0 deletions mule-artifact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"minMuleVersion": "4.12.0",
"javaSpecificationVersions": ["17"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
83 changes: 83 additions & 0 deletions openspec/specs/delivery-status/spec.md
Original file line number Diff line number Diff line change
@@ -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"}`
59 changes: 59 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>delivery-status-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>mule-application</packaging>
<name>delivery-status-api</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
<app.runtime>4.12.0</app.runtime>
<mule.maven.plugin.version>4.4.0</mule.maven.plugin.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-http-connector</artifactId>
<version>1.10.4</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-sockets-connector</artifactId>
<version>1.2.7</version>
<classifier>mule-plugin</classifier>
</dependency>
</dependencies>

<repositories>
<repository>
<id>mulesoft-releases</id>
<url>https://repository.mulesoft.org/releases/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>mulesoft-releases</id>
<url>https://repository.mulesoft.org/releases/</url>
</pluginRepository>
</pluginRepositories>
</project>
42 changes: 42 additions & 0 deletions src/main/mule/delivery-status.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">

<http:listener-config name="listenerConfig">
<http:listener-connection host="0.0.0.0" port="8081"/>
</http:listener-config>

<flow name="delivery-status">
<http:listener config-ref="listenerConfig" path="/api/orders/{orderNumber}/delivery-status">
<http:response statusCode="#[payload.code]">
<http:body>#[output application/json --- payload.body]</http:body>
<http:headers>#[{'Content-Type': 'application/json'}]</http:headers>
</http:response>
</http:listener>

<!-- The orders variable stands in for a database. -->
<ee:transform>
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/java
var orders = {"1001": "IN_TRANSIT", "1002": "PENDING", "1003": "DELIVERED"}
var orderNumber = attributes.uriParams.orderNumber
---
if (attributes.method != "GET")
{ code: 405, body: { message: "Method not allowed" } }
else if (!(orderNumber matches /[0-9]{1,20}/))
{ code: 400, body: { message: "Invalid order number: $(orderNumber)" } }
else if (orders[orderNumber] == null)
{ code: 404, body: { message: "Order $(orderNumber) not found" } }
else
{ code: 200, body: { orderNumber: orderNumber, status: orders[orderNumber] } }]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>
9 changes: 9 additions & 0 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console"><PatternLayout pattern="%-5p %d [%t] %c: %m%n"/></Console>
</Appenders>
<Loggers>
<AsyncRoot level="INFO"><AppenderRef ref="Console"/></AsyncRoot>
</Loggers>
</Configuration>
Loading