use of org.springdoc.core.OpenAPIService in project springdoc-openapi by springdoc.
the class AbstractOpenApiResourceTest method preLoadingModeShouldNotOverwriteServers.
@Test
void preLoadingModeShouldNotOverwriteServers() throws InterruptedException {
when(openAPIService.updateServers(any())).thenCallRealMethod();
when(openAPIService.getCachedOpenAPI(any())).thenCallRealMethod();
doAnswer(new CallsRealMethods()).when(openAPIService).setServersPresent(true);
doAnswer(new CallsRealMethods()).when(openAPIService).setServerBaseUrl(any());
doAnswer(new CallsRealMethods()).when(openAPIService).setCachedOpenAPI(any(), any());
String customUrl = "https://custom.com";
String generatedUrl = "https://generated.com";
OpenApiCustomiser openApiCustomiser = openApi -> openApi.setServers(singletonList(new Server().url(customUrl)));
SpringDocConfigProperties properties = new SpringDocConfigProperties();
properties.setPreLoadingEnabled(true);
resource = new EmptyPathsOpenApiResource(GROUP_NAME, openAPIBuilderObjectFactory, requestBuilder, responseBuilder, operationParser, Optional.empty(), Optional.of(singletonList(openApiCustomiser)), Optional.empty(), properties, springDocProviders);
// wait for executor to be done
Thread.sleep(1_000);
// emulate generating base url
openAPIService.setServerBaseUrl(generatedUrl);
openAPIService.updateServers(openAPI);
Locale locale = Locale.US;
OpenAPI after = resource.getOpenApi(locale);
assertThat(after.getServers().get(0).getUrl(), is(customUrl));
}
Aggregations