### JUnit Jupiter Integration - User Registration API
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Demonstrates integrating Citrus tests with JUnit Jupiter for user registration. This example shows how to send a POST request to register a user and validate the response.
```APIDOC
## POST /api/users/register
### Description
Tests the user registration API endpoint. A POST request is sent with user credentials, and the response is validated for success and returned user details.
### Method
POST
### Endpoint
/api/users/register
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **username** (string) - Required - The username for registration.
- **email** (string) - Required - The email address for the user.
- **password** (string) - Required - The password for the user.
### Request Example
```json
{
"username": "testuser123",
"email": "testuser123@example.com",
"password": "SecurePass123"
}
```
### Response
#### Success Response (201 Created)
- **id** (string) - The unique identifier for the registered user.
- **username** (string) - The registered username.
- **email** (string) - The registered email address.
#### Response Example
```json
{
"id": "456",
"username": "testuser123",
"email": "testuser123@example.com"
}
```
```
--------------------------------
### Configure JMS Queue and Topic Endpoints with Java
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Sets up JMS endpoints for testing message queues and topics, including the configuration of the connection factory and destination details. It demonstrates asynchronous endpoint setup for various JMS scenarios.
```java
import org.citrusframework.jms.endpoint.JmsEndpoint;
import org.citrusframework.endpoint.CitrusEndpoints;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.jms.ConnectionFactory;
@Configuration
public class JmsEndpointConfig {
@Bean
public ConnectionFactory jmsConnectionFactory() {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
factory.setBrokerURL("tcp://localhost:61616");
factory.setUserName("admin");
factory.setPassword("admin");
return factory;
}
@Bean
public JmsEndpoint orderInboundQueue() {
return CitrusEndpoints.jms()
.asynchronous()
.connectionFactory(jmsConnectionFactory())
.destination("order.inbound.queue")
.timeout(5000)
.build();
}
@Bean
public JmsEndpoint orderOutboundQueue() {
return CitrusEndpoints.jms()
.asynchronous()
.connectionFactory(jmsConnectionFactory())
.destination("order.outbound.queue")
.build();
}
@Bean
public JmsEndpoint notificationTopic() {
return CitrusEndpoints.jms()
.asynchronous()
.connectionFactory(jmsConnectionFactory())
.destination("notification.topic")
.pubSubDomain(true)
.build();
}
}
```
--------------------------------
### GET /api/config/staging
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Retrieves configuration details for the staging environment.
```APIDOC
## GET /api/config/staging
### Description
Retrieves configuration details specific to the staging environment.
### Method
GET
### Endpoint
/api/config/staging
### Parameters
(No parameters defined)
### Request Example
(No request body for GET request)
### Response
#### Success Response (200 OK)
- (Response content depends on the staging configuration)
#### Response Example
```json
{
"configKey": "configValue"
}
```
```
--------------------------------
### HTTP REST API Testing - Create and Retrieve Todo
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Demonstrates testing a RESTful service for creating and retrieving a todo item using Citrus Framework. It sends a POST request to create a todo and then a GET request to retrieve it, validating the response.
```APIDOC
## POST /api/todo and GET /api/todo/{todoId}
### Description
Tests the creation and retrieval of a todo item via a REST API. It first sends a POST request to create the todo and then a GET request to retrieve the created item, validating the response payload and status codes.
### Method
POST, GET
### Endpoint
POST /api/todo
GET /api/todo/${todoId}
### Parameters
#### Path Parameters
- **todoId** (string) - Required - The ID of the todo item to retrieve.
#### Query Parameters
None
#### Request Body
##### POST /api/todo
- **title** (string) - Required - The title of the todo item.
- **description** (string) - Required - The description of the todo item.
### Request Example
```json
// POST /api/todo Request Body
{
"title": "Buy groceries",
"description": "Milk and eggs"
}
// GET /api/todo/{todoId} Request
(No request body, uses path parameter todoId)
```
### Response
#### Success Response (201 Created for POST, 200 OK for GET)
- **id** (string) - The unique identifier of the created todo item.
- **title** (string) - The title of the todo item.
- **description** (string) - The description of the todo item.
#### Response Example
```json
// POST /api/todo Response Body (201 Created)
{
"id": "123",
"title": "Buy groceries",
"description": "Milk and eggs"
}
// GET /api/todo/{todoId} Response Body (200 OK)
{
"id": "123",
"title": "Buy groceries",
"description": "Milk and eggs"
}
```
```
--------------------------------
### JMS Queue and Topic Testing with Citrus
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Tests JMS messaging interactions, including sending messages to a queue and receiving confirmations from another queue. This example demonstrates setting message properties like priority and type, using payload templates with variables, and ignoring specific fields using '@ignore@'. It also includes timeout configurations for message reception.
```java
import org.citrusframework.jms.endpoint.JmsEndpoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.citrusframework.annotations.CitrusTest;
import org.testng.annotations.Test;
public class JmsMessagingTest extends TestNGCitrusSpringSupport {
@Autowired
private JmsEndpoint orderQueue;
@Autowired
private JmsEndpoint confirmationQueue;
@Test
@CitrusTest
public void testOrderProcessingFlow() {
variable("orderId", "ORD-" + "citrus:randomNumber(6)");
// Send order to processing queue
when(send(orderQueue)
.message()
.body("" +
"${orderId}" +
"Widget" +
"5" +
"49.99" +
"")
.header("JMSPriority", "9")
.header("JMSType", "ORDER")
.header("orderId", "${orderId}")
);
// Receive confirmation from confirmation queue
then(receive(confirmationQueue)
.message()
.body("" +
"${orderId}" +
"ACCEPTED" +
"@ignore@" +
"")
.header("JMSType", "CONFIRMATION")
.timeout(10000)
);
}
}
```
--------------------------------
### GET /api/service2/metrics
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Retrieves performance metrics for Service 2.
```APIDOC
## GET /api/service2/metrics
### Description
Retrieves performance metrics for Service 2.
### Method
GET
### Endpoint
/api/service2/metrics
### Parameters
(No parameters defined)
### Request Example
(No request body for GET request)
### Response
#### Success Response (200 OK)
- **responseTime** (number) - The response time for Service 2 in milliseconds.
#### Response Example
```json
{
"responseTime": 150
}
```
```
--------------------------------
### GET /api/service1/status
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Retrieves the status of Service 1.
```APIDOC
## GET /api/service1/status
### Description
Retrieves the operational status of Service 1.
### Method
GET
### Endpoint
/api/service1/status
### Parameters
(No parameters defined)
### Request Example
(No request body for GET request)
### Response
#### Success Response (200 OK)
- **status** (string) - The current status of Service 1 (e.g., "ONLINE").
#### Response Example
```json
{
"status": "ONLINE"
}
```
```
--------------------------------
### Test HTTP REST API with Java Fluent API
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
This Java code snippet demonstrates how to test RESTful services using Citrus Framework's fluent API. It shows sending HTTP POST and GET requests, validating response status codes, headers, and JSON payloads. It also demonstrates extracting data from responses for subsequent use in tests.
```java
import org.citrusframework.annotations.CitrusTest;
import org.citrusframework.http.client.HttpClient;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test;
import static org.citrusframework.http.actions.HttpActionBuilder.http;
public class RestApiTest extends TestNGCitrusSpringSupport {
@Autowired
private HttpClient todoClient;
@Test
@CitrusTest
public void testCreateAndRetrieveTodo() {
// Create a new todo
when(http()
.client(todoClient)
.send()
.post("/api/todo")
.message()
.contentType("application/json")
.body("{\"title\": \"Buy groceries\", \"description\": \"Milk and eggs\"}")
);
then(http()
.client(todoClient)
.receive()
.response(HttpStatus.CREATED)
.message()
.type("application/json")
.body("{\"id\": \"@isNumber()@\", \"title\": \"Buy groceries\", \"description\": \"@ignore@\"}")
.extract(fromBody().expression("$.id", "todoId"))
);
// Retrieve the created todo
when(http()
.client(todoClient)
.send()
.get("/api/todo/${todoId}")
.message()
.accept("application/json")
);
then(http()
.client(todoClient)
.receive()
.response(HttpStatus.OK)
.message()
.type("application/json")
.validate("$.id", "${todoId}")
.validate("$.title", "Buy groceries")
);
}
}
```
--------------------------------
### GET /api/health
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Checks the health status of the service.
```APIDOC
## GET /api/health
### Description
Checks the health status of the service.
### Method
GET
### Endpoint
/api/health
### Parameters
(No parameters defined)
### Request Example
(No request body for GET request)
### Response
#### Success Response (200 OK)
- **status** (string) - The health status of the service (e.g., "UP").
#### Response Example
```json
{
"status": "UP"
}
```
```
--------------------------------
### GET /api/users/{userId}
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Retrieves information for a specific user by their ID.
```APIDOC
## GET /api/users/{userId}
### Description
Retrieves information for a specific user identified by their user ID.
### Method
GET
### Endpoint
/api/users/${userId}
### Parameters
#### Path Parameters
- **userId** (string) - Required - The ID of the user to retrieve.
### Request Example
(No request body for GET request)
### Response
#### Success Response (200 OK)
- (User details)
#### Response Example
```json
{
"userId": "101",
"username": "user_abcde",
"email": "user_abcde@testdomain.com"
}
```
```
--------------------------------
### XML XPath Message Validation with Citrus
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Validates XML messages using XPath expressions, including support for namespaces. It showcases powerful validation matchers and assertions for specific node values, counts, and conditions. This example tests a SOAP service request and response.
```java
import org.springframework.http.HttpStatus;
import org.citrusframework.annotations.CitrusTest;
@CitrusTest
public void testXmlValidation() {
when(http()
.client(soapClient)
.send()
.post("/services/customerService")
.message()
.contentType("text/xml")
.body("" +
"CUST-001" +
"")
);
then(http()
.client(soapClient)
.receive()
.response(HttpStatus.OK)
.message()
.validate("//customer:name", "John Doe")
.validate("//customer:id", "CUST-001")
.validate("//customer:balance", "@greaterThan(0)@")
.validate("//customer:status", "ACTIVE")
.validate("count(//customer:orders/order)", "3")
);
}
```
--------------------------------
### Configure HTTP Client and Server Endpoints with Java
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Sets up HTTP clients and servers using CitrusEndpoints for testing REST APIs and mocking service endpoints. It demonstrates configuring request URLs, timeouts, and ports for both clients and servers.
```java
import org.citrusframework.endpoint.CitrusEndpoints;
import org.citrusframework.http.client.HttpClient;
import org.citrusframework.http.server.HttpServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class EndpointConfig {
@Bean
public HttpClient todoClient() {
return CitrusEndpoints.http()
.client()
.requestUrl("http://localhost:8080")
.timeout(5000)
.build();
}
@Bean
public HttpClient externalApiClient() {
return CitrusEndpoints.http()
.client()
.requestUrl("https://api.external-service.com")
.timeout(10000)
.requestFactory(requestFactory())
.build();
}
@Bean
public HttpServer mockApiServer() {
return CitrusEndpoints.http()
.server()
.port(8090)
.autoStart(true)
.timeout(5000)
.build();
}
@Bean
public HttpServer secureApiServer() {
return CitrusEndpoints.http()
.server()
.port(8443)
.autoStart(true)
.securePort(8443)
.build();
}
}
```
--------------------------------
### Quarkus Test Integration
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Demonstrates how to run Citrus tests within a Quarkus test environment, leveraging Quarkus dependency injection and native image support.
```APIDOC
## Quarkus Test Integration
### Description
Run Citrus tests within Quarkus test framework with native support for Quarkus dependency injection.
### Method
Uses Java code with JUnit 5 and Citrus annotations.
### Endpoint
`/q/health` for health check, `/api/products` for product API.
### Parameters
No explicit path, query, or body parameters are defined in this example, as they are handled within the Citrus test code.
### Request Example
```java
// Example for POST /api/products
when(http()
.client(httpClient)
.send()
.post("/api/products")
.message()
.body("{\"name\": \"Test Product\", \"price\": 99.99}")
);
```
### Response
#### Success Response (200 for /q/health)
- **status** (string) - Indicates the health status (e.g., "UP").
- **checks** (array) - A list of health check details.
#### Success Response (201 for POST /api/products)
- **id** (string) - The unique identifier of the created product.
- **name** (string) - The name of the product.
- **price** (string) - The price of the product.
#### Response Example
```json
// Example for GET /q/health response
{
"status": "UP",
"checks": [
// ... health check details ...
]
}
// Example for POST /api/products response
{
"id": "generated-id",
"name": "Test Product",
"price": "99.99"
}
```
```
--------------------------------
### Java Error Handling with Citrus Framework
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Demonstrates testing various error scenarios and exception handling in Java using the Citrus Framework. It covers testing for HTTP status codes like 404, 400, and 500, and asserting specific exception types and messages.
```java
@Test
@CitrusTest
public void testErrorHandlingScenarios() {
// Test 404 Not Found
when(http()
.client(apiClient)
.send()
.get("/api/users/999999")
);
then(http()
.client(apiClient)
.receive()
.response(HttpStatus.NOT_FOUND)
.message()
.body("{\"error\": \"User not found\", \"code\": \"USER_NOT_FOUND\"}")
);
// Test 400 Bad Request with validation errors
when(http()
.client(apiClient)
.send()
.post("/api/users")
.message()
.body("{\"username\": \"\", \"email\": \"invalid-email\"}")
);
then(http()
.client(apiClient)
.receive()
.response(HttpStatus.BAD_REQUEST)
.message()
.validate("$.errors.size()", "@greaterThan(0)@")
.validate("$.errors[0].field", "@matches(username|email)@")
);
// Test 500 Internal Server Error
when(http()
.client(apiClient)
.send()
.post("/api/process/error-trigger")
);
then(http()
.client(apiClient)
.receive()
.response(HttpStatus.INTERNAL_SERVER_ERROR)
.message()
.validate("$.error", "@notEmpty()@")
);
// Assert exception during operation
assertException()
.exception(CitrusRuntimeException.class)
.message("Connection timeout")
.when(
http().client(apiClient)
.send()
.get("/api/timeout-endpoint")
);
}
```
--------------------------------
### Configure Kafka Producer and Consumer Endpoints with Java
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Configures Kafka producers and consumers for event-driven integration testing. This includes setting up broker addresses, topics, consumer groups, and offset reset policies.
```java
import org.citrusframework.kafka.endpoint.KafkaEndpoint;
import org.citrusframework.endpoint.CitrusEndpoints;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class KafkaEndpointConfig {
@Bean
public KafkaEndpoint orderEventsProducer() {
return CitrusEndpoints.kafka()
.asynchronous()
.server("localhost:9092")
.topic("order-events")
.build();
}
@Bean
public KafkaEndpoint orderEventsConsumer() {
return CitrusEndpoints.kafka()
.asynchronous()
.server("localhost:9092")
.topic("order-events")
.consumerGroup("citrus-test-group")
.offsetReset("earliest")
.build();
}
@Bean
public KafkaEndpoint paymentEventsEndpoint() {
return CitrusEndpoints.kafka()
.asynchronous()
.server("kafka-broker-1:9092,kafka-broker-2:9092,kafka-broker-3:9092")
.topic("payment-events")
.consumerGroup("payment-test-group")
.autoCommit(true)
.timeout(10000)
.build();
}
}
```
--------------------------------
### Order Processing API
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
This section outlines the API calls involved in processing an order, including creation, status retrieval, and completion verification.
```APIDOC
## POST /api/orders
### Description
Creates a new order with the provided details.
### Method
POST
### Endpoint
/api/orders
### Parameters
#### Request Body
- **orderId** (string) - Required - The unique identifier for the order.
- **customerId** (string) - Required - The identifier for the customer placing the order.
- **items** (array) - Required - A list of items included in the order.
- **productId** (string) - Required - The identifier for the product.
- **quantity** (integer) - Required - The quantity of the product.
- **price** (number) - Required - The price of the product.
- **total** (number) - Required - The total amount for the order.
- **timestamp** (string) - Required - The date and time when the order was placed.
### Request Example
```json
{
"orderId": "123456",
"customerId": "CUST-12345",
"items": [
{"productId": "PROD-001", "quantity": 2, "price": 49.99}
],
"total": 99.98,
"timestamp": "2023-10-27T10:00:00Z"
}
```
### Response
#### Success Response (201)
- **orderId** (string) - The unique identifier for the created order.
- **status** (string) - The initial status of the order (e.g., PENDING).
- **total** (number) - The total amount for the order.
- **confirmationNumber** (string) - A confirmation number for the order.
#### Response Example
```json
{
"orderId": "123456",
"status": "PENDING",
"total": 99.98,
"confirmationNumber": "CONF-ABCDEF"
}
```
## GET /api/orders/{orderId}
### Description
Retrieves the details of a specific order.
### Method
GET
### Endpoint
/api/orders/{orderId}
### Parameters
#### Path Parameters
- **orderId** (string) - Required - The unique identifier for the order.
### Response
#### Success Response (200)
- **orderId** (string) - The unique identifier for the order.
- **confirmationNumber** (string) - The confirmation number for the order.
#### Response Example
```json
{
"orderId": "123456",
"confirmationNumber": "CONF-ABCDEF"
}
```
## GET /api/orders/{orderId}/status
### Description
Retrieves the current processing status of a specific order.
### Method
GET
### Endpoint
/api/orders/{orderId}/status
### Parameters
#### Path Parameters
- **orderId** (string) - Required - The unique identifier for the order.
### Response
#### Success Response (200)
- **status** (string) - The current status of the order (e.g., PROCESSED, COMPLETED).
#### Response Example
```json
{
"status": "PROCESSED"
}
```
```
--------------------------------
### YAML Test Specification for Order Processing
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Defines an integration test for order creation and processing using YAML. It outlines variables, actions including HTTP requests and responses, and assertions. Dependencies include the Citrus testing framework and an order API client.
```yaml
name: OrderProcessingTest
description: Test order creation and processing workflow
variables:
- name: orderId
value: "citrus:randomNumber(6)"
- name: customerId
value: "CUST-12345"
- name: timestamp
value: "citrus:currentDate('yyyy-MM-dd''T''HH:mm:ss''Z''')"
actions:
# Create order
- echo:
message: "Creating order with ID: ${orderId}"
- http:
client: orderApiClient
send:
method: POST
path: /api/orders
body:
type: json
value: |
{
"orderId": "${orderId}",
"customerId": "${customerId}",
"items": [
{"productId": "PROD-001", "quantity": 2, "price": 49.99}
],
"total": 99.98,
"timestamp": "${timestamp}"
}
- http:
client: orderApiClient
receive:
statusCode: 201
body:
type: json
validation:
jsonPath:
- path: $.orderId
value: "${orderId}"
- path: $.status
value: "PENDING"
- path: $.total
value: "99.98"
extract:
- path: $.confirmationNumber
variable: confirmationNumber
# Verify order status
- echo:
message: "Order created with confirmation: ${confirmationNumber}"
- http:
client: orderApiClient
send:
method: GET
path: /api/orders/${orderId}
- http:
client: orderApiClient
receive:
statusCode: 200
body:
type: json
validation:
jsonPath:
- path: $.orderId
value: "${orderId}"
- path: $.confirmationNumber
value: "${confirmationNumber}"
# Wait for order processing
- sleep:
milliseconds: 2000
# Verify order completion
- http:
client: orderApiClient
send:
method: GET
path: /api/orders/${orderId}/status
- http:
client: orderApiClient
receive:
statusCode: 200
body:
type: json
validation:
jsonPath:
- path: $.status
value: "@matches(PROCESSED|COMPLETED)@"
```
--------------------------------
### Integrate Citrus Tests with JUnit Jupiter using @CitrusSupport
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
This Java code snippet shows how to run Citrus integration tests as standard JUnit 5 tests. It utilizes the @CitrusSupport annotation to enable Citrus functionality within a JUnit test class and demonstrates defining variables and performing HTTP requests and responses.
```java
import org.citrusframework.annotations.CitrusTest;
import org.citrusframework.junit.jupiter.CitrusSupport;
import org.citrusframework.http.client.HttpClient;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.citrusframework.actions.SendMessageAction.Builder.send;
import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive;
import static org.citrusframework.http.actions.HttpActionBuilder.http;
@CitrusSupport
public class UserApiIT {
@Autowired
private HttpClient apiClient;
@Test
@CitrusTest
public void testUserRegistration() {
variable("username", "citrus:concat('user_', citrus:randomNumber(4))");
variable("email", "citrus:concat('${username}', '@example.com')");
when(http()
.client(apiClient)
.send()
.post("/api/users/register")
.message()
.body("{\"username\": \"${username}\", \"email\": \"${email}\", \"password\": \"SecurePass123\"}")
);
then(http()
.client(apiClient)
.receive()
.response(201)
.message()
.validate("$.username", "${username}")
.validate("$.email", "${email}")
.validate("$.id", "@isNumber()@")
);
}
}
```
--------------------------------
### Kafka Event Publishing and Consumption with Citrus
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Tests Kafka event publishing and consumption using Citrus. This snippet demonstrates sending an 'ORDER_CREATED' event with dynamic variables for order ID and timestamp, and then receiving an 'ORDER_CONFIRMED' event. It includes header and key specifications, along with a configurable timeout for consumption.
```java
import org.citrusframework.kafka.endpoint.KafkaEndpoint;
import org.citrusframework.annotations.CitrusTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test;
public class KafkaEventTest extends TestNGCitrusSpringSupport {
@Autowired
private KafkaEndpoint orderEventsEndpoint;
@Test
@CitrusTest
public void testOrderEventProcessing() {
variable("orderId", "citrus:randomUUID()");
variable("timestamp", "citrus:currentDate('yyyy-MM-dd'T'HH:mm:ss'Z')");
// Publish order created event
when(send(orderEventsEndpoint)
.message()
.body("{"eventType": "ORDER_CREATED", "orderId": "${orderId}", "timestamp": "${timestamp}", "amount": 299.99}")
.header("messageKey", "${orderId}")
.header("eventType", "ORDER_CREATED")
);
// Consume order confirmation event
then(receive(orderEventsEndpoint)
.message()
.body("{"eventType": "ORDER_CONFIRMED", "orderId": "${orderId}", "status": "CONFIRMED"}")
.header("messageKey", "${orderId}")
.timeout(5000)
);
}
}
```
--------------------------------
### POST /api/users
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
This endpoint creates a new user using dynamic variables for user data and extracts account details upon successful creation.
```APIDOC
## POST /api/users
### Description
Creates a new user with dynamically generated test data and extracts account information.
### Method
POST
### Endpoint
/api/users
### Parameters
#### Request Body
- **userId** (string) - Required - The unique identifier for the user.
- **uuid** (string) - Required - A universally unique identifier for the user.
- **username** (string) - Required - The username for the user.
- **email** (string) - Required - The email address of the user.
- **createdAt** (string) - Required - The timestamp when the user was created.
- **subscriptionExpiry** (string) - Required - The date when the user's subscription expires.
### Request Example
```json
{
"userId": "${userId}",
"uuid": "${uuid}",
"username": "${username}",
"email": "${email}",
"createdAt": "${timestamp}",
"subscriptionExpiry": "${expiryDate}"
}
```
### Response
#### Success Response (201 Created)
- **accountId** (string) - The unique identifier for the newly created account.
- **activationCode** (string) - The activation code for the account.
#### Response Example
```json
{
"accountId": "12345",
"activationCode": "ABCDE"
}
```
```
--------------------------------
### POST /api/users/{accountId}/activate
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
This endpoint activates a user account using the provided account ID and activation code.
```APIDOC
## POST /api/users/{accountId}/activate
### Description
Activates a user account using the provided account ID and activation code.
### Method
POST
### Endpoint
/api/users/${accountId}/activate
### Parameters
#### Path Parameters
- **accountId** (string) - Required - The ID of the account to activate.
#### Request Body
- **activationCode** (string) - Required - The activation code for the account.
### Request Example
```json
{
"activationCode": "${activationCode}"
}
```
### Response
#### Success Response (200 OK)
- (No specific fields defined in example)
#### Response Example
```json
{
"message": "Account activated successfully"
}
```
```
--------------------------------
### Error Handling API
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Demonstrates API calls designed to trigger and validate various error responses, including not found, bad request, and internal server errors.
```APIDOC
## GET /api/users/{userId} (Not Found)
### Description
Attempts to retrieve a user that does not exist, expecting a 404 Not Found response.
### Method
GET
### Endpoint
/api/users/999999
### Parameters
#### Path Parameters
- **userId** (string) - Required - The identifier for a non-existent user.
### Response
#### Error Response (404)
- **error** (string) - A message indicating the user was not found.
- **code** (string) - An error code, e.g., USER_NOT_FOUND.
#### Response Example
```json
{
"error": "User not found",
"code": "USER_NOT_FOUND"
}
```
## POST /api/users (Bad Request)
### Description
Attempts to create a user with invalid data, expecting a 400 Bad Request response with validation errors.
### Method
POST
### Endpoint
/api/users
### Parameters
#### Request Body
- **username** (string) - Required - An empty username.
- **email** (string) - Required - An invalid email format.
### Request Example
```json
{
"username": "",
"email": "invalid-email"
}
```
### Response
#### Error Response (400)
- **errors** (array) - A list of validation errors.
- **field** (string) - The field that has the validation error.
#### Response Example
```json
{
"errors": [
{
"field": "username"
},
{
"field": "email"
}
]
}
```
## POST /api/process/error-trigger (Internal Server Error)
### Description
Triggers an internal server error during processing, expecting a 500 Internal Server Error response.
### Method
POST
### Endpoint
/api/process/error-trigger
### Response
#### Error Response (500)
- **error** (string) - A message describing the internal server error.
#### Response Example
```json
{
"error": "An unexpected error occurred."
}
```
## GET /api/timeout-endpoint (Exception Handling)
### Description
Attempts to access an endpoint that causes a connection timeout, demonstrating exception handling.
### Method
GET
### Endpoint
/api/timeout-endpoint
### Response
#### Exception
- **exception** (CitrusRuntimeException) - Indicates a connection timeout.
- **message** (string) - "Connection timeout"
```
--------------------------------
### User Management API
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
This section details API endpoints for managing users, including retrieving user information and handling potential errors.
```APIDOC
## GET /api/users/{userId}
### Description
Retrieves information for a specific user.
### Method
GET
### Endpoint
/api/users/{userId}
### Parameters
#### Path Parameters
- **userId** (string) - Required - The unique identifier for the user.
### Response
#### Success Response (200)
- **userId** (string) - The unique identifier for the user.
- **username** (string) - The username.
- **email** (string) - The user's email address.
#### Response Example
```json
{
"userId": "12345",
"username": "johndoe",
"email": "john.doe@example.com"
}
```
## POST /api/users
### Description
Creates a new user.
### Method
POST
### Endpoint
/api/users
### Parameters
#### Request Body
- **username** (string) - Required - The desired username.
- **email** (string) - Required - The user's email address.
### Request Example
```json
{
"username": "newuser",
"email": "new.user@example.com"
}
```
### Response
#### Success Response (201)
- **userId** (string) - The unique identifier for the created user.
- **username** (string) - The username.
- **email** (string) - The user's email address.
#### Response Example
```json
{
"userId": "67890",
"username": "newuser",
"email": "new.user@example.com"
}
```
```
--------------------------------
### Cucumber BDD Feature Files for API Testing
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
Utilize Gherkin syntax with Citrus-provided step definitions to write behavior-driven tests for API interactions.
```APIDOC
## Cucumber BDD Feature Files
### Description
Write behavior-driven tests using Gherkin syntax with Citrus-provided step definitions for common operations.
### Method
Uses Gherkin syntax (Given, When, Then) for defining test scenarios.
### Endpoint
`/api/orders` for order management.
### Parameters
#### Path Parameters
- **orderId** (string) - The identifier for an order.
#### Query Parameters
None explicitly defined in the feature file structure.
#### Request Body
- **orderId** (string) - Unique identifier for the order.
- **customerId** (string) - Identifier for the customer placing the order.
- **items** (array) - List of items in the order.
- **productId** (string) - Identifier for the product.
- **quantity** (number) - Quantity of the product.
- **price** (number) - Price per unit of the product.
- **total** (number) - Total price of the order.
- **status** (string) - The current status of the order (for updates).
- **trackingNumber** (string) - Tracking number for shipped orders (for updates).
### Request Example
```gherkin
Scenario: Create a new order
Given variable orderId is "citrus:randomNumber(6)"
And HTTP request body
"""
{
"orderId": "${orderId}",
"customerId": "CUST-12345",
"items": [
{"productId": "PROD-001", "quantity": 2, "price": 49.99},
{"productId": "PROD-002", "quantity": 1, "price": 79.99}
],
"total": 179.97
}
"""
When I send POST request to "/api/orders"
```
### Response
#### Success Response (201 CREATED for POST /api/orders)
- **orderId** (string) - The identifier of the created order.
- **status** (string) - The initial status of the order (e.g., "PENDING").
- **total** (number) - The total amount of the order.
- **createdAt** (string) - Timestamp when the order was created.
#### Success Response (200 OK for GET /api/orders/{orderId})
- **orderId** (string) - The identifier of the order.
- **status** (string) - The current status of the order.
- **items** (array) - List of items in the order.
#### Success Response (200 OK for PUT /api/orders/{orderId}/status)
- **status** (string) - The updated status of the order.
- **trackingNumber** (string) - The tracking number associated with the shipment.
#### Response Example
```json
// Example for POST /api/orders response
{
"orderId": "123456",
"status": "PENDING",
"total": 179.97,
"createdAt": "2023-10-27T10:00:00Z"
}
// Example for GET /api/orders/{orderId} response
{
"orderId": "100001",
"status": "PROCESSING",
"items": [
// ... item details ...
]
}
// Example for PUT /api/orders/{orderId}/status response
{
"status": "SHIPPED",
"trackingNumber": "TRACK-XYZ789"
}
```
```
--------------------------------
### Cucumber BDD Feature Files with Citrus
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
These Gherkin feature files illustrate behavior-driven development with Citrus. They define scenarios for order management, including creating, retrieving, and updating orders using HTTP requests and responses.
```gherkin
Feature: Order Management API
Background:
Given HTTP endpoint "http://localhost:8080"
And HTTP header "Content-Type" is "application/json"
Scenario: Create a new order
Given variable orderId is "citrus:randomNumber(6)"
And HTTP request body
"""
{
"orderId": "${orderId}",
"customerId": "CUST-12345",
"items": [
{"productId": "PROD-001", "quantity": 2, "price": 49.99},
{"productId": "PROD-002", "quantity": 1, "price": 79.99}
],
"total": 179.97
}
"""
When I send POST request to "/api/orders"
Then I receive HTTP 201 CREATED
And HTTP response body should match
"""
{
"orderId": "${orderId}",
"status": "PENDING",
"total": 179.97,
"createdAt": "@ignore@"
}
"""
Scenario: Retrieve order by ID
Given variable orderId is "100001"
When I send GET request to "/api/orders/${orderId}"
Then I receive HTTP 200 OK
And HTTP response body should contain field $.orderId with value "${orderId}"
And HTTP response body should contain field $.status
And HTTP response body should contain field $.items.size() with value "@greaterThan(0)"
Scenario: Update order status
Given variable orderId is "100002"
And HTTP request body: {"status": "SHIPPED", "trackingNumber": "TRACK-12345"}
When I send PUT request to "/api/orders/${orderId}/status"
Then I receive HTTP 200 OK
And HTTP response body should match: {"status": "SHIPPED", "trackingNumber": "@ignore@"}
```
--------------------------------
### Configure Maven Dependencies for Citrus Testing
Source: https://context7.com/context7/citrusframework_4_8_1/llms.txt
This XML snippet configures a Maven project to include Citrus Framework dependencies. It specifies versions for Citrus Core, JUnit 5, and various protocol integrations like HTTP, Kafka, JMS, Spring Boot, Cucumber, WS, FTP, and Mail. The configuration ensures tests run with the specified Citrus version and uses the Surefire plugin for test execution.
```xml
4.0.0
com.example
integration-tests
1.0.0
4.8.1
17
17
org.citrusframework
citrus-base
${citrus.version}
test
org.citrusframework
citrus-junit5
${citrus.version}
test
org.citrusframework
citrus-http
${citrus.version}
test
org.citrusframework
citrus-kafka
${citrus.version}
test
org.citrusframework
citrus-jms
${citrus.version}
test
org.citrusframework
citrus-spring-boot
${citrus.version}
test
org.citrusframework
citrus-cucumber
${citrus.version}
test
org.citrusframework
citrus-ws
${citrus.version}
test
org.citrusframework
citrus-ftp
${citrus.version}
test
org.citrusframework
citrus-mail
${citrus.version}
test
org.apache.maven.plugins
maven-surefire-plugin
3.0.0
**/*Test.java
**/*IT.java
```