Skip to content

Commit adea5ff

Browse files
author
tjaneczko
committed
Add test for external response with no content, fixed test mocking
1 parent a989c2a commit adea5ff

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/ResolverCacheTest.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public class ResolverCacheTest {
3636
@Mocked
3737
RefUtils refUtils;
3838

39-
@Mocked
40-
DeserializationUtils deserializationUtils;
4139

4240
@Injectable
4341
OpenAPI openAPI;
@@ -50,7 +48,7 @@ public void testMock(@Injectable final Schema expectedResult) throws Exception {
5048
final String ref = "http://my.company.com/path/to/file.json";
5149
final String contentsOfExternalFile = "really good json";
5250

53-
new Expectations() {{
51+
new Expectations(DeserializationUtils.class) {{
5452
RefUtils.readExternalUrlRef(ref, format, auths, "http://my.company.com/path/parent.json");
5553
times = 1;
5654
result = contentsOfExternalFile;
@@ -75,7 +73,7 @@ public void testLoadExternalRef_NoDefinitionPath(@Injectable final Schema expect
7573
final String ref = "http://my.company.com/path/to/file.json";
7674
final String contentsOfExternalFile = "really good json";
7775

78-
new Expectations() {{
76+
new Expectations(DeserializationUtils.class) {{
7977
RefUtils.readExternalUrlRef(ref, format, auths, "http://my.company.com/path/parent.json");
8078
times = 1;
8179
result = contentsOfExternalFile;
@@ -128,6 +126,35 @@ public void testLoadExternalRefWithEscapedCharacters() throws Exception {
128126
assertNotNull(path);
129127
}
130128

129+
@Test
130+
public void testLoadExternalRefResponseWithNoContent() throws Exception {
131+
final RefFormat format = RefFormat.URL;
132+
final String ref = "http://my.company.com/path/to/main.yaml";
133+
final String contentsOfExternalFile = "openapi: 3.0.0\n" +
134+
"\n" +
135+
"info:\n" +
136+
" version: 1.0.0\n" +
137+
" title: Response include test case child\n" +
138+
"\n" +
139+
"components:\n" +
140+
" responses:\n" +
141+
" 200:\n" +
142+
" description: Success\n";
143+
144+
new Expectations() {{
145+
RefUtils.readExternalUrlRef(ref, format, auths, "http://my.company.com/path/parent.json");
146+
times = 1;
147+
result = contentsOfExternalFile;
148+
}};
149+
150+
ResolverCache cache = new ResolverCache(openAPI, auths, "http://my.company.com/path/parent.json");
151+
152+
ApiResponse response = cache.loadRef(ref+"#/components/responses/200", RefFormat.URL, ApiResponse.class);
153+
assertNotNull(response);
154+
assertEquals(response.getDescription(), "Success");
155+
assertNull(response.getContent());
156+
}
157+
131158
@Test
132159
public void testLoadInternalParameterRef(@Injectable Parameter mockedParameter) throws Exception {
133160
OpenAPI openAPI = new OpenAPI();

0 commit comments

Comments
 (0)