Skip to content

Commit

Permalink
Add failing test with multiple locales and customizer accessing getSe…
Browse files Browse the repository at this point in the history
…rvers()
  • Loading branch information
harsel committed Mar 21, 2023
1 parent 542f12f commit e02115f
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* * Copyright 2019-2020 the original author or authors.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * https://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

package test.org.springdoc.api.app189;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.http.MediaType;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;


@RestController
public class HelloController {


@Operation(summary = "Parse Resume")
@PostMapping(value = "/parse-resume", produces = { MediaType.APPLICATION_JSON_VALUE }, consumes = {
MediaType.MULTIPART_FORM_DATA_VALUE })
@ApiResponses({ @ApiResponse(responseCode = "400", description = "Invalid input") })
public Mono<String> parse(
@RequestPart(name = "resumeFile") @Parameter(description = "Resume file to be parsed", content = @Content(mediaType = MediaType.APPLICATION_OCTET_STREAM_VALUE)) FilePart resumeFile) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* * Copyright 2019-2020 the original author or authors.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * https://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

package test.org.springdoc.api.app189;

import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.springdoc.core.Constants;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.test.web.reactive.server.EntityExchangeResult;
import test.org.springdoc.api.AbstractCommonTest;

import java.time.Duration;

import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;

@WebFluxTest
public class SpringDocApp189Test extends AbstractCommonTest {

@Test
public void testWithDifferentLocales() throws Exception {
runTestWithLocale("en-GB");
runTestWithLocale("de-DE");
}

private void runTestWithLocale(String locale) throws JSONException {
EntityExchangeResult<byte[]> getResult = webTestClient.mutate().responseTimeout(Duration.ofMinutes(1000)).build()
.get().uri(Constants.DEFAULT_API_DOCS_URL)
.header("Accept-Language", locale)
.exchange()
.expectStatus().isOk().expectBody().returnResult();

String result = new String(getResult.getResponseBody());
String className = getClass().getSimpleName();
String testNumber = className.replaceAll("[^0-9]", "");
String expected = getContent("results/app" + testNumber + ".json");
assertEquals(expected, result, true);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
*
* * Copyright 2019-2020 the original author or authors.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * https://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

package test.org.springdoc.api.app189;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.customizers.OpenApiCustomiser;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = { "org.springdoc", "test.org.springdoc.api.app189" })
public class SpringDocTestApp {
public static void main(String[] args) {
SpringApplication.run(SpringDocTestApp.class, args);
}

@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.components(new Components().addSecuritySchemes("basicScheme",
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
.info(new Info().title("Tweet API").version("v0")
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}

@Bean
OpenApiCustomiser serverUrlCustomizer() {
return openApi ->
openApi.getServers().forEach(server -> {
server.setDescription("customized description");
server.setUrl("https://customized.url");
System.out.println(server);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"openapi": "3.0.1",
"info": {
"title": "Tweet API",
"license": {
"name": "Apache 2.0",
"url": "http://springdoc.org"
},
"version": "v0"
},
"servers": [
{
"url": "https://customized.url",
"description": "customized description"
}
],
"paths": {
"/parse-resume": {
"post": {
"tags": [
"hello-controller"
],
"summary": "Parse Resume",
"operationId": "parse",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [
"resumeFile"
],
"type": "object",
"properties": {
"resumeFile": {
"type": "string",
"description": "Resume file to be parsed",
"format": "binary"
}
}
}
}
}
},
"responses": {
"400": {
"description": "Invalid input",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {
"securitySchemes": {
"basicScheme": {
"type": "http",
"scheme": "basic"
}
}
}
}

0 comments on commit e02115f

Please sign in to comment.