Skip to content

Commit 7a5893c

Browse files
authored
OK response (#2856)
* fix(core): standardize "OK" status message across HTTP responses and tests * test(core): remove unused exceptions in `ResponseTest` methods * test(core): standardize "OK" casing in tests and update copyright headers - Corrected instances of "Ok" to "OK" in test assertions for consistency. - Added missing copyright header to `BodyDoesntThrowIOExceptionTest`. - Minor cleanup in `LargeBodyTest` to use `var` for improved readability.
1 parent 14867c8 commit 7a5893c

6 files changed

Lines changed: 14 additions & 13 deletions

File tree

core/src/main/java/com/predic8/membrane/core/util/HttpUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static boolean isAbsoluteURI(String uri) {
177177
public static String getMessageForStatusCode(int code) {
178178
return switch (code) {
179179
case 100 -> "Continue";
180-
case 200 -> "Ok";
180+
case 200 -> "OK";
181181
case 201 -> "Created";
182182
case 202 -> "Accepted";
183183
case 204 -> "No Content";

core/src/test/java/com/predic8/membrane/core/http/ResponseTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ void testWithNoContentLength() throws Exception {
193193
}
194194

195195
@Test
196-
void isEmpty() throws IOException {
196+
void isEmpty() {
197197
assertTrue(ok().build().isBodyEmpty());
198198
}
199199

200200
@Test
201-
void isNotEmpty() throws Exception {
201+
void isNotEmpty() {
202202
assertFalse(ok("ABC").build().isBodyEmpty());
203203
}
204204

@@ -218,7 +218,7 @@ void statusCodeBuilders(ResponseBuilder builder, int statusCode, String msg, boo
218218
private static Stream<Arguments> statusCodeMessageGenerator() {
219219
return Stream.of(
220220
// Do not check body
221-
of(ok(), 200, "Ok", false),
221+
of(ok(), 200, "OK", false),
222222
of(noContent(), 204, "No Content", false),
223223
of(forbidden(), 403, "Forbidden", false),
224224
of(continue100(), 100, "Continue", false),
@@ -251,7 +251,7 @@ void fromStatusCodeTest() {
251251
assertEquals(200,response.getStatusCode());
252252
assertTrue(isOfMediaType( TEXT_HTML,response.getHeader().getContentType()));
253253
assertEquals("""
254-
<html><head><title>200 Ok.</title></head><body><h1>200 Ok.</h1><p>The Message <b>is</b> this!</p></body></html>""",
254+
<html><head><title>200 OK.</title></head><body><h1>200 OK.</h1><p>The Message <b>is</b> this!</p></body></html>""",
255255
response.getBodyAsStringDecoded());
256256
}
257257

core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CUnitTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ void loginNotRequired() throws Exception {
383383
var exc = browser.applyWithoutRedirect(get(tc.getClientAddress() + "/api-no-auth-needed/"));
384384

385385
assertEquals(200, exc.getResponse().getStatusCode());
386-
assertEquals("Ok", exc.getResponse().getStatusMessage());
386+
assertEquals("OK", exc.getResponse().getStatusMessage());
387387
var res = om.readValue(exc.getResponse().getBodyAsStringDecoded(), Map.class);
388388
assertEquals("null", res.get("accessToken"));
389389

@@ -392,7 +392,7 @@ void loginNotRequired() throws Exception {
392392
// access 2: authenticated, expecting JWT
393393
exc = browser.applyWithoutRedirect(get(tc.getClientAddress() + "/api-no-auth-needed/"));
394394
assertEquals(200, exc.getResponse().getStatusCode());
395-
assertEquals("Ok", exc.getResponse().getStatusMessage());
395+
assertEquals("OK", exc.getResponse().getStatusMessage());
396396
res = om.readValue(exc.getResponse().getBodyAsStringDecoded(), Map.class);
397397
assertTrue(((String)res.get("accessToken")).startsWith("eyJ"));
398398
}
@@ -411,7 +411,7 @@ void returning4xx() throws Exception {
411411
// access 2: authenticated, expecting JWT
412412
exc = browser.applyWithoutRedirect(get(tc.getClientAddress() + "/api-no-redirect/"));
413413
assertEquals(200, exc.getResponse().getStatusCode());
414-
assertEquals("Ok", exc.getResponse().getStatusMessage());
414+
assertEquals("OK", exc.getResponse().getStatusMessage());
415415
var res = om.readValue(exc.getResponse().getBodyAsStringDecoded(), Map.class);
416416
assertTrue(((String)res.get("accessToken")).startsWith("eyJ"));
417417
}

core/src/test/java/com/predic8/membrane/integration/withinternet/LargeBodyTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.concurrent.atomic.*;
2929

3030
import static com.predic8.membrane.core.http.Header.*;
31+
import static com.predic8.membrane.core.http.Request.post;
3132
import static com.predic8.membrane.core.http.Response.*;
3233
import static com.predic8.membrane.core.interceptor.Outcome.*;
3334
import static java.lang.Integer.*;
@@ -109,8 +110,8 @@ public void large() throws Exception {
109110
public void largeChunked() throws Exception {
110111
long len = MAX_VALUE + 1L;
111112

112-
Exchange e = new Request.Builder().post("http://localhost:3041/foo").body(len, new ConstantInputStream(len)).header(TRANSFER_ENCODING, CHUNKED).buildExchange();
113-
try (HttpClient hc = new HttpClient(hcc)) {
113+
var e = post("http://localhost:3041/foo").body(len, new ConstantInputStream(len)).header(TRANSFER_ENCODING, CHUNKED).buildExchange();
114+
try (var hc = new HttpClient(hcc)) {
114115
hc.call(e);
115116
}
116117
assertTrue(e.getRequest().getBody().wasStreamed());

core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void jwtAuthentication() throws Exception {
9797
JSONObject jsonObject = new JSONObject(json);
9898
assertEquals("Bearer", jsonObject.getString("token_type"));
9999
assertNotNull(jsonObject.getString("access_token"));
100-
assertEquals("Ok", sendRequestToTarget(parseTokenRequestResponse("access_token", json)));
100+
assertEquals("OK", sendRequestToTarget(parseTokenRequestResponse("access_token", json)));
101101
}
102102

103103
@Test
@@ -114,7 +114,7 @@ void testJwtAuthenticationAfterRefresh() throws Exception {
114114

115115
assertEquals("Bearer", jsonObject.getString("token_type"));
116116
assertNotNull(jsonObject.getString("access_token"));
117-
assertEquals("Ok", sendRequestToTarget(parseTokenRequestResponse("access_token", json)));
117+
assertEquals("OK", sendRequestToTarget(parseTokenRequestResponse("access_token", json)));
118118

119119
assertEquals(getJwtClaim(at1, "iss"), getJwtClaim(at2, "iss"));
120120
assertEquals(getJwtClaim(at1, "sub"), getJwtClaim(at2, "sub"));

distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/OAuth2CredentialsExampleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void testIt() throws Exception {
5757
.withWatcher(logger)
5858
.script("client")
5959
.withParameters("john password")
60-
.waitAfterStartFor("Ok")
60+
.waitAfterStartFor("OK")
6161
.start()) {
6262
assertTrue(true);
6363
}

0 commit comments

Comments
 (0)