forked from springdoc/springdoc-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractSwaggerIndexTransformerTest.java
68 lines (57 loc) · 2.42 KB
/
AbstractSwaggerIndexTransformerTest.java
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.springdoc.ui;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springdoc.core.properties.SwaggerUiConfigParameters;
import org.springdoc.core.properties.SwaggerUiConfigProperties;
import org.springdoc.core.properties.SwaggerUiOAuthProperties;
import org.springdoc.core.providers.ObjectMapperProvider;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
@ExtendWith(MockitoExtension.class)
public class AbstractSwaggerIndexTransformerTest {
private SwaggerUiConfigProperties swaggerUiConfig;
@Mock
private SwaggerUiOAuthProperties swaggerUiOAuthProperties;
@Mock
private SwaggerUiConfigParameters swaggerUiConfigParameters;
@Mock
private ObjectMapperProvider objectMapperProvider;
private AbstractSwaggerIndexTransformer underTest;
private final String swaggerInitJs = "window.onload = function() {\n" +
"\n" +
" window.ui = SwaggerUIBundle({\n" +
" url: \"https://petstore.swagger.io/v2/swagger.json\",\n" +
" dom_id: '#swagger-ui',\n" +
" deepLinking: true,\n" +
" presets: [\n" +
" SwaggerUIBundle.presets.apis,\n" +
" SwaggerUIStandalonePreset\n" +
" ],\n" +
" plugins: [\n" +
" SwaggerUIBundle.plugins.DownloadUrl\n" +
" ],\n" +
" layout: \"StandaloneLayout\"\n" +
" });\n" +
"\n" +
" //</editor-fold>\n" +
"};";
private final InputStream is = new ByteArrayInputStream(swaggerInitJs.getBytes());
private final String apiDocUrl = "http://test.springdoc.com/apidoc";
@BeforeEach
public void setup(){
swaggerUiConfig = new SwaggerUiConfigProperties();
swaggerUiConfig.setUrl(apiDocUrl);
underTest = new AbstractSwaggerIndexTransformer(swaggerUiConfig, swaggerUiOAuthProperties, swaggerUiConfigParameters, objectMapperProvider);
}
@Test
void setApiDocUrlCorrectly() throws IOException {
var html = underTest.defaultTransformations(is);
assertThat(html, containsString(apiDocUrl));
}
}