Skip to content

Commit

Permalink
test: application must return OpenAPI specification JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
wonderbird committed Apr 1, 2024
1 parent 9369219 commit de92b96
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/test/java/systems/boos/traindelays/unit/OpenApiTest.java
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("}"));
}
}

0 comments on commit de92b96

Please sign in to comment.