Skip to content

Commit

Permalink
Add more integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pboos committed Nov 29, 2023
1 parent ab550db commit 5f24099
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ public void whenTestOptionsCallThenShouldNotValidate() throws Exception {
assertEquals(0, openApiViolationLogger.getViolations().size());
}

@Test
public void whenTestNoBodyThenShouldReturnSuccessAndNoViolation() throws Exception {
mockMvc.perform(post("/test/no-body"))
.andExpectAll(
status().isNoContent(),
content().string(Matchers.blankOrNullString())
);
Thread.sleep(100);

assertEquals(0, openApiViolationLogger.getViolations().size());
}

@Nullable
private OpenApiViolation getViolationByRule(List<OpenApiViolation> violations, String rule) {
return violations.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public ResponseEntity<TestResponse> postTest(PostTestRequest postTestRequest) {
}
return ResponseEntity.noContent().build();
}

@Override
public ResponseEntity<TestResponse> postTestNoBody() {
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.getyourguide.openapi.validation.api.model.OpenApiViolation;
import com.getyourguide.openapi.validation.test.TestViolationLogger;
import com.getyourguide.openapi.validation.test.openapi.webflux.model.TestResponse;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -134,6 +138,19 @@ public void whenTestOptionsCallThenShouldNotValidate() throws Exception {
assertEquals(0, openApiViolationLogger.getViolations().size());
}

@Test
public void whenTestNoBodyThenShouldReturnSuccessAndNoViolation() throws Exception {
webTestClient
.post().uri("/test/no-body")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isNoContent()
.expectBody().isEmpty();
Thread.sleep(100);

assertEquals(0, openApiViolationLogger.getViolations().size());
}

@Nullable
private OpenApiViolation getViolationByRule(List<OpenApiViolation> violations, String rule) {
return violations.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public Mono<ResponseEntity<TestResponse>> postTest(
return Mono.just(ResponseEntity.noContent().build());
});
}

@Override
public Mono<ResponseEntity<TestResponse>> postTestNoBody(ServerWebExchange exchange) {
return Mono.just(ResponseEntity.noContent().build());
}
}
13 changes: 13 additions & 0 deletions test/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ paths:
"$ref": "#/components/schemas/TestResponse"
'204':
description: Successful response without content
"/test/no-body":
post:
description: Post test without request/response body
operationId: postTestNoBody
responses:
'200':
description: Successful response
content:
application/json:
schema:
"$ref": "#/components/schemas/TestResponse"
'204':
description: Successful response without content
components:
schemas:
TestResponse:
Expand Down

0 comments on commit 5f24099

Please sign in to comment.