-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpecFromPathTest.java
More file actions
53 lines (39 loc) · 1.53 KB
/
Copy pathSpecFromPathTest.java
File metadata and controls
53 lines (39 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.retailsvc.http.spec;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
class SpecFromPathTest {
@Test
void loadsJsonSpecViaGson() throws Exception {
Path resource = Path.of(getClass().getResource("/openapi.json").toURI());
Spec spec = Spec.fromPath(resource);
assertThat(spec.openapi()).startsWith("3.1");
assertThat(spec.basePath()).isEqualTo("/api/v1");
assertThat(spec.operations()).isNotEmpty();
}
@Test
void loadsYamlSpecViaSnakeYaml() throws Exception {
Path resource = Path.of(getClass().getResource("/openapi.yaml").toURI());
Spec spec = Spec.fromPath(resource);
assertThat(spec.openapi()).startsWith("3.1");
assertThat(spec.operations()).isNotEmpty();
}
@Test
void loadsYmlSpecViaSnakeYaml() throws Exception {
Path resource = Path.of(getClass().getResource("/openapi.yml").toURI());
Spec spec = Spec.fromPath(resource);
assertThat(spec.openapi()).startsWith("3.1");
assertThat(spec.operations()).isNotEmpty();
}
@Test
void rejectsUnknownExtension(@TempDir Path tmp) throws Exception {
Path unknown = tmp.resolve("spec.txt");
Files.writeString(unknown, "{}");
assertThatThrownBy(() -> Spec.fromPath(unknown))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Unrecognised OpenAPI spec extension");
}
}