-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpecFromClasspathTest.java
More file actions
50 lines (39 loc) · 1.44 KB
/
Copy pathSpecFromClasspathTest.java
File metadata and controls
50 lines (39 loc) · 1.44 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
package com.retailsvc.http.spec;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.jupiter.api.Test;
class SpecFromClasspathTest {
@Test
void loadsJsonSpecFromClasspath() {
Spec spec = Spec.fromClasspath(getClass(), "/openapi.json");
assertThat(spec.openapi()).startsWith("3.1");
assertThat(spec.basePath()).isEqualTo("/api/v1");
assertThat(spec.operations()).isNotEmpty();
}
@Test
void loadsYamlSpecFromClasspath() {
Spec spec = Spec.fromClasspath(getClass(), "/openapi.yaml");
assertThat(spec.openapi()).startsWith("3.1");
assertThat(spec.operations()).isNotEmpty();
}
@Test
void loadsYmlSpecFromClasspath() {
Spec spec = Spec.fromClasspath(getClass(), "/openapi.yml");
assertThat(spec.openapi()).startsWith("3.1");
assertThat(spec.operations()).isNotEmpty();
}
@Test
void rejectsMissingResource() {
Class<?> loader = getClass();
assertThatThrownBy(() -> Spec.fromClasspath(loader, "/does-not-exist.yaml"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("classpath resource not found");
}
@Test
void rejectsUnknownExtension() {
Class<?> loader = getClass();
assertThatThrownBy(() -> Spec.fromClasspath(loader, "/openapi.txt"))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Unrecognised OpenAPI spec extension");
}
}