| 1 | package fr.sii.ogham.sms.util.http; | |
| 2 | ||
| 3 | /** | |
| 4 | * Enum that contains all HTTP status. | |
| 5 | * | |
| 6 | * @author Aurélien Baudet | |
| 7 | * | |
| 8 | */ | |
| 9 | public enum HttpStatus { | |
| 10 | // --- 1xx Informational --- | |
| 11 | ||
| 12 | /** <strong>100 Continue</strong> (HTTP/1.1 - RFC 2616) */ | |
| 13 | CONTINUE(100, "Continue"), | |
| 14 | /** <strong>101 Switching Protocols</strong> (HTTP/1.1 - RFC 2616) */ | |
| 15 | SWITCHING_PROTOCOLS(101, "Switching Protocols"), | |
| 16 | /** <strong>102 Processing</strong> (WebDAV - RFC 2518) */ | |
| 17 | PROCESSING(102, "Processing"), | |
| 18 | ||
| 19 | // --- 2xx Success --- | |
| 20 | ||
| 21 | /** <strong>200 OK</strong> (HTTP/1.0 - RFC 1945) */ | |
| 22 | OK(200, "OK"), | |
| 23 | /** <strong>201 Created</strong> (HTTP/1.0 - RFC 1945) */ | |
| 24 | CREATED(201, "Created"), | |
| 25 | /** <strong>202 Accepted</strong> (HTTP/1.0 - RFC 1945) */ | |
| 26 | ACCEPTED(202, "Accepted"), | |
| 27 | /** <strong>203 Non Authoritative Information</strong> (HTTP/1.1 - RFC 2616) */ | |
| 28 | NON_AUTHORITATIVE_INFORMATION(203, "Non Authoritative Information"), | |
| 29 | /** <strong>204 No Content</strong> (HTTP/1.0 - RFC 1945) */ | |
| 30 | NO_CONTENT(204, "No Content"), | |
| 31 | /** <strong>205 Reset Content</strong> (HTTP/1.1 - RFC 2616) */ | |
| 32 | RESET_CONTENT(205, "Reset Content"), | |
| 33 | /** <strong>206 Partial Content</strong> (HTTP/1.1 - RFC 2616) */ | |
| 34 | PARTIAL_CONTENT(206, "Partial Content"), | |
| 35 | /** | |
| 36 | * <strong>207 Multi-Status</strong> (WebDAV - RFC 2518) or <strong>207 Partial Update | |
| 37 | * OK</strong> (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?) | |
| 38 | */ | |
| 39 | MULTI_STATUS(207, "Multi-Status"), | |
| 40 | /** | |
| 41 | * <strong>207 Multi-Status</strong> (WebDAV - RFC 2518) or <strong>207 Partial Update | |
| 42 | * OK</strong> (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?) | |
| 43 | */ | |
| 44 | PARTIAL_UPDATE_OK(207, "Partial Update OK"), | |
| 45 | ||
| 46 | // --- 3xx Redirection --- | |
| 47 | ||
| 48 | /** <strong>300 Mutliple Choices</strong> (HTTP/1.1 - RFC 2616) */ | |
| 49 | MULTIPLE_CHOICES(300, "Mutliple Choices"), | |
| 50 | /** <strong>301 Moved Permanently</strong> (HTTP/1.0 - RFC 1945) */ | |
| 51 | MOVED_PERMANENTLY(301, "Moved Permanently"), | |
| 52 | /** | |
| 53 | * <strong>302 Moved Temporarily</strong> (Sometimes <strong>Found</strong>) (HTTP/1.0 - RFC | |
| 54 | * 1945) | |
| 55 | */ | |
| 56 | MOVED_TEMPORARILY(302, "Moved Temporarily"), | |
| 57 | /** <strong>303 See Other</strong> (HTTP/1.1 - RFC 2616) */ | |
| 58 | SEE_OTHER(303, "See Other"), | |
| 59 | /** <strong>304 Not Modified</strong> (HTTP/1.0 - RFC 1945) */ | |
| 60 | NOT_MODIFIED(304, "Not Modified"), | |
| 61 | /** <strong>305 Use Proxy</strong> (HTTP/1.1 - RFC 2616) */ | |
| 62 | USE_PROXY(305, "Use Proxy"), | |
| 63 | /** <strong>307 Temporary Redirect</strong> (HTTP/1.1 - RFC 2616) */ | |
| 64 | TEMPORARY_REDIRECT(307, "Temporary Redirect"), | |
| 65 | ||
| 66 | // --- 4xx Client Error --- | |
| 67 | ||
| 68 | /** <strong>400 Bad Request</strong> (HTTP/1.1 - RFC 2616) */ | |
| 69 | BAD_REQUEST(400, "Bad Request"), | |
| 70 | /** <strong>401 Unauthorized</strong> (HTTP/1.0 - RFC 1945) */ | |
| 71 | UNAUTHORIZED(401, "Unauthorized"), | |
| 72 | /** <strong>402 Payment Required</strong> (HTTP/1.1 - RFC 2616) */ | |
| 73 | PAYMENT_REQUIRED(402, "Payment Required"), | |
| 74 | /** <strong>403 Forbidden</strong> (HTTP/1.0 - RFC 1945) */ | |
| 75 | FORBIDDEN(403, "Forbidden"), | |
| 76 | /** <strong>404 Not Found</strong> (HTTP/1.0 - RFC 1945) */ | |
| 77 | NOT_FOUND(404, "Not Found"), | |
| 78 | /** <strong>405 Method Not Allowed</strong> (HTTP/1.1 - RFC 2616) */ | |
| 79 | METHOD_NOT_ALLOWED(405, "Method Not Allowed"), | |
| 80 | /** <strong>406 Not Acceptable</strong> (HTTP/1.1 - RFC 2616) */ | |
| 81 | NOT_ACCEPTABLE(406, "Not Acceptable"), | |
| 82 | /** <strong>407 Proxy Authentication Required</strong> (HTTP/1.1 - RFC 2616) */ | |
| 83 | PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"), | |
| 84 | /** <strong>408 Request Timeout</strong> (HTTP/1.1 - RFC 2616) */ | |
| 85 | REQUEST_TIMEOUT(408, "Request Timeout"), | |
| 86 | /** <strong>409 Conflict</strong> (HTTP/1.1 - RFC 2616) */ | |
| 87 | CONFLICT(409, "Conflict"), | |
| 88 | /** <strong>410 Gone</strong> (HTTP/1.1 - RFC 2616) */ | |
| 89 | GONE(410, "Gone"), | |
| 90 | /** <strong>411 Length Required</strong> (HTTP/1.1 - RFC 2616) */ | |
| 91 | LENGTH_REQUIRED(411, "Length Required"), | |
| 92 | /** <strong>412 Precondition Failed</strong> (HTTP/1.1 - RFC 2616) */ | |
| 93 | PRECONDITION_FAILED(412, "Precondition Failed"), | |
| 94 | /** <strong>413 Request Entity Too Large</strong> (HTTP/1.1 - RFC 2616) */ | |
| 95 | REQUEST_TOO_LONG(413, "Request Entity Too Large"), | |
| 96 | /** <strong>414 Request-URI Too Long</strong> (HTTP/1.1 - RFC 2616) */ | |
| 97 | REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"), | |
| 98 | /** <strong>415 Unsupported Media Type</strong> (HTTP/1.1 - RFC 2616) */ | |
| 99 | UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"), | |
| 100 | /** <strong>416 Requested Range Not Satisfiable</strong> (HTTP/1.1 - RFC 2616) */ | |
| 101 | REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested Range Not Satisfiable"), | |
| 102 | /** <strong>417 Expectation Failed</strong> (HTTP/1.1 - RFC 2616) */ | |
| 103 | EXPECTATION_FAILED(417, "Expectation Failed"), | |
| 104 | ||
| 105 | /** | |
| 106 | * Static constant for a 418 error. <strong>418 Unprocessable Entity</strong> | |
| 107 | * (WebDAV drafts?) or <strong>418 Reauthentication Required</strong> (HTTP/1.1 | |
| 108 | * drafts?) | |
| 109 | */ | |
| 110 | // not used | |
| 111 | // UNPROCESSABLE_ENTITY(418, "Unprocessable Entity"); | |
| 112 | ||
| 113 | /** | |
| 114 | * Static constant for a 419 error. | |
| 115 | * <strong>419 Insufficient Space on Resource</strong> (WebDAV - | |
| 116 | * draft-ietf-webdav-protocol-05?) or | |
| 117 | * <strong>419 Proxy Reauthentication Required</strong> (HTTP/1.1 drafts?) | |
| 118 | */ | |
| 119 | INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space on Resource"), | |
| 120 | /** | |
| 121 | * Static constant for a 419 error. | |
| 122 | * <strong>419 Insufficient Space on Resource</strong> (WebDAV - | |
| 123 | * draft-ietf-webdav-protocol-05?) or | |
| 124 | * <strong>419 Proxy Reauthentication Required</strong> (HTTP/1.1 drafts?) | |
| 125 | */ | |
| 126 | PROXY_REAUTHENTICATION_REQUIRED(419, "Proxy Reauthentication Required"), | |
| 127 | /** | |
| 128 | * Static constant for a 420 error. <strong>420 Method Failure</strong> (WebDAV - | |
| 129 | * draft-ietf-webdav-protocol-05?) | |
| 130 | */ | |
| 131 | METHOD_FAILURE(420, "Method Failure"), | |
| 132 | /** <strong>422 Unprocessable Entity</strong> (WebDAV - RFC 2518) */ | |
| 133 | UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"), | |
| 134 | /** <strong>423 Locked</strong> (WebDAV - RFC 2518) */ | |
| 135 | LOCKED(423, "Locked"), | |
| 136 | /** <strong>424 Failed Dependency</strong> (WebDAV - RFC 2518) */ | |
| 137 | FAILED_DEPENDENCY(424, "Failed Dependency"), | |
| 138 | ||
| 139 | // --- 5xx Server Error --- | |
| 140 | ||
| 141 | /** <strong>500 Server Error</strong> (HTTP/1.0 - RFC 1945) */ | |
| 142 | INTERNAL_SERVER_ERROR(500, "Server Error"), | |
| 143 | /** <strong>501 Not Implemented</strong> (HTTP/1.0 - RFC 1945) */ | |
| 144 | NOT_IMPLEMENTED(501, "Not Implemented"), | |
| 145 | /** <strong>502 Bad Gateway</strong> (HTTP/1.0 - RFC 1945) */ | |
| 146 | BAD_GATEWAY(502, "Bad Gateway"), | |
| 147 | /** <strong>503 Service Unavailable</strong> (HTTP/1.0 - RFC 1945) */ | |
| 148 | SERVICE_UNAVAILABLE(503, "Service Unavailable"), | |
| 149 | /** <strong>504 Gateway Timeout</strong> (HTTP/1.1 - RFC 2616) */ | |
| 150 | GATEWAY_TIMEOUT(504, "Gateway Timeout"), | |
| 151 | /** <strong>505 HTTP Version Not Supported</strong> (HTTP/1.1 - RFC 2616) */ | |
| 152 | HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version Not Supported"), | |
| 153 | ||
| 154 | /** <strong>507 Insufficient Storage</strong> (WebDAV - RFC 2518) */ | |
| 155 | INSUFFICIENT_STORAGE(507, "Insufficient Storage"); | |
| 156 | ||
| 157 | private static final int SERVER_ERROR_STATUS_START = 500; | |
| 158 | private static final int CLIENT_ERROR_STATUS_START = 400; | |
| 159 | private static final int REDIRECT_STATUS_START = 300; | |
| 160 | private static final int SUCCESS_STATUS_START = 200; | |
| 161 | private static final int INFORMAL_STATUS_START = 100; | |
| 162 | ||
| 163 | private int code; | |
| 164 | ||
| 165 | private String reason; | |
| 166 | ||
| 167 | HttpStatus(int code, String reason) { | |
| 168 | this.code = code; | |
| 169 | this.reason = reason; | |
| 170 | } | |
| 171 | ||
| 172 | public int getCode() { | |
| 173 |
2
1. getCode : replaced int return with 0 for fr/sii/ogham/sms/util/http/HttpStatus::getCode → NO_COVERAGE 2. getCode : replaced int return with 0 for fr/sii/ogham/sms/util/http/HttpStatus::getCode → KILLED |
return code; |
| 174 | } | |
| 175 | ||
| 176 | public String getReason() { | |
| 177 |
1
1. getReason : replaced return value with "" for fr/sii/ogham/sms/util/http/HttpStatus::getReason → NO_COVERAGE |
return reason; |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| 181 | * Is the HTTP status stand for informal (between 100 inclusive and 200 | |
| 182 | * exclusive) | |
| 183 | * | |
| 184 | * @return true if informal | |
| 185 | */ | |
| 186 | public boolean isInformal() { | |
| 187 |
5
1. isInformal : replaced boolean return with true for fr/sii/ogham/sms/util/http/HttpStatus::isInformal → NO_COVERAGE 2. isInformal : changed conditional boundary → NO_COVERAGE 3. isInformal : changed conditional boundary → NO_COVERAGE 4. isInformal : negated conditional → NO_COVERAGE 5. isInformal : negated conditional → NO_COVERAGE |
return code >= INFORMAL_STATUS_START && code < SUCCESS_STATUS_START; |
| 188 | } | |
| 189 | ||
| 190 | /** | |
| 191 | * Is the HTTP status stand for success (between 200 inclusive and 300 | |
| 192 | * exclusive) | |
| 193 | * | |
| 194 | * @return true if success | |
| 195 | */ | |
| 196 | public boolean isSuccess() { | |
| 197 |
10
1. isSuccess : replaced boolean return with true for fr/sii/ogham/sms/util/http/HttpStatus::isSuccess → NO_COVERAGE 2. isSuccess : changed conditional boundary → NO_COVERAGE 3. isSuccess : changed conditional boundary → NO_COVERAGE 4. isSuccess : negated conditional → NO_COVERAGE 5. isSuccess : negated conditional → NO_COVERAGE 6. isSuccess : replaced boolean return with true for fr/sii/ogham/sms/util/http/HttpStatus::isSuccess → TIMED_OUT 7. isSuccess : changed conditional boundary → TIMED_OUT 8. isSuccess : changed conditional boundary → KILLED 9. isSuccess : negated conditional → KILLED 10. isSuccess : negated conditional → KILLED |
return code >= SUCCESS_STATUS_START && code < REDIRECT_STATUS_START; |
| 198 | } | |
| 199 | ||
| 200 | /** | |
| 201 | * Is the HTTP status stand for redirect (between 300 inclusive and 400 | |
| 202 | * exclusive) | |
| 203 | * | |
| 204 | * @return true if redirect | |
| 205 | */ | |
| 206 | public boolean isRedirect() { | |
| 207 |
5
1. isRedirect : replaced boolean return with true for fr/sii/ogham/sms/util/http/HttpStatus::isRedirect → NO_COVERAGE 2. isRedirect : changed conditional boundary → NO_COVERAGE 3. isRedirect : changed conditional boundary → NO_COVERAGE 4. isRedirect : negated conditional → NO_COVERAGE 5. isRedirect : negated conditional → NO_COVERAGE |
return code >= REDIRECT_STATUS_START && code < CLIENT_ERROR_STATUS_START; |
| 208 | } | |
| 209 | ||
| 210 | /** | |
| 211 | * Is the HTTP status stand for client error (between 400 inclusive and 500 | |
| 212 | * exclusive) | |
| 213 | * | |
| 214 | * @return true if client error | |
| 215 | */ | |
| 216 | public boolean isClientError() { | |
| 217 |
5
1. isClientError : replaced boolean return with true for fr/sii/ogham/sms/util/http/HttpStatus::isClientError → NO_COVERAGE 2. isClientError : changed conditional boundary → NO_COVERAGE 3. isClientError : changed conditional boundary → NO_COVERAGE 4. isClientError : negated conditional → NO_COVERAGE 5. isClientError : negated conditional → NO_COVERAGE |
return code >= CLIENT_ERROR_STATUS_START && code < SERVER_ERROR_STATUS_START; |
| 218 | } | |
| 219 | ||
| 220 | /** | |
| 221 | * Is the HTTP status stand for server error (between 500 inclusive and 600 | |
| 222 | * exclusive) | |
| 223 | * | |
| 224 | * @return true if server error | |
| 225 | */ | |
| 226 | public boolean isServerError() { | |
| 227 |
3
1. isServerError : replaced boolean return with true for fr/sii/ogham/sms/util/http/HttpStatus::isServerError → NO_COVERAGE 2. isServerError : changed conditional boundary → NO_COVERAGE 3. isServerError : negated conditional → NO_COVERAGE |
return code >= SERVER_ERROR_STATUS_START; |
| 228 | } | |
| 229 | ||
| 230 | public static HttpStatus valueOf(int code) { | |
| 231 | HttpStatus[] values = HttpStatus.values(); | |
| 232 | for (HttpStatus value : values) { | |
| 233 |
2
1. valueOf : negated conditional → NO_COVERAGE 2. valueOf : negated conditional → KILLED |
if (value.getCode() == code) { |
| 234 |
2
1. valueOf : replaced return value with null for fr/sii/ogham/sms/util/http/HttpStatus::valueOf → NO_COVERAGE 2. valueOf : replaced return value with null for fr/sii/ogham/sms/util/http/HttpStatus::valueOf → KILLED |
return value; |
| 235 | } | |
| 236 | } | |
| 237 | throw new IllegalArgumentException("Unknown HTTP status code (" + code + ")"); | |
| 238 | } | |
| 239 | } | |
Mutations | ||
| 173 |
1.1 2.2 |
|
| 177 |
1.1 |
|
| 187 |
1.1 2.2 3.3 4.4 5.5 |
|
| 197 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 |
|
| 207 |
1.1 2.2 3.3 4.4 5.5 |
|
| 217 |
1.1 2.2 3.3 4.4 5.5 |
|
| 227 |
1.1 2.2 3.3 |
|
| 233 |
1.1 2.2 |
|
| 234 |
1.1 2.2 |