Skip to content

Commit 5f23dc2

Browse files
authored
fx: Added some HttpStatusCode for MockFaster (#152)
1 parent 2a13e70 commit 5f23dc2

File tree

4 files changed

+99
-3
lines changed

4 files changed

+99
-3
lines changed

tzatziki-http/src/main/java/com/decathlon/tzatziki/steps/HttpSteps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.jetbrains.annotations.NotNull;
1717
import org.mockserver.model.Body;
1818
import org.mockserver.model.HttpRequest;
19-
import org.mockserver.model.HttpStatusCode;
19+
import com.decathlon.tzatziki.utils.HttpStatusCode;
2020
import org.mockserver.model.LogEventRequestAndResponse;
2121
import org.mockserver.verify.VerificationTimes;
2222

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.decathlon.tzatziki.utils;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public enum HttpStatusCode {
7+
NOT_SET_000(0, "Not Set"),
8+
CONTINUE_100(100, "Continue"),
9+
SWITCHING_PROTOCOLS_101(101, "Switching Protocols"),
10+
PROCESSING_102(102, "Processing"),
11+
CHECKPOINT_103(103, "Checkpoint"),
12+
OK_200(200, "OK"),
13+
CREATED_201(201, "Created"),
14+
ACCEPTED_202(202, "Accepted"),
15+
NON_AUTHORITATIVE_INFORMATION_203(203, "Non-Authoritative Information"),
16+
NO_CONTENT_204(204, "No Content"),
17+
RESET_CONTENT_205(205, "Reset Content"),
18+
PARTIAL_CONTENT_206(206, "Partial Content"),
19+
MULTI_STATUS_207(207, "Multi-Status"),
20+
ALREADY_REPORTED_208(208, "Already Reported"),
21+
IM_USED_226(226, "IM Used"),
22+
MULTIPLE_CHOICES_300(300, "Multiple Choices"),
23+
MOVED_PERMANENTLY_301(301, "Moved Permanently"),
24+
FOUND_302(302, "Found"),
25+
MOVED_TEMPORARILY_302(302, "Moved Temporarily"),
26+
SEE_OTHER_303(303, "See Other"),
27+
NOT_MODIFIED_304(304, "Not Modified"),
28+
USE_PROXY_305(305, "Use Proxy"),
29+
TEMPORARY_REDIRECT_307(307, "Temporary Redirect"),
30+
PERMANENT_REDIRECT_308(308, "Permanent Redirect"),
31+
BAD_REQUEST_400(400, "Bad Request"),
32+
UNAUTHORIZED_401(401, "Unauthorized"),
33+
PAYMENT_REQUIRED_402(402, "Payment Required"),
34+
FORBIDDEN_403(403, "Forbidden"),
35+
NOT_FOUND_404(404, "Not Found"),
36+
METHOD_NOT_ALLOWED_405(405, "Method Not Allowed"),
37+
NOT_ACCEPTABLE_406(406, "Not Acceptable"),
38+
PROXY_AUTHENTICATION_REQUIRED_407(407, "Proxy Authentication Required"),
39+
REQUEST_TIMEOUT_408(408, "Request Timeout"),
40+
CONFLICT_409(409, "Conflict"),
41+
GONE_410(410, "Gone"),
42+
LENGTH_REQUIRED_411(411, "Length Required"),
43+
PRECONDITION_FAILED_412(412, "Precondition Failed"),
44+
PAYLOAD_TOO_LARGE_413(413, "Payload Too Large"),
45+
REQUEST_ENTITY_TOO_LARGE_413(413, "Request Entity Too Large"),
46+
URI_TOO_LONG_414(414, "URI Too Long"),
47+
REQUEST_URI_TOO_LONG_414(414, "Request-URI Too Long"),
48+
UNSUPPORTED_MEDIA_TYPE_415(415, "Unsupported Media Type"),
49+
REQUESTED_RANGE_NOT_SATISFIABLE_416(416, "Requested range not satisfiable"),
50+
EXPECTATION_FAILED_417(417, "Expectation Failed"),
51+
INSUFFICIENT_SPACE_ON_RESOURCE_419(419, "Insufficient Space On Resource"),
52+
METHOD_FAILURE_420(420, "Method Failure"),
53+
DESTINATION_LOCKED_421(421, "Destination Locked"),
54+
UNPROCESSABLE_ENTITY_422(422, "Unprocessable Entity"),
55+
LOCKED_423(423, "Locked"),
56+
FAILED_DEPENDENCY_424(424, "Failed Dependency"),
57+
TOO_EARLY_425(425, "Too Early"),
58+
UPGRADE_REQUIRED_426(426, "Upgrade Required"),
59+
PRECONDITION_REQUIRED_428(428, "Precondition Required"),
60+
TOO_MANY_REQUESTS_429(429, "Too Many Requests"),
61+
REQUEST_HEADER_FIELDS_TOO_LARGE_431(431, "Request Header Fields Too Large"),
62+
UNAVAILABLE_FOR_LEGAL_REASONS_451(451, "Unavailable For Legal Reasons"),
63+
INTERNAL_SERVER_ERROR_500(500, "Internal Server Error"),
64+
NOT_IMPLEMENTED_501(501, "Not Implemented"),
65+
BAD_GATEWAY_502(502, "Bad Gateway"),
66+
SERVICE_UNAVAILABLE_503(503, "Service Unavailable"),
67+
GATEWAY_TIMEOUT_504(504, "Gateway Timeout"),
68+
HTTP_VERSION_NOT_SUPPORTED_505(505, "HTTP Version not supported"),
69+
VARIANT_ALSO_NEGOTIATES_506(506, "Variant Also Negotiates"),
70+
INSUFFICIENT_STORAGE_507(507, "Insufficient Storage"),
71+
LOOP_DETECTED_508(508, "Loop Detected"),
72+
BANDWIDTH_LIMIT_EXCEEDED_509(509, "Bandwidth Limit Exceeded"),
73+
NOT_EXTENDED_510(510, "Not Extended"),
74+
NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required");
75+
76+
private final int code;
77+
private final String message;
78+
79+
HttpStatusCode(int code, String message) {
80+
this.code = code;
81+
this.message = message;
82+
}
83+
84+
public static HttpStatusCode code(int code) {
85+
for (HttpStatusCode httpStatusCode : HttpStatusCode.values()) {
86+
if (httpStatusCode.getCode() == code) {
87+
return httpStatusCode;
88+
}
89+
}
90+
return null;
91+
}
92+
}

tzatziki-http/src/main/java/com/decathlon/tzatziki/utils/Interaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public static Response fromHttpResponse(HttpResponse httpResponse) {
176176

177177
public HttpResponse toHttpResponseIn(ObjectSteps objects, Matcher urlParamMatcher) {
178178
return HttpResponse.response()
179-
.withStatusCode(status != null ? HttpSteps.getHttpStatusCode(status).code() : 200)
179+
.withStatusCode(status != null ? HttpSteps.getHttpStatusCode(status).getCode() : 200)
180180
.withHeaders(headers.entrySet().stream()
181181
.map(e -> new Header(e.getKey(), e.getValue()))
182182
.collect(toList()))

tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps/http.feature

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,4 +1457,8 @@ Feature: to interact with an http service and setup mocks
14571457
body:
14581458
payload:
14591459
message: Hello little you!
1460-
"""
1460+
"""
1461+
1462+
Scenario: Http status codes are extended and not limited to MockServer ones
1463+
Given that getting on "http://backend/tooManyRequest" will return a status TOO_MANY_REQUESTS_429
1464+
Then getting on "http://backend/tooManyRequest" returns a status TOO_MANY_REQUESTS_429

0 commit comments

Comments
 (0)