-
Notifications
You must be signed in to change notification settings - Fork 5
[NU-1739] Add OpenAPI mocks and sample "Customer Offer Based On Activity Event" scenario #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0a4c20a
[NU-1738] Add DB mock
20db78e
Merge remote-tracking branch 'origin/staging' into feature/NU-1739_op…
coutoPL 6cfee00
wip
coutoPL 06555ce
wip
coutoPL 9476d67
Merge remote-tracking branch 'origin/staging' into feature/NU-1739_op…
coutoPL 8dcce99
wip
coutoPL 702af50
wip
coutoPL 44cad21
wip
coutoPL 7f76fe9
wip
coutoPL 52d966b
wip
coutoPL 740371b
wip
coutoPL 03e56ff
wip
coutoPL 4e43e1a
wip
coutoPL 951fbf6
wip
coutoPL bd79b32
improvements
coutoPL 4ff2735
fix
coutoPL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could add information that OpenApi mappings can be modified in gui with address: http://localhost:18080/__admin/webapp/? Or we should not provide gui to the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it can be useful for testing purposes but it won't be useful in runtime. I will write example dev docs in the next task, so I will write about it there (at the moment I've added the Readme file to not forget about these links)