Skip to content

Commit d17e632

Browse files
committed
test(core): cover accept.notAllowed exclusion on 204 responses
A 204 response has no body, so the request Accept header cannot cause a mismatch. Assert that validation.request.accept.notAllowed is excluded for 204 and still reported for 200 (TRX-1066).
1 parent 6d8c3c7 commit d17e632

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎openapi-validation-core/src/test/java/com/getyourguide/openapi/validation/core/exclusions/InternalViolationExclusionsTest.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public void whenViolationThenViolationNotExcluded() {
2929
checkViolationNotExcluded(buildSimpleViolation(Direction.RESPONSE, 404));
3030
checkViolationNotExcluded(buildSimpleViolation(Direction.RESPONSE, 400));
3131
checkViolationNotExcluded(buildSimpleViolation(Direction.REQUEST, 200));
32+
checkViolationNotExcluded(buildSimpleViolation(Direction.REQUEST, 204));
3233
checkViolationNotExcluded(buildSimpleViolation(Direction.REQUEST, null));
3334
checkViolationNotExcluded(buildSimpleViolation(Direction.RESPONSE, 200));
3435
}
@@ -159,6 +160,30 @@ public void when406ResponseCodeWithStatusUnknownViolationThenViolationExcluded()
159160
.build());
160161
}
161162

163+
@Test
164+
public void when204ResponseCodeWithAcceptNotAllowedViolationThenViolationExcluded() {
165+
when(customViolationExclusions.isExcluded(any())).thenReturn(false);
166+
167+
checkViolationExcluded(buildAcceptNotAllowedViolation(204));
168+
}
169+
170+
@Test
171+
public void whenNon204ResponseCodeWithAcceptNotAllowedViolationThenViolationNotExcluded() {
172+
when(customViolationExclusions.isExcluded(any())).thenReturn(false);
173+
174+
checkViolationNotExcluded(buildAcceptNotAllowedViolation(200));
175+
}
176+
177+
private static OpenApiViolation buildAcceptNotAllowedViolation(int responseStatus) {
178+
return OpenApiViolation.builder()
179+
.direction(Direction.REQUEST)
180+
.rule("validation.request.accept.notAllowed")
181+
.responseStatus(responseStatus)
182+
.message("Request Accept header '[application/json]' does not match any defined response types. "
183+
+ "Must be one of: [application/problem+json].")
184+
.build();
185+
}
186+
162187
@Test
163188
public void whenUnknownErrorWithConcurrentModificationExceptionThenViolationExcluded() {
164189
when(customViolationExclusions.isExcluded(any())).thenReturn(false);

0 commit comments

Comments
 (0)