-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: application must return OpenAPI specification JSON
- Loading branch information
1 parent
9369219
commit de92b96
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/test/java/systems/boos/traindelays/unit/OpenApiTest.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,35 @@ | ||
package systems.boos.traindelays.unit; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
|
||
import static org.hamcrest.Matchers.endsWith; | ||
import static org.hamcrest.Matchers.startsWith; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
class OpenApiTest { | ||
@LocalServerPort | ||
private int port; | ||
|
||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Test | ||
void contextLoads() { | ||
assertTrue(true, "Spring application context must load."); | ||
} | ||
|
||
@Test | ||
void getOpenApiJson__ReturnsValidOpenApiDescription() { | ||
String response = this.restTemplate.getForObject("http://localhost:" + port + "/v3/api-docs", String.class); | ||
assertThat(response, startsWith("{\"openapi\":\"")); | ||
assertThat(response, endsWith("}")); | ||
} | ||
} |