-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NU-1739] Add OpenAPI mocks and sample "Customer Offer Based On Activ…
…ity Event" scenario (#184)
- Loading branch information
Showing
23 changed files
with
817 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FROM holomekc/wiremock-gui:3.8.1 AS wiremock | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y wget && \ | ||
wget -P /var/wiremock/extensions https://repo1.maven.org/maven2/org/wiremock/extensions/wiremock-faker-extension-standalone/0.2.0/wiremock-faker-extension-standalone-0.2.0.jar | ||
|
||
FROM phusion/baseimage:noble-1.0.0 | ||
|
||
# Use baseimage-docker's init system. | ||
CMD ["/sbin/my_init"] | ||
|
||
# install | ||
USER root | ||
|
||
RUN apt-get update -y && \ | ||
apt -y install openjdk-11-jre-headless && \ | ||
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
# WIREMOCK | ||
COPY --from=wiremock /var/wiremock /var/wiremock | ||
COPY --from=wiremock /home/wiremock /home/wiremock | ||
|
||
COPY http-service/mocks /home/wiremock/ | ||
COPY http-service/scripts /etc/service/http-service | ||
RUN mv /etc/service/http-service/run-wiremock.sh /etc/service/http-service/run | ||
|
||
EXPOSE 8080 | ||
|
||
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=30 \ | ||
CMD (curl -f http://localhost:8080/__admin/) || exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# MOCKS | ||
|
||
## Resources: | ||
https://github.com/wiremock/wiremock-faker-extension/blob/main/docs/reference.md | ||
https://docs.wiremock.io/response-templating/basics/ | ||
https://docs.wiremock.io/response-templating/dates-and-times/ |
Empty file.
106 changes: 106 additions & 0 deletions
106
mocks/http-service/mocks/__files/openapi/CustomerApi.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Customer API | ||
version: 1.0.0 | ||
description: API for retrieving customer profiles and offers based on customer type. | ||
|
||
paths: | ||
'/customer/{customerId}/profile': | ||
get: | ||
summary: Get customer profile by customer's ID | ||
description: Retrieve detailed profile information for a customer using their unique customer ID. | ||
operationId: getCustomerProfile | ||
parameters: | ||
- name: customerId | ||
in: path | ||
required: true | ||
description: The unique identifier of the customer. | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: Customer profile found successfully. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/CustomerProfile' | ||
'404': | ||
description: No customer profile found for the given ID. | ||
|
||
'/customer/{customerType}/offers': | ||
get: | ||
summary: Get offers by customer type | ||
description: Retrieve offers available for a specific type of customer. | ||
operationId: getOffersForCustomerType | ||
parameters: | ||
- name: customerType | ||
in: path | ||
required: true | ||
description: The type/category of the customer. | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: Offers found for the specified customer type. | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/CustomerTypeOffer' | ||
'404': | ||
description: No offer found for the specified customer type. | ||
|
||
components: | ||
schemas: | ||
CustomerProfile: | ||
title: CustomerProfile | ||
type: object | ||
description: Schema representing a customer's profile information. | ||
properties: | ||
id: | ||
type: string | ||
description: The unique identifier of the customer profile. | ||
customerId: | ||
type: string | ||
description: The identifier of customer | ||
customerType: | ||
type: string | ||
description: The type or category of the customer. | ||
customerName: | ||
type: string | ||
description: The customer's name | ||
customerMsisdn: | ||
type: string | ||
description: The customer's phone number | ||
customerAge: | ||
type: integer | ||
description: The customer's age | ||
customerSex: | ||
type: string | ||
description: The customer's sex | ||
isPremiumCustomer: | ||
type: boolean | ||
description: Indicates if the customer is a premium one | ||
|
||
CustomerTypeOffer: | ||
title: CustomerTypeOffer | ||
type: object | ||
description: Schema representing an offer available for a specific type of customer. | ||
properties: | ||
id: | ||
type: string | ||
description: The unique identifier of the offer. | ||
name: | ||
type: string | ||
description: The name or title of the offer. | ||
message: | ||
type: string | ||
description: A human-readable offer description | ||
price: | ||
type: integer | ||
description: Price of the offer | ||
validity: | ||
type: string | ||
format: date-time | ||
description: The validity date of the offer. |
10 changes: 10 additions & 0 deletions
10
mocks/http-service/mocks/__files/responses/customer-api/CustomerProfile.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": "{{randomValue length=10 type='NUMERIC'}}", | ||
"customerId": "{{request.path.[1]}}", | ||
"customerType": "{{{pickRandom 'Freemium' 'Regular' 'VIP'}}}", | ||
"customerName": "{{random 'Name.fullName'}}", | ||
"customerMsisdn": "{{random 'PhoneNumber.phoneNumber'}}", | ||
"customerAge": {{randomInt lower=10 upper=99}}, | ||
"customerSex": "{{{pickRandom 'Male' 'Female' 'N/A'}}}", | ||
"isPremiumCustomer": {{random 'Bool.bool'}} | ||
} |
1 change: 1 addition & 0 deletions
1
mocks/http-service/mocks/__files/responses/customer-api/CustomerTypeOffers0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
9 changes: 9 additions & 0 deletions
9
mocks/http-service/mocks/__files/responses/customer-api/CustomerTypeOffers1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
{ | ||
"id": "{{randomValue length=10 type='NUMERIC'}}", | ||
"name": "{{random 'Commerce.productName'}} promotion", | ||
"message": "{{random 'Lorem.sentence'}} {{random 'Lorem.sentence'}} {{random 'Lorem.sentence'}}", | ||
"price": {{randomInt lower=10 upper=50}}, | ||
"validity": "{{dateFormat (now offset='3 days') format='yyyy-MM-dd\'T\'HH:mm:ss\'Z\''}}" | ||
} | ||
] |
16 changes: 16 additions & 0 deletions
16
mocks/http-service/mocks/__files/responses/customer-api/CustomerTypeOffers2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[ | ||
{ | ||
"id": "{{randomValue length=10 type='NUMERIC'}}", | ||
"name": "{{random 'Commerce.productName'}} promotion", | ||
"message": "{{random 'Lorem.sentence'}} {{random 'Lorem.sentence'}} {{random 'Lorem.sentence'}}", | ||
"price": {{randomInt lower=10 upper=50}}, | ||
"validity": "{{dateFormat (now offset='3 days') format='yyyy-MM-dd\'T\'HH:mm:ss\'Z\''}}" | ||
}, | ||
{ | ||
"id": "{{randomValue length=10 type='NUMERIC'}}", | ||
"name": "{{random 'Commerce.productName'}} promotion", | ||
"message": "{{random 'Lorem.sentence'}} {{random 'Lorem.sentence'}} {{random 'Lorem.sentence'}}", | ||
"price": {{randomInt lower=10 upper=50}}, | ||
"validity": "{{dateFormat (now offset='3 days') format='yyyy-MM-dd\'T\'HH:mm:ss\'Z\''}}" | ||
} | ||
] |
Empty file.
13 changes: 13 additions & 0 deletions
13
mocks/http-service/mocks/mappings/customer-api/GetCustomerProfile.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"request": { | ||
"urlPattern": "/customer/(.+)/profile", | ||
"method": "GET" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"bodyFileName": "responses/customer-api/CustomerProfile.json" | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
mocks/http-service/mocks/mappings/customer-api/GetOffersForCusomerType.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"request": { | ||
"urlPattern": "/customer/(.+)/offers", | ||
"method": "GET" | ||
}, | ||
"response": { | ||
"status": 404 | ||
} | ||
}, | ||
{ | ||
"request": { | ||
"urlPattern": "/customer/(?i)(Freemium|Regular|VIP)/offers", | ||
"method": "GET" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"bodyFileName": "responses/customer-api/CustomerTypeOffers{{{pickRandom '0' '1' '2'}}}.json" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh -e | ||
|
||
java $JAVA_OPTS -cp /var/wiremock/lib/*:/var/wiremock/extensions/* wiremock.Run \ | ||
--port=8080 \ | ||
--root-dir=/home/wiremock \ | ||
--max-request-journal=1000 \ | ||
--global-response-templating \ | ||
--extensions=org.wiremock.RandomExtension \ | ||
--async-response-enable=true \ | ||
--async-response-threads=30 |
10 changes: 10 additions & 0 deletions
10
quickstart-setup/data/kafka/generate-messages/customerEvents.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash -e | ||
|
||
cd "$(dirname "$0")" | ||
|
||
source ../../../scripts/utils/lib.sh | ||
|
||
ID=$(random_Ndigit_number 10) | ||
EVENT_TYPE="$(pick_randomly "ClientCloseToShowroom" "ClientBrowseOffers" "ClientEndedCallWithCustomerService" "ClientSentTerminationLetter" "Other")" | ||
|
||
echo "{ \"customerId\": \"$ID\", \"eventType\": \"$EVENT_TYPE\" }" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Topic name the static and generated messages should be sent to | ||
Transactions | ||
CustomerEvents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ Customers | |
ProcessedTransactions | ||
SmsesWithOffer | ||
Transactions | ||
CustomerEvents | ||
OfferProposalsBasedOnCustomerEvents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.