-
-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'smou-2.0.4/add-setting-swagger-ui-url' into 2.x
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...pi-starter-common/src/test/java/org/springdoc/ui/AbstractSwaggerIndexTransformerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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)); | ||
} | ||
} |