java -jar wiremock-jre8-standalone-2.35.0.jar
아래처럼 실행되면서 mappings폴더와 __files 폴더가 생성됨

테스트용 stub 파일 설정
{
"request": {
"url": "/test/abc",
"method": "GET"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"code": 0,
"message": "OK",
"data": "success"
}
}
}
mappings 폴더 하위로 복사

process 재실행

8080 포트로 API 테스트 결과

version: '2.14.0'
services:
wiremock:
container_name: wiremock-test
image: 'wiremock/wiremock:2.35.0'
ports:
- '8081:8080'
- '8443:8443'
command: '--https-port 8443 --verbose'
volumes:
- "./mappings:/home/wiremock/mappings"
restart: unless-stopped
docker-compose up -d

http 프로토콜 8081 포트로 API 테스트

https 프로토콜 8443 포트로 API 테스트

{
"mappings": [
{
"request": {
"url": "/v1/get-test",
"method": "GET",
"headers": {
"x-api-key": {
"equalTo": "test-token",
"caseInsensitive": true
}
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": [
{
"order_id": "ORD-11111",
"user_id": "user11111",
"product_id": "SHOES11111",
"product_name": "NIKE SHOES",
"requested_at": "2022-12-07T00:00:00.000Z",
"canceled": false,
"fee": 3000
},
{
"order_id": "ORD-22222",
"user_id": "user22222",
"product_id": "SHOES22222",
"product_name": "ADIDAS SHOES",
"requested_at": "2022-12-10T00:00:0.000Z",
"canceled": false,
"fee": 3000
}
]
}
},
{
"request": {
"urlPattern": "/v1/get-test/([0-9a-zA-Z\\-]*)",
"method": "GET",
"headers": {
"x-api-key": {
"equalTo": "test-token",
"caseInsensitive": true
}
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"order_id": "ORD-11111",
"user_id": "user11111",
"product_id": "SHOES11111",
"product_name": "NIKE SHOES",
"requested_at": "2022-12-07T00:00:00.000Z",
"canceled": false,
"fee": 3000
}
}
},
{
"request": {
"url": "/v1/post-test",
"method": "POST",
"headers": {
"x-api-key": {
"equalTo": "test-token",
"caseInsensitive": true
}
},
"bodyPatterns": [
{
"matchesJsonPath": "$.order_id"
}
]
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"code": 0,
"message": "OK",
"data": "success"
}
}
}
]
}
pom.xml 에 library 추가

@WireMockTest 어노테이션 추가

Wiremock 구동 후 stub 후 API 호출 테스트
