Skip to content

Commit 4546c46

Browse files
committed
fix: Fix error reason for http playbooks
1 parent 688b4cb commit 4546c46

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/main/java/dev/dochia/cli/core/http/ResponseCodeFamily.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ static boolean is4xxCode(int code) {
7171
return String.valueOf(code).startsWith("4");
7272
}
7373

74+
/**
75+
* Checks if the provided integer code corresponds to a 5xx HTTP response status code.
76+
*
77+
* @param code The integer response code to check.
78+
* @return True if the code corresponds to a 5xx status code, false otherwise.
79+
*/
80+
static boolean is5xxCode(int code) {
81+
return String.valueOf(code).startsWith("5");
82+
}
83+
7484
/**
7585
* Checks if the provided integer code corresponds to an HTTP response status code indicating that
7686
* the operation is unimplemented (501).

src/main/java/dev/dochia/cli/core/playbook/body/HttpMethodPlaybookUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ private void handle405(HttpResponse response, PlaybookData data) {
8585
}
8686
KeyValuePair<String, String> allowHeader = response.getHeader("Allow");
8787
if (allowHeader == null) {
88-
testCaseListener.reportResultWarn(logger, data, "Request failed as expected for http method [{}] with response code [{}], but missing Allow header", response.getHttpMethod(), response.getResponseCode());
88+
testCaseListener.reportResultWarn(logger, data, "Missing Allowed header", "Request failed as expected for http method [{}] with response code [{}], but missing Allow header", response.getHttpMethod(), response.getResponseCode());
8989
} else if (allowHeader.getValue().contains(response.getHttpMethod())) {
90-
testCaseListener.reportResultWarn(logger, data, "Request failed as expected for http method [{}] with response code [{}], but Allow header contains [{}]", response.getHttpMethod(), response.getResponseCode(), response.getHttpMethod());
90+
testCaseListener.reportResultWarn(logger, data, "Wrong Allowed header", "Request failed as expected for http method [{}] with response code [{}], but Allow header contains [{}]", response.getHttpMethod(), response.getResponseCode(), response.getHttpMethod());
9191
} else {
9292
testCaseListener.reportResultInfo(logger, data, "Request failed as expected for http method [{}] with response code [{}]",
9393
response.getHttpMethod(), response.getResponseCode());

src/main/java/dev/dochia/cli/core/util/DochiaModelUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public static boolean isIntegerSchema(Schema<?> schema) {
9191
return schema instanceof IntegerSchema || isType(schema, SchemaTypeUtil.INTEGER_TYPE);
9292
}
9393

94+
public static boolean isUrlSchema(Schema<?> schema) {
95+
return isStringSchema(schema) && "url".equals(schema.getFormat());
96+
}
97+
9498
public static boolean isDateSchema(Schema<?> schema) {
9599
return (schema instanceof DateSchema || isType(schema, SchemaTypeUtil.STRING_TYPE)) && SchemaTypeUtil.DATE_FORMAT.equals(schema.getFormat());
96100
}

src/test/java/dev/dochia/cli/core/http/ResponseCodeFamilyPredefinedTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,16 @@ void shouldReturnProperWordingBasedOnRequired(boolean required, String expected)
186186
void shouldReturnTooManyHeaders(int code, boolean result) {
187187
Assertions.assertThat(ResponseCodeFamily.isTooManyHeaders(code)).isEqualTo(result);
188188
}
189+
190+
@Test
191+
void shouldReturnIs5xxTrue() {
192+
Assertions.assertThat(ResponseCodeFamily.is5xxCode(500)).isTrue();
193+
Assertions.assertThat(ResponseCodeFamily.is5xxCode(503)).isTrue();
194+
}
195+
196+
@Test
197+
void shouldReturnIs5xxFalse() {
198+
Assertions.assertThat(ResponseCodeFamily.is5xxCode(200)).isFalse();
199+
Assertions.assertThat(ResponseCodeFamily.is5xxCode(404)).isFalse();
200+
}
189201
}

0 commit comments

Comments
 (0)