-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GDC-161] openapi doc strings with literal block style (#915)
- Loading branch information
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...est/java/org/dotwebstack/framework/service/openapi/handler/OpenApiRequestHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.dotwebstack.framework.service.openapi.handler; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.List; | ||
import lombok.NonNull; | ||
import org.dotwebstack.framework.service.openapi.TestResources; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.codec.HttpMessageWriter; | ||
import org.springframework.mock.http.server.reactive.MockServerHttpRequest; | ||
import org.springframework.mock.web.server.MockServerWebExchange; | ||
import org.springframework.web.reactive.function.server.HandlerStrategies; | ||
import org.springframework.web.reactive.function.server.ServerRequest; | ||
import org.springframework.web.reactive.function.server.ServerResponse; | ||
import org.springframework.web.reactive.result.view.ViewResolver; | ||
import reactor.test.StepVerifier; | ||
|
||
|
||
class OpenApiRequestHandlerTest { | ||
|
||
private ServerResponse.Context context; | ||
|
||
@BeforeEach | ||
public void createContext() { | ||
HandlerStrategies strategies = HandlerStrategies.withDefaults(); | ||
context = new ServerResponse.Context() { | ||
|
||
@NonNull | ||
@Override | ||
public List<HttpMessageWriter<?>> messageWriters() { | ||
return strategies.messageWriters(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public List<ViewResolver> viewResolvers() { | ||
return strategies.viewResolvers(); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
void handle_returnsExpectedServerResponse_whenRequested() { | ||
var serverHttpRequest = MockServerHttpRequest.method(HttpMethod.GET, "") | ||
.build(); | ||
var exchange = MockServerWebExchange.from(serverHttpRequest); | ||
var request = ServerRequest.create(exchange, List.of()); | ||
|
||
var responseMono = new OpenApiRequestHandler(TestResources.openApiStream()).handle(request) | ||
.flatMap(serverResponse -> { | ||
assertThat(serverResponse.statusCode(), is(HttpStatus.OK)); | ||
assertThat(serverResponse.headers() | ||
.get("Content-type"), hasItem("text/yaml;charset=utf-8")); | ||
return serverResponse.writeTo(exchange, context); | ||
}); | ||
|
||
StepVerifier.create(responseMono) | ||
.verifyComplete(); | ||
|
||
StepVerifier.create(exchange.getResponse() | ||
.getBodyAsString()) | ||
.assertNext(body -> { | ||
assertThat(body, containsString("openapi: \"3.0.2\"")); | ||
assertThat(body, containsString(""" | ||
description: | | ||
This is an API for brewery data. | ||
It tells you all about breweries and their beers. | ||
And much much more. | ||
""")); | ||
}) | ||
.verifyComplete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters