|
| 1 | +package org.springdoc.ui; |
| 2 | + |
| 3 | +import java.io.ByteArrayInputStream; |
| 4 | +import java.io.IOException; |
| 5 | +import java.io.InputStream; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.BeforeEach; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 10 | +import org.mockito.Mock; |
| 11 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 12 | +import org.springdoc.core.SwaggerUiConfigParameters; |
| 13 | +import org.springdoc.core.SwaggerUiConfigProperties; |
| 14 | +import org.springdoc.core.SwaggerUiOAuthProperties; |
| 15 | +import org.springdoc.core.providers.ObjectMapperProvider; |
| 16 | + |
| 17 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 18 | +import static org.hamcrest.Matchers.containsString; |
| 19 | + |
| 20 | +@ExtendWith(MockitoExtension.class) |
| 21 | +public class AbstractSwaggerIndexTransformerTest { |
| 22 | + |
| 23 | + private SwaggerUiConfigProperties swaggerUiConfig; |
| 24 | + @Mock |
| 25 | + private SwaggerUiOAuthProperties swaggerUiOAuthProperties; |
| 26 | + @Mock |
| 27 | + private SwaggerUiConfigParameters swaggerUiConfigParameters; |
| 28 | + @Mock |
| 29 | + private ObjectMapperProvider objectMapperProvider; |
| 30 | + |
| 31 | + private AbstractSwaggerIndexTransformer underTest; |
| 32 | + |
| 33 | + private final String swaggerInitJs = "window.onload = function() {\n" + |
| 34 | + "\n" + |
| 35 | + " window.ui = SwaggerUIBundle({\n" + |
| 36 | + " url: \"https://petstore.swagger.io/v2/swagger.json\",\n" + |
| 37 | + " dom_id: '#swagger-ui',\n" + |
| 38 | + " deepLinking: true,\n" + |
| 39 | + " presets: [\n" + |
| 40 | + " SwaggerUIBundle.presets.apis,\n" + |
| 41 | + " SwaggerUIStandalonePreset\n" + |
| 42 | + " ],\n" + |
| 43 | + " plugins: [\n" + |
| 44 | + " SwaggerUIBundle.plugins.DownloadUrl\n" + |
| 45 | + " ],\n" + |
| 46 | + " layout: \"StandaloneLayout\"\n" + |
| 47 | + " });\n" + |
| 48 | + "\n" + |
| 49 | + " //</editor-fold>\n" + |
| 50 | + "};"; |
| 51 | + private final InputStream is = new ByteArrayInputStream(swaggerInitJs.getBytes()); |
| 52 | + |
| 53 | + private final String apiDocUrl = "http://test.springdoc.com/apidoc"; |
| 54 | + |
| 55 | + @BeforeEach |
| 56 | + public void setup(){ |
| 57 | + swaggerUiConfig = new SwaggerUiConfigProperties(); |
| 58 | + swaggerUiConfig.setUrl(apiDocUrl); |
| 59 | + underTest = new AbstractSwaggerIndexTransformer(swaggerUiConfig, swaggerUiOAuthProperties, swaggerUiConfigParameters, objectMapperProvider); |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + void setApiDocUrlCorrectly() throws IOException { |
| 65 | + String html = underTest.defaultTransformations(is); |
| 66 | + assertThat(html, containsString(apiDocUrl)); |
| 67 | + } |
| 68 | +} |
0 commit comments